sculpto
application.cpp
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file application.cpp
3 * \brief
4 *
5 * \author Sabitov Kirill
6 * \date 19 June 2022
7 *********************************************************************/
8
9#include "sclpch.h"
10
11#include <imgui.h>
12
13#include "application.h"
14#include "../render/render_bridge.h"
15#include "../render/renderer.h"
16
17scl::application *scl::application::Instance = nullptr;
18
19scl::application::application(const std::string &Name)
20{
21 // Application singleton instance initialisation
22 SCL_CORE_ASSERT(Instance == nullptr, "Application instance already exist.");
23 Instance = this;
24
25 // Application core subsystems initialisation
27 Window = window::Create(700, 400, Name + " (Sculpto application).");
28 render_bridge::InitContext();
29 // renderer::Initialize();
30 gui::Init();
31
32 // Setup event handlers
33 event_dispatcher::AddEventListner<close_event>([&](close_event &) { SCL_CORE_INFO("Application close event handled."); IsRunning = false; return false; });
34}
35
36scl::application::~application()
37{
38 // Do nothing in destructor (do nont deinitialise application subsystems)
39 // for having oportunity to do it when everything still do not destroed. E.g.
40 // when application destructor called window is already destroyed and Dead ImGui
41 // cannot be deintialised properly.
42}
43
44void scl::application::LoopIterationActions()
45{
46 // Update application subsystems
47 timer::Get()->Response();
48 input_system::Response();
49
50 // Update window
51 Window->Update();
52
53 // Do nothing if application is already closed.
54 if (!IsRunning) return;
55
56 // Rendering GUI, handle user actions
57 if (GuiEnabled)
58 {
59 gui::BeginUpdate();
60 OnGuiUpdate();
61 gui::SubmitUpdate();
62 }
63
64 // Update application
65 OnUpdate(timer::GetDeltaTime());
66
67 render_bridge::SwapBuffers();
68}
69
70void scl::application::Run()
71{
72 // Client application initialisation.
73 // Not called in constructor, after all subsystems initilisation, because of
74 // imposibility to call virtual functions in constructor.
75 // Is happes due to the fact that the table of virtual pointers is created
76 // only after the call to the base class constructor has completed
77 SCL_CORE_INFO("User application initialisation started");
78 this->OnInit();
79 SCL_CORE_INFO("User application initialised.");
80
81 // Starting main loop
82 SCL_CORE_INFO("Application main loop started.");
83 while (IsRunning)
84 this->LoopIterationActions();
85
86 SCL_CORE_INFO("Application main loop ended.");
87
88 // Deisnitalise application subsystems
89 this->OnClose();
90 gui::Close();
91 render_bridge::CloseContext();
92}
93
94void scl::application::ShutDown()
95{
96 SCL_CORE_INFO("Application shut down function called.");
97 Window->ShutDown();
98}
#define SCL_CORE_ASSERT(expr,...)
Definition: assert.h:69
static void Init()
Definition: log.cpp:15
#define SCL_CORE_INFO(...)
Definition: log.h:41
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.