summaryrefslogtreecommitdiff
path: root/examples/snake.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/snake.rs')
-rw-r--r--examples/snake.rs47
1 files changed, 27 insertions, 20 deletions
diff --git a/examples/snake.rs b/examples/snake.rs
index b284dba..49ea212 100644
--- a/examples/snake.rs
+++ b/examples/snake.rs
@@ -1,4 +1,7 @@
-use std::time::{Duration, SystemTime};
+use std::{
+ io::BufWriter,
+ time::{Duration, SystemTime},
+};
use bytemuck::{Pod, Zeroable, bytes_of, from_bytes_mut};
use crossterm::{event::KeyCode, style::ContentStyle};
@@ -8,6 +11,7 @@ use tortuise::{
input::InputManager,
scene::{ResourceRequirements, Scene, switch_scenes},
script::{ScriptContext, ScriptDeclaration, ScriptManager, WasmRunner},
+ time::TimeContext,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Pod, Zeroable)]
@@ -106,38 +110,39 @@ fn main() {
first_scene: 0,
scenes: Box::from([Scene {
name: Box::from("main"),
+ preload_scenes: Box::from([]),
scripts: ResourceRequirements {
required: Box::from([0, 1]),
preload: Box::from([]),
},
}]),
+ scripts: Box::from([
+ ScriptDeclaration::Static {
+ start: None,
+ update: Some(exit_on_escape),
+ end: None,
+ },
+ ScriptDeclaration::Static {
+ start: Some(init_scene),
+ update: Some(render),
+ end: None,
+ },
+ ]),
};
- let stdout = Box::new(std::io::stdout().lock());
+ let stdout = Box::new(BufWriter::new(std::io::stdout().lock()));
let mut buffer = Buffer::new(stdout).unwrap();
+ let mut files = FileManager::default();
let mut input = InputManager::new();
+ let wasm_runner = WasmRunner::new();
+ let mut scripts = ScriptManager::new(&manifest.scripts);
+ let mut time = TimeContext::new();
+
let mut context = ScriptContext {
buffer: &mut buffer,
input: &input,
+ time: &time,
};
-
- let scripts = [
- ScriptDeclaration::Static {
- start: None,
- update: Some(exit_on_escape),
- end: None,
- },
- ScriptDeclaration::Static {
- start: Some(init_scene),
- update: Some(render),
- end: None,
- },
- ];
-
- let mut files = FileManager::default();
- let mut scripts = ScriptManager::new(&scripts);
- let wasm_runner = WasmRunner::new();
-
switch_scenes(
&manifest.scenes,
&mut scripts,
@@ -158,9 +163,11 @@ fn main() {
let mut context = ScriptContext {
buffer,
input: &input,
+ time: &time,
};
scripts.run_scripts(&mut context, &wasm_runner, &mut files);
input.reset_next_frame();
+ time.next_frame();
}
})
.unwrap();