-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tesseratos): add play pause plugin
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// @dir | ||
/// @brief @ref tesseratos-play-pause-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup tesseratos-play-pause-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/prelude.hpp> | ||
|
||
namespace tesseratos | ||
{ | ||
/// @defgroup tesseratos-play-pause-plugin Play Pause | ||
/// @ingroup tesseratos | ||
/// @brief Allows changing the current simulation speed, or even pause it. | ||
/// | ||
/// ## Dependencies | ||
/// - @ref imgui-plugin | ||
/// - @ref tesseratos-toolbox-plugin | ||
|
||
/// @brief Plugin entry function. | ||
/// @param cubos @b CUBOS. main class | ||
/// @ingroup tesseratos-play-pause-plugin | ||
void playPausePlugin(cubos::engine::Cubos& cubos); | ||
} // namespace tesseratos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <imgui.h> | ||
|
||
#include <cubos/engine/imgui/plugin.hpp> | ||
|
||
#include <tesseratos/play_pause/plugin.hpp> | ||
#include <tesseratos/toolbox/plugin.hpp> | ||
|
||
using cubos::core::reflection::reflect; | ||
|
||
using cubos::engine::Cubos; | ||
using cubos::engine::DeltaTime; | ||
|
||
namespace | ||
{ | ||
struct State | ||
{ | ||
bool paused{false}; | ||
float multiplier{1.0F}; | ||
}; | ||
} // namespace | ||
|
||
void tesseratos::playPausePlugin(Cubos& cubos) | ||
{ | ||
cubos.addPlugin(cubos::engine::imguiPlugin); | ||
cubos.addPlugin(toolboxPlugin); | ||
|
||
cubos.addResource<State>(); | ||
|
||
cubos.system("show Play Pause UI").tagged("cubos.imgui").call([](State& state, Toolbox& toolbox, DeltaTime& dt) { | ||
if (!toolbox.isOpen("Play Pause")) | ||
{ | ||
return; | ||
} | ||
|
||
if (ImGui::Begin("Play Pause")) | ||
{ | ||
if (ImGui::Button("Play")) | ||
{ | ||
state.paused = false; | ||
dt.multiplier = state.multiplier; | ||
} | ||
|
||
ImGui::SameLine(); | ||
|
||
if (ImGui::Button("Pause")) | ||
{ | ||
state.paused = true; | ||
dt.multiplier = 0.0; | ||
} | ||
|
||
ImGui::SameLine(); | ||
|
||
ImGui::Text(state.paused ? "(Paused)" : "(Running)"); | ||
|
||
ImGui::SliderFloat("Speed Multiplier", &state.multiplier, 0.0F, 5.0F); | ||
|
||
if (ImGui::Button("Reset")) | ||
{ | ||
state.multiplier = 1.0F; | ||
} | ||
|
||
ImGui::End(); | ||
} | ||
|
||
if (!state.paused) | ||
{ | ||
dt.multiplier = state.multiplier; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters