Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
GameState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include "Event.hpp"
6#include "VisualState.hpp"
7#include "WorldState.hpp"
9
15class GameState {
16 public:
18 int timeUnit = -1;
19 std::string winnerTeam = "";
20 int gameDurationSeconds = -1; // gwt: time the winner took to win (-1 = not yet received)
21 int64_t gameDurationTicks = -1; // gwt: same in game-time ticks (-1 = not yet received)
22 float tileSize = 1.0f;
23 unsigned int serverUptimeSeconds = 0;
24 bool receivedStuResponse = false;
25
30 void applyEvent(const Event& e);
31
37 bool isDirty() const { return dirty; }
38
44 void clearDirty() const { dirty = false; }
45
46 private:
47 mutable bool dirty = false;
48
49 void _applyMapSize(const MapSize& e);
50 void _applyTileContent(const TileContent& e);
51 void _applyTeamName(const TeamName& e);
52 void _applyPlayerNew(const PlayerNew& e);
54 void _applyPlayerLevel(const PlayerLevel& e);
60 void _applyPlayerFork(const PlayerFork& e);
63 void _applyPlayerDeath(const PlayerDeath& e);
64 void _applyEggNew(const EggNew& e);
65 void _applyEggHatch(const EggHatch& e);
66 void _applyEggDeath(const EggDeath& e);
67 void _applyTimeUnit(const TimeUnit& e);
69 void _applyGameEnd(const GameEnd& e);
70 void _applyServerUptime(const ServerUptime& e);
72 void _applyWinDuration(const WinDuration& e);
73
74 static void _pushBehavior(VisualState& visual, std::unique_ptr<IBehavior> b);
75};
std::variant< MapSize, TileContent, TeamName, PlayerNew, PlayerPosition, PlayerLevel, PlayerInventory, PlayerExpulsion, PlayerBroadcast, IncantationStart, IncantationEnd, PlayerFork, PlayerResourceDrop, PlayerResourceTake, PlayerDeath, EggNew, EggHatch, EggDeath, TimeUnit, TimeUnitChange, GameEnd, ServerMessage, UnknownCommand, BadParameters, ServerUptime, ServerSpawnedEgg, WinDuration > Event
Represents an event received from the server. Is a variant of all possible events,...
Definition Event.hpp:188
Represents the current state of the game. Knows the world state, some metadata, and how to apply even...
Definition GameState.hpp:15
bool isDirty() const
Checks if the game state has been modified since the last time it was cleared (dirty flag).
Definition GameState.hpp:37
unsigned int serverUptimeSeconds
Definition GameState.hpp:23
WorldState world
Definition GameState.hpp:17
void _applyPlayerInventory(const PlayerInventory &e)
int64_t gameDurationTicks
Definition GameState.hpp:21
void _applyTimeUnitChange(const TimeUnitChange &e)
std::string winnerTeam
Definition GameState.hpp:19
void _applyIncantationStart(const IncantationStart &e)
static void _pushBehavior(VisualState &visual, std::unique_ptr< IBehavior > b)
void _applyServerUptime(const ServerUptime &e)
float tileSize
Definition GameState.hpp:22
void _applyTileContent(const TileContent &e)
Definition GameState.cpp:88
void _applyPlayerDeath(const PlayerDeath &e)
void clearDirty() const
Sets the dirty flag to false.
Definition GameState.hpp:44
void _applyPlayerResourceDrop(const PlayerResourceDrop &e)
void _applyTeamName(const TeamName &e)
Definition GameState.cpp:90
void _applyPlayerBroadcast(const PlayerBroadcast &e)
void _applyPlayerExpulsion(const PlayerExpulsion &e)
void _applyMapSize(const MapSize &e)
Definition GameState.cpp:81
void _applyPlayerLevel(const PlayerLevel &e)
void _applyTimeUnit(const TimeUnit &e)
void _applyServerSpawnedEgg(const ServerSpawnedEgg &e)
void _applyEggNew(const EggNew &e)
void _applyEggDeath(const EggDeath &e)
void applyEvent(const Event &e)
Applies an event to the game state, modifying it accordingly and setting the dirty flag.
Definition GameState.cpp:17
void _applyPlayerResourceTake(const PlayerResourceTake &e)
void _applyEggHatch(const EggHatch &e)
bool receivedStuResponse
Definition GameState.hpp:24
void _applyIncantationEnd(const IncantationEnd &e)
void _applyPlayerNew(const PlayerNew &e)
Definition GameState.cpp:92
void _applyWinDuration(const WinDuration &e)
void _applyPlayerFork(const PlayerFork &e)
void _applyPlayerPosition(const PlayerPosition &e)
int gameDurationSeconds
Definition GameState.hpp:20
void _applyGameEnd(const GameEnd &e)
Visual-only state for an entity, driven by behaviors each frame. Logical state (x,...
Represents the state of the world in the game, including the map size, tile contents,...