Brenta Engine 1.2
Loading...
Searching...
No Matches
app.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8namespace brenta
9{
10
11class RenderPipeline;
12
13//
14// App runner
15// ----------
16//
17// This class provides a simple main, and a structure to organize the
18// overall execution of an application in distinct phases. This is
19// just for convenience since the main loop of many applications look
20// the same.
21//
22// The user needs to define setup(), set_pipeline(), update(), draw()
23// and cleanup(). Define BRENTA_MAIN before including this header to
24// include a main function.
25//
26class App
27{
28public:
29
30 App() = delete;
31 ~App() = delete;
32
33 static bool setup();
34 static tenno::shared_ptr<RenderPipeline> set_pipeline();
35 static bool update(float delta_time);
36 static bool draw(tenno::shared_ptr<RenderPipeline> pipeline);
37 static void cleanup();
38
39};
40
41} // namespace brenta
42
43
44#ifdef BRENTA_MAIN
45
46int main()
47{
48 if (!brenta::App::setup()) // user implemented
49 return 1;
50
51 {
52 auto pipeline = brenta::App::set_pipeline(); // user implemented
53
54 while(!brenta::Window::should_close())
55 {
56 auto delta_time = brenta::Window::get_time().delta;
57
58 if (!brenta::App::update(delta_time)) // user implemented
59 break;
60
61 if (!brenta::App::draw(pipeline)) // user implemented
62 break;
63
64 brenta::Window::poll_events();
65 brenta::Window::swap_buffers();
66 }
67
68 }
69
70 brenta::App::cleanup(); // user implemented
71 return 0;
72}
73
74#endif