This commit is contained in:
Michael Zhang 2021-10-24 01:07:55 -05:00
parent c9dac158ee
commit ffba55becd
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
11 changed files with 1174 additions and 769 deletions

1821
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -10,10 +10,10 @@ lto = true
panic = 'abort'
[dependencies]
glium = "0.25"
image = "0.21"
json5 = "0.2"
nalgebra = "0.18"
nalgebra-glm = "0.4"
serde = "1.0"
serde_derive = "1.0"
glium = "0.29.1"
image = "0.23.14"
json5 = "0.3.0"
nalgebra = "0.26.2"
nalgebra-glm = "0.12.0"
serde = "1.0.125"
serde_derive = "1.0.125"

4
fuzz/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
target
corpus
artifacts

26
fuzz/Cargo.toml Normal file
View file

@ -0,0 +1,26 @@
[package]
name = "wedge-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
[dependencies.wedge]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
test = false
doc = false

View file

@ -0,0 +1,6 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
});

View file

@ -1,6 +1,6 @@
use std::time::Duration;
use glium::glutin::{ElementState, Event, WindowEvent};
use glium::glutin::event::{ElementState, Event, WindowEvent};
use glium::{Display, Frame};
use crate::keymap::Keymap;
@ -46,7 +46,11 @@ impl<'a> Game<'a> {
}
}
pub fn handle_event(&mut self, event: Event) {
pub fn target(&self) -> Frame {
self.display.draw()
}
pub fn handle_event(&mut self, event: Event<()>) {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::Resized(size) => self.resources.window_dimensions = size.into(),

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use glium::glutin::VirtualKeyCode;
use glium::glutin::event::VirtualKeyCode;
pub struct Keymap(HashMap<VirtualKeyCode, bool>);

View file

@ -16,9 +16,16 @@ mod resources;
mod screens;
use std::time::Instant;
use std::rc::Rc;
use std::cell::RefCell;
use glium::glutin::dpi::PhysicalSize;
use glium::glutin::{ContextBuilder, Event, EventsLoop, WindowBuilder, WindowEvent};
use glium::glutin::{
event::{Event, WindowEvent},
event_loop::{EventLoop, ControlFlow},
window::WindowBuilder,
ContextBuilder,
};
use glium::{Display, Surface};
use crate::game::Game;
@ -27,49 +34,54 @@ const GAME_WIDTH: u32 = 1024;
const GAME_HEIGHT: u32 = 768;
fn main() {
let mut events_loop = EventsLoop::new();
let primary_monitor = events_loop.get_primary_monitor();
let dpi_factor = primary_monitor.get_hidpi_factor();
let dimensions: PhysicalSize = (GAME_WIDTH, GAME_HEIGHT).into();
let mut event_loop = EventLoop::new();
let primary_monitor = match event_loop.primary_monitor() {
Some(v) => v,
None => panic!("no primary monitor"),
};
let dpi_factor = primary_monitor.scale_factor();
let dimensions: PhysicalSize<u32> = (GAME_WIDTH, GAME_HEIGHT).into();
let wb = WindowBuilder::new()
.with_dimensions(dimensions.to_logical(dpi_factor))
.with_inner_size(dimensions.to_logical::<u32>(dpi_factor))
.with_resizable(false)
.with_title("wedge");
let cb = ContextBuilder::new();
let display = Display::new(wb, cb, &events_loop).unwrap();
let display = Display::new(wb, cb, &event_loop).unwrap();
{
let gl_window = display.gl_window();
let window = gl_window.window();
println!("size: {:?}", window.get_inner_size());
println!("size: {:?}", window.inner_size());
}
let mut game = Game::new(&display);
let mut closed = false;
let mut prev = Instant::now();
while !closed {
let now = Instant::now();
let delta = now - prev;
let mut prev = Rc::new(RefCell::new(Instant::now()));
// while !closed {
events_loop.poll_events(|event| match event {
event_loop.run(move |event, _, ctrl_flow| {
let now = Instant::now();
let delta = now - *prev.borrow();
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => closed = true,
} => *ctrl_flow = ControlFlow::Exit,
_ => game.handle_event(event),
});
};
game.update(delta);
let mut target = display.draw();
let mut target = game.target();
target.clear(None, Some((0.0, 0.0, 0.0, 1.0)), true, None, None);
let mut renderer = game.create_renderer(&mut target);
game.render(&mut renderer);
target.finish().unwrap();
prev = now;
prev.replace(now);
std::thread::sleep(std::time::Duration::from_millis(17));
}
});
}

View file

@ -34,9 +34,9 @@ impl Resources {
let name = name.as_ref().to_owned();
let dimensions = image.dimensions();
let image = if alpha {
RawImage2d::from_raw_rgba_reversed(&image.raw_pixels(), dimensions)
RawImage2d::from_raw_rgba_reversed(image.as_bytes(), dimensions)
} else {
RawImage2d::from_raw_rgb_reversed(&image.raw_pixels(), dimensions)
RawImage2d::from_raw_rgb_reversed(image.as_bytes(), dimensions)
};
// TODO: don't unwrap
let texture = Texture2d::new(display, image).unwrap();

View file

@ -1,6 +1,6 @@
use std::time::Duration;
use glium::glutin::VirtualKeyCode;
use glium::glutin::event::VirtualKeyCode;
use crate::keymap::Keymap;
use crate::screens::{PlayScreen, Screen, ScreenAction};

View file

@ -1,6 +1,6 @@
use std::time::Duration;
use glium::glutin::VirtualKeyCode;
use glium::glutin::event::VirtualKeyCode;
use crate::animations::AnimationState;
use crate::enums::{Board, PushDir};
@ -88,11 +88,7 @@ impl PlayScreen {
}
pub fn new() -> PlayScreen {
let levels = vec![
LEVEL_TUTORIAL,
LEVEL_TUTORIAL2,
LEVEL_1,
];
let levels = vec![LEVEL_TUTORIAL, LEVEL_TUTORIAL2, LEVEL_1];
PlayScreen {
levels,