@@ -14,7 +14,7 @@ namespace volt::runtime {
14
14
{}
15
15
16
16
Scene::Scene (const std::string &name)
17
- : m_name{name}, m_running{false }
17
+ : m_name{name}, m_running{false }, m_paused{ false }
18
18
{}
19
19
20
20
Scene::~Scene (void ) {
@@ -60,9 +60,11 @@ namespace volt::runtime {
60
60
void Scene::Play (void ) noexcept {
61
61
if (not m_running) m_running = true ;
62
62
// Box2D physics world creation
63
- b2WorldDef worldDef = b2DefaultWorldDef ();
64
- worldDef.gravity = {0 .0f , 9 .81f };
65
- m_worldID = b2CreateWorld (&worldDef);
63
+ if (not m_paused) {
64
+ b2WorldDef worldDef = b2DefaultWorldDef ();
65
+ worldDef.gravity = {0 .0f , 9 .81f };
66
+ m_worldID = b2CreateWorld (&worldDef);
67
+ }
66
68
// Box2D body creation of all entities with Rigidbody2D
67
69
ForAll<TransformComponent, Rigidbody2DComponent, renderer::SpriteRendererComponent>([this ](auto e, auto &t, auto &rb, auto &sr) {
68
70
rb.SetExtent ({sr.scale * sr.sprite .width () * 0 .5f , sr.scale * sr.sprite .height () * 0 .5f });
@@ -76,20 +78,23 @@ namespace volt::runtime {
76
78
b2Polygon polygon { b2MakeBox (rb.GetExtent ().x , rb.GetExtent ().y ) };
77
79
b2ShapeDef shapeDef { b2DefaultShapeDef () };
78
80
b2CreatePolygonShape (rb.GetBodyID (), &shapeDef, &polygon);
79
- // Save initial position and rotation
80
- initial_positions[e.GetID ()] = t.position ;
81
- initial_rotations[e.GetID ()] = t.rotation ;
81
+ // Save initial position and rotation (if wasn't in paused state, to not overwrite actual initial values)
82
+ if (not m_paused) {
83
+ initial_positions[e.GetID ()] = t.position ;
84
+ initial_rotations[e.GetID ()] = t.rotation ;
85
+ }
82
86
});
87
+ if (m_paused) m_paused = false ;
83
88
}
84
89
85
90
void Scene::Pause (void ) noexcept {
86
91
if (m_running) m_running = false ;
92
+ if (not m_paused) m_paused = true ;
87
93
}
88
94
89
95
void Scene::Stop (void ) noexcept {
90
- Pause ();
91
- // TODO: figure out how to reset/rewind the scene
92
- // Maybe iterate both hashmaps and ...
96
+ if (m_running) m_running = false ;
97
+ if (m_paused) m_paused = false ;
93
98
for (auto &[id, pos] : initial_positions) {
94
99
auto &t { FindEntityByID (id)->GetComponent <TransformComponent>() };
95
100
t.position = pos;
0 commit comments