summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-07-03 15:33:08 -0400
committerMica White <botahamec@outlook.com>2026-07-03 15:33:08 -0400
commit73ffbee638c03da132aea0e5d600ca5e8144fd8e (patch)
tree4ea897e8b3aaad2876625e241e740493e9b5b8b8 /src/main.rs
parentbb7525206da1782fd9af49621aa52d87bd227838 (diff)
Support WASM, kinda
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 81fffcf..7c4f249 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,22 +7,21 @@ use tortuise::{
file::FileManager,
input::InputManager,
scene::switch_scenes,
- script::{ScriptContext, ScriptDeclaration, ScriptManager},
+ script::{ScriptContext, ScriptDeclaration, ScriptManager, WasmRunner},
};
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
fn get_timestamp() -> u128 {
- SystemTime::UNIX_EPOCH.elapsed().unwrap().as_nanos()
+ SystemTime::UNIX_EPOCH.elapsed().unwrap().as_micros()
}
-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]>) {
- ctx.buffer.cells.clear();
+fn render_frame_rate(ctx: &mut ScriptContext, state: &mut Box<[u8]>) {
let end = get_timestamp();
let last_frame_start = u128::from_ne_bytes(*state.as_array().unwrap());
let frame_time = end - last_frame_start + 1;
@@ -53,6 +52,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();
@@ -60,6 +67,7 @@ fn main() {
buffer: &mut buffer,
input: &input,
};
+
let scripts = [
ScriptDeclaration::Static {
start: Some(init_first_frame),
@@ -74,17 +82,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,
);
@@ -100,7 +103,7 @@ fn main() {
buffer,
input: &input,
};
- scripts.run_scripts(&mut context);
+ scripts.run_scripts(&mut context, &wasm_runner, &mut files);
input.reset_next_frame();
}
})