summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-07-06 14:59:20 -0400
committerMica White <botahamec@outlook.com>2026-07-06 14:59:20 -0400
commit07018cb37b278dbd73c864a662454f1cf9d33457 (patch)
tree5796096d60f6e09d35498b567c596d42b9c32baf /src/main.rs
parente8f85e4a723b772c099a3c03a6cb721c48561e4b (diff)
Patch GameManifest through ScriptContext
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs49
1 files changed, 4 insertions, 45 deletions
diff --git a/src/main.rs b/src/main.rs
index d39b0f8..2978393 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,8 @@
-use std::{io::BufWriter, time::SystemTime};
+use std::io::BufWriter;
-use crossterm::{event::KeyCode, style::ContentStyle};
use mimalloc::MiMalloc;
use tortuise::{
- buffer::{Buffer, Cell, Event},
+ buffer::{Buffer, Event},
file::FileManager,
input::InputManager,
scene::switch_scenes,
@@ -14,47 +13,6 @@ use tortuise::{
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
-fn get_timestamp() -> u128 {
- SystemTime::UNIX_EPOCH.elapsed().unwrap().as_nanos()
-}
-
-fn init_first_frame(_: &mut ScriptContext, state: &mut Box<[u8]>) {
- *state = Box::from(get_timestamp().to_ne_bytes());
-}
-
-fn render_frame_rate(ctx: &mut ScriptContext, state: &mut Box<[u8]>) {
- puffin::profile_function!();
- let end = get_timestamp();
- let last_frame_start = u128::from_ne_bytes(*state.as_array().unwrap());
- let frame_time = end - last_frame_start + 1;
- let digits = [
- frame_time % 1_000_000 / 100_000,
- frame_time % 100_000 / 10_000,
- frame_time % 10_000 / 1_000,
- frame_time % 1_000 / 100,
- 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(),
- x: x as u16,
- y: 0,
- z: 0,
- style: ContentStyle::new(),
- });
- }
- *state = Box::from(end.to_ne_bytes());
-}
-
-fn exit_on_escape(ctx: &mut ScriptContext, _: &mut Box<[u8]>) {
- puffin::profile_function!();
- if ctx.input.is_key_pressed_this_frame(KeyCode::Esc) {
- ctx.exit();
- }
-}
-
fn main() {
let mut files = FileManager::default();
let wasm_runner = WasmRunner::new();
@@ -70,13 +28,13 @@ fn main() {
let mut time = TimeContext::new();
let mut scripts = ScriptManager::new(&manifest.scripts);
let mut context = ScriptContext {
+ manifest: &manifest,
buffer: &mut buffer,
input: &input,
time: &time,
};
switch_scenes(
- &manifest.scenes,
&mut scripts,
&mut context,
&mut files,
@@ -97,6 +55,7 @@ fn main() {
Event::Render => {
buffer.cells.clear();
let mut context = ScriptContext {
+ manifest: &manifest,
buffer,
input: &input,
time: &time,