summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0830429)
Now moving the mouse no longer hangs rendering, but events can still
cause the game timer (t) to advance too fast. Will fix this another
time.
use cgmath::conv::array4x4;
use cgmath::{Euler, Matrix4, Rad, SquareMatrix, Vector3, Vector4, Zero};
use glium::glutin::event::{ self, Event, VirtualKeyCode, WindowEvent };
use cgmath::conv::array4x4;
use cgmath::{Euler, Matrix4, Rad, SquareMatrix, Vector3, Vector4, Zero};
use glium::glutin::event::{ self, Event, VirtualKeyCode, WindowEvent };
-use glium::glutin::event_loop::{ ControlFlow };
+use glium::glutin::event_loop::ControlFlow;
use glium::{Display, Program, Surface, uniform};
use glium::{Display, Program, Surface, uniform};
use mandelwow_lib::*;
use std::f32::consts::PI;
use std::rc::Rc;
use mandelwow_lib::*;
use std::f32::consts::PI;
use std::rc::Rc;
-use instant::{Duration, Instant};
#[cfg(target_os = "emscripten")]
use std::os::raw::{c_int, c_void};
#[cfg(target_os = "emscripten")]
use std::os::raw::{c_int, c_void};
let mut fullscreen = false;
event_loop.run(move |event, _, control_flow| {
let mut fullscreen = false;
event_loop.run(move |event, _, control_flow| {
let t = timer.t;
let new_hit = sound::hit_event(&mut soundplayer);
if new_hit > world.last_hit {
let t = timer.t;
let new_hit = sound::hit_event(&mut soundplayer);
if new_hit > world.last_hit {
- *control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::from_nanos(16_666_667));
+ *control_flow = ControlFlow::WaitUntil(timer.now + Duration::from_nanos(16_666_667));
+ Event::MainEventsCleared => {
+ world.draw_frame(&display, &camera, t);
+ }
Event::NewEvents(cause) => {
match cause {
event::StartCause::ResumeTimeReached { .. } | event::StartCause::Init => {
Event::NewEvents(cause) => {
match cause {
event::StartCause::ResumeTimeReached { .. } | event::StartCause::Init => {
- world.draw_frame(&display, &camera, t);
VirtualKeyCode::PageUp => timer.t += 0.1,
VirtualKeyCode::PageDown => timer.t -= 0.2,
VirtualKeyCode::F10 => screenshot::take_screenshot(&display),
VirtualKeyCode::PageUp => timer.t += 0.1,
VirtualKeyCode::PageDown => timer.t -= 0.2,
VirtualKeyCode::F10 => screenshot::take_screenshot(&display),
- VirtualKeyCode::F11 | VirtualKeyCode::Return => {
+ VirtualKeyCode::F | VirtualKeyCode::F11 | VirtualKeyCode::Return => {
fullscreen ^= true;
let fs = if fullscreen {
// let monitor_handle = display.gl_window().window()
fullscreen ^= true;
let fs = if fullscreen {
// let monitor_handle = display.gl_window().window()
#[derive(Debug)]
pub struct Timer {
pub t: f32,
#[derive(Debug)]
pub struct Timer {
pub t: f32,
frame: u32,
last_report_time: Instant,
frame: u32,
last_report_time: Instant,
let now = Instant::now();
Timer {
t: 0.0,
let now = Instant::now();
Timer {
t: 0.0,
frame: 0,
last_report_time: now,
last_report_frame: 0,
frame: 0,
last_report_time: now,
last_report_frame: 0,
}
pub fn update(&mut self) {
}
pub fn update(&mut self) {
- let now = Instant::now();
+ self.now = Instant::now();
self.poll_rocket();
if !self.pause {
// Increment time
self.t += 0.01;
self.frame += 1;
}
self.poll_rocket();
if !self.pause {
// Increment time
self.t += 0.01;
self.frame += 1;
}
- self.maybe_report(now);
}
#[cfg(not(feature = "logging"))]
}
#[cfg(not(feature = "logging"))]
- fn maybe_report(&mut self, _: Instant) {}
+ fn maybe_report(&mut self) {}
#[cfg(feature = "logging")]
#[cfg(feature = "logging")]
- fn maybe_report(&mut self, now: Instant) {
- if now - self.last_report_time > Duration::from_secs(5) {
- self.report(now);
- self.last_report_time = now;
+ fn maybe_report(&mut self) {
+ if self.now - self.last_report_time > Duration::from_secs(5) {
+ self.report(self.now);
+ self.last_report_time = self.now;
self.last_report_frame = self.frame;
self.accum_draw_time = Duration::new(0, 0);
self.accum_idle_time = Duration::new(0, 0);
self.last_report_frame = self.frame;
self.accum_draw_time = Duration::new(0, 0);
self.accum_idle_time = Duration::new(0, 0);