Skylicht Engine
Loading...
Searching...
No Matches
CBaseApp.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "pch.h"
28#include "IApplicationEventReceiver.h"
29
30namespace Skylicht
31{
37 {
38 AppEventUpdate,
39 AppEventRender,
40 AppEventPostRender,
41 AppEventPause,
42 AppEventResume,
43 AppEventBack,
44 AppEventQuit,
45 AppEventInit,
46 AppEventResize
47 };
48
57 {
58 protected:
61
64
67
68 SExposedVideoData m_videoData;
69
72
75
78
81
84
87
88 // Flag for running logic when paused
89 bool m_enableRunWhenPause;
90
93
95 std::string m_appName;
96
97 public:
102
106 virtual ~CBaseApp();
107
109 typedef std::pair<std::string, IApplicationEventReceiver*> appEventType;
110
112 std::vector<appEventType> m_appEventReceivers;
113
114 public:
119 inline const char* getAppName()
120 {
121 return m_appName.c_str();
122 }
123
128
132 static void reportLeakMemory();
133
139 {
140 return m_device;
141 }
142
148 {
149 return m_driver;
150 }
151
157 {
158 return m_fileSystem;
159 }
160
166
172 {
173 return m_videoData;
174 }
175
180 inline float getTimeStep()
181 {
182 return m_timeStep;
183 }
184
190 io::path getBuiltInPath(const char* name);
191
198 std::string getTexturePackageName(const char* name, const char* ext=".zip");
199
204 inline void showFPS(bool b)
205 {
206 m_showFPS = b;
207 }
208
213 int getWidth();
214
220
226
232
237 inline void clearScreenTime(float t)
238 {
240 }
241
246 inline void enableRender(bool b)
247 {
248 m_renderEnabled = b;
249 }
250
255 inline bool isRenderEnabled()
256 {
257 return m_renderEnabled;
258 }
259
265 void registerAppEvent(const std::string& name, IApplicationEventReceiver* pEvent);
266
272
279 void sendEventToAppReceiver(int eventID, int param1 = 0, int param2 = 0);
280
285 void setLimitFPS(int fps);
286
290 inline int getLimitFPS()
291 {
292 return m_limitFPS;
293 }
294
300 {
301 m_enableRunWhenPause = b;
302 }
303
307 void openURL(const char* url);
308
313 };
314
315 extern CBaseApp* getApplication();
316}
Base class for managing the application lifecycle, rendering, and event system in Skylicht Engine.
Definition CBaseApp.h:57
void enableRender(bool b)
Enable or disable rendering.
Definition CBaseApp.h:246
std::pair< std::string, IApplicationEventReceiver * > appEventType
Type for mapping application event receivers by name.
Definition CBaseApp.h:109
IVideoDriver * m_driver
Video driver pointer.
Definition CBaseApp.h:63
io::IFileSystem * m_fileSystem
File system pointer.
Definition CBaseApp.h:66
void showDebugConsole()
Show debug console (Windows only).
void sendEventToAppReceiver(int eventID, int param1=0, int param2=0)
Send an event to all registered application event receivers.
IVideoDriver * getDriver()
Get the Irrlicht video driver.
Definition CBaseApp.h:147
CBaseApp()
Default constructor for CBaseApp.
video::SColor m_clearColor
Color used to clear the screen.
Definition CBaseApp.h:92
bool isWideScreen()
Check if screen is widescreen format.
float m_timeStep
Time step for each frame(ms).
Definition CBaseApp.h:71
SExposedVideoData & getVideoData()
Get exposed video data for rendering pipeline.
Definition CBaseApp.h:171
float getSizeRatio()
Get the screen aspect ratio (width/height).
bool isRenderEnabled()
Check if rendering is enabled.
Definition CBaseApp.h:255
float getTimeStep()
Get the time step for the current frame.
Definition CBaseApp.h:180
bool m_renderEnabled
Flag to enable / disable rendering.
Definition CBaseApp.h:86
bool m_showFPS
Flag to display FPS in window caption.
Definition CBaseApp.h:80
void enableRunWhenPause(bool b)
Enable or disable running logic when the application is paused.
Definition CBaseApp.h:299
float m_clearScreenTime
Time to clear screen before rendering.
Definition CBaseApp.h:83
io::path getBuiltInPath(const char *name)
Get built-in asset path based on platform.
void unRegisterAppEvent(IApplicationEventReceiver *pEvent)
Unregister an application event receiver.
int getLimitFPS()
Get the FPS limit.
Definition CBaseApp.h:290
bool isNetworkAvailable()
Check network available or not?
void openURL(const char *url)
Open browse with url.
float m_totalTime
Total elapsed time since app started(ms).
Definition CBaseApp.h:74
void showFPS(bool b)
Show or hide FPS in window caption.
Definition CBaseApp.h:204
int m_limitFPS
FPS limit(-1 for unlimited).
Definition CBaseApp.h:77
IrrlichtDevice * getDevice()
Get the Irrlicht device.
Definition CBaseApp.h:138
int getHeight()
Get the screen height.
void setClearColor(const video::SColor &c)
Set the color used to clear the screen before rendering.
void registerAppEvent(const std::string &name, IApplicationEventReceiver *pEvent)
Register a new application event receiver.
int getWidth()
Get the screen width.
std::string getTexturePackageName(const char *name, const char *ext=".zip")
Get texture package name based on platform and compression support.
std::string m_appName
Application name.
Definition CBaseApp.h:95
void setLimitFPS(int fps)
Set the FPS limit for the application.
static void reportLeakMemory()
Report memory leaks (Visual Leak Detector, debug only).
io::IFileSystem * getFileSystem()
Get the Irrlicht file system.
Definition CBaseApp.h:156
void clearScreenTime(float t)
Set the duration to clear the screen before rendering.
Definition CBaseApp.h:237
IrrlichtDevice * m_device
Irrlicht device pointer.
Definition CBaseApp.h:60
virtual ~CBaseApp()
Destructor for CBaseApp.
std::vector< appEventType > m_appEventReceivers
List of registered application event receivers.
Definition CBaseApp.h:112
const char * getAppName()
Get the name of the application.
Definition CBaseApp.h:119
Definition IApplicationEventReceiver.h:31
The Irrlicht device. You can create it with createDevice() or createDeviceEx().
Definition IrrlichtDevice.h:44
The FileSystem manages files and archives and provides access to them.
Definition IFileSystem.h:33
Interface to driver which is able to perform 2d and 3d graphics functions.
Definition IVideoDriver.h:388
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
EAppEvent
Enumeration of application event types for event receiver system.
Definition CBaseApp.h:37
core::string< fschar_t > path
Type used for all file system related strings.
Definition path.h:17
structure for holding data describing a driver and operating system specific data.
Definition SExposedVideoData.h:29