resonance 1.0.1
Loading...
Searching...
No Matches
MainLoop Class Reference

The game's frame loop. More...

#include <mainloop.h>

Inheritance diagram for MainLoop:
Collaboration diagram for MainLoop:

Public Member Functions

 MainLoop (int nInCharge, Sch::Scheduler *pWatchdog, GameManagerImpl *pGameManager)
 Create the frame loop and take over the long-operation callbacks.
virtual ~MainLoop ()
 Drop the instance pointer and remove the poll callback.
void Run ()
 Pump the frame loop until it stops.
void Callback (long long nNowNs)
 Fire every timer whose deadline has passed, then recompute the next deadline.
void UpdateCallbackTime ()
 Recompute the earliest of the two timer deadlines.
void Resume ()
 Write the watchdog's readings out now and disarm the scheduled write.
void Step (int nFrames)
 Schedule the watchdog's readings to be written out after a further run of frames.
Public Member Functions inherited from Task
 Task ()
 Task (const Task &other)
 Construct a task with its own fresh node.
virtual ~Task ()
 Unlink the task and release its node.
Task & operator= (const Task &other)
 Reset the task to kTaskStateIdle.
int Start (int bBlocking)
 Begin running the task.
int Suspend ()
 Unlink the task and retain its position.
int Reset ()
 Return the task to kTaskStateIdle so that it can be started again.
int Finish ()
 Retire the task.
int State () const
 Read the task's lifecycle position.
int InProgress () const
 Test whether the task has been started and has not yet finished.
float GetProgress ()
 Read how far the task has progressed.
HxStr GetStatus () const
 Read the task's display title.
int GetQuiet ()
 Test whether the task suppresses its progress report.
Public Member Functions inherited from Attachment
 Attachment ()
virtual ~Attachment ()
int Release ()
 Give back one reference and destroy the object once the last one is gone.
virtual void Destroy ()
 Destroy the object.

Static Public Member Functions

static void PumpTimers ()
 Drive the two periodic timers while the frame loop is blocked.
static void KeepAliveDraw ()
 Redraw the display during a long operation.
Static Public Member Functions inherited from Task
static int PollTasks ()
 Poll every running task once.
Static Public Member Functions inherited from Attachment
static void ReleaseIfSet (Attachment *pAttachment)
 Give back one reference to an object that may be null.

Protected Member Functions

virtual float Progress ()
 Report no progress, because the frame loop never finishes.
virtual HxStr Name () const
 Report an empty title.
virtual int Poll ()
 Run one frame.
Protected Member Functions inherited from Task
virtual int Quiet ()
 Report whether the task suppresses its progress report.
virtual int CheckStateChange (int nFrom, int nTo)
 Approve or refuse a lifecycle change.

Additional Inherited Members

Public Attributes inherited from Attachment
int mRefs

Detailed Description

The game's frame loop.

Its RTTI descriptor is at 0x00901f80. It derives from Task. The declared members occupy +0x0c through +0x37, and the virtual Attachment base closes the object at +0x38. The allocation is 0x40 bytes. The MainLoop table is at 0x007e7ce0.

Globals::Init() creates the single instance and Globals::RunMainLoop() drives it. Every member below is private, because the only code that reads one is a member of this class.

Run() pumps Poll() until mRunning is cleared. Nothing in the image clears it, so the loop is where the whole game runs and Run() never returns. Poll() samples the profiler clock, advances the asynchronous loader and the synth stream, recomputes the frames-per-second reading once a second, and then requests one frame from the game manager.

Two periodic timers run alongside the frame, each with a four-millisecond period. One polls the game manager and the other services the long-operation watchdog. Callback() is what a blocked long operation calls back into through the poll callback the constructor installs, so both timers continue to run while the frame loop itself is stalled.

Constructor & Destructor Documentation

◆ MainLoop()

MainLoop::MainLoop ( int nInCharge,
Sch::Scheduler * pWatchdog,
GameManagerImpl * pGameManager )

Create the frame loop and take over the long-operation callbacks.

Parameters
nInChargeThe call site always passes 1. The flag selects virtual-base setup the compiler emits. The body does not use the flag.
pWatchdogThe long-operation watchdog to service.
pGameManagerThe game manager to draw through.
Ghidra address:
NTSC-U/C: 0x001ec998
Ghidra address:
PAL: 0x001f2c20

◆ ~MainLoop()

virtual MainLoop::~MainLoop ( )
virtual

Drop the instance pointer and remove the poll callback.

The redraw callback the constructor installed is not removed.

Ghidra address:
NTSC-U/C: 0x001ef158
Ghidra address:
PAL: 0x001f54f8

Member Function Documentation

◆ Run()

void MainLoop::Run ( )

Pump the frame loop until it stops.

Nothing in the image clears mRunning, so the routine does not return.

Ghidra address:
NTSC-U/C: 0x001ef290
Ghidra address:
PAL: 0x001f5630

◆ Callback()

void MainLoop::Callback ( long long nNowNs)

Fire every timer whose deadline has passed, then recompute the next deadline.

Parameters
nNowNsThe current reading of the frame clock in nanoseconds.
Ghidra address:
NTSC-U/C: 0x001ef308
Ghidra address:
PAL: 0x001f56a8

◆ UpdateCallbackTime()

void MainLoop::UpdateCallbackTime ( )

Recompute the earliest of the two timer deadlines.

Ghidra address:
NTSC-U/C: 0x001ef2e0
Ghidra address:
PAL: 0x001f5680

◆ Resume()

void MainLoop::Resume ( )

Write the watchdog's readings out now and disarm the scheduled write.

The routine is unreferenced in the image.

Ghidra address:
NTSC-U/C: 0x001ef230
Ghidra address:
PAL: 0x001f55d0

◆ Step()

void MainLoop::Step ( int nFrames)

Schedule the watchdog's readings to be written out after a further run of frames.

The routine is unreferenced in the image.

Parameters
nFramesThe number of frames to wait.
Ghidra address:
NTSC-U/C: 0x001ef260
Ghidra address:
PAL: 0x001f5600

◆ PumpTimers()

void MainLoop::PumpTimers ( )
static

Drive the two periodic timers while the frame loop is blocked.

The long-operation poll callback. Renderer's constructor also calls it directly, at 0x0042c3bc, before it waits for the common loads.

Ghidra address:
NTSC-U/C: 0x001ec7d0
Ghidra address:
PAL: 0x001f2a58

◆ KeepAliveDraw()

void MainLoop::KeepAliveDraw ( )
static

Redraw the display during a long operation.

Refreshes the display at most once every 18 milliseconds of the profiler clock, or every 21 milliseconds in the PAL build. Public because GrooveWorld::EndLevel() at 0x0018eb70 installs it as the bank-load progress hook.

Ghidra address:
NTSC-U/C: 0x001ec8c0
Ghidra address:
PAL: 0x001f2b48

◆ Progress()

virtual float MainLoop::Progress ( )
protectedvirtual

Report no progress, because the frame loop never finishes.

Returns
Always zero.
Ghidra address:
NTSC-U/C: 0x001ef118
Ghidra address:
PAL: 0x001f54b8

Implements Task.

◆ Name()

virtual HxStr MainLoop::Name ( ) const
protectedvirtual

Report an empty title.

Returns
An empty string.
Ghidra address:
NTSC-U/C: 0x001ef128
Ghidra address:
PAL: 0x001f54c8

Implements Task.

◆ Poll()

virtual int MainLoop::Poll ( )
protectedvirtual

Run one frame.

Returns
Always 1, so the frame loop is never retired by the run ring.
Ghidra address:
NTSC-U/C: 0x001ecc90
Ghidra address:
PAL: 0x001f2f98

Implements Task.


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