Skip to content

Commit

Permalink
🔀 Merge pull request #93 from CoolLibs/Time-Speed
Browse files Browse the repository at this point in the history
Time speed
  • Loading branch information
JulesFouchy authored Mar 12, 2024
2 parents 89ef195 + 215bcd5 commit 5ff549e
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cool
Submodule Cool updated 35 files
+2 −2 src/Cool/Audio/AudioManager.cpp
+5 −5 src/Cool/Exporter/ExporterGui.cpp
+3 −2 src/Cool/Exporter/ExporterGui.h
+5 −3 src/Cool/Exporter/VideoExportProcess.cpp
+1 −1 src/Cool/Exporter/VideoExportProcess.h
+4 −0 src/Cool/Gpu/OpenGL/Shader.cpp
+2 −0 src/Cool/Gpu/OpenGL/Shader.h
+10 −0 src/Cool/StrongTypes/TimeSpeed.cpp
+27 −0 src/Cool/StrongTypes/TimeSpeed.h
+53 −4 src/Cool/Time/Clock.cpp
+47 −8 src/Cool/Time/Clock.h
+5 −3 src/Cool/Time/ClockU.cpp
+1 −1 src/Cool/Time/ClockU.h
+0 −41 src/Cool/Time/Clock_FixedTimestep.cpp
+6 −10 src/Cool/Time/Clock_FixedTimestep.h
+7 −51 src/Cool/Time/Clock_Realtime.cpp
+3 −47 src/Cool/Time/Clock_Realtime.h
+12 −0 src/Cool/Utils/sum.h
+1 −0 src/Cool/Variables/Variable.tpp
+20 −0 src/Cool/Variables/Variable_TimeSpeed.cpp
+2 −0 src/Cool/Variables/Variable_TimeSpeed.h
+2 −1 src/Cool/Variables/generated/AnySharedVariable.inl
+2 −1 src/Cool/Variables/generated/AnySharedVariableDefinition.inl
+2 −1 src/Cool/Variables/generated/AnyVariable.inl
+2 −1 src/Cool/Variables/generated/AnyVariableData.inl
+42 −0 src/Cool/Variables/generated/Variable_TimeSpeed.inl
+1 −0 src/Cool/Variables/generated/all_types_includes.inl
+3 −0 src/Cool/Variables/generated/always_requires_shader_code_generation.inl
+6 −0 src/Cool/Variables/generated/glsl_type.inl
+1 −0 src/Cool/Variables/generated/variables_includes.inl
+8 −0 src/Cool/Variables/generator_variables.py
+53 −60 src/Cool/Variables/internal/BoundsMetadataWidget.h
+78 −76 src/Cool/type_from_string/generated/evaluate_function_template.inl
+1 −0 src/Cool/type_from_string/generated/includes.inl
+5 −0 src/Cool/type_from_string/generated/string_to_type_associations.inl
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

## 🐣beta-15 WIP

- ✨ Added a Time Speed on the timeline, which allows you to slow down or speed up your entire animation easily.
- 🐛 Fixed camera movements when using particles
- 🐛 When dragging gizmos, mouse can now wrap around the screen
- 🐛 Fixed: When writing your own nodes, they were not detected.
Expand Down
36 changes: 17 additions & 19 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void App::update()
{
_project.clock.update();
render_view().update_size(_project.view_constraint); // TODO(JF) Integrate the notion of View Constraint inside the RenderView ? But that's maybe too much coupling
polaroid().render(_project.clock.time(), _project.clock.delta_time());
polaroid().render(_project.clock.time_in_seconds(), _project.clock.delta_time_in_seconds());
}
else
{
Expand Down Expand Up @@ -254,16 +254,6 @@ void App::render(Cool::RenderTarget& render_target, float time, float delta_time
);
}

void App::imgui_commands_debug_windows()
{
auto const the_ui = ui();
the_ui.window({.name = "History"}, [&]() {
_project.history.imgui_show([](const ReversibleCommand& command) {
return command_to_string(command);
});
});
}

