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

Renderer lifecycle Lua primitives: create the process's one renderer from a script, inspect it, ask it to stop. More...

#include <luarendererapi.h>

Static Public Member Functions

static bool CheckHandle (lua_State *pLuaState, int nIndex, std ::string &strError)
 Check that argument nIndex names the current renderer.
 
static bool ValidateZoomFactor (double fFactor, unsigned &nZoomPos, std ::string &strError)
 Check a zoom FACTOR and convert it to sunlight's zoom position.
 
static void Register (lua_State *pLuaState)
 Register the renderer lifecycle Lua-callable functions and constants.
 

Detailed Description

Renderer lifecycle Lua primitives: create the process's one renderer from a script, inspect it, ask it to stop.

By default a game never has to think about the renderer: the first call that needs a window (app_set_name, set_font, tilemap_load_map, ...) creates one with Scarab's default configuration, and a script that needs none still gets it when it finishes. renderer_create is for a game that wants to choose its own window/render settings up front.

Ordering rule — renderer_create must be the first window-needing call in the entry script. The entry script runs before any window exists, and renderer_create opens the window the moment it succeeds. Anything that needs a window before it has run creates the default renderer first, and a later renderer_create then fails with nil, "renderer already created: ..." naming the call that did it. Calls that need no window are fine before it: load_json, dofile, sound_*, sp_*, pool_*, the sprite_* handle calls, set_timer, collision_set_handler, crypto_*, pack_*, app_get_platform.

One renderer per process run. Every function here reports failure as nil, "message" — it never raises a Lua error. Handles are opaque integers.

Member Function Documentation

◆ CheckHandle()

bool Scarab::Engine::Lua::LuaRendererApi::CheckHandle ( lua_State *  pLuaState,
int  nIndex,
std ::string &  strError 
)
static

Check that argument nIndex names the current renderer.

◆ Register()

void Scarab::Engine::Lua::LuaRendererApi::Register ( lua_State *  pLuaState)
static

Register the renderer lifecycle Lua-callable functions and constants.

◆ ValidateZoomFactor()

bool Scarab::Engine::Lua::LuaRendererApi::ValidateZoomFactor ( double  fFactor,
unsigned &  nZoomPos,
std ::string &  strError 
)
static

Check a zoom FACTOR and convert it to sunlight's zoom position.

A valid factor is a whole multiple of ZOOM_STEP within [ZOOM_FACTOR_MIN, ZOOM_FACTOR_MAX]; factor(p) = (p + 1) x ZOOM_STEP. ZOOM_STEP is a power of two, so every valid factor is exact and this needs no rounding of what the script wrote: 3.8125 is valid, 3.8 is not (it is almost certainly a typo, so it is rejected, not silently rounded). The message names the nearest valid factor. Shared by renderer_create's zoom option and the view zoom setters.

Parameters
fFactorThe requested zoom factor;
nZoomPosReceives the zoom position on success;
strErrorReceives the reason on failure;

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