Skip to content

Commit 7afc7a2

Browse files
committed
Add App::m_game
1 parent 7f8d075 commit 7afc7a2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/app.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <imgui.h>
22
#include <app.hpp>
33
#include <djson/json.hpp>
4+
#include <game.hpp>
5+
#include <klib/visitor.hpp>
46
#include <log.hpp>
57

68
namespace miracle {
@@ -19,13 +21,22 @@ App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("as
1921
}
2022

2123
void App::run() {
22-
while (m_context.is_running()) {
23-
m_context.next_frame();
24+
auto game = Game{&m_services};
2425

25-
ImGui::ShowDemoWindow();
26+
auto const event_visitor = klib::SubVisitor{
27+
[&game](le::event::CursorPos const& cursor_pos) { game.on_cursor_pos(cursor_pos); },
28+
};
2629

30+
auto delta_time = kvf::DeltaTime{};
31+
while (m_context.is_running()) {
32+
m_context.next_frame();
33+
auto const dt = delta_time.tick();
34+
for (auto const& event : m_context.event_queue()) { std::visit(event_visitor, event); }
35+
game.tick(dt);
36+
if (auto renderer = m_context.begin_render()) { game.render(renderer); }
2737
m_context.present();
2838
}
39+
m_context.wait_idle();
2940
}
3041

3142
void App::bind_services() {

0 commit comments

Comments
 (0)