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

Pausable view of scheduler time, together with the tempo that maps it to a song position. More...

#include <tickclock.h>

Inheritance diagram for Sch::TickClock:
Collaboration diagram for Sch::TickClock:

Public Member Functions

 TickClock (Scheduler *pWatchdog, TempoMap *pTempoMap)
 Start a clock against a scheduler, with a tempo map of its own or a shared one.
 ~TickClock ()
 Give back the reference to the tempo map.
void SetTempoMap (TempoMap *pTempoMap)
 Share a different tempo map, giving back the reference to the current one.
int SongTick ()
 Report the song position the clock has arrived at.
void SetSongTick (Sch::Tick tick)
 Move the clock to a song position.
void PostAt (Command *pCommand, Time tick)
 Queue a command at an absolute scheduler time, discarding the handle.
void PostAtSongTick (Command *pCommand, long long nTick, CmdID &id, int nUnused=0)
 Queue a command at a song position, under a handle the caller retains.
void PostAtSongTick (Command *pCommand, long long nTick)
 Queue a command at a song position, discarding the handle.
Public Member Functions inherited from Sch::TimeClock
 TimeClock (Scheduler *pWatchdog)
void SetOrigin (long long nNanoseconds)
 Fix the origin of the time base.
long long Now ()
 Report the current time.
void Pause ()
 Stop the time base at its current reading.
void Resume ()
 Restart the time base from the reading Pause() stopped it at.
void Post (Sch::Command *pCommand, Sch::Time tick, CmdID &id, int bRecordable, int bDelta)
 Queue a command, choosing between the absolute and the delta path.
void Withdraw (const CmdID &id)
 Withdraw the first wrapper queued under a handle.
void PostIn (Sch::Command *pCommand, Sch::Time tick, CmdID &id, int bRecordable)
 Queue a command a distance from now, under a handle the caller retains.
void PostIn (Sch::Command *pCommand, Sch::Time tick)
 Queue a command a distance from now, discarding the handle.

Public Attributes

TempoMap * mTempoMap
 Map between song position and scheduler time.
Public Attributes inherited from Sch::TimeClock
long long mNegatedOrigin
 The origin, negated, in nanoseconds.
long long mPausedNs
 The reading Now() reports while no origin is set, in nanoseconds.
int mHasOrigin
 Non-zero while the time base runs against the scheduler.
Scheduler * mWatchdog
 The scheduler whose current time the readings follow.

Detailed Description

Pausable view of scheduler time, together with the tempo that maps it to a song position.

The class is not polymorphic and does not emit RTTI. Its name comes from the one recorded signature that mentions it. Catcher's constructor takes a Sch::TickClock *. That signature identifies this class rather than its base, because Catcher's handler at 0x001ac760 calls SongTick(), and SongTick() reads mTempoMap.

An instance is 0x1c bytes. The base subobject occupies +0x00 through +0x17 and this class adds one pointer at +0x18, which the constructor at 0x004a79f8 is the last write of and which the destructor at 0x004a7aa8 releases.

The base is the 0x18-byte class that Globals::InitServices() instantiates directly at 0x00117118, with its own constructor at 0x004a7780 and its own destructor at 0x004a7798 that releases no tempo map. Two measurements prove the base and derived classes are distinct. The two destructors differ in behaviour, and a class has exactly one destructor. Start(), Resume(), Pause(), and Now() exist as single bodies that both the Globals object and GrooveWorld's object are passed to, and none of the four touches +0x18.

Every post below wraps the command in a Sch::TimedCommand, hands the wrapper to one of the scheduler's two queueing paths, and then gives back its reference. The queue is then the only owner. The member titles are inferred from those bodies. The script command clock at 0x00150d88 supplies the words tempo, tick, and song_bar, the source of the name SongTick(). The bare name Tick would hide the type Sch::Tick inside this class.

Constructor & Destructor Documentation

◆ TickClock()

Sch::TickClock::TickClock ( Scheduler * pWatchdog,
TempoMap * pTempoMap )

Start a clock against a scheduler, with a tempo map of its own or a shared one.

A null tempo map produces a private one at the default tempo of 500000 microseconds per quarter note. A tempo map the caller supplies is shared, and its reference count is incremented directly at 0x004a7a28.

Parameters
pWatchdogThe scheduler this clock posts to.
pTempoMapThe tempo map to share, or null for a private one.
Ghidra address:
NTSC-U/C: 0x004a79f8
Ghidra address:
PAL: 0x004e5b08

◆ ~TickClock()

Sch::TickClock::~TickClock ( )

Give back the reference to the tempo map.

Ghidra address:
NTSC-U/C: 0x004a7aa8
Ghidra address:
PAL: 0x004e5bb8

Member Function Documentation

◆ SetTempoMap()

void Sch::TickClock::SetTempoMap ( TempoMap * pTempoMap)

Share a different tempo map, giving back the reference to the current one.

The new map's reference count is incremented before the old map is released, and a null map is stored without a reference. GrooveWorld::FinishLoad() is the recovered caller, with the tempo map a converted level reports.

Parameters
pTempoMapThe tempo map to share, or null.
Ghidra address:
NTSC-U/C: 0x004a7be0
Ghidra address:
PAL: 0x004e5cf0

◆ SongTick()

int Sch::TickClock::SongTick ( )

Report the song position the clock has arrived at.

The body divides the current time, biased by TempoMap::mCeilingBias, by TempoMap::mNanosecondsPerTick, which rounds up to the next whole MIDI tick. The result is then wrapped in a Sch::Tick, whose constructor runs the discarded Sch::Tick::IsInRange() check at 0x00100ab8.

Returns
The song position, in MIDI ticks at 480 per quarter note.
Ghidra address:
NTSC-U/C: 0x004a7af8
Ghidra address:
PAL: 0x004e5c08

◆ SetSongTick()

void Sch::TickClock::SetSongTick ( Sch::Tick tick)

Move the clock to a song position.

The body converts the position to scheduler time through mTempoMap and stores it as the paused reading, but only when it differs from the current reading. The store happens even while the clock runs, when Now() does not report the paused reading.

The position is a Sch::Tick passed by value in one register. Both callers, GrooveWorld's PrepareLevel() at 0x0018ddd8 and StopLevel() at 0x0018ed6c, construct it through Sch::Tick(int) immediately before the call.

Parameters
tickThe song position.
Ghidra address:
NTSC-U/C: 0x004a7b60
Ghidra address:
PAL: 0x004e5c70

◆ PostAt()

void Sch::TickClock::PostAt ( Command * pCommand,
Time tick )

Queue a command at an absolute scheduler time, discarding the handle.

Parameters
pCommandThe command to run.
tickThe scheduler time to run it at, in this clock's frame.
Ghidra address:
NTSC-U/C: 0x004a5fd0
Ghidra address:
PAL: 0x004e4070

◆ PostAtSongTick() [1/2]

void Sch::TickClock::PostAtSongTick ( Command * pCommand,
long long nTick,
CmdID & id,
int nUnused = 0 )

Queue a command at a song position, under a handle the caller retains.

Parameters
pCommandThe command to run.
nTickThe song position, in MIDI ticks at 480 per quarter note. Callers widen a 32-bit position into the 64-bit register, and the body multiplies the full width through its 64-bit helper at 0x00600270.
idThe handle to queue under.
nUnusedAll 17 call sites pass 0 as the fifth argument, and the body never reads it. The type and the meaning are not recoverable.
Ghidra address:
NTSC-U/C: 0x004a6248
Ghidra address:
PAL: 0x004e42e8

◆ PostAtSongTick() [2/2]

void Sch::TickClock::PostAtSongTick ( Command * pCommand,
long long nTick )

Queue a command at a song position, discarding the handle.

Parameters
pCommandThe command to run.
nTickThe song position, in MIDI ticks at 480 per quarter note.
Ghidra address:
NTSC-U/C: 0x004a6330
Ghidra address:
PAL: 0x004e43d0

Member Data Documentation

◆ mTempoMap

TempoMap* Sch::TickClock::mTempoMap

Map between song position and scheduler time.

Public because the clock tempo script command reads it directly at 0x001511ec, the undeclared Globals accessor at 0x00118ce8 reads it inline, and the image has no out-of-line accessor.

+0x18


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