Represents a player counter with overflow-safe increment arithmetic.
More...
#include <server_counter.h>
|
| | Server_Counter (int _id, const QString &_name, const color &_counterColor, int _radius, int _count=0) |
| | ~Server_Counter () |
| int | getId () const |
| QString | getName () const |
| const color & | getColor () const |
| int | getRadius () const |
| int | getCount () const |
| bool | setCount (int _count) |
| | Sets the counter to an exact value.
|
| bool | incrementCount (int delta) |
| | Increments the counter by delta with overflow-safe arithmetic.
|
| void | getInfo (ServerInfo_Counter *info) |
| | Populates info with this counter's current state for network serialization.
|
Represents a player counter with overflow-safe increment arithmetic.
All value modifications return whether the value actually changed, enabling callers to skip unnecessary network events.
- Note
- Direct assignment via setCount() does not clamp; only incrementCount() enforces int boundary saturation.
-
Unlike card counters, player counters are never auto-removed when they reach zero - they persist with value 0.
◆ Server_Counter()
| Server_Counter::Server_Counter |
( |
int | _id, |
|
|
const QString & | _name, |
|
|
const color & | _counterColor, |
|
|
int | _radius, |
|
|
int | _count = 0 ) |
◆ ~Server_Counter()
| Server_Counter::~Server_Counter |
( |
| ) |
|
|
inline |
◆ getColor()
| const color & Server_Counter::getColor |
( |
| ) |
const |
|
inline |
◆ getCount()
| int Server_Counter::getCount |
( |
| ) |
const |
|
inline |
◆ getId()
| int Server_Counter::getId |
( |
| ) |
const |
|
inline |
◆ getInfo()
| void Server_Counter::getInfo |
( |
ServerInfo_Counter * | info | ) |
|
Populates info with this counter's current state for network serialization.
- Parameters
-
| info | The protobuf message to populate. |
◆ getName()
| QString Server_Counter::getName |
( |
| ) |
const |
|
inline |
◆ getRadius()
| int Server_Counter::getRadius |
( |
| ) |
const |
|
inline |
◆ incrementCount()
| bool Server_Counter::incrementCount |
( |
int | delta | ) |
|
|
nodiscard |
Increments the counter by delta with overflow-safe arithmetic.
- Parameters
-
| delta | The amount to add (may be negative for decrement). |
- Returns
- true if the value changed, false otherwise.
- Note
- Clamps result to [INT_MIN, INT_MAX] to prevent overflow.
- Todo
- Extract overflow-safe arithmetic into shared helper. Duplicated in Server_Card::incrementCounter() - keep in sync if modified.
◆ setCount()
| bool Server_Counter::setCount |
( |
int | _count | ) |
|
|
inlinenodiscard |
Sets the counter to an exact value.
- Parameters
-
| _count | The new value (assigned directly without clamping). |
- Returns
- true if the value changed, false otherwise.
- Warning
- This performs raw assignment. For overflow-safe incrementing, use incrementCount().
◆ count
| int Server_Counter::count |
|
protected |
◆ counterColor
| color Server_Counter::counterColor |
|
protected |
◆ id
◆ name
| QString Server_Counter::name |
|
protected |
◆ radius
| int Server_Counter::radius |
|
protected |
The documentation for this class was generated from the following files: