|
resonance 1.0.1
|
Scheduler that runs queued commands when their due time arrives. More...
#include <scheduler.h>

Classes | |
| struct | QueueOrder |
| Order of the command queue: by due tick, then by order as an unsigned quantity. More... | |
Public Member Functions | |
| Scheduler () | |
| Construct an idle scheduler with an empty queue and a fresh clock. | |
| ~Scheduler () | |
| Block queueing, release every queued wrapper, and release the recorder and the playback. | |
| void | BeginRecording (OBStream &stream) |
| Start recording every recordable command queued from now on. | |
| void | QueueAbsolute (Sch::TimedCommand *pCommand, long long nTick, CmdID &id, int bRecordable, int nOrder) |
| Queue a wrapper at an absolute scheduler time. | |
| void | QueueDelta (Sch::TimedCommand *pCommand, long long nDelta, CmdID &id, int bRecordable, int nOrder) |
| Queue a wrapper at a distance from the current time. | |
| void | PostUnreferenced (Sch::Command *pCommand) |
| Build a wrapper for a command while recording, and discard it. | |
| void | QueueReplayed (Sch::TimedCommand *pCommand) |
| Queue a command the playback reader supplies. | |
| void | WithdrawByCmdID (const CmdID &id) |
| Withdraw the first queued wrapper whose handle matches. | |
| void | Withdraw (Sch::TimedCommand *pCommand) |
| Withdraw the entry at a wrapper's position in the queue. | |
| void | ResetTimes () |
| Reset the clock to zero and the current time with it. | |
| void | StopRecOrPlayback () |
| Release the recorder and the playback and leave both stream modes. | |
| void | StartPlayback (IBStream &stream) |
| Start replaying a recorded command stream. | |
| void | Service () |
| Run every queued command whose due time has arrived. | |
| void | Flush () |
| Mark the clock at the current time and record the reading in g_llWatchdogSecondNs. | |
| void | Snapshot () |
| Empty the command queue, releasing every wrapper it held. | |
Public Attributes | |
| SystemTime | mClock |
| Clock every due time is measured against. | |
Friends | |
| class | TimeClock |
Scheduler that runs queued commands when their due time arrives.
The class is not polymorphic and has no RTTI, and no literal in the retail images identifies it. Its name comes from the debugging symbols of the North American demo release.
What the class does is measured rather than inferred. The member at +0x00 is the one pointer of a red-black tree of Sch::TimedCommand pointers, whose header node the constructor takes from the container pool at 0x00667080 and self-links through +0x08 and +0x0c. The ordering predicate at 0x004ac4f8 reads the due tick as a signed 64-bit quantity and falls back to the order member as unsigned.
Service() walks that tree from the left, stops as soon as the front entry is still in the future, runs the wrapper it takes, clears the command's queued flag, and releases the wrapper. It does not observe progress and it reports nothing.
The threshold of six seconds in Service() is not a stall limit. When the distance from the last reading exceeds it, the clock is marked back to the current time and re-read, which stops the loop from running six seconds of arrears in one burst.
The member at +0x0c is a stream mode, one for recording and two for playback, and +0x10 is the Sch::Recorder that BeginRecording() installs. The member at +0x48 blocks every queueing path while it is set.
mClock is public because MainLoop::Poll() reads its origin directly and the image has no accessor for it. It sits amid unrecovered words, so the members below are grouped by access rather than by offset, and each trailing comment records the real offset.
| Sch::Scheduler::Scheduler | ( | ) |
Construct an idle scheduler with an empty queue and a fresh clock.
| Sch::Scheduler::~Scheduler | ( | ) |
Block queueing, release every queued wrapper, and release the recorder and the playback.
| void Sch::Scheduler::BeginRecording | ( | OBStream & | stream | ) |
Start recording every recordable command queued from now on.
Installs a Sch::Recorder over the stream, sets mStreamMode to 1, and resets the clock and the current time to zero. GameRecorder is the caller. The name is inferred.
| stream | The stream the recording is written to. |
| void Sch::Scheduler::QueueAbsolute | ( | Sch::TimedCommand * | pCommand, |
| long long | nTick, | ||
| CmdID & | id, | ||
| int | bRecordable, | ||
| int | nOrder ) |
Queue a wrapper at an absolute scheduler time.
Performs no work while queueing is blocked. Otherwise the wrapper takes the order and the due tick, the handle is allocated when it still reads -2 and copied into the wrapper, and the wrapper is queued with a reference of the queue's own. The recordable flag is not read on this path. Every Sch::TickClock post that resolves an absolute time is a caller.
| pCommand | The wrapper. |
| nTick | The due time in nanoseconds. |
| id | The handle, allocated in place when it reads -2. |
| bRecordable | Unread. |
| nOrder | The order among wrappers due at the same time. |
| void Sch::Scheduler::QueueDelta | ( | Sch::TimedCommand * | pCommand, |
| long long | nDelta, | ||
| CmdID & | id, | ||
| int | bRecordable, | ||
| int | nOrder ) |
Queue a wrapper at a distance from the current time.
A recordable command is dropped during playback, because the recording supplies it. The due time is the later of the current time and the clock reading, plus nDelta, and queueing then proceeds as in QueueAbsolute(), except that the command is marked queued and, while recording, a recordable wrapper is written to the recording.
| pCommand | The wrapper. |
| nDelta | The distance from now in nanoseconds. |
| id | The handle, allocated in place when it reads -2. |
| bRecordable | Non-zero for a command the recording carries. |
| nOrder | The order among wrappers due at the same time. |
| void Sch::Scheduler::PostUnreferenced | ( | Sch::Command * | pCommand | ) |
Build a wrapper for a command while recording, and discard it.
While recording, a wrapper is built on the stack with the current time and a fresh handle, and then destroyed without being queued or recorded. The image has no caller. The name is inferred.
| pCommand | The command. |
| void Sch::Scheduler::QueueReplayed | ( | Sch::TimedCommand * | pCommand | ) |
Queue a command the playback reader supplies.
The command is marked queued, and the wrapper is queued with a reference of the queue's own unless queueing is blocked. The due tick is the one the recording stored. Sch::Playbacker's start routine is the caller. The name is inferred.
| pCommand | The wrapper to queue. |
| void Sch::Scheduler::WithdrawByCmdID | ( | const CmdID & | id | ) |
Withdraw the first queued wrapper whose handle matches.
A handle that is not positive withdraws nothing. The walk stops at the first match, which is erased and released.
| id | The handle. |
| void Sch::Scheduler::Withdraw | ( | Sch::TimedCommand * | pCommand | ) |
Withdraw the entry at a wrapper's position in the queue.
The entry erased is the one that sorts equivalent to pCommand (the same due tick and order), which need not be pCommand itself, and the reference released is pCommand's. Nothing is erased or released when no entry is equivalent. The image has no caller. The title is inferred.
| pCommand | The wrapper whose position is withdrawn. |
| void Sch::Scheduler::ResetTimes | ( | ) |
Reset the clock to zero and the current time with it.
Sch::Playbacker::Play() calls this before queueing a recording.
| void Sch::Scheduler::StopRecOrPlayback | ( | ) |
Release the recorder and the playback and leave both stream modes.
GameRecorder's end of recording and GamePlaybacker's destructor are the callers.
| void Sch::Scheduler::StartPlayback | ( | IBStream & | stream | ) |
Start replaying a recorded command stream.
Installs a Sch::Playbacker in mPlayback, has it read the stream, sets mStreamMode to 2, and starts it. GamePlaybacker's constructor is the caller. The title is inferred.
| stream | The recording, positioned after the session state. |
| void Sch::Scheduler::Service | ( | ) |
Run every queued command whose due time has arrived.
The loop takes the leftmost entry of the queue, stops once that entry is still in the future, erases it, copies its due tick into the scheduler's current time, dispatches Sch::TimedCommand::Run(), clears the command's queued flag, and releases the wrapper. A std::exception that escapes a command is shown through ShowReportedMessage() for 50 units and the loop continues.
Before the loop, g_llWatchdogSecondNs catches up with the clock when more than a second behind, and a clock more than six seconds past the current time is marked back to it and re-read. When the loop stops, the current time advances to the clock reading if that is later.
| void Sch::Scheduler::Flush | ( | ) |
Mark the clock at the current time and record the reading in g_llWatchdogSecondNs.
| void Sch::Scheduler::Snapshot | ( | ) |
Empty the command queue, releasing every wrapper it held.
The queue is copied, emptied, and the copy's wrappers are released one by one, so a release that reaches back into the scheduler finds the queue already empty. The name is inferred.
|
friend |
| SystemTime Sch::Scheduler::mClock |
Clock every due time is measured against.
+0x20