Skip to content

Commit 3eb3023

Browse files
Also use TPS const in server
1 parent fe6ddd4 commit 3eb3023

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

server/src/server/gamestate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rand::{thread_rng, Rng};
1111
use self::super::Client;
1212
use self::super::WebSocketEvent;
1313

14+
// TODO: substitute when doing config, see `mod.rs`
1415
const TPS: u32 = 60;
1516
static BULLET_RADIUS: f32 = 5.0;
1617
static PLAYER_RADIUS: f32 = 10.0;

server/src/server/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use std::time::Duration;
2727
pub use self::events::*;
2828
pub use self::gamestate::GameState;
2929

30+
// TODO: substitute when doing config, see `mod.rs`
31+
const TPS: f32 = 60.0;
32+
3033
/// The main listening loop for the server.
3134
pub fn listen(host: &str,
3235
port: u16,
@@ -61,11 +64,11 @@ pub fn listen(host: &str,
6164

6265
/// Spawns the main game loop in a separate thread and returns the handle therefor. Non-blocking.
6366
///
64-
/// The general idea for the game loop is to update the game state every 16 milliseconds (60 FPS), processing messages along the way.
67+
/// The general idea for the game loop is to update the game state every 1/TPS milliseconds, processing messages along the way.
6568
pub fn start_game_loop(game_messages: mpsc::Receiver<WebSocketEvent>,
6669
cont: &Arc<RwLock<bool>>)
6770
-> thread::JoinHandle<()> {
68-
static ITER_LENGTH: u64 = 16 * 1000000; // 16 milliseconds
71+
static ITER_LENGTH: u64 = (1.0 / TPS * 1000.0) as u64 * 1000000; // 1/TPS milliseconds
6972

7073
let cont = cont.clone();
7174
thread::spawn(move || {

0 commit comments

Comments
 (0)