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

Owns the process's one renderer and creates it on demand. More...

#include <rendererprovider.h>

Inheritance diagram for Scarab::Host::RendererProvider:
Collaboration diagram for Scarab::Host::RendererProvider:

Public Types

typedef std ::function< void(SunLight ::Renderer ::TileMapRenderer &)> CreatedHook
 

Public Member Functions

 RendererProvider (const SunLight ::Renderer ::RendererConfig &defaults, const stHeadlessSettings &headless)
 Constructor.
 
virtual ~RendererProvider (void)
 Destructor. Destroys the renderer, if one was ever created (its window is normally already closed by then - main() Stop()s it).
 
void SetCreatedHook (CreatedHook hook)
 Set the function called with every renderer right after it is created and before its window opens - where the engine host registers itself as the tile-map listener and the Lua bridge attaches its collision listener.
 
bool Create (const SunLight ::Renderer ::RendererConfig &config, Origin origin, const std ::string &strTrigger, std ::string *pError)
 Create the process's renderer and open its window.
 
void EnsureCreated (const char *szTrigger)
 Create the default renderer if none exists yet - called when the entry script has finished, so a game that never asked for a window-needing primitive still gets its one renderer to run on.
 
SunLight::Renderer::TileMapRenderer * GetRenderer (void)
 The renderer, or nullptr if none exists yet (never creates one).
 
const stHeadlessSettings & GetHeadlessSettings (void) const
 What the command line asked of –headless.
 
SunLight::TileMap::ITileMap * GetTileMap (const char *szTrigger)
 
SunLight::DrawSurface::IDrawSurface * GetDrawSurface (const char *szTrigger)
 
SunLight::DrawSurface::IDrawSurface * PeekDrawSurface (void)
 
bool CreateRenderer (const SunLight ::Renderer ::RendererConfig &config, std ::string *pError)
 Explicitly create the renderer (renderer_create). The error for "a renderer already exists" says which of the two ways it got there, and - when it was the default, created implicitly - names the primitive that needed a window first, since that call, not this one, is what to move below renderer_create.
 
Origin GetOrigin (void)
 
bool IsHeadless (void)
 
SunLight::Renderer::RendererConfig GetDefaultConfig (void)
 
SunLight::Renderer::RendererConfig GetEffectiveConfig (void)
 
void NoteWindowTitle (const std ::string &strTitle)
 Keep the effective configuration's title current: app_set_name changes the live window title, and sunlight has no getter for it to read back.
 

Detailed Description

Owns the process's one renderer and creates it on demand.

The renderer is created either explicitly (Create, from renderer_create) or implicitly with the default configuration the first time a primitive needs a window (GetTileMap/GetDrawSurface) or when the entry script finishes without needing one (EnsureCreated). Either way it is Start()ed immediately, so its window is open by the time Create returns - load-time code like set_font keeps working.

Member Typedef Documentation

◆ CreatedHook

typedef std :: function<void( SunLight :: Renderer :: TileMapRenderer& )> Scarab::Host::RendererProvider::CreatedHook

Constructor & Destructor Documentation

◆ RendererProvider()

Scarab::Host::RendererProvider::RendererProvider ( const SunLight ::Renderer ::RendererConfig &  defaults,
const stHeadlessSettings &  headless 
)

Constructor.

Parameters
defaultsThe configuration used when a renderer has to be created implicitly (today's hardcoded values, see main.cpp);
headlessWhat the command line asked of –headless;

◆ ~RendererProvider()

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

Destructor. Destroys the renderer, if one was ever created (its window is normally already closed by then - main() Stop()s it).

Member Function Documentation

◆ Create()

bool Scarab::Host::RendererProvider::Create ( const SunLight ::Renderer ::RendererConfig &  config,
Origin  origin,
const std ::string &  strTrigger,
std ::string *  pError 
)

Create the process's renderer and open its window.

Applies –headless on top of the requested configuration: the null backend is forced (asking for another one is an error), and the command line's –fast/–max-frames win over whatever the configuration says. Only one renderer exists per process run.

Parameters
configThe requested configuration;
originHow this creation came about;
strTriggerFor an implicit creation, the primitive that needed a window;
pErrorReceives the reason on failure (may be null);
Returns
true if the renderer exists now, false (with *pError set) if not;

◆ CreateRenderer()

bool Scarab::Host::RendererProvider::CreateRenderer ( const SunLight ::Renderer ::RendererConfig &  config,
std ::string *  pError 
)

Explicitly create the renderer (renderer_create). The error for "a renderer already exists" says which of the two ways it got there, and - when it was the default, created implicitly - names the primitive that needed a window first, since that call, not this one, is what to move below renderer_create.

◆ EnsureCreated()

void Scarab::Host::RendererProvider::EnsureCreated ( const char *  szTrigger)

Create the default renderer if none exists yet - called when the entry script has finished, so a game that never asked for a window-needing primitive still gets its one renderer to run on.

◆ GetDefaultConfig()

SunLight::Renderer::RendererConfig Scarab::Host::RendererProvider::GetDefaultConfig ( void  )

◆ GetDrawSurface()

SunLight::DrawSurface::IDrawSurface * Scarab::Host::RendererProvider::GetDrawSurface ( const char *  szTrigger)

◆ GetEffectiveConfig()

SunLight::Renderer::RendererConfig Scarab::Host::RendererProvider::GetEffectiveConfig ( void  )

◆ GetHeadlessSettings()

const stHeadlessSettings & Scarab::Host::RendererProvider::GetHeadlessSettings ( void  ) const

What the command line asked of –headless.

◆ GetOrigin()

RendererProvider::Origin Scarab::Host::RendererProvider::GetOrigin ( void  )

◆ GetRenderer()

SunLight::Renderer::TileMapRenderer * Scarab::Host::RendererProvider::GetRenderer ( void  )

The renderer, or nullptr if none exists yet (never creates one).

◆ GetTileMap()

SunLight::TileMap::ITileMap * Scarab::Host::RendererProvider::GetTileMap ( const char *  szTrigger)

◆ IsHeadless()

bool Scarab::Host::RendererProvider::IsHeadless ( void  )

◆ NoteWindowTitle()

void Scarab::Host::RendererProvider::NoteWindowTitle ( const std ::string &  strTitle)

Keep the effective configuration's title current: app_set_name changes the live window title, and sunlight has no getter for it to read back.

◆ PeekDrawSurface()

SunLight::DrawSurface::IDrawSurface * Scarab::Host::RendererProvider::PeekDrawSurface ( void  )

◆ SetCreatedHook()

void Scarab::Host::RendererProvider::SetCreatedHook ( CreatedHook  hook)

Set the function called with every renderer right after it is created and before its window opens - where the engine host registers itself as the tile-map listener and the Lua bridge attaches its collision listener.


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