diff options
| author | Mica White <botahamec@outlook.com> | 2026-07-03 16:35:05 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-07-03 16:35:05 -0400 |
| commit | bdbd5faeb7be5e5f81c1f4a952c8110df9e9b990 (patch) | |
| tree | 324a84ed9cba6b4ac5427775362ae25c6588b4db /src/main.rs | |
| parent | f31fda79035077a9dab8dee07a11d71fac3ba791 (diff) | |
| parent | cbbe1ca7f7b36b03e813fbf7e0147341090762bb (diff) | |
merge
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index 14e3925..bd42e18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use tortuise::{ file::FileManager, input::InputManager, scene::switch_scenes, - script::{ScriptContext, ScriptDeclaration, ScriptManager}, + script::{ScriptContext, ScriptDeclaration, ScriptManager, WasmRunner}, }; #[global_allocator] @@ -17,13 +17,12 @@ fn get_timestamp() -> u128 { SystemTime::UNIX_EPOCH.elapsed().unwrap().as_nanos() } -fn init_first_frame<'a>(_: &mut ScriptContext<'a>, state: &mut Box<[u8]>) { +fn init_first_frame(_: &mut ScriptContext, state: &mut Box<[u8]>) { *state = Box::from(get_timestamp().to_ne_bytes()); } -fn render_frame_rate<'a>(ctx: &mut ScriptContext<'a>, state: &mut Box<[u8]>) { +fn render_frame_rate(ctx: &mut ScriptContext, state: &mut Box<[u8]>) { puffin::profile_function!(); - ctx.buffer.cells.clear(); let end = get_timestamp(); let last_frame_start = u128::from_ne_bytes(*state.as_array().unwrap()); let frame_time = end - last_frame_start + 1; @@ -35,6 +34,7 @@ fn render_frame_rate<'a>(ctx: &mut ScriptContext<'a>, state: &mut Box<[u8]>) { frame_time % 100 / 10, frame_time % 10, ]; + ctx.buffer.cells.clear(); for (x, digit) in digits.into_iter().enumerate() { ctx.buffer.cells.push(Cell { character: char::from_digit(digit as u32, 10).unwrap(), @@ -55,6 +55,14 @@ fn exit_on_escape(ctx: &mut ScriptContext, _: &mut Box<[u8]>) { } fn main() { + let mut files = FileManager::default(); + let wasm_runner = WasmRunner::new(); + let manifest = files + .load_file(Box::from("manifest.toml".as_ref()), &wasm_runner.engine) + .unwrap() + .unwrap_manifest() + .clone(); + let stdout = Box::new(std::io::stdout().lock()); let mut buffer = Buffer::new(stdout).unwrap(); let mut input = InputManager::new(); @@ -62,6 +70,7 @@ fn main() { buffer: &mut buffer, input: &input, }; + let scripts = [ ScriptDeclaration::Static { start: Some(init_first_frame), @@ -76,17 +85,12 @@ fn main() { ]; let mut scripts = ScriptManager::new(&scripts); - let mut files = FileManager::default(); - let manifest = files - .load_file(Box::from("manifest.toml".as_ref())) - .unwrap() - .unwrap_manifest() - .clone(); switch_scenes( &manifest.scenes, &mut scripts, &mut context, &mut files, + &wasm_runner, manifest.first_scene, ); @@ -105,7 +109,7 @@ fn main() { buffer, input: &input, }; - scripts.run_scripts(&mut context); + scripts.run_scripts(&mut context, &wasm_runner, &mut files); input.reset_next_frame(); puffin::GlobalProfiler::lock().new_frame(); } |
