aboutsummaryrefslogtreecommitdiff
path: root/src/core/application.h
blob: cbd741d0991a9466e149032dcce45f7a05adbea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "memory.h"
#include "window.h"
#include "event.h"
#include "log.h"

#include "rendering/rhi.h"
#include "rendering/render_path.h"
#include "rendering/view.h"
#include "scene/scene.h"
#include "ui/ui_layer.h"

#include <string>

namespace Donut
{
    // Thin shell: owns the window, the RHI device, the Scene (document), the
    // RenderPath (device-side rendering) and the UILayer (tabbed workspaces), and
    // runs the frame loop that wires them together. All the rendering lives in the
    // RHI + shared renderers; all the editing lives in the Scene + workspaces.
    class Application
    {
    public:
        Application(const std::string& name = "Donut",
                    int width = 1280, int height = 720);
        ~Application();

        auto run() -> void;
        auto close() -> void;

        auto get_window() -> Window&      { return *m_window;   }
        static auto get() -> Application&  { return *s_instance; }

    private:
        auto on_init() -> void;
        auto on_shutdown() -> void;
        auto on_event(Event& event) -> void;

        auto render_frame() -> void;
        auto update_input(View view) -> void;   // orbit / free-fly / zoom for the active camera

    private:
        Scope<Window>      m_window;
        Scope<RHI::Device> m_device;
        Scope<Scene>       m_scene;
        Scope<RenderPath>  m_render_path;
        Scope<UILayer>     m_ui;

        // input tracking (per-frame transient state)
        bool   m_left_was_down = false;
        double m_fps_last_x = 0.0, m_fps_last_y = 0.0;
        double m_last_frame_time = 0.0;
        double m_start_time = 0.0;
        bool   m_user_moving = false;

        bool m_running   = true;
        bool m_minimized = false;

        static Application* s_instance;
    };
}