Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
GameState Class Reference

Represents the current state of the game. Knows the world state, some metadata, and how to apply events to update itself. Also tracks whether it has been modified since the last time it was cleared (dirty flag). More...

#include <GameState.hpp>

+ Collaboration diagram for GameState:

Public Member Functions

void applyEvent (const Event &e)
 Applies an event to the game state, modifying it accordingly and setting the dirty flag.
 
bool isDirty () const
 Checks if the game state has been modified since the last time it was cleared (dirty flag).
 
void clearDirty () const
 Sets the dirty flag to false.
 

Public Attributes

WorldState world
 
int timeUnit = -1
 
std::string winnerTeam = ""
 
int gameDurationSeconds = -1
 
int64_t gameDurationTicks = -1
 
float tileSize = 1.0f
 
unsigned int serverUptimeSeconds = 0
 
bool receivedStuResponse = false
 

Private Member Functions

void _applyMapSize (const MapSize &e)
 
void _applyTileContent (const TileContent &e)
 
void _applyTeamName (const TeamName &e)
 
void _applyPlayerNew (const PlayerNew &e)
 
void _applyPlayerPosition (const PlayerPosition &e)
 
void _applyPlayerLevel (const PlayerLevel &e)
 
void _applyPlayerInventory (const PlayerInventory &e)
 
void _applyPlayerExpulsion (const PlayerExpulsion &e)
 
void _applyPlayerBroadcast (const PlayerBroadcast &e)
 
void _applyIncantationStart (const IncantationStart &e)
 
void _applyIncantationEnd (const IncantationEnd &e)
 
void _applyPlayerFork (const PlayerFork &e)
 
void _applyPlayerResourceDrop (const PlayerResourceDrop &e)
 
void _applyPlayerResourceTake (const PlayerResourceTake &e)
 
void _applyPlayerDeath (const PlayerDeath &e)
 
void _applyEggNew (const EggNew &e)
 
void _applyEggHatch (const EggHatch &e)
 
void _applyEggDeath (const EggDeath &e)
 
void _applyTimeUnit (const TimeUnit &e)
 
void _applyTimeUnitChange (const TimeUnitChange &e)
 
void _applyGameEnd (const GameEnd &e)
 
void _applyServerUptime (const ServerUptime &e)
 
void _applyServerSpawnedEgg (const ServerSpawnedEgg &e)
 
void _applyWinDuration (const WinDuration &e)
 

Static Private Member Functions

static void _pushBehavior (VisualState &visual, std::unique_ptr< IBehavior > b)
 

Private Attributes

bool dirty = false
 

Detailed Description

Represents the current state of the game. Knows the world state, some metadata, and how to apply events to update itself. Also tracks whether it has been modified since the last time it was cleared (dirty flag).

Definition at line 15 of file GameState.hpp.

Member Function Documentation

◆ _applyEggDeath()

void GameState::_applyEggDeath ( const EggDeath e)
private

Definition at line 256 of file GameState.cpp.

References WorldState::eggs, EggDeath::id, and world.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyEggHatch()

void GameState::_applyEggHatch ( const EggHatch e)
private

Definition at line 250 of file GameState.cpp.

References WorldState::eggs, EggHatch::id, and world.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyEggNew()

void GameState::_applyEggNew ( const EggNew e)
private

Definition at line 236 of file GameState.cpp.

References _pushBehavior(), EggNew::eggId, WorldState::eggs, WorldState::height, Egg::id, EggNew::playerId, WorldState::players, tileSize, RenderingHelper::tileToWorld(), timeUnit, WorldState::width, world, EggNew::x, and EggNew::y.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyGameEnd()

void GameState::_applyGameEnd ( const GameEnd e)
private

Definition at line 262 of file GameState.cpp.

References winnerTeam, and GameEnd::winningTeam.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyIncantationEnd()

void GameState::_applyIncantationEnd ( const IncantationEnd e)
private

Definition at line 189 of file GameState.cpp.

References WorldState::players, IncantationEnd::success, world, IncantationEnd::x, and IncantationEnd::y.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyIncantationStart()

void GameState::_applyIncantationStart ( const IncantationStart e)
private

Definition at line 168 of file GameState.cpp.

References _pushBehavior(), WorldState::height, IncantationStart::playerIds, WorldState::players, tileSize, timeUnit, WorldState::width, world, IncantationStart::x, and IncantationStart::y.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyMapSize()

void GameState::_applyMapSize ( const MapSize e)
private

Definition at line 81 of file GameState.cpp.

References MapSize::height, WorldState::height, WorldState::tiles, MapSize::width, WorldState::width, and world.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyPlayerBroadcast()

void GameState::_applyPlayerBroadcast ( const PlayerBroadcast e)
private

Definition at line 156 of file GameState.cpp.

References _pushBehavior(), WorldState::height, PlayerBroadcast::id, WorldState::players, timeUnit, WorldState::width, and world.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyPlayerDeath()

void GameState::_applyPlayerDeath ( const PlayerDeath e)
private

Definition at line 223 of file GameState.cpp.

References _pushBehavior(), VisualState::behaviors, WorldState::dyingPlayers, PlayerDeath::id, WorldState::players, timeUnit, and world.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyPlayerExpulsion()

void GameState::_applyPlayerExpulsion ( const PlayerExpulsion e)
private

Definition at line 151 of file GameState.cpp.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyPlayerFork()

void GameState::_applyPlayerFork ( const PlayerFork e)
private

Definition at line 200 of file GameState.cpp.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyPlayerInventory()

void GameState::_applyPlayerInventory ( const PlayerInventory e)
private

Definition at line 143 of file GameState.cpp.

References PlayerInventory::id, PlayerInventory::inventory, WorldState::players, and world.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyPlayerLevel()

void GameState::_applyPlayerLevel ( const PlayerLevel e)
private

Definition at line 134 of file GameState.cpp.

References _pushBehavior(), PlayerLevel::id, PlayerLevel::level, WorldState::players, timeUnit, and world.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyPlayerNew()

void GameState::_applyPlayerNew ( const PlayerNew e)
private

Definition at line 92 of file GameState.cpp.

References WorldState::height, PlayerNew::id, PlayerNew::orientation, WorldState::players, tileSize, RenderingHelper::tileToWorld(), toAngle(), WorldState::width, world, PlayerNew::x, and PlayerNew::y.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyPlayerPosition()

void GameState::_applyPlayerPosition ( const PlayerPosition e)
private

Definition at line 105 of file GameState.cpp.

References _pushBehavior(), VisualState::angle, VisualState::behaviors, WorldState::height, PlayerPosition::id, Player::orientation, PlayerPosition::orientation, WorldState::players, tileSize, timeUnit, toAngle(), WorldState::width, world, Player::x, PlayerPosition::x, Player::y, and PlayerPosition::y.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyPlayerResourceDrop()

void GameState::_applyPlayerResourceDrop ( const PlayerResourceDrop e)
private

Definition at line 205 of file GameState.cpp.

References WorldState::at(), PlayerResourceDrop::playerId, WorldState::players, PlayerResourceDrop::resourceId, and world.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyPlayerResourceTake()

void GameState::_applyPlayerResourceTake ( const PlayerResourceTake e)
private

Definition at line 214 of file GameState.cpp.

References WorldState::at(), PlayerResourceTake::playerId, WorldState::players, PlayerResourceTake::resourceId, and world.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyServerSpawnedEgg()

void GameState::_applyServerSpawnedEgg ( const ServerSpawnedEgg e)
private

Definition at line 270 of file GameState.cpp.

References _pushBehavior(), ServerSpawnedEgg::eggId, WorldState::eggs, WorldState::height, Egg::id, ServerSpawnedEgg::team, tileSize, RenderingHelper::tileToWorld(), timeUnit, WorldState::width, world, ServerSpawnedEgg::x, and ServerSpawnedEgg::y.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyServerUptime()

void GameState::_applyServerUptime ( const ServerUptime e)
private

Definition at line 264 of file GameState.cpp.

References receivedStuResponse, serverUptimeSeconds, and ServerUptime::uptimeSeconds.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyTeamName()

void GameState::_applyTeamName ( const TeamName e)
private

Definition at line 90 of file GameState.cpp.

References TeamName::name, WorldState::teams, and world.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyTileContent()

void GameState::_applyTileContent ( const TileContent e)
private

