OpenBlox
A game engine which provides a simple and easy to learn Lua API.
OBEngine.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2018 John M. Harris, Jr. <johnmh@openblox.org>
3  *
4  * This file is part of OpenBlox.
5  *
6  * OpenBlox is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenBlox is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the Lesser GNU General Public License
17  * along with OpenBlox. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
29 #ifndef OB_OBENGINE
30 #define OB_OBENGINE
31 
32 #include "oblibconfig.h"
33 
34 #include "obtype.h"
35 #include "mem.h"
36 
37 #include "OBLogger.h"
38 #include "AssetLocator.h"
39 #include "OBSerializer.h"
40 #include "PluginManager.h"
41 #include "OBRenderUtils.h"
42 
43 #include "OBInputEventReceiver.h"
44 
45 #include <lua/OBLua.h>
46 
47 #include <instance/DataModel.h>
48 
49 #include <pthread.h>
50 
51 #if HAVE_IRRLICHT
52 #include <irrlicht/irrlicht.h>
53 #endif
54 
55 #if HAVE_SDL2
56 #define SDL_MAIN_HANDLED
57 #include <SDL.h>
58 #ifdef vector
59 #undef vector
60 #endif
61 #ifdef pixel
62 #undef pixel
63 #endif
64 #ifdef bool
65 #undef bool
66 #endif
67 #endif
68 
69 namespace OB{
70 #ifndef OB_TASKSCHEDULER
71  class TaskScheduler;
72 #endif
73 #ifndef OB_ASSETLOCATOR
74  class AssetLocator;
75 #endif
76 #ifndef OB_PLUGINMANAGER
77  class PluginManager;
78 #endif
79 #ifndef OB_OBRENDERUTILS
81 #endif
82 
83 #if HAVE_IRRLICHT
84  typedef std::function<void(irr::video::IVideoDriver*)> post_render_func_t;
85 #endif
86 
95  class OBEngine{
96  public:
97  OBEngine();
98  virtual ~OBEngine();
99 
106  shared_ptr<TaskScheduler> getTaskScheduler();
107 
114  shared_ptr<TaskScheduler> getSecondaryTaskScheduler();
115 
122  shared_ptr<OBSerializer> getSerializer();
123 
133  void init();
134 
142  void setExitCode(int exitCode);
143 
151  int getExitCode();
152 
159  void shutdown();
160 
167  bool isRunning();
168 
180  void tick();
181 
189  void render();
190 
198  lua_State* getGlobalLuaState();
199 
208 
216  bool doesRendering();
217 
225  void setRendering(bool renders);
226 
234  int getInitWidth();
235 
242  void setInitWidth(int w);
243 
251  int getInitHeight();
252 
259  void setInitHeight(int h);
260 
268  bool getUseVsync();
269 
277  void setUseVsync(bool useVsync);
278 
286  bool getResizable();
287 
295  void setResizable(bool Resizable);
296 
308  void* getWindowId();
309 
320  void setWindowId(void* wId);
321 
331  void resized(int width, int height);
332 
333 #if HAVE_IRRLICHT
334 
340  irr::IrrlichtDevice* getIrrlichtDevice();
341 
348 
359 
366  shared_ptr<OBRenderUtils> getRenderUtils();
367 #endif
368 
375  shared_ptr<Instance::DataModel> getDataModel();
376 
383  shared_ptr<AssetLocator> getAssetLocator();
384 
392  shared_ptr<PluginManager> getPluginManager();
393 
400  shared_ptr<OBLogger> getLogger();
401 
409 
410  private:
411  // State helpers
412  bool initialized;
413  ob_uint64 startTime;
414  bool _isRunning;
415  int exitCode;
416  pthread_t secondaryTaskThread;
417 
418  // Init options
419  bool doRendering;
420  int startWidth;
421  int startHeight;
422  bool vsync;
423  void* windowId;
424  bool resizable;
425 
426  lua_State* globalState;
427 
428 #if HAVE_SDL2
429  SDL_Window* sdl_window;
430 #endif
431 
432 #if HAVE_IRRLICHT
433  post_render_func_t custPostRender;
434 
435  irr::IrrlichtDevice* irrDev;
436  irr::video::IVideoDriver* irrDriv;
437  irr::scene::ISceneManager* irrSceneMgr;
438 
439  shared_ptr<OBRenderUtils> renderUtils;
440 #endif
441 
442  OBInputEventReceiver* eventReceiver;
443 
444  shared_ptr<TaskScheduler> taskSched;
445  shared_ptr<TaskScheduler> secondaryTaskSched;
446  shared_ptr<AssetLocator> assetLocator;
447  shared_ptr<PluginManager> pluginManager;
448  shared_ptr<OBSerializer> serializer;
449  shared_ptr<OBLogger> logger;
450  shared_ptr<Instance::DataModel> dm;
451  };
452 }
453 
454 #endif // OB_OBENGINE
455 
456 // Local Variables:
457 // mode: c++
458 // End:
OBInputEventReceiver * getInputEventReceiver()
int getInitHeight()
void shutdown()
void setInitHeight(int h)
ob_uint64 getStartTime()
shared_ptr< TaskScheduler > getSecondaryTaskScheduler()
bool getUseVsync()
post_render_func_t getPostRenderFunc()
Definition: OBRenderUtils.h:42
virtual ~OBEngine()
int getExitCode()
bool doesRendering()
shared_ptr< TaskScheduler > getTaskScheduler()
void setPostRenderFunc(post_render_func_t prf)
shared_ptr< AssetLocator > getAssetLocator()
Definition: OBEngine.h:95
Definition: AssetLocator.h:38
int getInitWidth()
void setExitCode(int exitCode)
shared_ptr< OBSerializer > getSerializer()
shared_ptr< PluginManager > getPluginManager()
Definition: OBInputEventReceiver.h:58
void setWindowId(void *wId)
void resized(int width, int height)
void * getWindowId()
shared_ptr< OBLogger > getLogger()
void setInitWidth(int w)
void setResizable(bool Resizable)
bool isRunning()
lua_State * getGlobalLuaState()
void setUseVsync(bool useVsync)
void setRendering(bool renders)
std::function< void(irr::video::IVideoDriver *)> post_render_func_t
Definition: OBEngine.h:80
shared_ptr< OBRenderUtils > getRenderUtils()
irr::IrrlichtDevice * getIrrlichtDevice()
shared_ptr< Instance::DataModel > getDataModel()
unsigned long long int ob_uint64
Definition: obtype.h:45
bool getResizable()