Unravel Engine C++ Reference
Loading...
Searching...
No Matches
play_mode.h
Go to the documentation of this file.
1#pragma once
2
3#include <engine/engine_export.h>
4
5#include <base/basetypes.hpp>
6#include <context/context.hpp>
7
8#include "splash_scene.h"
9
10namespace unravel
11{
12
13struct events;
14
17{
18 enum class phase
19 {
21 splash,
22 running,
23 };
24
25 auto init(rtti::context& ctx) -> bool;
26 auto deinit(rtti::context& ctx) -> bool;
27
28 void toggle(rtti::context& ctx, bool allow_splash = true);
29 void set_active(rtti::context& ctx, bool active, bool allow_splash = true);
30 void set_paused(rtti::context& ctx, bool paused);
31 void toggle_pause(rtti::context& ctx);
33
35
36 [[nodiscard]] auto is_active() const -> bool
37 {
38 return current_phase_ != phase::inactive;
39 }
40
41 [[nodiscard]] auto is_simulation_running() const -> bool
42 {
43 return current_phase_ == phase::running;
44 }
45
46 [[nodiscard]] auto is_splash() const -> bool
47 {
48 return current_phase_ == phase::splash;
49 }
50
51 [[nodiscard]] auto is_paused() const -> bool
52 {
53 return is_paused_;
54 }
55
56 [[nodiscard]] auto frames_running() const -> uint64_t
57 {
58 return frames_running_;
59 }
60
62
63 [[nodiscard]] auto current_phase() const -> phase
64 {
65 return current_phase_;
66 }
67
68private:
69 void begin_play(rtti::context& ctx, bool allow_splash = true);
70 void end_play(rtti::context& ctx);
71 void enter_running(rtti::context& ctx);
72 [[nodiscard]] auto should_show_splash(rtti::context& ctx) const -> bool;
73
74 phase current_phase_ = phase::inactive;
75 bool is_paused_ = false;
76 uint64_t frames_running_ = 0;
77 splash_scene_state splash_state_{};
78
79 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
80};
81
82} // namespace unravel
std::chrono::duration< float > delta_t
Owns play-mode state and orchestrates the splash -> running lifecycle.
Definition play_mode.h:17
auto deinit(rtti::context &ctx) -> bool
Definition play_mode.cpp:23
void toggle(rtti::context &ctx, bool allow_splash=true)
Definition play_mode.cpp:33
void set_paused(rtti::context &ctx, bool paused)
Definition play_mode.cpp:59
auto is_paused() const -> bool
Definition play_mode.h:51
void set_active(rtti::context &ctx, bool active, bool allow_splash=true)
Definition play_mode.cpp:43
auto init(rtti::context &ctx) -> bool
Definition play_mode.cpp:15
void skip_next_frame(rtti::context &ctx)
Definition play_mode.cpp:84
void toggle_pause(rtti::context &ctx)
Definition play_mode.cpp:74
auto is_splash() const -> bool
Definition play_mode.h:46
auto frames_running() const -> uint64_t
Definition play_mode.h:56
auto is_simulation_running() const -> bool
Definition play_mode.h:41
void on_frame_update(rtti::context &ctx, delta_t dt)
Definition play_mode.cpp:97
auto is_active() const -> bool
Definition play_mode.h:36
auto current_phase() const -> phase
Definition play_mode.h:63