mirror of
https://codeberg.org/demostf/sync.git
synced 2026-06-03 16:44:07 +02:00
add sync for speed
This commit is contained in:
parent
74df62fe9c
commit
d94395de63
4 changed files with 15 additions and 8 deletions
8
flake.lock
generated
8
flake.lock
generated
|
|
@ -59,16 +59,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1746557022,
|
"lastModified": 1750400657,
|
||||||
"narHash": "sha256-QkNoyEf6TbaTW5UZYX0OkwIJ/ZMeKSSoOMnSDPQuol0=",
|
"narHash": "sha256-3vkjFnxCOP6vm5Pm13wC/Zy6/VYgei/I/2DWgW4RFeA=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "1d3aeb5a193b9ff13f63f4d9cc169fb88129f860",
|
"rev": "b2485d56967598da068b5a6946dadda8bfcbcd37",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-24.11",
|
"ref": "nixos-25.05",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "nixpkgs/nixos-24.11";
|
nixpkgs.url = "nixpkgs/nixos-25.05";
|
||||||
flakelight = {
|
flakelight = {
|
||||||
url = "github:nix-community/flakelight";
|
url = "github:nix-community/flakelight";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ pub enum SyncCommand<'a> {
|
||||||
Join { session: &'a str },
|
Join { session: &'a str },
|
||||||
Tick { session: &'a str, tick: u64 },
|
Tick { session: &'a str, tick: u64 },
|
||||||
Play { session: &'a str, play: bool },
|
Play { session: &'a str, play: bool },
|
||||||
|
Speed { session: &'a str, speed: f32 },
|
||||||
Clients { session: &'a str, count: usize },
|
Clients { session: &'a str, count: usize },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,6 +122,7 @@ impl Server {
|
||||||
None => error!(session = session_name, "session not found for command"),
|
None => error!(session = session_name, "session not found for command"),
|
||||||
},
|
},
|
||||||
session_command @ (SyncCommand::Play { session, .. }
|
session_command @ (SyncCommand::Play { session, .. }
|
||||||
|
| SyncCommand::Speed { session, .. }
|
||||||
| SyncCommand::Tick { session, .. }) => match self.sessions.get_mut(*session) {
|
| SyncCommand::Tick { session, .. }) => match self.sessions.get_mut(*session) {
|
||||||
Some(mut session) => {
|
Some(mut session) => {
|
||||||
if session.owner == sender {
|
if session.owner == sender {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ pub struct Session {
|
||||||
owner_token: String,
|
owner_token: String,
|
||||||
clients: Vec<PeerId>,
|
clients: Vec<PeerId>,
|
||||||
tick: u64,
|
tick: u64,
|
||||||
|
speed: f32,
|
||||||
playing: bool,
|
playing: bool,
|
||||||
owner_left: Option<Instant>,
|
owner_left: Option<Instant>,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
|
|
@ -26,6 +27,7 @@ impl Session {
|
||||||
clients: Vec::new(),
|
clients: Vec::new(),
|
||||||
playing: false,
|
playing: false,
|
||||||
tick: 0,
|
tick: 0,
|
||||||
|
speed: 1.0,
|
||||||
owner_left: None,
|
owner_left: None,
|
||||||
token,
|
token,
|
||||||
}
|
}
|
||||||
|
|
@ -57,6 +59,10 @@ impl Session {
|
||||||
session: &self.token,
|
session: &self.token,
|
||||||
play: self.playing,
|
play: self.playing,
|
||||||
},
|
},
|
||||||
|
SyncCommand::Speed {
|
||||||
|
session: &self.token,
|
||||||
|
speed: self.speed,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
}
|
}
|
||||||
|
|
@ -71,10 +77,9 @@ impl Session {
|
||||||
|
|
||||||
pub fn handle_command(&mut self, command: &SyncCommand) {
|
pub fn handle_command(&mut self, command: &SyncCommand) {
|
||||||
match command {
|
match command {
|
||||||
SyncCommand::Tick { tick, .. } => {
|
SyncCommand::Tick { tick, .. } => self.tick = *tick,
|
||||||
self.tick = *tick;
|
|
||||||
}
|
|
||||||
SyncCommand::Play { play, .. } => self.playing = *play,
|
SyncCommand::Play { play, .. } => self.playing = *play,
|
||||||
|
SyncCommand::Speed { speed, .. } => self.speed = *speed,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue