Timing Module Update
- Implement a new timing module - Utilize the new timing module in glium platform implementation for frame limiting and fixed engine updates timing.
This commit is contained in:
parent
5e8897c271
commit
84ab3a26b1
9 changed files with 221 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use raidillon_platform::{Platform, PlatformContext};
|
||||
use raidillon_platform::{Platform, PlatformContext, TimeContext};
|
||||
use glium::backend::glutin::Display;
|
||||
use glium::backend::glutin::SimpleWindowBuilder;
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
|
|
@ -11,6 +11,8 @@ use crate::system::{RenderingContext, RenderingSystemManager};
|
|||
use winit::event::{Event, WindowEvent};
|
||||
use raidillon_assets::ModelManagerRef;
|
||||
use raidillon_core::engine::EngineTrait;
|
||||
use raidillon_core::time;
|
||||
use raidillon_core::time::Time;
|
||||
use crate::render::debug_ui::ImguiBridge;
|
||||
use crate::render::BasicMeshRenderingSystem;
|
||||
use crate::GliumAssetManager;
|
||||
|
|
@ -22,6 +24,7 @@ pub struct GliumPlatform<E: EngineTrait<PlatformCtx = PlatformContext>> {
|
|||
rendering_system_manager: RenderingSystemManager,
|
||||
asset_manager: ModelManagerRef,
|
||||
engine: E,
|
||||
time: time::Time,
|
||||
}
|
||||
|
||||
impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatform<E> {
|
||||
|
|
@ -38,6 +41,9 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
let asset_manager: ModelManagerRef = Rc::new(RefCell::new(Box::new(GliumAssetManager::new(Box::new(display.clone())))));
|
||||
let mut rendering_system_manager = RenderingSystemManager::new();
|
||||
|
||||
let time_cfg = time::Config::default();
|
||||
let time = time::Time::new(time_cfg);
|
||||
|
||||
// Install rendering systems
|
||||
rendering_system_manager.add::<BasicMeshRenderingSystem>(&display, &window);
|
||||
rendering_system_manager.add::<ImguiBridge>(&display, &window);
|
||||
|
|
@ -49,6 +55,7 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
rendering_system_manager,
|
||||
asset_manager,
|
||||
engine,
|
||||
time,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +66,7 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
asset_manager: self.asset_manager.clone(),
|
||||
frame_width: w as f32,
|
||||
frame_height: h as f32,
|
||||
time_ctx: self.construct_time_ctx(),
|
||||
};
|
||||
self.engine.initialize(ctx.clone());
|
||||
let _ = &self.event_loop.run(move |event, el| {
|
||||
|
|
@ -98,9 +106,22 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
_ => {},
|
||||
},
|
||||
Event::AboutToWait => {
|
||||
let plan = self.time.begin_frame_blocking();
|
||||
|
||||
let mut ctx2 = ctx.clone();
|
||||
ctx2.current_event = event.clone();
|
||||
self.engine.update(ctx2);
|
||||
ctx2.time_ctx = TimeContext {
|
||||
frame_dt: self.time.frame_dt_seconds(),
|
||||
fixed_dt: self.time.fixed_dt_seconds(),
|
||||
alpha: self.time.alpha(),
|
||||
};
|
||||
ctx2.current_event = Event::AboutToWait;
|
||||
|
||||
for _ in 0..plan.updates {
|
||||
self.engine.fixed_update(ctx2.clone());
|
||||
}
|
||||
|
||||
self.engine.frame_update(ctx2.clone());
|
||||
|
||||
self.rendering_system_manager
|
||||
.systems
|
||||
.values_mut()
|
||||
|
|
@ -112,3 +133,13 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EngineTrait<PlatformCtx = PlatformContext>> GliumPlatform<E> {
|
||||
fn construct_time_ctx(&self) -> TimeContext {
|
||||
TimeContext {
|
||||
frame_dt: self.time.frame_dt_seconds(),
|
||||
fixed_dt: self.time.fixed_dt_seconds(),
|
||||
alpha: self.time.alpha(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue