Skip to content

Commit

Permalink
feat(tesseratos): add play pause plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Feb 15, 2024
1 parent eaa1c95 commit ebc68d1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/tesseratos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(TESSERATOS_SOURCE
"src/tesseratos/transform_gizmo/plugin.cpp"
"src/tesseratos/metrics_panel/plugin.cpp"
"src/tesseratos/collider_gizmos/plugin.cpp"
"src/tesseratos/play_pause/plugin.cpp"
)

add_library(tesseratos ${TESSERATOS_SOURCE})
Expand Down
26 changes: 26 additions & 0 deletions tools/tesseratos/include/tesseratos/play_pause/plugin.hpp
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
70 changes: 70 additions & 0 deletions tools/tesseratos/src/tesseratos/play_pause/plugin.cpp
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;
}
});
}
2 changes: 2 additions & 0 deletions tools/tesseratos/src/tesseratos/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tesseratos/debug_camera/plugin.hpp>
#include <tesseratos/entity_inspector/plugin.hpp>
#include <tesseratos/metrics_panel/plugin.hpp>
#include <tesseratos/play_pause/plugin.hpp>
#include <tesseratos/plugin.hpp>
#include <tesseratos/scene_editor/plugin.hpp>
#include <tesseratos/settings_inspector/plugin.hpp>
Expand All @@ -22,4 +23,5 @@ void tesseratos::plugin(cubos::engine::Cubos& cubos)
cubos.addPlugin(metricsPanelPlugin);
cubos.addPlugin(transformGizmoPlugin);
cubos.addPlugin(colliderGizmosPlugin);
cubos.addPlugin(playPausePlugin);
}

0 comments on commit ebc68d1

Please sign in to comment.