File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use rand::{thread_rng, Rng};
1111use self :: super :: Client ;
1212use self :: super :: WebSocketEvent ;
1313
14+ // TODO: substitute when doing config, see `mod.rs`
1415const TPS : u32 = 60 ;
1516static BULLET_RADIUS : f32 = 5.0 ;
1617static PLAYER_RADIUS : f32 = 10.0 ;
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ use std::time::Duration;
2727pub use self :: events:: * ;
2828pub 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.
3134pub 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.
6568pub 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 || {
You can’t perform that action at this time.
0 commit comments