Definition at line 88 of file GameState.cpp.

References WorldState::at(), TileContent::resources, world, TileContent::x, and TileContent::y.

Referenced by applyEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _applyTimeUnit()

void GameState::_applyTimeUnit ( const TimeUnit e)
private

Definition at line 258 of file GameState.cpp.

References TimeUnit::timeUnit, and timeUnit.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyTimeUnitChange()

void GameState::_applyTimeUnitChange ( const TimeUnitChange e)
private

Definition at line 260 of file GameState.cpp.

References TimeUnitChange::timeUnit, and timeUnit.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _applyWinDuration()

void GameState::_applyWinDuration ( const WinDuration e)
private

Definition at line 280 of file GameState.cpp.

References gameDurationSeconds, gameDurationTicks, WinDuration::seconds, and WinDuration::ticks.

Referenced by applyEvent().

+ Here is the caller graph for this function:

◆ _pushBehavior()

void GameState::_pushBehavior ( VisualState visual,
std::unique_ptr< IBehavior b 
)
staticprivate

Definition at line 286 of file GameState.cpp.

References VisualState::behaviors.

Referenced by _applyEggNew(), _applyIncantationStart(), _applyPlayerBroadcast(), _applyPlayerDeath(), _applyPlayerLevel(), _applyPlayerPosition(), and _applyServerSpawnedEgg().

+ Here is the caller graph for this function:

◆ applyEvent()

void GameState::applyEvent ( const Event e)

Applies an event to the game state, modifying it accordingly and setting the dirty flag.

Definition at line 17 of file GameState.cpp.

References _applyEggDeath(), _applyEggHatch(), _applyEggNew(), _applyGameEnd(), _applyIncantationEnd(), _applyIncantationStart(), _applyMapSize(), _applyPlayerBroadcast(), _applyPlayerDeath(), _applyPlayerExpulsion(), _applyPlayerFork(), _applyPlayerInventory(), _applyPlayerLevel(), _applyPlayerNew(), _applyPlayerPosition(), _applyPlayerResourceDrop(), _applyPlayerResourceTake(), _applyServerSpawnedEgg(), _applyServerUptime(), _applyTeamName(), _applyTileContent(), _applyTimeUnit(), _applyTimeUnitChange(), _applyWinDuration(), and dirty.

Referenced by App::run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearDirty()

void GameState::clearDirty ( ) const
inline

Sets the dirty flag to false.

Note
This should be called after the game state has been rendered or processed, to indicate that it is now clean.

Definition at line 44 of file GameState.hpp.

References dirty.

Referenced by HeadlessRenderer::render().

+ Here is the caller graph for this function:

◆ isDirty()

bool GameState::isDirty ( ) const
inline

Checks if the game state has been modified since the last time it was cleared (dirty flag).

Returns
true if the game state is dirty, false otherwise.

Definition at line 37 of file GameState.hpp.

References dirty.

Referenced by HeadlessRenderer::render().

+ Here is the caller graph for this function:

Member Data Documentation

◆ dirty

bool GameState::dirty = false
mutableprivate

Definition at line 47 of file GameState.hpp.

Referenced by applyEvent(), clearDirty(), and isDirty().

◆ gameDurationSeconds

int GameState::gameDurationSeconds = -1

Definition at line 20 of file GameState.hpp.

Referenced by _applyWinDuration(), and RaylibRenderer::_render2D().

◆ gameDurationTicks

int64_t GameState::gameDurationTicks = -1

Definition at line 21 of file GameState.hpp.

Referenced by _applyWinDuration(), and RaylibRenderer::_render2D().

◆ receivedStuResponse

bool GameState::receivedStuResponse = false

Definition at line 24 of file GameState.hpp.

Referenced by _applyServerUptime(), and App::_trySendStu().

◆ serverUptimeSeconds

unsigned int GameState::serverUptimeSeconds = 0

Definition at line 23 of file GameState.hpp.

Referenced by _applyServerUptime(), and RaylibRenderer::render().

◆ tileSize

float GameState::tileSize = 1.0f

◆ timeUnit

◆ winnerTeam

std::string GameState::winnerTeam = ""

◆ world


The documentation for this class was generated from the following files: