Raito 0.1
Loading...
Searching...
No Matches
Application.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2023 Víctor Falcón Zaro
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#pragma once
26
28#include "ECS/Scene.h"
29
30namespace Raito::Core
31{
35 {
36 std::string Name = "Raito - App";
38 u32 Width = 1280;
39 u32 Height = 720;
43 bool Fullscreen = false;
44 };
45
47
51 {
52 public:
54 static Application& Get() { return *s_Application; }
55
57 virtual ~Application() = default;
58
60
61
65 bool Initialize();
67
71 bool Update();
73
76 void Shutdown();
77
79 /*
80 * Puts a flag for the application to be call Shutdown()
81 * Reminder: It always completes the EndTimeUpdate() call before shutting down the application
82 */
83 void Close() { m_Running = false; }
84
85 public:
86 // Test scene
88
89 protected:
90
92 virtual bool OnInit() { return true; }
93
96 virtual bool OnRenderGUI() { return true; }
97
100 virtual bool OnUpdate() { return true; }
101
103 virtual void OnShutdown() {}
104
106 Application() = default;
107
108 bool m_Running = false;
109 private:
110
111
112 inline static Application* s_Application = nullptr;
113 ApplicationInfo m_Info{};
115 friend int RunApp(Application& app, ApplicationInfo info, int argc, char** argv);
116 };
119 int RunApp(Application& app, ApplicationInfo info, int argc, char** argv);
120}
121
122#ifndef DIST
126#define CREATE_AND_RUN(app_class, app_info) \
127 int main(int argc, char** argv) \
128 { \
129 app_class app{}; \
130 return Raito::Core::RunApp(app, app_info, argc, argv); \
131 }
132
133#else
134
135#define CREATE_AND_RUN(app_class, app_info) \
136 INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) \
137 { \
138 app_class app{}; \
139 return Raito::Core::RunApp(app, app_info, __argc, __argv); \
140 }
141
142#endif
143
unsigned __int32 u32
Unsigned integer 32 bit type.
Definition BasicTypes.h:55
#define DISABLE_MOVE_AND_COPY(T)
Definition Common.h:75
Application base class.
Definition Application.h:51
virtual bool OnUpdate()
Definition Application.h:100
void Shutdown()
Shutdown function.
Definition Application.cpp:101
ECS::Scene Scene
Definition Application.h:87
static Application & Get()
Application getter.
Definition Application.h:54
void Close()
Close function.
Definition Application.h:83
friend int RunApp(Application &app, ApplicationInfo info, int argc, char **argv)
Definition Application.cpp:109
virtual void OnShutdown()
Shutdown event function.
Definition Application.h:103
bool m_Running
Definition Application.h:108
virtual bool OnInit()
Initialization event function.
Definition Application.h:92
bool Update()
EndTimeUpdate function.
Definition Application.cpp:83
virtual ~Application()=default
Virtual destructor.
bool Initialize()
Initialization function.
Definition Application.cpp:51
virtual bool OnRenderGUI()
Definition Application.h:96
Application()=default
Application constructor.
Scene class.
Definition Scene.h:43
Definition Application.cpp:43
int RunApp(Application &app, ApplicationInfo info, int argc, char **argv)
Definition Application.cpp:109
API
Renderer Api enumerator.
Definition GraphicsAPI.h:31
Definition Application.h:35
Renderer::API GraphicsAPI
Definition Application.h:41
u32 Height
Definition Application.h:39
std::string Name
Definition Application.h:36
bool Fullscreen
Definition Application.h:43
u32 Width
Definition Application.h:38