Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies to latest versions #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,665 changes: 1,186 additions & 479 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ engine = { path = "engine" }
game = { path = "game" }
math = { path = "math" }

env_logger = "0.8.3"
env_logger = "0.10.1"
structopt = "0.3.21"
failure = "0.1.8"

Expand All @@ -23,5 +23,3 @@ features = ["release_max_level_info"]
version = "0.4.8"

[workspace]


9 changes: 7 additions & 2 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ edition = "2018"
math = { path = "../math" }
engine_derive = { path = "../engine_derive" }

glium-typed-buffer-any = "0.6.0"
idcontain = "0.7.6"
num-traits = "0.2.14"
rusttype = "0.9.2"
unicode-normalization = "0.1.17"
failure = "0.1.8"
failchain = "0.1018.2"
winit = "0.29.9"

[dependencies.glium-typed-buffer-any]
version = "0.6.0"
git = "https://github.com/hovinen/glium-typed-buffer-any"
branch = "update-dependency"

[dependencies.log]
features = ["release_max_level_info"]
version = "0.4.14"

[dependencies.glium]
features = ["glutin"]
version = "0.26"
version = "0.34.0"

[dev-dependencies]
env_logger = "*"
87 changes: 46 additions & 41 deletions engine/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use super::type_list::{Cons, Nil, Peek, Pluck, PluckInto};
use super::window::Window;
use failchain::ResultExt;
use failure::{AsFail, Fail};
use glium::glutin::event_loop::ControlFlow as GlutinControlFlow;
use std::{marker::PhantomData, time::Instant};
use winit::event_loop::ControlFlow as WinitControlFlow;

pub trait Context {
fn step(&mut self) -> Result<()>;
fn destroy(&mut self) -> Result<()>;

fn run(self) -> !;
fn run(self) -> Result<()>;
}

pub struct ContextBuilder<SystemListT> {
Expand Down Expand Up @@ -162,53 +162,58 @@ where
SystemListT::update_list(self.systems_mut()).chain_err(|| ErrorKind::Context("update"))
}

