1
0
Fork 0
mirror of https://codeberg.org/demostf/sync.git synced 2026-06-03 08:34:08 +02:00

add sync for speed

This commit is contained in:
Robin Appelman 2025-06-22 22:57:51 +02:00
commit d94395de63
4 changed files with 15 additions and 8 deletions

8
flake.lock generated
View file

@ -59,16 +59,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1746557022,
"narHash": "sha256-QkNoyEf6TbaTW5UZYX0OkwIJ/ZMeKSSoOMnSDPQuol0=",
"lastModified": 1750400657,
"narHash": "sha256-3vkjFnxCOP6vm5Pm13wC/Zy6/VYgei/I/2DWgW4RFeA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1d3aeb5a193b9ff13f63f4d9cc169fb88129f860",
"rev": "b2485d56967598da068b5a6946dadda8bfcbcd37",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-24.11",
"ref": "nixos-25.05",
"type": "indirect"
}
},

View file

@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-24.11";
nixpkgs.url = "nixpkgs/nixos-25.05";
flakelight = {
url = "github:nix-community/flakelight";
inputs.nixpkgs.follows = "nixpkgs";

View file

@ -39,6 +39,7 @@ pub enum SyncCommand<'a> {
Join { session: &'a str },
Tick { session: &'a str, tick: u64 },
Play { session: &'a str, play: bool },
Speed { session: &'a str, speed: f32 },
Clients { session: &'a str, count: usize },
}
@ -121,6 +122,7 @@ impl Server {
None => error!(session = session_name, "session not found for command"),
},
session_command @ (SyncCommand::Play { session, .. }
| SyncCommand::Speed { session, .. }
| SyncCommand::Tick { session, .. }) => match self.sessions.get_mut(*session) {
Some(mut session) => {
if session.owner == sender {

View file

@ -7,6 +7,7 @@ pub struct Session {
owner_token: String,
clients: Vec<PeerId>,
tick: u64,
speed: f32,
playing: bool,
owner_left: Option<Instant>,
pub token: String,
@ -26,6 +27,7 @@ impl Session {
clients: Vec::new(),
playing: false,
tick: 0,
speed: 1.0,
owner_left: None,
token,
}
@ -57,6 +59,10 @@ impl Session {
session: &self.token,
play: self.playing,
},
SyncCommand::Speed {
session: &self.token,
speed: self.speed,
},
]
.into_iter()
}
@ -71,10 +77,9 @@ impl Session {
pub fn handle_command(&mut self, command: &SyncCommand) {
match command {
SyncCommand::Tick { tick, .. } => {
self.tick = *tick;
}
SyncCommand::Tick { tick, .. } => self.tick = *tick,
SyncCommand::Play { play, .. } => self.playing = *play,
SyncCommand::Speed { speed, .. } => self.speed = *speed,
_ => {}
}
}