2D_Game_Engine
Loading...
Searching...
No Matches
application.cpp
Go to the documentation of this file.
1#include <pch.hpp>
2#include <application.hpp>
3#include <buttons.hpp>
4#include <utilities.hpp>
5
6Application::Application(const char *window_name,unsigned int width,unsigned int height,unsigned int fullscreen_width,unsigned int fullscreen_height,bool resizable,bool imgui){
7 m_WindowName=window_name;
10 Window::FullscreenWidth=fullscreen_width;
11 Window::FullscreenHeight=fullscreen_height;
13
14 m_ImGui=imgui;
15
16 Window::InitGlfwWindow(window_name,resizable);
17 m_Scene=new Scene;
18 m_Scene->m_Camera.InitializeProj();
19
20 if(imgui)
22
23 #ifdef DEBUG
24 last_time=glfwGetTime();
26 #endif
27}
28
34
37 if(f11.current && !f11.previous)
39
41 if(f10.current && !f10.previous)
43
45 if(f9.current && !f9.previous)
47
49 if(q.current && !q.previous)
50 glfwSetWindowShouldClose(Window::Window,GL_TRUE);
51}
52
54 PROFILE_FUNCTION();
55
56 while(!glfwWindowShouldClose(Window::Window)){
57 glfwPollEvents();
58
61
62 #ifdef ENABLE_PROFILING
64 if(p.current && !p.previous){
65 Instrumentor::Get().BeginSession("Application","Application.json");
66 printf("Started profiling\n");
67 }
68 #endif
69
71 m_Scene->m_Camera.InitializeProj();
73 }
74
75 Window::CurrentFrameTime=glfwGetTime();
78
79 if(Window::DeltaTime>0.25f)
81
86 }
87
89
91
92 if(m_ImGui){
95 }
96
97 OnRender();
98
101
102 if(m_ImGui){
105 }
106
107 glfwSwapBuffers(Window::Window);
108
109 #ifdef DEBUG
110 double current_time=glfwGetTime();
111 if(current_time-last_time>=4.0){
112 last_time=current_time;
113 printf("FPS: %f\n",1.0/Window::DeltaTime);
115 }
116 #endif
117
118 #ifdef ENABLE_PROFILING
119 if(p.current && !p.previous){
120 Instrumentor::Get().EndSession();
121 printf("Stopped profiling\n");
122 }
123 #endif
124 }
125}
126
127void Application::OnUpdate(const double frame_time){
128 PROFILE_FUNCTION();
129
130 RENDERER->Clear();
131}
132
134 PROFILE_FUNCTION();
135
136 RENDERER->Render();
139}
140
142 PROFILE_FUNCTION();
143
145}
146
148 PROFILE_FUNCTION();
149
151}
void HandleInputs()
#define KEY_P
Definition buttons.hpp:39
#define KEY_Q
Definition buttons.hpp:40
#define KEY_F9
Definition buttons.hpp:84
#define KEY_F11
Definition buttons.hpp:86
#define KEY_F10
Definition buttons.hpp:85
virtual void OnUpdate(const double frame_time)
virtual void OnImGuiRender()
bool m_ImGui
Enable or disable imgui.
virtual void OnRender()
float m_Accumulator
const char * m_WindowName
float m_FixedTimeStep
Physics update time.
Scene * m_Scene
virtual void OnImGuiUpdate()
Application(const char *window_name, unsigned int width, unsigned int height, unsigned int fullscreen_width, unsigned int fullscreen_height, bool resizable=false, bool imgui=true)
void InitializeProj()
Definition camera.cpp:11
void UpdateStates()
Definition input.cpp:5
KeyState GetKey(int key)
Definition input.hpp:20
static void ImGui_End_Frame()
void Clear(bool ambient_light=false) const
Definition renderer.cpp:732
static void ImGui_Close()
void StartScene()
Definition renderer.cpp:446
static void ImGui_Theme()
void DrawScene()
Definition renderer.cpp:481
void ApplyLight()
Definition renderer.cpp:916
static void ImGui_Start_Frame()
static void ImGui_Content()
static void ImGui_Init()
void Render(bool post_processing=false)
Definition renderer.cpp:565
Definition scene.hpp:6
GLFWwindow * Window
Definition window.cpp:225
float Height
Definition window.hpp:43
float BaseWidth
Definition window.cpp:228
void ShowMetrics()
Definition window.cpp:58
const float MAX_WIDTH
Definition window.cpp:251
void ToggleFullScreen()
Definition window.cpp:128
bool ProjUpdate
Definition window.cpp:242
bool ShowMetrics_
Definition window.cpp:239
int InitGlfwWindow(const char *window_name, bool resizable)
Definition window.cpp:71
float Width
Definition window.cpp:227
float MAX_HEIGHT
Definition window.cpp:252
void PrintDebugInfo()
Definition window.cpp:204
float CurrentFrameTime
Definition window.cpp:232
float LastFrameTime
Definition window.cpp:233
float FullscreenWidth
Definition window.cpp:229
void ToggleVSync()
Definition window.cpp:144
float BaseHeight
Definition window.hpp:44
float FullscreenHeight
Definition window.hpp:45
float DeltaTime
Definition window.cpp:234
float Alpha
Definition window.cpp:235
bool previous
Definition input.hpp:11
bool current
Definition input.hpp:10
Renderer * RENDERER
The main renderer.
Definition window.cpp:12
Input * INPUT
The input manager.
Definition window.cpp:14