R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
client::ClientGameRules Class Reference

Client-side storage for game rules synchronized from server. More...

#include <ClientGameRules.hpp>

Collaboration diagram for client::ClientGameRules:
Collaboration graph

Public Member Functions

 ClientGameRules (const ClientGameRules &)=delete
 
ClientGameRulesoperator= (const ClientGameRules &)=delete
 
float get (GameruleKey key, float defaultValue=0.0f) const
 Get a gamerule value (type-safe with enum)
 
float get (const std::string &key, float defaultValue=0.0f) const
 Get a gamerule value (string version)
 
void update (GameruleKey key, float value)
 Update a gamerule value (type-safe with enum)
 
void update (const std::string &key, float value)
 Update a gamerule value (string version)
 
void updateMultiple (const std::unordered_map< std::string, float > &gamerules)
 Update multiple gamerules at once.
 
bool has (GameruleKey key) const
 Check if a gamerule exists (type-safe with enum)
 
bool has (const std::string &key) const
 Check if a gamerule exists (string version)
 
void clear ()
 Clear all gamerules.
 
size_t size () const
 Get the number of stored gamerules.
 

Static Public Member Functions

static ClientGameRulesgetInstance ()
 Get the singleton instance.
 

Private Member Functions

 ClientGameRules ()=default
 
 ~ClientGameRules ()=default
 

Private Attributes

std::mutex mutex_
 
std::unordered_map< std::string, float > rules_
 

Detailed Description

Client-side storage for game rules synchronized from server.

This class stores game constants that are received from the server. These values are used for client-side prediction and other gameplay features.

The class is thread-safe to allow updates from the network thread while the game loop reads values.

Usage: auto& rules = ClientGameRules::getInstance();

// Type-safe with enum (recommended) float speed = rules.get(GameruleKey::PLAYER_SPEED, 200.0f); rules.update(GameruleKey::PLAYER_SPEED, 250.0f);

// String-based (for custom keys) float customValue = rules.get("custom.value", 0.0f);

Definition at line 37 of file ClientGameRules.hpp.

Constructor & Destructor Documentation

◆ ClientGameRules() [1/2]

client::ClientGameRules::ClientGameRules ( const ClientGameRules )
delete

◆ ClientGameRules() [2/2]

client::ClientGameRules::ClientGameRules ( )
privatedefault

◆ ~ClientGameRules()

client::ClientGameRules::~ClientGameRules ( )
privatedefault

Member Function Documentation

◆ clear()

void client::ClientGameRules::clear ( )
inline

Clear all gamerules.

Definition at line 122 of file ClientGameRules.hpp.

References mutex_, and rules_.

◆ get() [1/2]

float client::ClientGameRules::get ( const std::string &  key,
float  defaultValue = 0.0f 
) const
inline

Get a gamerule value (string version)

Parameters
keyThe gamerule key (e.g., "player.speed")
defaultValueValue to return if key doesn't exist
Returns
The gamerule value or defaultValue

Definition at line 68 of file ClientGameRules.hpp.

References mutex_, and rules_.

◆ get() [2/2]

float client::ClientGameRules::get ( GameruleKey  key,
float  defaultValue = 0.0f 
) const
inline

Get a gamerule value (type-safe with enum)

Parameters
keyThe gamerule key enum
defaultValueValue to return if key doesn't exist
Returns
The gamerule value or defaultValue

Definition at line 58 of file ClientGameRules.hpp.

References get(), and GameruleKeys::toString().

Referenced by get().

Here is the call graph for this function:

◆ getInstance()

static ClientGameRules & client::ClientGameRules::getInstance ( )
inlinestatic

Get the singleton instance.

Returns
Reference to the singleton instance

Definition at line 43 of file ClientGameRules.hpp.

Referenced by GameLoop::handleGameruleUpdate().

◆ has() [1/2]

bool client::ClientGameRules::has ( const std::string &  key) const
inline

Check if a gamerule exists (string version)

Parameters
keyThe gamerule key
Returns
True if the gamerule exists

Definition at line 114 of file ClientGameRules.hpp.

References mutex_, and rules_.

◆ has() [2/2]

bool client::ClientGameRules::has ( GameruleKey  key) const
inline

Check if a gamerule exists (type-safe with enum)

Parameters
keyThe gamerule key enum
Returns
True if the gamerule exists

Definition at line 107 of file ClientGameRules.hpp.

References has(), and GameruleKeys::toString().

Referenced by has().

Here is the call graph for this function:

◆ operator=()

ClientGameRules & client::ClientGameRules::operator= ( const ClientGameRules )
delete

◆ size()

size_t client::ClientGameRules::size ( ) const
inline

Get the number of stored gamerules.

Returns
Number of gamerules

Definition at line 131 of file ClientGameRules.hpp.

References mutex_, and rules_.

◆ update() [1/2]

void client::ClientGameRules::update ( const std::string &  key,
float  value 
)
inline

Update a gamerule value (string version)

Parameters
keyThe gamerule key
valueThe new value

Definition at line 86 of file ClientGameRules.hpp.

References mutex_, and rules_.

◆ update() [2/2]

void client::ClientGameRules::update ( GameruleKey  key,
float  value 
)
inline

Update a gamerule value (type-safe with enum)

Parameters
keyThe gamerule key enum
valueThe new value

Definition at line 79 of file ClientGameRules.hpp.

References GameruleKeys::toString(), and update().

Referenced by update().

Here is the call graph for this function:

◆ updateMultiple()

void client::ClientGameRules::updateMultiple ( const std::unordered_map< std::string, float > &  gamerules)
inline

Update multiple gamerules at once.

Parameters
gamerulesMap of key-value pairs to update

Definition at line 95 of file ClientGameRules.hpp.

References mutex_, and rules_.

Member Data Documentation

◆ mutex_

std::mutex client::ClientGameRules::mutex_
mutableprivate

Definition at line 140 of file ClientGameRules.hpp.

Referenced by clear(), get(), has(), size(), update(), and updateMultiple().

◆ rules_

std::unordered_map<std::string, float> client::ClientGameRules::rules_
private

Definition at line 141 of file ClientGameRules.hpp.

Referenced by clear(), get(), has(), size(), update(), and updateMultiple().


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