Scarab
A thin, game-agnostic 2D engine host built on the sunlight tile-map engine
Loading...
Searching...
No Matches
Scarab::Host::EngineHost Class Reference

Scarab's own game engine: the state machine (init/ run-stage/fatal-error handlers), the ScriptProcessor/LuaEngine wiring, and the small amount of per-frame bookkeeping (BGM looping, sp_wait_queue_empty resolution) that isn't Lua's job. Used to be split across WorldBase (a reusable base class) and WorldEngine (Scarab's state machine subclassing it) - merged since nothing else ever subclassed WorldBase and the split no longer served polymorphism, just indirection. Renamed from WorldEngine/Caravellius::World once the Lua refactor left it owning no "world" state at all (no tile map pointer, no sprite queues, no camera) - it's a lifecycle/Lua-bridge host, not a world model. More...

#include <enginehost.h>

Inheritance diagram for Scarab::Host::EngineHost:
Collaboration diagram for Scarab::Host::EngineHost:

Public Member Functions

 EngineHost (Scarab ::Host ::RendererProvider *pRendererProvider, std ::string strEntryArg, std ::string strEntryOverride=std ::string())
 
virtual ~EngineHost (void)
 
void RunEntryScript (void)
 Run the entry script (main.lua, or whatever the entry argument resolves to) - BEFORE the window exists, called by main() ahead of the frame loop. The script may create the renderer itself (renderer_create); anything that needs a window before it has done so creates the default renderer on the spot (see RendererProvider), and a script that never needs one gets the default when it finishes, so the loop always has a renderer to run on.
 
void UseVirtualTime (void)
 Headless (–headless) only - make Lua's os.time()/ os.clock() follow the null renderer's virtual clock. Called by main() right after construction, before Start() (so before any Lua script has run); a no-op for a real-window run, which never calls it.
 
void OnUpdate (SunLight ::TileMap ::ITileMap &tileMap)
 
void OnStop (void)
 Perform world listener cleaning before world window closing. Runs while TileMapRenderer's window/GL context is still alive (see TileMapRenderer::Stop(), which calls every listener's OnStop() before CloseWindow()) - releasing the sprite pool's textures here, rather than leaving it to ~SpritePool() at program exit, avoids unloading GPU textures after the context is already gone.
 
void OnCommand (SunLight ::Scripting ::Commands cmd, uint16_t nEventId)
 Must be implemented to respond STOP_SONG_CMD command;.
 
void OnError (std ::string strError)
 Runtime error handling.
 

Detailed Description

Scarab's own game engine: the state machine (init/ run-stage/fatal-error handlers), the ScriptProcessor/LuaEngine wiring, and the small amount of per-frame bookkeeping (BGM looping, sp_wait_queue_empty resolution) that isn't Lua's job. Used to be split across WorldBase (a reusable base class) and WorldEngine (Scarab's state machine subclassing it) - merged since nothing else ever subclassed WorldBase and the split no longer served polymorphism, just indirection. Renamed from WorldEngine/Caravellius::World once the Lua refactor left it owning no "world" state at all (no tile map pointer, no sprite queues, no camera) - it's a lifecycle/Lua-bridge host, not a world model.

Constructor & Destructor Documentation

◆ EngineHost()

Scarab::Host::EngineHost::EngineHost ( Scarab ::Host ::RendererProvider *  pRendererProvider,
std ::string  strEntryArg,
std ::string  strEntryOverride = std :: string() 
)

Constructor. Initialize all class data.

Parameters
pRendererProviderThe provider the renderer is created through (lazily - it does not exist yet); this registers itself as the tile-map listener of whatever renderer it creates;
strEntryArgThe entry argument main.cpp requires on the command line (a .lua script path or a .json project file) - resolved later, from RunEntryScript, since a failure there already has a normal fatal-error path to report through.

◆ ~EngineHost()

Scarab::Host::EngineHost::~EngineHost ( void  )
virtual

Destructor. Finalize all class data.

Member Function Documentation

◆ OnCommand()

void Scarab::Host::EngineHost::OnCommand ( SunLight ::Scripting ::Commands  cmd,
uint16_t  nEventId 
)

Must be implemented to respond STOP_SONG_CMD command;.

Parameters
cmdThe command received/
nEventIdThe event id;

◆ OnError()

void Scarab::Host::EngineHost::OnError ( std ::string  strError)

Runtime error handling.

Parameters
strErrorThe engine error message received;

◆ OnStop()

void Scarab::Host::EngineHost::OnStop ( void  )

Perform world listener cleaning before world window closing. Runs while TileMapRenderer's window/GL context is still alive (see TileMapRenderer::Stop(), which calls every listener's OnStop() before CloseWindow()) - releasing the sprite pool's textures here, rather than leaving it to ~SpritePool() at program exit, avoids unloading GPU textures after the context is already gone.

◆ OnUpdate()

void Scarab::Host::EngineHost::OnUpdate ( SunLight ::TileMap ::ITileMap &  tileMap)

Provide action on each frame update.

Parameters
tileMapThe object used to interact with tile map renderer implementation;

◆ RunEntryScript()

void Scarab::Host::EngineHost::RunEntryScript ( void  )

Run the entry script (main.lua, or whatever the entry argument resolves to) - BEFORE the window exists, called by main() ahead of the frame loop. The script may create the renderer itself (renderer_create); anything that needs a window before it has done so creates the default renderer on the spot (see RendererProvider), and a script that never needs one gets the default when it finishes, so the loop always has a renderer to run on.

A failure is a normal fatal error: reported and the process exits, exactly as it used to from the first frame of the loop - just without a window having flashed open first.

◆ UseVirtualTime()

void Scarab::Host::EngineHost::UseVirtualTime ( void  )

Headless (–headless) only - make Lua's os.time()/ os.clock() follow the null renderer's virtual clock. Called by main() right after construction, before Start() (so before any Lua script has run); a no-op for a real-window run, which never calls it.


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