mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-11-22 05:33:02 +00:00
Move scene handling code to Game, doesn't make sense to have it in
backends
This commit is contained in:
parent
48a2233862
commit
5a8842669b
|
@ -402,14 +402,6 @@ impl BackendEventLoop for HorizonEventLoop {
|
|||
break;
|
||||
}
|
||||
|
||||
if state_ref.next_scene.is_some() {
|
||||
mem::swap(&mut game.scene, &mut state_ref.next_scene);
|
||||
state_ref.next_scene = None;
|
||||
game.scene.as_mut().unwrap().init(state_ref, ctx).unwrap();
|
||||
game.loops = 0;
|
||||
state_ref.frame_time = 0.0;
|
||||
}
|
||||
|
||||
game.draw(ctx).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,15 +46,7 @@ impl BackendEventLoop for NullEventLoop {
|
|||
break;
|
||||
}
|
||||
|
||||
if game.state.get_mut().next_scene.is_some() {
|
||||
mem::swap(game.scene.get_mut(), &mut game.state.get_mut().next_scene);
|
||||
game.state.get_mut().next_scene = None;
|
||||
game.scene.borrow_mut().as_mut().unwrap().init(game.state.get_mut(), ctx).unwrap();
|
||||
game.loops = 0;
|
||||
game.state.get_mut().frame_time = 0.0;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
|
||||
game.draw(ctx).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -430,14 +430,6 @@ impl BackendEventLoop for SDL2EventLoop {
|
|||
|
||||
game.update(ctx).unwrap();
|
||||
|
||||
if game.state.get_mut().next_scene.is_some() {
|
||||
let mut state = game.state.borrow_mut();
|
||||
*game.scene.get_mut() = mem::take(&mut state.next_scene);
|
||||
game.scene.get_mut().as_mut().unwrap().init(&mut state, ctx).unwrap();
|
||||
game.loops = 0;
|
||||
state.frame_time = 0.0;
|
||||
}
|
||||
|
||||
imgui_sdl2.prepare_frame(
|
||||
imgui.io_mut(),
|
||||
self.refs.deref().borrow().window.window(),
|
||||
|
|
|
@ -281,15 +281,6 @@ impl ApplicationHandler for WinitEventLoop {
|
|||
}
|
||||
|
||||
window.request_redraw();
|
||||
|
||||
if game.state.get_mut().next_scene.is_some() {
|
||||
let mut state_ref = game.state.borrow_mut();
|
||||
mem::swap(game.scene.get_mut(), &mut state_ref.next_scene);
|
||||
state_ref.next_scene = None;
|
||||
game.scene.borrow_mut().as_mut().unwrap().init(&mut state_ref, ctx).unwrap();
|
||||
game.loops = 0;
|
||||
state_ref.frame_time = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -254,10 +254,11 @@ impl PhysicalFS {
|
|||
continue;
|
||||
}
|
||||
|
||||
let node_lower = node.to_ascii_lowercase();
|
||||
if let Ok(entries) = root_path2.read_dir() {
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name();
|
||||
if name.to_ascii_lowercase() != node.to_ascii_lowercase() {
|
||||
if name.to_ascii_lowercase() != node_lower {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,8 +77,9 @@ impl Game {
|
|||
}
|
||||
|
||||
pub(crate) fn update(&mut self, ctx: &mut Context) -> GameResult {
|
||||
let state_ref = self.state.get_mut();
|
||||
|
||||
if let Some(scene) = self.scene.get_mut() {
|
||||
let state_ref = self.state.get_mut();
|
||||
|
||||
let speed = if state_ref.textscript_vm.mode == ScriptMode::Map
|
||||
&& state_ref.textscript_vm.flags.cutscene_skip()
|
||||
|
@ -127,6 +128,16 @@ impl Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
let next_scene = std::mem::take(&mut state_ref.next_scene);
|
||||
if let Some(mut next_scene) = next_scene {
|
||||
next_scene.init(state_ref, ctx)?;
|
||||
*self.scene.get_mut() = Some(next_scene);
|
||||
|
||||
self.loops = 0;
|
||||
state_ref.frame_time = 0.0;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue