Scarab
A thin, game-agnostic 2D engine host built on the sunlight tile-map engine
Loading...
Searching...
No Matches
enginehost.h
Go to the documentation of this file.
1/*
2 * Copyright (c) since 2021 by PopolonY2k and Leidson Campos A. Ferreira
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 */
20
21#ifndef __ENGINEHOST_H__
22#define __ENGINEHOST_H__
23
24#include <string>
25#include <array>
26#include <functional>
27#include <cstdint>
28#include "tilemap/itilemaplistener.h"
29#include "drawsurface/idrawsurface.h"
30#include "scripting/scriptprocessor.h"
31#include "sound/soundmanager.h"
32#include "lua/luaengine.h"
33#include "engine/spritepool.h"
35
36
37/*
38 * Module definition
39 */
40#define MAX_STATE_HANDLERS 255
41
42
43namespace Scarab {
44 namespace Host {
59 class EngineHost : public SunLight :: TileMap :: ITileMapListener,
60 public SunLight :: Scripting :: IScriptListener {
61
62 typedef std :: function<void( void )> FUNCTION_STATE_HANDLER;
63 typedef std :: array<FUNCTION_STATE_HANDLER, MAX_STATE_HANDLERS> FunctionStateHandlers;
64
65 uint16_t m_CurrentSong;
66 uint64_t m_nClearInactiveSpriteQueueMilli;
67 FUNCTION_STATE_HANDLER m_CurrentStateHandler;
68 SunLight :: Scripting :: ScriptProcessor m_ScriptProcessorMachine;
69 SunLight :: Sound :: SoundManager m_SoundManager;
70 Scarab :: Lua :: LuaEngine m_LuaEngine;
71 Engine :: SpritePool m_SpritePool;
72
73 std :: string m_strEntryArg;
74 std :: string m_strEntryOverride;
75 std :: string m_strLastError;
76 bool m_bEntryScriptDone;
77 FunctionStateHandlers m_aEngineStateHandlers;
78
79 // Queue management update handlers
80 void CheckSpritesQueueEmpty( void );
81
82 // Script processing routines
83 void RunScriptMachine( void );
84
85 // Sound support
86 bool PlaySound( uint16_t id, bool bIgnorePlaying = false );
87 bool PauseSound( uint16_t id );
88 bool StopSound( uint16_t id );
89 bool ResumeSound( uint16_t id );
90
91 // Script management routines
92 bool LoadLuaScript( std :: string strFileName );
93 bool RunLuaScriptMainEntryPoint( void );
94 bool ResolveEntryScript( const std :: string& strEntryArg, std :: string& strOutScriptPath );
95
96 // Machine state handlers
97 void FatalErrorHandler( void );
98 void InitEngineStateHandler( void );
99 void RunStageStateHandler( void );
100
101 public:
102
103 EngineHost( Scarab :: Host :: RendererProvider *pRendererProvider,
104 std :: string strEntryArg,
105 std :: string strEntryOverride = std :: string() );
106 virtual ~EngineHost( void );
107
108 // Runs the entry script - before the window exists, see the definition
109 void RunEntryScript( void );
110
111 // Headless (--headless) only - see LuaAppApi::InstallVirtualClock
112 void UseVirtualTime( void );
113
114 // World listener event handler implementation
115 void OnUpdate( SunLight :: TileMap :: ITileMap& tileMap );
116 void OnStop( void );
117
118 void OnCommand( SunLight :: Scripting :: Commands cmd, uint16_t nEventId );
119 void OnError( std :: string strError );
120 };
121 }
122}
123
124#endif /* __ENGINEHOST_H__ */
Scarab's own game engine: the state machine (init/ run-stage/fatal-error handlers),...
Definition enginehost.h:60
void RunEntryScript(void)
Run the entry script (main.lua, or whatever the entry argument resolves to) - BEFORE the window exist...
Definition enginehost.cpp:409
void OnUpdate(SunLight ::TileMap ::ITileMap &tileMap)
Definition enginehost.cpp:544
void OnError(std ::string strError)
Runtime error handling.
Definition enginehost.cpp:703
void OnCommand(SunLight ::Scripting ::Commands cmd, uint16_t nEventId)
Must be implemented to respond STOP_SONG_CMD command;.
Definition enginehost.cpp:568
virtual ~EngineHost(void)
Definition enginehost.cpp:535
void OnStop(void)
Perform world listener cleaning before world window closing. Runs while TileMapRenderer's window/GL c...
Definition enginehost.cpp:558
void UseVirtualTime(void)
Headless (–headless) only - make Lua's os.time()/ os.clock() follow the null renderer's virtual clock...
Definition enginehost.cpp:527
Definition irendererprovider.h:32
Definition irendererprovider.h:27