|
@@ -11,6 +11,7 @@
|
|
|
|
|
|
|
|
#include "game/engine/events.hpp"
|
|
#include "game/engine/events.hpp"
|
|
|
#include "game/engine/scene.hpp"
|
|
#include "game/engine/scene.hpp"
|
|
|
|
|
+#include "game/util/env.hpp"
|
|
|
|
|
|
|
|
namespace engine {
|
|
namespace engine {
|
|
|
namespace {
|
|
namespace {
|
|
@@ -21,8 +22,9 @@ namespace engine {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
game_dispatch::game_dispatch()
|
|
game_dispatch::game_dispatch()
|
|
|
- : screen_size({1920.f, 1080.f}), minimum_frame_duration(engine::fps::v60),
|
|
|
|
|
- scenes(), current_timestamp(clock::now()), curr_scene() {}
|
|
|
|
|
|
|
+ : screen_size(env::screen_size()),
|
|
|
|
|
+ minimum_frame_duration(engine::fps::v60), scenes(),
|
|
|
|
|
+ current_timestamp(clock::now()), curr_scene() {}
|
|
|
|
|
|
|
|
game_dispatch::current_scene_info::current_scene_info() {}
|
|
game_dispatch::current_scene_info::current_scene_info() {}
|
|
|
|
|
|
|
@@ -53,7 +55,7 @@ namespace engine {
|
|
|
return {now, now - current_timestamp};
|
|
return {now, now - current_timestamp};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- double game_dispatch::next_frame() {
|
|
|
|
|
|
|
+ float game_dispatch::next_frame() {
|
|
|
tick t = get_tick();
|
|
tick t = get_tick();
|
|
|
|
|
|
|
|
while (t.since < minimum_frame_duration) {
|
|
while (t.since < minimum_frame_duration) {
|
|
@@ -62,19 +64,10 @@ namespace engine {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
current_timestamp = t.now;
|
|
current_timestamp = t.now;
|
|
|
- return std::chrono::duration<double>(t.since).count();
|
|
|
|
|
|
|
+ return std::chrono::duration<float>(t.since).count();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void game_dispatch::gameloop() try {
|
|
|
|
|
- while (running) {
|
|
|
|
|
- single_frame(next_frame());
|
|
|
|
|
- }
|
|
|
|
|
- cleanup_resources();
|
|
|
|
|
- exit(EXIT_SUCCESS);
|
|
|
|
|
- } catch (std::exception const & ex) {
|
|
|
|
|
- // todo: logging
|
|
|
|
|
- exit(EXIT_FAILURE);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ void game_dispatch::update() { curr_scene.ptr->update(next_frame()); }
|
|
|
|
|
|
|
|
- void game_dispatch::quit() { running = false; }
|
|
|
|
|
|
|
+ void game_dispatch::render() { curr_scene.ptr->render(); }
|
|
|
}
|
|
}
|