resonance 1.0.1
Loading...
Searching...
No Matches
Sch::Scheduler Class Reference

Scheduler that runs queued commands when their due time arrives. More...

#include <scheduler.h>

Collaboration diagram for Sch::Scheduler:

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ Scheduler()

Sch::Scheduler::Scheduler ( )

Construct an idle scheduler with an empty queue and a fresh clock.

Ghidra address:
NTSC-U/C: 0x004a9858
Ghidra address:
PAL: 0x004e7968

◆ ~Scheduler()

Sch::Scheduler::~Scheduler ( )

Block queueing, release every queued wrapper, and release the recorder and the playback.

Ghidra address:
NTSC-U/C: 0x004a9980
Ghidra address:
PAL: 0x004e7a90

Member Function Documentation

◆ BeginRecording()

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.

Parameters
streamThe stream the recording is written to.
Ghidra address:
NTSC-U/C: 0x004ac8c0
Ghidra address:
PAL: 0x004eaa60

◆ QueueAbsolute()

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.

Parameters
pCommandThe wrapper.
nTickThe due time in nanoseconds.
idThe handle, allocated in place when it reads -2.
bRecordableUnread.
nOrderThe order among wrappers due at the same time.
Ghidra address:
NTSC-U/C: 0x004ac608
Ghidra address:
PAL: 0x004ea7a8

◆ QueueDelta()

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.

Parameters
pCommandThe wrapper.
nDeltaThe distance from now in nanoseconds.
idThe handle, allocated in place when it reads -2.
bRecordableNon-zero for a command the recording carries.
nOrderThe order among wrappers due at the same time.
Ghidra address:
NTSC-U/C: 0x004ac698
Ghidra address:
PAL: 0x004ea838

◆ PostUnreferenced()

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.

Parameters
pCommandThe command.
Ghidra address:
NTSC-U/C: 0x004ac808
Ghidra address:
PAL: 0x004ea9a8

◆ QueueReplayed()

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.

Parameters
pCommandThe wrapper to queue.
Ghidra address:
NTSC-U/C: 0x004ac7b0
Ghidra address:
PAL: 0x004ea950

◆ WithdrawByCmdID()

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.

Parameters
idThe handle.
Ghidra address:
NTSC-U/C: 0x004aa260
Ghidra address:
PAL: 0x004e8370

◆ Withdraw()

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.

Parameters
pCommandThe wrapper whose position is withdrawn.
Ghidra address:
NTSC-U/C: 0x004a9d00
Ghidra address:
PAL: 0x004e7e10

◆ ResetTimes()

void Sch::Scheduler::ResetTimes ( )

Reset the clock to zero and the current time with it.

Sch::Playbacker::Play() calls this before queueing a recording.

Ghidra address:
NTSC-U/C: 0x004aca30
Ghidra address:
PAL: 0x004eabd0

◆ StopRecOrPlayback()

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.

Ghidra address:
NTSC-U/C: 0x004ac9e8
Ghidra address:
PAL: 0x004eab88

◆ StartPlayback()

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.

Parameters
streamThe recording, positioned after the session state.
Ghidra address:
NTSC-U/C: 0x004ac950
Ghidra address:
PAL: 0x004eaaf0

◆ Service()

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.

Ghidra address:
NTSC-U/C: 0x004aa848
Ghidra address:
PAL: 0x004e8958

◆ Flush()

void Sch::Scheduler::Flush ( )

Mark the clock at the current time and record the reading in g_llWatchdogSecondNs.

Ghidra address:
NTSC-U/C: 0x004aca60
Ghidra address:
PAL: 0x004eac00

◆ Snapshot()

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.

Ghidra address:
NTSC-U/C: 0x004a9a78
Ghidra address:
PAL: 0x004e7b88

◆ TimeClock

friend class TimeClock
friend

Member Data Documentation

◆ mClock

SystemTime Sch::Scheduler::mClock

Clock every due time is measured against.

+0x20


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