summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-10-31 12:38:00 -0400
committerMica White <botahamec@outlook.com>2026-10-31 12:38:00 -0400
commit3b39c7561ec71dadb0cb03a153550e9a6e2cddff (patch)
treec4d5dd4b4314371a818053c4c6741209967089b3 /src/main.rs
parent2987e310e8e6eaeaa60546bb92a61d9c3713263a (diff)
OptimizationHEADmain
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 3b6605a..bf6eae4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,16 +1,25 @@
-#![cfg_attr(target_arch = "wasm32", no_std)]
+#![no_std]
#![cfg_attr(target_arch = "wasm32", no_main)]
extern crate alloc;
+mod detect_controller;
mod exit_on_escape;
mod move_snake;
mod render;
+mod render_frametime;
mod snake_controller;
+mod update_high_score;
use alloc::vec::Vec;
use core::time::Duration;
-use tortuise_script::{entity::Entity, time::Instant, TortuiseScene};
+use tortuise_script::{
+ entity::Entity,
+ input::Gamepad,
+ storage::{Config, Storage},
+ time::Instant,
+ TortuiseScene,
+};
use serde::{Deserialize, Serialize};
@@ -20,8 +29,25 @@ struct Position {
pub y: i16,
}
+#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+struct SaveData {
+ high_score: usize,
+}
+
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
+struct ConfigOptions {
+ #[serde(default)]
+ framerate_limit: Option<u32>,
+}
+
const GRID_SIZE: u16 = 16;
+static SAVE_DATA: Storage<SaveData> = Storage::new(SaveData::default);
+static CONFIG: Config<ConfigOptions> = Config::new(ConfigOptions::default);
+
+static CONNECTED_GAMEPAD_QUEUE: Entity<Vec<Gamepad>> =
+ Entity::new("connected_gamepad_queue", |_| Vec::new());
+static IS_PAUSED: Entity<bool> = Entity::new("is_paused", |_| false);
static APPLE_LOCATION: Entity<Position> =
Entity::new("apple_location", |_| Position { x: 2, y: 2 });
static SNAKE_CELLS: Entity<Vec<Position>> = Entity::new("snake_cells", |_| {
@@ -39,10 +65,21 @@ tortuise_script::game! {
first_scene: "main",
scenes: {
"main" => TortuiseScene {
- scripts: &["snake_controller", "exit_on_escape", "move_snake", "render"],
+ scripts: &[
+ "frametime",
+ "detect_controller",
+ "update_high_score",
+ "snake_controller",
+ "exit_on_escape",
+ "move_snake",
+ "render"
+ ],
}
},
scripts: {
+ "frametime" => render_frametime::RENDER_FRAMETIME,
+ "detect_controller" => detect_controller::DETECT_CONTROLLER,
+ "update_high_score" => update_high_score::UPDATE_HIGH_SCORE,
"snake_controller" => snake_controller::SNAKE_CONTROLLER,
"exit_on_escape" => exit_on_escape::EXIT_ON_ESCAPE,
"move_snake" => move_snake::MOVE_SNAKE,