summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-04-30 22:08:53 -0400
committerLLLL Colonq <llll@colonq>2026-04-30 22:08:53 -0400
commit4c9541f35913bb8e68a07ad6ab4628d241099482 (patch)
tree598e30587e9c280479d922cd8147cf0494274a49
parent5bc3f17670c8979e65eaac67787b55dfef2e87c1 (diff)
Update flake.nix
-rw-r--r--crates/teleia/src/state.rs27
-rw-r--r--crates/teleia/src/ui.rs103
-rw-r--r--flake.lock6
-rw-r--r--flake.nix13
4 files changed, 83 insertions, 66 deletions
diff --git a/crates/teleia/src/state.rs b/crates/teleia/src/state.rs
index 2e50fbf..b7b8899 100644
--- a/crates/teleia/src/state.rs
+++ b/crates/teleia/src/state.rs
@@ -72,19 +72,19 @@ impl Keys {
pub fn start(&self) -> bool { self.pressed[Key::Start] }
pub fn select(&self) -> bool { self.pressed[Key::Select] }
pub fn debug(&self) -> bool { self.pressed[Key::Debug] }
- pub fn new_up(&mut self) -> bool { let ret = self.new[Key::Up]; self.new[Key::Up] = false; ret }
- pub fn new_down(&mut self) -> bool { let ret = self.new[Key::Down]; self.new[Key::Down] = false; ret }
- pub fn new_left(&mut self) -> bool { let ret = self.new[Key::Left]; self.new[Key::Left] = false; ret }
- pub fn new_right(&mut self) -> bool { let ret = self.new[Key::Right]; self.new[Key::Right] = false; ret }
- pub fn new_a(&mut self) -> bool { let ret = self.new[Key::A]; self.new[Key::A] = false; ret }
- pub fn new_b(&mut self) -> bool { let ret = self.new[Key::B]; self.new[Key::B] = false; ret }
- pub fn new_x(&mut self) -> bool { let ret = self.new[Key::X]; self.new[Key::X] = false; ret }
- pub fn new_y(&mut self) -> bool { let ret = self.new[Key::Y]; self.new[Key::Y] = false; ret }
- pub fn new_l(&mut self) -> bool { let ret = self.new[Key::L]; self.new[Key::L] = false; ret }
- pub fn new_r(&mut self) -> bool { let ret = self.new[Key::R]; self.new[Key::R] = false; ret }
- pub fn new_start(&mut self) -> bool { let ret = self.new[Key::Start]; self.new[Key::Start] = false; ret }
- pub fn new_select(&mut self) -> bool { let ret = self.new[Key::Select]; self.new[Key::Select] = false; ret }
- pub fn new_debug(&mut self) -> bool { let ret = self.new[Key::Debug]; self.new[Key::Debug] = false; ret }
+ pub fn new_up(&self) -> bool { self.new[Key::Up] }
+ pub fn new_down(&self) -> bool { self.new[Key::Down] }
+ pub fn new_left(&self) -> bool { self.new[Key::Left] }
+ pub fn new_right(&self) -> bool { self.new[Key::Right] }
+ pub fn new_a(&self) -> bool { self.new[Key::A] }
+ pub fn new_b(&self) -> bool { self.new[Key::B] }
+ pub fn new_x(&self) -> bool { self.new[Key::X] }
+ pub fn new_y(&self) -> bool { self.new[Key::Y] }
+ pub fn new_l(&self) -> bool { self.new[Key::L] }
+ pub fn new_r(&self) -> bool { self.new[Key::R] }
+ pub fn new_start(&self) -> bool { self.new[Key::Start] }
+ pub fn new_select(&self) -> bool { self.new[Key::Select] }
+ pub fn new_debug(&self) -> bool { self.new[Key::Debug] }
}
pub struct PointLight {
@@ -544,6 +544,7 @@ impl State {
self.tick += 1;
self.frames_this_second += 1;
game.update(ctx, self)?;
+ self.keys.new = enum_map! { _ => false };
}
if now - self.start_this_second > 1.0 { // track FPS
self.start_this_second = now;
diff --git a/crates/teleia/src/ui.rs b/crates/teleia/src/ui.rs
index 09afdf9..056f78a 100644
--- a/crates/teleia/src/ui.rs
+++ b/crates/teleia/src/ui.rs
@@ -1,4 +1,4 @@
-use crate::utils;
+use crate::{state, utils};
fn compute_reverse(frames: u64, tick: u64, start: u64) -> u64 {
let leftover = frames - (tick - start)
@@ -14,7 +14,6 @@ pub enum ModeToggle {
pub struct Mode {
frames: u64,
toggle: ModeToggle,
- locked: bool,
}
impl Mode {
@@ -22,7 +21,6 @@ impl Mode {
Self {
frames,
toggle: ModeToggle::Inactive { start: 0 },
- locked: false,
}
}
@@ -34,10 +32,6 @@ impl Mode {
}
}
- pub fn is_locked(&self) -> bool {
- self.locked
- }
-
/// Has the current transition finished?
pub fn is_ready(&self, tick: u64) -> bool {
let started = match self.toggle {
@@ -61,35 +55,22 @@ impl Mode {
}
pub fn reset(&mut self) {
- self.locked = false;
self.toggle = ModeToggle::Inactive { start: 0 };
}
- pub fn reverse(&mut self, tick: u64) -> bool {
- if !self.locked {
- self.locked = true;
- match self.toggle {
- ModeToggle::Inactive { start } => {
- self.toggle = ModeToggle::Active {
- start: compute_reverse(self.frames, tick, start)
- };
- },
- ModeToggle::Active { start } => {
- self.toggle = ModeToggle::Inactive {
- start: compute_reverse(self.frames, tick, start)
- };
- },
- }
- true
- } else { false }
- }
-
- pub fn lock(&mut self) {
- self.locked = true;
- }
-
- pub fn unlock(&mut self) {
- self.locked = false;
+ pub fn toggle(&mut self, tick: u64) {
+ match self.toggle {
+ ModeToggle::Inactive { start } => {
+ self.toggle = ModeToggle::Active {
+ start: compute_reverse(self.frames, tick, start)
+ };
+ },
+ ModeToggle::Active { start } => {
+ self.toggle = ModeToggle::Inactive {
+ start: compute_reverse(self.frames, tick, start)
+ };
+ },
+ }
}
}
@@ -99,7 +80,6 @@ pub struct Cursor {
pub change_started: u64,
pub bound: i32,
pub frames: u64,
- pub locked: bool,
}
impl Cursor {
@@ -110,7 +90,6 @@ impl Cursor {
change_started: 0,
bound,
frames,
- locked: false,
}
}
@@ -129,25 +108,63 @@ impl Cursor {
}
pub fn set(&mut self, val: i32, tick: u64) -> bool {
- if self.is_ready(tick) || !self.locked {
+ if self.is_ready(tick) {
self.change_started = tick;
self.prev_index = self.index;
self.index = val;
self.index %= self.bound;
- self.locked = true;
true
} else { false }
}
+ pub fn increment(&mut self, tick: u64) -> bool { self.set(self.index + 1, tick) }
+ pub fn decrement(&mut self, tick: u64) -> bool { self.set(self.index + self.bound - 1, tick) }
- pub fn increment(&mut self, tick: u64) -> bool {
- self.set(self.index + 1, tick)
+ pub fn set_unlocked(&mut self, val: i32, tick: u64) {
+ self.change_started = tick;
+ self.prev_index = self.index;
+ self.index = val;
+ self.index %= self.bound;
}
+ pub fn increment_unlocked(&mut self, tick: u64) -> bool { self.set_unlocked(self.index + 1, tick); true }
+ pub fn decrement_unlocked(&mut self, tick: u64) -> bool { self.set_unlocked(self.index + self.bound - 1, tick); true }
- pub fn decrement(&mut self, tick: u64) -> bool {
- self.set(self.index + self.bound - 1, tick)
+ /// Read keypresses to update this cursor (assuming that the left/right keys decrement/increment)
+ /// Returns true if an update was performed (e.g. to determine whether to play a sound).
+ pub fn update_horizontal(&mut self, st: &state::State) -> bool {
+ if st.keys.new_left() {
+ self.decrement_unlocked(st.tick);
+ true
+ } else if st.keys.new_right() {
+ self.increment_unlocked(st.tick);
+ true
+ } else if st.keys.left() {
+ self.decrement(st.tick)
+ } else if st.keys.right() {
+ self.increment(st.tick)
+ } else { false }
}
- pub fn unlock(&mut self) {
- self.locked = false;
+ pub fn update_vertical(&mut self, st: &state::State) -> bool {
+ if st.keys.new_up() {
+ self.decrement_unlocked(st.tick)
+ } else if st.keys.new_down() {
+ self.increment_unlocked(st.tick)
+ } else if st.keys.up() {
+ self.decrement(st.tick)
+ } else if st.keys.down() {
+ self.increment(st.tick)
+ } else { false }
+ }
+
+ pub fn update_lr(&mut self, st: &state::State) -> bool {
+ if st.keys.new_l() {
+ self.decrement_unlocked(st.tick)
+ } else if st.keys.new_r() {
+ self.increment_unlocked(st.tick)
+ } else if st.keys.l() {
+ self.decrement(st.tick)
+ } else if st.keys.r() {
+ self.increment(st.tick)
+ } else { false }
}
}
diff --git a/flake.lock b/flake.lock
index 7d433fa..4bcf437 100644
--- a/flake.lock
+++ b/flake.lock
@@ -53,11 +53,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1753432016,
- "narHash": "sha256-cnL5WWn/xkZoyH/03NNUS7QgW5vI7D1i74g48qplCvg=",
+ "lastModified": 1777425547,
+ "narHash": "sha256-d57AbflkNfZNoFaZDzssEq1RfPoM9dLtOGI2O+N/68Q=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "6027c30c8e9810896b92429f0092f624f7b1aace",
+ "rev": "ebc08544afa77957cc348ba72dc490ec73b87f68",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 7aea32e..04dcf96 100644
--- a/flake.nix
+++ b/flake.nix
@@ -56,13 +56,13 @@
buildInputs = [
pkgs.openssl.dev
glfw
- pkgs.xorg.libX11
- pkgs.xorg.libXcursor
- pkgs.xorg.libXi
- pkgs.xorg.libXrandr
- pkgs.xorg.libXinerama
+ pkgs.libX11
+ pkgs.libXcursor
+ pkgs.libXi
+ pkgs.libXrandr
+ pkgs.libXinerama
pkgs.libxkbcommon
- pkgs.xorg.libxcb
+ pkgs.libxcb
pkgs.libglvnd
pkgs.alsa-lib
];
@@ -230,7 +230,6 @@
packages = [
pkgs.trunk
pkgs.rust-analyzer
- pkgs.glxinfo
pkgs.cmake
pkgs.mold
] ++ native.nativeBuildInputs ++ native.buildInputs;