void App::imgui_window_cameras()
{
static constexpr auto help_text = "When disabled, prevents you from changing your camera by clicking in the View. This can be useful when working with both 2D and 3D nodes: you don't want both the 2D and 3D cameras active at the same time.";
Expand Down Expand Up @@ -348,8 +338,9 @@ void App::imgui_window_exporter()
{
_project.exporter.imgui_windows({
.polaroid = polaroid(),
.time = _project.clock.time(),
.delta_time = _project.clock.delta_time(),
.time = _project.clock.time_in_seconds(),
.delta_time = _project.clock.delta_time_in_seconds(),
.time_speed = _project.clock.time_speed().value(),
.on_image_exported = [&](std::filesystem::path const& exported_image_path) {
auto folder_path = exported_image_path;
folder_path.replace_extension(); // Give project folder the same name as the image.
Expand Down Expand Up @@ -382,7 +373,11 @@ void App::imgui_windows_only_when_inputs_are_allowed()
auto const the_ui = ui();
// Time
ImGui::Begin(Cool::icon_fmt("Time", ICOMOON_STOPWATCH).c_str());
Cool::ClockU::imgui_timeline(_project.clock, /* on_time_reset = */ [&]() { on_time_reset(); });
Cool::ClockU::imgui_timeline(
_project.clock,
/* extra_widgets = */ [&]() { the_ui.widget(_project.clock.time_speed()); },
/* on_time_reset = */ [&]() { on_time_reset(); }
);
ImGui::End();
// Cameras
ImGui::Begin(Cool::icon_fmt("Cameras", ICOMOON_CAMERA).c_str());
Expand All @@ -403,7 +398,7 @@ void App::imgui_windows_only_when_inputs_are_allowed()
// Share online
_gallery_poster.imgui_window([&](img::Size size) {
auto the_polaroid = polaroid();
the_polaroid.render(_project.clock.time(), _project.clock.delta_time(), size);
the_polaroid.render(_project.clock.time_in_seconds(), _project.clock.delta_time_in_seconds(), size);
auto const image = the_polaroid.render_target.download_pixels();
return img::save_png_to_string(image);
});
Expand All @@ -417,10 +412,13 @@ void App::imgui_windows_only_when_inputs_are_allowed()
if (DebugOptions::show_imgui_demo_window()) // Show the big demo window (Most of the sample code is
ImGui::ShowDemoWindow(&DebugOptions::show_imgui_demo_window()); // in ImGui::ShowDemoWindow()! You can browse its code
// to learn more about Dear ImGui!).
if (DebugOptions::show_commands_debug_windows())
{
imgui_commands_debug_windows();
}
DebugOptions::show_history_window([&] {
ImGui::PushFont(Cool::Font::monospace());
_project.history.imgui_show([](ReversibleCommand const& command) {
return command_to_string(command);
});
ImGui::PopFont();
});
if (DebugOptions::show_nodes_and_links_registries())
{
_project.modules_graph->debug_show_nodes_and_links_registries_windows(ui());
Expand Down
2 changes: 0 additions & 2 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ class App : public Cool::IApp {
void imgui_window_view();
void imgui_window_exporter();

void imgui_commands_debug_windows();

void compile_all_is0_nodes();

private:
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/generated/register_set_variable_commands.inl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LAB_REGISTER_COMMAND(Lab::Command_SetVariable<glm::mat3>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariable<glm::mat4>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariable<Cool::MidiChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariable<Cool::OSCChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariable<Cool::TimeSpeed>)

LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<bool>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<int>)
Expand All @@ -54,3 +55,4 @@ LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<glm::mat3>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<glm::mat4>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<Cool::MidiChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<Cool::OSCChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariable<Cool::TimeSpeed>)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultMetadata<glm::mat3>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultMetadata<glm::mat4>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultMetadata<Cool::MidiChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultMetadata<Cool::OSCChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultMetadata<Cool::TimeSpeed>)

LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadata<bool>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadata<int>)
Expand All @@ -54,3 +55,4 @@ LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadat
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadata<glm::mat4>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadata<Cool::MidiChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadata<Cool::OSCChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultMetadata<Cool::TimeSpeed>)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultValue<glm::mat3>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultValue<glm::mat4>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultValue<Cool::MidiChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultValue<Cool::OSCChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableDefaultValue<Cool::TimeSpeed>)

LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<bool>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<int>)
Expand All @@ -54,3 +55,4 @@ LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<g
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<glm::mat4>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<Cool::MidiChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<Cool::OSCChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableDefaultValue<Cool::TimeSpeed>)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LAB_REGISTER_COMMAND(Lab::Command_SetVariableMetadata<glm::mat3>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableMetadata<glm::mat4>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableMetadata<Cool::MidiChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableMetadata<Cool::OSCChannel>)
LAB_REGISTER_COMMAND(Lab::Command_SetVariableMetadata<Cool::TimeSpeed>)

LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<bool>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<int>)
Expand All @@ -54,3 +55,4 @@ LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<glm::
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<glm::mat4>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<Cool::MidiChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<Cool::OSCChannel>)
LAB_REGISTER_REVERSIBLE_COMMAND(Lab::ReversibleCommand_SetVariableMetadata<Cool::TimeSpeed>)
6 changes: 4 additions & 2 deletions src/Debug/generate_debug_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def all_debug_options():
available_in_release=True,
),
DebugOption(
name_in_code="show_commands_debug_windows",
name_in_ui="Commands windows",
name_in_code="show_history_window",
name_in_ui="Show history",
window_name="History",
kind=Kind.WINDOW,
available_in_release=True,
),
DebugOption(
Expand Down
26 changes: 17 additions & 9 deletions src/Debug/generated/DebugOptions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ public:
}
}
[[nodiscard]] static auto show_imgui_demo_window() -> bool& { return instance().show_imgui_demo_window; }
[[nodiscard]] static auto show_commands_debug_windows() -> bool& { return instance().show_commands_debug_windows; }
static void show_history_window(std::function<void()> callback)
{
if (instance().show_history_window)
{
ImGui::Begin(Cool::icon_fmt("History", ICOMOON_WRENCH).c_str(), &instance().show_history_window, ImGuiWindowFlags_NoFocusOnAppearing);
callback();
ImGui::End();
}
}
[[nodiscard]] static auto show_nodes_and_links_registries() -> bool& { return instance().show_nodes_and_links_registries; }
[[nodiscard]] static auto log_when_rendering() -> bool& { return instance().log_when_rendering; }
[[nodiscard]] static auto log_when_updating_particles() -> bool& { return instance().log_when_updating_particles; }
Expand Down Expand Up @@ -80,7 +88,7 @@ private:
bool copy_info_dump_to_clipboard{false};
bool show_framerate_window{false};
bool show_imgui_demo_window{false};
bool show_commands_debug_windows{false};
bool show_history_window{false};
bool show_nodes_and_links_registries{false};
bool log_when_rendering{false};
bool log_when_updating_particles{false};
Expand All @@ -103,7 +111,7 @@ private:
#if DEBUG
cereal::make_nvp("Framerate window", show_framerate_window),
cereal::make_nvp("ImGui Demo window", show_imgui_demo_window),
cereal::make_nvp("Commands windows", show_commands_debug_windows),
cereal::make_nvp("Show history", show_history_window),
cereal::make_nvp("Show nodes and links registries", show_nodes_and_links_registries),
cereal::make_nvp("Log when rendering", log_when_rendering),
cereal::make_nvp("Log when updating particles", log_when_updating_particles),
Expand All @@ -118,7 +126,7 @@ private:
#else
cereal::make_nvp("Framerate window", show_framerate_window),
cereal::make_nvp("ImGui Demo window", show_imgui_demo_window),
cereal::make_nvp("Commands windows", show_commands_debug_windows),
cereal::make_nvp("Show history", show_history_window),
cereal::make_nvp("Show nodes and links registries", show_nodes_and_links_registries),
cereal::make_nvp("Log when rendering", log_when_rendering),
cereal::make_nvp("Log when updating particles", log_when_updating_particles),
Expand All @@ -140,7 +148,7 @@ private:
{
instance().show_framerate_window = false;
instance().show_imgui_demo_window = false;
instance().show_commands_debug_windows = false;
instance().show_history_window = false;
instance().show_nodes_and_links_registries = false;
instance().log_when_rendering = false;
instance().log_when_updating_particles = false;
Expand Down Expand Up @@ -200,9 +208,9 @@ private:
Cool::ImGuiExtras::toggle("ImGui Demo window", &instance().show_imgui_demo_window);
}

if (wafl::similarity_match({filter, "Commands windows"}) >= wafl::Matches::Strongly)
if (wafl::similarity_match({filter, "Show history"}) >= wafl::Matches::Strongly)
{
Cool::ImGuiExtras::toggle("Commands windows", &instance().show_commands_debug_windows);
Cool::ImGuiExtras::toggle("Show history", &instance().show_history_window);
}

if (wafl::similarity_match({filter, "Show nodes and links registries"}) >= wafl::Matches::Strongly)
Expand Down Expand Up @@ -288,9 +296,9 @@ private:
throw 0.f; // To understand why we need to throw, see `toggle_first_option()` in <Cool/DebugOptions/DebugOptionsManager.h>
}

if (wafl::similarity_match({filter, "Commands windows"}) >= wafl::Matches::Strongly)
if (wafl::similarity_match({filter, "Show history"}) >= wafl::Matches::Strongly)
{
instance().show_commands_debug_windows = !instance().show_commands_debug_windows;
instance().show_history_window = !instance().show_history_window;
throw 0.f; // To understand why we need to throw, see `toggle_first_option()` in <Cool/DebugOptions/DebugOptionsManager.h>
}

Expand Down
4 changes: 2 additions & 2 deletions src/Dependencies/Ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Ui_Ref {
}

template<typename T>
void widget(Cool::SharedVariable<T>& var)
void widget(Cool::SharedVariable<T>& var) const
{
ImGui::PushID(&var);
auto const prev_value = var.value();
Expand Down Expand Up @@ -63,7 +63,7 @@ class Ui_Ref {
ImGui::PopID();
}

void widget(Cool::AnySharedVariable& var)
void widget(Cool::AnySharedVariable& var) const
{
std::visit([&](auto&& var) { widget(var); }, var);
}
Expand Down

0 comments on commit 5ff549e

Please sign in to comment.