From a23f400cd91b3e23b7fdb7a317c396b4cc8dd525 Mon Sep 17 00:00:00 2001 From: Tyler Lentz Date: Tue, 4 Jun 2024 14:51:05 -0700 Subject: [PATCH 1/2] fix timer drift --- include/server/game/servergamestate.hpp | 6 +++--- include/shared/game/constants.hpp | 6 ++---- include/shared/game/sharedgamestate.hpp | 8 ++++---- include/shared/utilities/time.hpp | 4 +++- src/client/gui/gui.cpp | 2 +- src/server/game/servergamestate.cpp | 9 ++++----- src/shared/game/sharedgamestate.cpp | 2 +- src/shared/utilities/time.cpp | 6 ++++++ 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/server/game/servergamestate.hpp b/include/server/game/servergamestate.hpp index 08ed53da..773ed116 100644 --- a/include/server/game/servergamestate.hpp +++ b/include/server/game/servergamestate.hpp @@ -311,11 +311,11 @@ class ServerGameState { MatchPhase matchPhase; /** - * @brief Amount of time, in timesteps, left until the end of the match - * This value only becomes relevant when matchPhase is set to + * @brief epoch timestamp of when the match will end + * This value only becomes set when matchPhase is set to * MatchPhase::RelayRace */ - unsigned int timesteps_left; + time_t relay_finish_time; /** * @brief Player victory is by default false - only becomes true if a Player diff --git a/include/shared/game/constants.hpp b/include/shared/game/constants.hpp index 64381c25..879960f3 100644 --- a/include/shared/game/constants.hpp +++ b/include/shared/game/constants.hpp @@ -7,9 +7,7 @@ /* Game phase information */ // Time limit initially set to 5 minutes -#define TIME_LIMIT_MS std::chrono::milliseconds(300000) -//#define TIME_LIMIT_MS std::chrono::milliseconds(5 * 60 * 1000) +#define TIME_LIMIT_S std::chrono::seconds(300) /* Number of player deaths to update match state to MatchState::RelayRace */ -#define PLAYER_DEATHS_TO_RELAY_RACE 5 -//#define PLAYER_DEATHS_TO_RELAY_RACE 15 \ No newline at end of file +#define PLAYER_DEATHS_TO_RELAY_RACE 3 \ No newline at end of file diff --git a/include/shared/game/sharedgamestate.hpp b/include/shared/game/sharedgamestate.hpp index bc694cd6..5c30d952 100644 --- a/include/shared/game/sharedgamestate.hpp +++ b/include/shared/game/sharedgamestate.hpp @@ -175,7 +175,7 @@ struct SharedGameState { MatchPhase matchPhase; - unsigned int timesteps_left; + time_t relay_finish_time; bool playerVictory; @@ -188,7 +188,7 @@ struct SharedGameState { this->timestep = FIRST_TIMESTEP; this->lobby.max_players = MAX_PLAYERS; this->matchPhase = MatchPhase::MazeExploration; - this->timesteps_left = TIME_LIMIT_MS / TIMESTEP_LEN; + this->relay_finish_time = 0; this->playerVictory = false; this->numPlayerDeaths = 0; } @@ -201,14 +201,14 @@ struct SharedGameState { this->lobby.max_players = config.server.max_players; this->lobby.name = config.server.lobby_name; this->matchPhase = MatchPhase::MazeExploration; - this->timesteps_left = TIME_LIMIT_MS / TIMESTEP_LEN; + this->relay_finish_time = 0; this->playerVictory = false; this->numPlayerDeaths = 0; } DEF_SERIALIZE(Archive& ar, const unsigned int version) { ar & objects & timestep & lobby & phase & matchPhase - & timesteps_left & playerVictory & numPlayerDeaths; + & relay_finish_time & playerVictory & numPlayerDeaths; } /** diff --git a/include/shared/utilities/time.hpp b/include/shared/utilities/time.hpp index fefafbfa..3dd8cd1e 100644 --- a/include/shared/utilities/time.hpp +++ b/include/shared/utilities/time.hpp @@ -1,3 +1,5 @@ #pragma once -long long getMsSinceEpoch(); \ No newline at end of file +long long getMsSinceEpoch(); + +long long getSecSinceEpoch(); \ No newline at end of file diff --git a/src/client/gui/gui.cpp b/src/client/gui/gui.cpp index 331ad516..5681a1fd 100644 --- a/src/client/gui/gui.cpp +++ b/src/client/gui/gui.cpp @@ -1655,7 +1655,7 @@ void GUI::_layoutGameHUD() { // Add timer string if (client->gameState.matchPhase == MatchPhase::RelayRace) { std::string timerString = "Time Left: "; - int timerSeconds = client->gameState.timesteps_left * ((float)TIMESTEP_LEN.count()) / 1000; + auto timerSeconds = client->gameState.relay_finish_time - getSecSinceEpoch(); timerString += std::to_string(timerSeconds); timerString += (timerSeconds > 1) ? " seconds" : " second"; diff --git a/src/server/game/servergamestate.cpp b/src/server/game/servergamestate.cpp index 731e4ae8..db2597c8 100644 --- a/src/server/game/servergamestate.cpp +++ b/src/server/game/servergamestate.cpp @@ -52,7 +52,7 @@ ServerGameState::ServerGameState(GameConfig config) { // Initialize game instance match phase data // Match begins in MazeExploration phase (no timer) this->matchPhase = MatchPhase::MazeExploration; - this->timesteps_left = TIME_LIMIT_MS / TIMESTEP_LEN; + this->relay_finish_time = 0; // Player victory is by default false (need to collide with an open exit // while holding the Orb to win, whereas DM wins on time limit expiration) this->playerVictory = false; @@ -116,7 +116,7 @@ std::vector ServerGameState::generateSharedGameState(bool send_ curr_update.lobby = this->lobby; curr_update.phase = this->phase; curr_update.matchPhase = this->matchPhase; - curr_update.timesteps_left = this->timesteps_left; + curr_update.relay_finish_time = this->relay_finish_time; curr_update.playerVictory = this->playerVictory; curr_update.numPlayerDeaths = this->numPlayerDeaths; return curr_update; @@ -786,9 +786,7 @@ void ServerGameState::update(const EventList& events) { // Countdown timer if the Orb has been picked up by a Player and the match // phase is now RelayRace if (this->matchPhase == MatchPhase::RelayRace) { - this->timesteps_left--; - - if (this->timesteps_left == 0) { + if (std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) > this->relay_finish_time) { // Dungeon Master won on time limit expiration this->phase = GamePhase::RESULTS; } @@ -1570,6 +1568,7 @@ void ServerGameState::transitionToRelayRace() { this->matchPhase = MatchPhase::RelayRace; + this->relay_finish_time = getSecSinceEpoch() + TIME_LIMIT_S.count(); // Open all exits! for (int i = 0; i < this->objects.getExits().size(); i++) { Exit* exit = this->objects.getExits().get(i); diff --git a/src/shared/game/sharedgamestate.cpp b/src/shared/game/sharedgamestate.cpp index 81e64473..b00acbab 100644 --- a/src/shared/game/sharedgamestate.cpp +++ b/src/shared/game/sharedgamestate.cpp @@ -8,7 +8,7 @@ void SharedGameState::update(const SharedGameState& other) { this->phase = other.phase; this->timestep = other.timestep; this->matchPhase = other.matchPhase; - this->timesteps_left = other.timesteps_left; + this->relay_finish_time = other.relay_finish_time; this->playerVictory = other.playerVictory; this->numPlayerDeaths = other.numPlayerDeaths; diff --git a/src/shared/utilities/time.cpp b/src/shared/utilities/time.cpp index 729cb54f..c6c33936 100644 --- a/src/shared/utilities/time.cpp +++ b/src/shared/utilities/time.cpp @@ -7,3 +7,9 @@ long long getMsSinceEpoch() { std::chrono::system_clock::now().time_since_epoch() ).count(); } + +long long getSecSinceEpoch() { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch() + ).count(); +} From 1617106f2aad9c9bb51b47ae616472b08157cad0 Mon Sep 17 00:00:00 2001 From: Tyler Lentz Date: Tue, 4 Jun 2024 15:01:46 -0700 Subject: [PATCH 2/2] touch up lighting of rooms --- config.json | 2 +- maps/rooms/20x20/crush_axis.hard | 8 +++---- maps/rooms/20x20/dark_halls_1.hard | 8 +++---- maps/rooms/20x20/dark_halls_2.hard | 8 +++---- maps/rooms/20x20/dark_room_1.hard | 8 +++---- maps/rooms/20x20/dark_room_2.hard | 20 ++++++++-------- maps/rooms/20x20/pillar_maze_bottom_1.orb | 10 ++++---- maps/rooms/20x20/pillar_maze_bottom_2.orb | 4 ++-- maps/rooms/20x20/pillar_maze_top_1.orb | 8 +++---- maps/rooms/20x20/pillar_maze_top_2.orb | 10 ++++---- maps/rooms/20x20/teleporter_hall.hard | 28 +++++++++++------------ 11 files changed, 57 insertions(+), 57 deletions(-) diff --git a/config.json b/config.json index 89280081..73a02df0 100644 --- a/config.json +++ b/config.json @@ -2,7 +2,7 @@ "game": { "maze": { "directory": "maps", - "procedural": false, + "procedural": true, "maze_file": "test/itemRoom.maze" } }, diff --git a/maps/rooms/20x20/crush_axis.hard b/maps/rooms/20x20/crush_axis.hard index 62efa7e2..ef4cad6f 100644 --- a/maps/rooms/20x20/crush_axis.hard +++ b/maps/rooms/20x20/crush_axis.hard @@ -4,14 +4,14 @@ #..![#########..!..# .......|XXXX|....... .......|XXXX|....... -#..!..########..!..# -#..#....|..|....#..# -#..#....|..|....#..# +#..!..###[####..!..# #..#....|..|....#..# #..#....|..|....#..# +#..{....|..|....#..# +#..#....|..|....}..# {..#....|..|....#..# #..#....|..|....#..# -#..!..########..!..# +#..!..####]###..!..# .......|XXXX|....... .......|XXXX|....... #..!##[##########..# diff --git a/maps/rooms/20x20/dark_halls_1.hard b/maps/rooms/20x20/dark_halls_1.hard index eca364ab..58a05c34 100644 --- a/maps/rooms/20x20/dark_halls_1.hard +++ b/maps/rooms/20x20/dark_halls_1.hard @@ -1,20 +1,20 @@ ####..########..#### ####..########..#### ####..########..#### -####..########..#### +##[#..########..#### .......X............ ............X....... ####..###..###..#### -####..###.X###.X#### +####..###.X##{.X#### ####X.###..###..#### ####..###..###..#### ####..###..###..#### -####..###X.###..#### +####..}##X.###..#### ####.X###..###..#### ####..###..###X.#### .......X............ .............X...... -####..########..#### +####..########..#]## ####..########..#### ####..########..#### ####..########..#### \ No newline at end of file diff --git a/maps/rooms/20x20/dark_halls_2.hard b/maps/rooms/20x20/dark_halls_2.hard index f071dfb6..c952bad6 100644 --- a/maps/rooms/20x20/dark_halls_2.hard +++ b/maps/rooms/20x20/dark_halls_2.hard @@ -1,20 +1,20 @@ ####..########..#### ####..########..#### ####..###vv###..#### -####..###..###..#### +#[##..###..###..##[# .................... .................... ####..###..###..#### ####..###..###..#### ##>..............<## -####..###..###..#### +####..#]#..###..#### ####..###..###..#### ##>..............<## -####..###..###..#### +####..###..#]#..#### ####..###..###..#### .................... .............X...... -####..###..###..#### +#]##..###..###..##]# ####..###^^###..#### ####..########..#### ####..########..#### \ No newline at end of file diff --git a/maps/rooms/20x20/dark_room_1.hard b/maps/rooms/20x20/dark_room_1.hard index 6d18d4fe..ad3ef7e4 100644 --- a/maps/rooms/20x20/dark_room_1.hard +++ b/maps/rooms/20x20/dark_room_1.hard @@ -6,10 +6,10 @@ .................... ####............#### ####.............<## -##>.............#### -####.............<## -##>.............#### -####.............<## +##>......]!.....#### +####....!##!.....<## +##>.....!##!....#### +####.....![......<## ##>.............#### ####............#### .................... diff --git a/maps/rooms/20x20/dark_room_2.hard b/maps/rooms/20x20/dark_room_2.hard index 24911320..549d7b34 100644 --- a/maps/rooms/20x20/dark_room_2.hard +++ b/maps/rooms/20x20/dark_room_2.hard @@ -2,18 +2,18 @@ ####..########..#### ####..########..#### ####..########..#### -....X....X.......... -..............X..... -####..X..X......#### -####........X...#### +....X....##......... +.........##...X..... +####..X..##.....#### +###{.....##.X...}### ####.X....X.....#### -####..........X.#### -####..X....X....F.p# +#######......####### +#######....X.##F..p# ####...X.....X..#### -####............#### -####..X....X....#### -.................... -..............X..... +###{.....##.....}### +####..X..##X....#### +.........##......... +.........##...X..... ####..########..#### ####..########..#### ####..########..#### diff --git a/maps/rooms/20x20/pillar_maze_bottom_1.orb b/maps/rooms/20x20/pillar_maze_bottom_1.orb index a63a1fc0..8908c97c 100644 --- a/maps/rooms/20x20/pillar_maze_bottom_1.orb +++ b/maps/rooms/20x20/pillar_maze_bottom_1.orb @@ -1,17 +1,17 @@ #################### #################### -#################### +###[############]### ##................## ##..!.!!!.!.!.!.!.## ##........!...!...<# -##..!.!*!.!.!.!.!.## +##..!.!*!.!.}.!.!.## ##....!...........## ##..!.!!!.!.!!!.!.## -#>........!.......## -##..!.!.!.!.!.!.!.## +#>........!.......}# +##..!.!.{.!.!.!.!.## ##............!...## ##..!!!.!.!.!.!.!.## -##................<# +#{................<# ##..!.!.!.!.!.!.!.## ##..........!.....## ####..########..#### diff --git a/maps/rooms/20x20/pillar_maze_bottom_2.orb b/maps/rooms/20x20/pillar_maze_bottom_2.orb index eb9ee7be..6290969c 100644 --- a/maps/rooms/20x20/pillar_maze_bottom_2.orb +++ b/maps/rooms/20x20/pillar_maze_bottom_2.orb @@ -4,13 +4,13 @@ ##w...............## ##!!!.!!!.!.!.!.!.## ##.p......!.s.!...## -##.!!.!.![!.!.!.!.## +##.!!.!.![!.!.[.!.## ##....!...........## ##!]!.!.!.!.!!.!!.## ##..!.....!...*...## ##..!.!.!.!.!!.!!.## ##............!...## -##.!!!!.!.!.!.!.!.## +##.!![!.!.!.!.!.!.## ##................## ##..!.!.!.!.!.].!.## ##....!.!...!....p## diff --git a/maps/rooms/20x20/pillar_maze_top_1.orb b/maps/rooms/20x20/pillar_maze_top_1.orb index 2f2fa4d9..398eca2b 100644 --- a/maps/rooms/20x20/pillar_maze_top_1.orb +++ b/maps/rooms/20x20/pillar_maze_top_1.orb @@ -4,14 +4,14 @@ ##................## ##..!.!!!.!.!.!.!.## #{........!.s.!...<# -##..!.!.!.!.!.!.!.## +##..!.!.[.!.!.!.!.## ##..p.!...........## ##..!.!.!.!.!]!.!.## -#>........!.......## +#>........!.......}# ##..!.!.!!!.!.!.!.## ##............!.w.## -##..![!.!!!.!.!.!.## -##......!*........<# +##..![!.!]!.!.!.!.## +##{.....!*........<# ##..!.!.!.!.!.}.!.## ##..p.......!.....## #################### diff --git a/maps/rooms/20x20/pillar_maze_top_2.orb b/maps/rooms/20x20/pillar_maze_top_2.orb index b04cc76f..f4bb2627 100644 --- a/maps/rooms/20x20/pillar_maze_top_2.orb +++ b/maps/rooms/20x20/pillar_maze_top_2.orb @@ -2,18 +2,18 @@ ###{..}######{..}### ####..########..#### ##................## -##..!.!!!.!.!.!.!.## +##..!.!!!.].!.!.!.## #{..p.....!...!...<# ##..!.![!.!.!.!.!.## ##....!.......!...## ##..!.!.!.!.!]!.!.## #>....!.s.!.......## -##..!.!.!.!.!.!.!.## -##..........!.!.w.## -##!!![!.!!!.!.!.!.## +##..!.!.!.!.!.!.!.}# +#{..........!.!.w.## +##!!![!.!!!.[.!.!.## ##..*!...!........<# ##.!!!!.!!!.!.}.!.## -##..........!...p.## +#{..........!...p.## #################### #################### #################### diff --git a/maps/rooms/20x20/teleporter_hall.hard b/maps/rooms/20x20/teleporter_hall.hard index d1366a58..a96b4e33 100644 --- a/maps/rooms/20x20/teleporter_hall.hard +++ b/maps/rooms/20x20/teleporter_hall.hard @@ -1,20 +1,20 @@ ####..########..#### ####..##[##[##..#### -####........T...#### -###!...T........!### -...........T........ -....T.........T..... -##....T..T..T.....## -##.................# +####.....##.....#### +######...##...###### +.........##T........ +....T....##...T..... +##....T..##.T.....## +##.......!!........! #{.T....T...T...T.1# -##....T...T...T....# -#..T..............## +##....T...T...T....! +!..T..............## #2....T....T..T...}# -#..............T..## -##.T..T...T......T## -.............T...... -........T........... -###!............!### -####...T...T....#### +!........!!....T..## +##.T..T..##......T## +.........##..T...... +........T##......... +######...##...###### +####.....##.....#### ####..##]##]##..#### ####..########..#### \ No newline at end of file