hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/core/application.h
blob: 84cc60084379b9e3046a6af45f3758b4b0349961 (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
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

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

#include "rendering/rhi.h"
#include "rendering/scene_renderer.h"
#include "rendering/black_hole_renderer.h"

#include <string>
#include <vector>

namespace Donut
{
    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 build_ui() -> void;
        auto build_scene_ui() -> void;

        auto process_input() -> void;
        auto set_free_fly(bool enabled) -> void;
        auto reset_camera() -> void;
        auto set_hdri(const std::string& path) -> void;

        auto render_frame() -> void;

    private:
        Scope<Window> m_window;

        Scope<RHI::Device>        m_device;
        Scope<SceneRenderer>      m_scene_renderer;
        Scope<BlackHoleRenderer>  m_black_hole_renderer;
        Ref<RHI::Texture>         m_cubemap;

        Camera m_camera{ 60.0f, 16.0f / 9.0f, 0.1f, 100.0f };
        Camera m_scene_camera{ 45.0f, 16.0f / 9.0f, 0.1f, 1000.0f };

        BlackHoleParams m_bh_params;
        std::vector<SceneObject> m_scene_objects{ SceneObject{} };
        int  m_selected_object = 0;
        bool m_scene_mode = false;
        std::string m_hdri_path;

        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;
        bool m_minimized;

        static Application* s_instance;
    };
}