fn run(mut self) -> ! {
fn run(mut self) -> Result<()> {
let event_loop = {
let window: &mut Window = self.systems_mut().peek_mut();
window.take_event_loop().expect("none event loop in window")
};

event_loop.run(move |event, _target, glutin_control_flow| {
if *glutin_control_flow == GlutinControlFlow::Exit {
return;
}
let input: &mut Input = self.systems_mut().peek_mut();
if !input.handle_event(event) {
return;
}
let result = self.step().and_then(|_| {
let input: &mut Input = self.systems_mut().peek_mut();
input.reset();
let control_flow: &mut ControlFlow = self.systems_mut().peek_mut();
*glutin_control_flow = control_flow
.sleep_until
.take()
.map_or(GlutinControlFlow::Poll, GlutinControlFlow::WaitUntil);
if !control_flow.quit_requested {
return Ok(());
event_loop
.run(move |event, target| {
if target.exiting() {
return;
}
*glutin_control_flow = GlutinControlFlow::Exit;
self.destroy()
});

if let Err(error) = result {
log::error!("Fatal error: {}", error);
let mut cause = error.as_fail();
while let Some(new_cause) = cause.cause() {
cause = new_cause;
log::error!(" caused by: {}", cause);
let input: &mut Input = self.systems_mut().peek_mut();
if !input.handle_event(event) {
return;
}
if std::env::var("RUST_BACKTRACE")
.map(|value| value == "1")
.unwrap_or(false)
{
log::error!("Backtrace:\n{:?}", error.backtrace());
} else {
log::error!("Run with RUST_BACKTRACE=1 to capture backtrace.");
let result = self.step().and_then(|_| {
let input: &mut Input = self.systems_mut().peek_mut();
input.reset();
let control_flow: &mut ControlFlow = self.systems_mut().peek_mut();
target.set_control_flow(
control_flow
.sleep_until
.take()
.map_or(WinitControlFlow::Poll, WinitControlFlow::WaitUntil),
);
if !control_flow.quit_requested {
return Ok(());
}
target.exit();
self.destroy()
});

if let Err(error) = result {
log::error!("Fatal error: {}", error);
let mut cause = error.as_fail();
while let Some(new_cause) = cause.cause() {
cause = new_cause;
log::error!(" caused by: {}", cause);
}
if std::env::var("RUST_BACKTRACE")
.map(|value| value == "1")
.unwrap_or(false)
{
log::error!("Backtrace:\n{:?}", error.backtrace());
} else {
log::error!("Run with RUST_BACKTRACE=1 to capture backtrace.");
}
target.exit();
}
*glutin_control_flow = GlutinControlFlow::Exit;
}
})
})
.chain_err(|| ErrorKind::Context("Event loop"))?;
Ok(())
}

fn destroy(&mut self) -> Result<()> {
Expand Down
14 changes: 2 additions & 12 deletions engine/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ impl ChainErrorKind for ErrorKind {
}

impl ErrorKind {
pub(crate) fn create_window(
width: u32,
height: u32,
) -> impl FnOnce(glium::backend::glutin::DisplayCreationError) -> Self {
move |error| {
ErrorKind::CreateWindow(format!(
"Window creation failed with {}x{}: {}",
width, height, error
))
}
}

pub(crate) fn glium<NeededByT: Into<String>, ErrorT: ConvertGlium>(
needed_by: NeededByT,
) -> impl FnOnce(ErrorT) -> Error {
Expand Down Expand Up @@ -153,6 +141,7 @@ impl ConvertGlium for glium::DrawError {
| ProvokingVertexNotSupported
| RasterizerDiscardNotSupported
| DepthClampNotSupported
| ClipControlNotSupported
| BlendingParameterNotSupported => ErrorKind::UnsupportedFeature { needed_by },

NoDepthBuffer
Expand All @@ -170,6 +159,7 @@ impl ConvertGlium for glium::DrawError {
| SubroutineUniformMissing { .. }
| SubroutineUniformToValue { .. }
| ClipPlaneIndexOutOfBounds { .. }
| InsufficientImageUnits
| WrongQueryOperation => panic!("Invalid draw call: {:?}", self),
}
}
Expand Down
45 changes: 22 additions & 23 deletions engine/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ use super::errors::{Error, Result};
use super::system::System;
use super::window::Window;
use crate::internal_derive::DependenciesFrom;
use glium::glutin::event::{
DeviceEvent, ElementState, Event, KeyboardInput, StartCause, VirtualKeyCode, WindowEvent,
};
use math::Vec2f;
use num_traits::Zero;
use std::vec::Vec;
use winit::{
event::{DeviceEvent, ElementState, Event, KeyEvent, StartCause, WindowEvent},
keyboard::{KeyCode, PhysicalKey},
window::CursorGrabMode,
};

pub use glium::glutin::event::{MouseButton, VirtualKeyCode as Scancode};
pub use winit::event::MouseButton;

pub type Sensitivity = f32;

pub enum Gesture {
NoGesture,
KeyHold(VirtualKeyCode),
KeyTrigger(VirtualKeyCode),
KeyHold(KeyCode),
KeyTrigger(KeyCode),
ButtonHold(MouseButton),
ButtonTrigger(MouseButton),
AnyOf(Vec<Gesture>),
Expand Down Expand Up @@ -50,7 +52,7 @@ impl Input {
self.mouse_rel = Vec2f::zero();
}

pub(crate) fn handle_event(&mut self, event: Event<'_, ()>) -> bool {
pub(crate) fn handle_event(&mut self, event: Event<()>) -> bool {
match event {
Event::NewEvents(StartCause::WaitCancelled { .. }) => {}
Event::NewEvents(StartCause::ResumeTimeReached {
Expand All @@ -59,7 +61,7 @@ impl Input {
Event::NewEvents(_) => {
self.new_step = true;
}
Event::MainEventsCleared => {
Event::AboutToWait => {
let new_step = self.new_step;
self.new_step = false;
return new_step;
Expand All @@ -73,10 +75,10 @@ impl Input {
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
event:
KeyEvent {
state,
virtual_keycode: Some(virtual_keycode),
physical_key: PhysicalKey::Code(virtual_keycode),
..
},
..
Expand Down Expand Up @@ -233,19 +235,14 @@ impl<'context> System<'context> for Input {
if self.new_mouse_grabbed != self.mouse_grabbed {
self.mouse_grabbed = self.new_mouse_grabbed;
deps.window
.facade()
.gl_window()
.window()
.set_cursor_grab(self.mouse_grabbed)
.set_cursor_grab(if self.mouse_grabbed {
CursorGrabMode::Locked
} else {
CursorGrabMode::None
})
.ok();
deps.window
.facade()
.gl_window()
.window()
.set_cursor_visible(!self.mouse_grabbed);
}
if self.mouse_grabbed {
let _ = deps.window.facade().gl_window().window();
deps.window.window().set_cursor_visible(!self.mouse_grabbed);
}
Ok(())
}
Expand All @@ -267,6 +264,8 @@ fn mouse_button_to_index(button: MouseButton) -> usize {
MouseButton::Left => 1,
MouseButton::Middle => 2,
MouseButton::Right => 3,
MouseButton::Other(index) => ((index + 4) as usize).min(NUM_MOUSE_BUTTONS - 1),
MouseButton::Back => 4,
MouseButton::Forward => 5,
MouseButton::Other(index) => ((index + 6) as usize).min(NUM_MOUSE_BUTTONS - 1),
}
}
2 changes: 1 addition & 1 deletion engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use self::context::{Context, ContextBuilder, ControlFlow};
pub use self::entities::{Entities, Entity, EntityId};
pub use self::errors::{Error, ErrorKind, Result};
pub use self::frame_timers::{FrameTimerId, FrameTimers};
pub use self::input::{Analog2d, Gesture, Input, MouseButton, Scancode};
pub use self::input::{Analog2d, Gesture, Input, MouseButton};
pub use self::materials::{MaterialId, MaterialRefMut, Materials};
pub use self::meshes::{Mesh, MeshId, Meshes};
pub use self::pipeline::RenderPipeline;
Expand Down
2 changes: 0 additions & 2 deletions engine/src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(target_os = "linux")]
mod internal {
pub const GL_MAJOR_VERSION: u8 = 3;
pub const GL_MINOR_VERSION: u8 = 1;
pub const GLSL_VERSION_STRING: &str = "140";
}

Expand Down
51 changes: 20 additions & 31 deletions engine/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use super::errors::{Error, ErrorKind, Result};
use super::platform;
use super::system::System;
use glium::{
glutin::{
dpi::PhysicalSize, event_loop::EventLoop, window::WindowBuilder, Api, ContextBuilder,
GlProfile, GlRequest,
},
Display, Frame, Surface,
};
use crate::ErrorKind;

const OPENGL_DEPTH_SIZE: u8 = 24;
use super::errors::{Error, Result};
use super::system::System;
use glium::backend::glutin::SimpleWindowBuilder;
use glium::glutin::surface::WindowSurface;
use glium::{Display, Frame, Surface};
use winit::event_loop::EventLoop;

pub struct WindowConfig {
pub width: u32,
Expand All @@ -18,7 +14,8 @@ pub struct WindowConfig {
}

pub struct Window {
display: Display,
display: Display<WindowSurface>,
window: winit::window::Window,
event_loop: Option<EventLoop<()>>,
width: u32,
height: u32,
Expand All @@ -43,10 +40,14 @@ impl Window {
frame
}

pub fn facade(&self) -> &Display {
pub fn facade(&self) -> &Display<WindowSurface> {
&self.display
}

pub fn window(&self) -> &winit::window::Window {
&self.window
}

pub(crate) fn take_event_loop(&mut self) -> Option<EventLoop<()>> {
self.event_loop.take()
}
Expand All @@ -57,28 +58,16 @@ impl<'context> System<'context> for Window {
type Error = Error;

fn create(config: &'context WindowConfig) -> Result<Self> {
let events = EventLoop::new();

let window = WindowBuilder::new()
.with_inner_size(PhysicalSize {
width: config.width,
height: config.height,
})
.with_title(config.title.clone());

let context = ContextBuilder::new()
.with_gl_profile(GlProfile::Core)
.with_gl(GlRequest::Specific(
Api::OpenGl,
(platform::GL_MAJOR_VERSION, platform::GL_MINOR_VERSION),
))
.with_depth_buffer(OPENGL_DEPTH_SIZE);
let events = EventLoop::new().map_err(|e| ErrorKind::CreateWindow(e.to_string()))?;

let display = Display::new(window, context, &events)
.map_err(ErrorKind::create_window(config.width, config.height))?;
let (window, display) = SimpleWindowBuilder::new()
.with_inner_size(config.width, config.height)
.with_title(&config.title)
.build(&events);

Ok(Window {
display,
window,
event_loop: Some(events),
width: config.width,
height: config.height,
Expand Down
Loading