|
Zappy Server
C++ game server: world, rules, scheduler, network
|
Single owner of game frequency and elapsed game time. More...
#include <GameClock.hpp>
Collaboration diagram for GameClock:Classes | |
| struct | Stamp |
| A clock reading: wall time and ticks since boot, captured at one instant. More... | |
Public Member Functions | |
| GameClock (int freq) | |
| int | freq () const |
| std::chrono::microseconds | elapsed () const |
| Wall-clock time since construction. | |
| double | ticks () const |
| Total ticks elapsed: integral of freq over time. Fractional by nature. | |
| float | setFreq (int newFreq) |
| Change frequency, banking ticks accrued at the old rate first. | |
| void | recordJoin (const std::string &team) |
| std::optional< Stamp > | joinOf (const std::string &team) const |
The join stamp for team, or nullopt if the team never joined. | |
Private Member Functions | |
| double | _ticksSince (std::chrono::steady_clock::time_point from) const |
Private Attributes | |
| int | _freq |
| std::chrono::steady_clock::time_point | _startTime |
| std::chrono::steady_clock::time_point | _lastFreqChange |
| double | _accumTicks = 0.0 |
| std::unordered_map< std::string, Stamp > | _joins |
Single owner of game frequency and elapsed game time.
A tick is one time unit, lasting 1/freq seconds. The server is wall-clock driven, so ticks are not counted one by one: instead this integrates freq over time. Every freq change (GUI sst) banks the ticks accrued so far at the old rate, so ticks() stays correct across any number of changes.
Also stamps when each team first joined, so win timing can be measured from the team's entry rather than from server boot (which includes idle lobby time before any AI connected).
Definition at line 22 of file GameClock.hpp.
|
explicit |
Definition at line 3 of file GameClock.cpp.
|
private |
Definition at line 14 of file GameClock.cpp.
References _freq.
Referenced by setFreq(), and ticks().
Here is the caller graph for this function:| std::chrono::microseconds GameClock::elapsed | ( | ) | const |
Wall-clock time since construction.
Definition at line 8 of file GameClock.cpp.
References _startTime.
Referenced by CommandDispatcher::gameElapsed(), and recordJoin().
Here is the caller graph for this function:
|
inline |
Definition at line 32 of file GameClock.hpp.
References _freq.
Referenced by CommandDispatcher::_handleBroadcast(), CommandDispatcher::_handleEject(), CommandDispatcher::_handleFork(), CommandDispatcher::_handleForward(), CommandDispatcher::_handleIncantation(), CommandDispatcher::_handleInventory(), CommandDispatcher::_handleLeft(), CommandDispatcher::_handleLook(), CommandDispatcher::_handleRight(), CommandDispatcher::_handleSet(), CommandDispatcher::_handleSgt(), CommandDispatcher::_handleSst(), CommandDispatcher::_handleTake(), HandshakeHandler::_promoteToGui(), and CommandDispatcher::_startStarvationTimer().
Here is the caller graph for this function:| std::optional< GameClock::Stamp > GameClock::joinOf | ( | const std::string & | team | ) | const |
The join stamp for team, or nullopt if the team never joined.
Definition at line 37 of file GameClock.cpp.
References _joins.
Referenced by CommandDispatcher::teamJoin().
Here is the caller graph for this function:| void GameClock::recordJoin | ( | const std::string & | team | ) |
Stamp a team's join moment. Write-once: later calls for the same team are ignored, so it keeps the first player's entry.
Definition at line 31 of file GameClock.cpp.
References _joins, elapsed(), and ticks().
Referenced by CommandDispatcher::_onAiJoined().
Here is the call graph for this function:
Here is the caller graph for this function:| float GameClock::setFreq | ( | int | newFreq | ) |
Change frequency, banking ticks accrued at the old rate first.
Definition at line 22 of file GameClock.cpp.
References _accumTicks, _freq, _lastFreqChange, and _ticksSince().
Referenced by CommandDispatcher::_handleSst().
Here is the call graph for this function:
Here is the caller graph for this function:| double GameClock::ticks | ( | ) | const |
Total ticks elapsed: integral of freq over time. Fractional by nature.
Definition at line 20 of file GameClock.cpp.
References _accumTicks, _lastFreqChange, and _ticksSince().
Referenced by CommandDispatcher::_handleStu(), CommandDispatcher::gameTicks(), and recordJoin().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 59 of file GameClock.hpp.
|
private |
Definition at line 56 of file GameClock.hpp.
Referenced by _ticksSince(), freq(), and setFreq().
|
private |
Definition at line 60 of file GameClock.hpp.
Referenced by joinOf(), and recordJoin().
|
private |
Definition at line 58 of file GameClock.hpp.
|
private |
Definition at line 57 of file GameClock.hpp.
Referenced by elapsed().