From 398027b443cfb331fee64cf351036ca45502ae1b Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Fri, 29 Jan 2021 11:16:03 +0100 Subject: rstnode: update dependencies and fixing game build --- games/rstnode/src/_if.rs | 13 +++++++++++-- games/rstnode/src/_loop.rs | 1 + games/rstnode/src/_match.rs | 8 ++++---- games/rstnode/src/lib.rs | 25 ++++++++++++++----------- games/rstnode/src/server.rs | 5 +++++ 5 files changed, 35 insertions(+), 17 deletions(-) (limited to 'games/rstnode/src') diff --git a/games/rstnode/src/_if.rs b/games/rstnode/src/_if.rs index 59d80fb165af..1a842840708c 100644 --- a/games/rstnode/src/_if.rs +++ b/games/rstnode/src/_if.rs @@ -8,7 +8,12 @@ use async_std::sync::Arc; use async_trait::async_trait; use chrono::{DateTime, Utc}; -/// The main game interface implemented by the server and client +/// Main game interface implemented by the server and client +/// +/// The client implementation simply translates requests to network +/// requests that are sent to the server. The server implementation +/// consists of two parts: the network layer listening loop, and the +/// game server state which then implements the actual game logic. #[async_trait] pub trait GameIf { /// Register a new user on a game server @@ -38,7 +43,11 @@ pub trait GameIf { ) -> Result; /// Send a start request (as lobby admin) - async fn start_req(self: Arc, user: UserId, lobby: LobbyId) -> Result, LobbyErr>; + async fn start_req( + self: Arc, + user: UserId, + lobby: LobbyId, + ) -> Result, LobbyErr>; /// Perform a game action as a user async fn perform_action(self: Arc, user: User, mtch: MatchId, act: Action) diff --git a/games/rstnode/src/_loop.rs b/games/rstnode/src/_loop.rs index 7ba7ad7cdd27..862325490322 100644 --- a/games/rstnode/src/_loop.rs +++ b/games/rstnode/src/_loop.rs @@ -11,6 +11,7 @@ use std::{ }; /// Number of ticks per second +#[from_env("RSTNODE_TICKS")] const TICKS: u64 = 100; const TICK_TIME: Duration = Duration::from_millis(1000 / TICKS); diff --git a/games/rstnode/src/_match.rs b/games/rstnode/src/_match.rs index 53f4d2604fe4..6ae69c54e935 100644 --- a/games/rstnode/src/_match.rs +++ b/games/rstnode/src/_match.rs @@ -17,7 +17,7 @@ pub struct Match { pub players: Vec, /// The active game map pub map: Map, - /// Input inbox, + /// Input inbox (handled in-order each game tick) inbox: RwLock>, /// The time the match was initialised init_t: DateTime, @@ -59,9 +59,9 @@ impl Match { self.inbox.write().await.push_back(cmd); } - pub async fn handle_inbex(&mut self) { - for act in self.inbox.write().await.drain() { + pub async fn handle_inbox(&mut self) { + // for act in self.inbox.write().await.drain() { - } + // } } } diff --git a/games/rstnode/src/lib.rs b/games/rstnode/src/lib.rs index 94117ddbcffc..e063da34d8bf 100644 --- a/games/rstnode/src/lib.rs +++ b/games/rstnode/src/lib.rs @@ -1,21 +1,24 @@ #![allow(warnings)] +#[macro_use] +extern crate const_env; + mod _if; pub use _if::GameIf; pub mod data; pub mod gens; -mod _loop; -mod _match; -mod config; -mod io; -mod lobby; -mod map; -mod mapstore; -mod server; -mod stats; -mod users; -mod wire; +pub mod _loop; +pub mod _match; +pub mod config; +pub mod io; +pub mod lobby; +pub mod map; +pub mod mapstore; +pub mod server; +pub mod stats; +pub mod users; +pub mod wire; pub use identity::Identity as Id; diff --git a/games/rstnode/src/server.rs b/games/rstnode/src/server.rs index 7a2fad27bb1f..3d95c3638c98 100644 --- a/games/rstnode/src/server.rs +++ b/games/rstnode/src/server.rs @@ -1,3 +1,8 @@ +//! Game server state handler +//! +//! A server can host many lobbies at the same time. It listens for +//! connections according to a address given to the initialiser. + use crate::{ _if::GameIf, _match::Match, -- cgit v1.2.3