Skip to content

Commit

Permalink
✨ [Time] Strong type
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed May 26, 2024
1 parent de55796 commit 2faf6ee
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cool
Submodule Cool updated 48 files
+1 −1 lib/Audio
+2 −2 src/Cool/Audio/AudioManager.cpp
+1 −1 src/Cool/Exporter/ExporterGui.cpp
+3 −3 src/Cool/Exporter/ExporterGui.h
+1 −1 src/Cool/Exporter/ExporterU.cpp
+1 −1 src/Cool/Exporter/ExporterU.h
+16 −16 src/Cool/Exporter/VideoExportParams.cpp
+4 −3 src/Cool/Exporter/VideoExportParams.h
+18 −16 src/Cool/Exporter/VideoExportProcess.cpp
+7 −7 src/Cool/Exporter/VideoExportProcess.h
+3 −3 src/Cool/Exporter/internal/ImageExportJob.h
+4 −3 src/Cool/Exporter/internal/Polaroid.h
+9 −9 src/Cool/Exporter/internal/origin_of_frames.h
+4 −0 src/Cool/Gpu/OpenGL/Shader.cpp
+2 −2 src/Cool/Gpu/OpenGL/Shader.h
+11 −3 src/Cool/ImGui/ImGuiExtras.cpp
+2 −1 src/Cool/ImGui/ImGuiExtras.h
+9 −13 src/Cool/Image/SaveImage.cpp
+9 −9 src/Cool/Image/SaveImage.h
+3 −3 src/Cool/Midi/MidiManager.cpp
+2 −1 src/Cool/Midi/MidiManager.h
+0 −10 src/Cool/StrongTypes/TimeSpeed.cpp
+2 −2 src/Cool/TextureSource/TextureLibrary_Image.cpp
+2 −2 src/Cool/TextureSource/TextureLibrary_Video.cpp
+13 −36 src/Cool/Time/Clock.cpp
+16 −13 src/Cool/Time/Clock.h
+2 −7 src/Cool/Time/ClockU.cpp
+0 −1 src/Cool/Time/ClockU.h
+4 −4 src/Cool/Time/Clock_FixedTimestep.h
+2 −2 src/Cool/Time/Clock_Realtime.cpp
+1 −1 src/Cool/Time/Clock_Realtime.h
+72 −0 src/Cool/Time/Time.cpp
+51 −0 src/Cool/Time/Time.h
+16 −0 src/Cool/Time/TimeSpeed.cpp
+4 −3 src/Cool/Time/TimeSpeed.h
+16 −12 src/Cool/Time/time_formatted_hms.cpp
+3 −3 src/Cool/Time/time_formatted_hms.h
+2 −5 src/Cool/Variables/Variable_TimeSpeed.cpp
+4 −4 src/Cool/Variables/generated/Variable_TimeSpeed.inl
+1 −1 src/Cool/Variables/generated/all_types_includes.inl
+8 −9 src/Cool/Variables/generator_variables.py
+17 −0 src/Cool/Variables/internal/BoundsMetadataWidget.h
+1 −1 src/Cool/Video/VideoDescriptor.cpp
+4 −2 src/Cool/Video/VideoDescriptor.h
+5 −6 src/Cool/Video/VideoPlayer.cpp
+2 −2 src/Cool/Video/VideoPlayer.h
+4 −3 src/Cool/Video/hack_get_global_time_in_seconds.h
+1 −1 src/Cool/type_from_string/generated/includes.inl
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

## 🐣beta-18 WIP

- ✨ The Output Window can now easily be turned fullscreen with F10
- ✨ Every time input is now nicely formatted like "1h 27m 53s"
- ✨ The Output Window can now easily be turned fullscreen with <kbd>F10</kbd>
- ✨ When opening the Output Window, the aspect ratio automatically adapts to it
- ✨ The Output Window now doesn't have a title bar
- 🟦 Nodes: Added "MIDI Multi-Select with Transition"
Expand Down
20 changes: 12 additions & 8 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void App::update()
_project.current_clock(),
_project.exporter.is_exporting() /* force_sync_time */
);
Cool::hack_get_global_time_in_seconds() = _project.current_clock().time_in_seconds();
Cool::hack_get_global_time_in_seconds() = _project.current_clock().time();
Cool::hack_get_is_exporting() = _project.exporter.is_exporting();
_project.audio.update(/*on_audio_data_changed = */ [&]() {
_project.modules_graph->on_audio_changed();
Expand All @@ -158,7 +158,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_in_seconds(), _project.clock.delta_time_in_seconds());
polaroid().render(_project.clock.time(), _project.clock.delta_time());
}
else
{
Expand Down Expand Up @@ -215,7 +215,7 @@ Cool::Polaroid App::polaroid()
{
return {
.render_target = render_view().render_target(), // TODO(Modules) Each module should have its own render target that it renders on. The views shouldn't have a render target, but receive the one of the top-most module by reference.
.render_fn = [this](Cool::RenderTarget& render_target, float time, float delta_time) {
.render_fn = [this](Cool::RenderTarget& render_target, Cool::Time time, Cool::Time delta_time) {
if (_last_time != time)
{
_last_time = time;
Expand Down Expand Up @@ -244,7 +244,7 @@ static void imgui_window_console()
#endif
}

void App::render(Cool::RenderTarget& render_target, float time, float delta_time)
void App::render(Cool::RenderTarget& render_target, Cool::Time time, Cool::Time delta_time)
{
_project.modules_graph->render(
render_target,
Expand Down Expand Up @@ -337,8 +337,8 @@ void App::imgui_window_exporter()
{
_project.exporter.imgui_windows({
.polaroid = polaroid(),
.time = _project.clock.time_in_seconds(),
.delta_time = _project.clock.delta_time_in_seconds(),
.time = _project.clock.time(),
.delta_time = _project.clock.delta_time(),
.time_speed = _project.clock.time_speed().value(),
.on_image_exported = [&](std::filesystem::path const& exported_image_path) {
auto folder_path = exported_image_path;
Expand Down Expand Up @@ -374,7 +374,11 @@ void App::imgui_windows_only_when_inputs_are_allowed()
ImGui::Begin(Cool::icon_fmt("Time", ICOMOON_STOPWATCH).c_str());
Cool::ClockU::imgui_timeline(
_project.clock,
/* extra_widgets = */ [&]() { the_ui.widget(_project.clock.time_speed()); },
/* extra_widgets = */ [&]() {
ImGui::SetNextItemWidth(70.f);
the_ui.widget(_project.clock.time_speed());
//
},
/* on_time_reset = */ [&]() { on_time_reset(); }
);
ImGui::End();
Expand All @@ -397,7 +401,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_in_seconds(), _project.clock.delta_time_in_seconds(), size);
the_polaroid.render(_project.clock.time(), _project.clock.delta_time(), size);
auto const image = the_polaroid.render_target.download_pixels();
return img::save_png_to_string(image);
});
Expand Down
6 changes: 3 additions & 3 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class App : public Cool::IApp {
auto nodes_library() const -> Cool::NodesLibrary const& { return _nodes_library_manager.library(); }

private:
void render(Cool::RenderTarget& render_target, float time, float delta_time);
void render(Cool::RenderTarget& render_target, Cool::Time time, Cool::Time delta_time);
void on_time_changed();
void on_time_reset();
auto render_view() -> Cool::RenderView&;
Expand All @@ -75,7 +75,7 @@ class App : public Cool::IApp {
auto command_executor_without_history () { return CommandExecutor_WithoutHistory_Ref{}; }
auto command_executor_top_level () -> CommandExecutor_TopLevel { return CommandExecutor_TopLevel{command_executor_without_history(), _project.history, make_reversible_commands_context()}; }
auto command_executor () { return CommandExecutor{command_execution_context()}; }
auto system_values (img::Size render_target_size, float time, float delta_time) { return SystemValues{render_target_size, time, delta_time, _project.camera_2D_manager.camera(), _project.camera_3D_manager.camera(), _project.audio}; }
auto system_values (img::Size render_target_size, Cool::Time time, Cool::Time delta_time) { return SystemValues{render_target_size, time, delta_time, _project.camera_2D_manager.camera(), _project.camera_3D_manager.camera(), _project.audio}; }
auto ui () { return Ui_Ref{command_executor()}; }
// clang-format on

Expand Down Expand Up @@ -105,7 +105,7 @@ class App : public Cool::IApp {
Project _project{};
std::optional<std::filesystem::path> _current_project_path{};
RecentlyOpened _recently_opened_projects{};
float _last_time{0.f};
Cool::Time _last_time{0s};
bool _wants_view_in_fullscreen{false}; // Boolean that anyone can set to true or false at any moment to toggle the view's fullscreen mode.
bool _view_was_in_fullscreen_last_frame{false};
GalleryPoster _gallery_poster{};
Expand Down
4 changes: 2 additions & 2 deletions src/Dependencies/SystemValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Lab {

struct SystemValues {
img::Size render_target_size{};
float time{};
float delta_time{};
Cool::Time time{};
Cool::Time delta_time{};
Cool::Camera2D camera_2D{};
Cool::Camera camera_3D{};
std::reference_wrapper<Cool::AudioManager const> audio_manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Nodes/Node.h"
#include "Nodes/valid_input_name.h"


namespace Lab {

template<typename T>
Expand Down Expand Up @@ -102,12 +101,12 @@ auto set_uniforms_for_shader_based_module(
shader.set_uniform("_height", system_values.height());
shader.set_uniform("_last_midi_button_pressed", Cool::midi_manager().all_values().last_button_pressed());
shader.set_uniform("_last_last_midi_button_pressed", Cool::midi_manager().all_values().last_last_button_pressed());
shader.set_uniform("_time_since_last_midi_button_pressed", Cool::midi_manager().all_values().time_since_last_button_pressed_in_seconds());
shader.set_uniform("_time_since_last_midi_button_pressed", Cool::midi_manager().all_values().time_since_last_button_pressed().as_seconds_float());
shader.set_uniform("_aspect_ratio", system_values.aspect_ratio());
shader.set_uniform("_inverse_aspect_ratio", system_values.inverse_aspect_ratio());
shader.set_uniform_texture("mixbox_lut", Cool::TextureLibrary_Image::instance().get(Cool::Path::root() / "res/mixbox/mixbox_lut.png")->id());
shader.set_uniform("_time", system_values.time);
shader.set_uniform("_delta_time", system_values.delta_time);
shader.set_uniform("_time", system_values.time.as_seconds_float());
shader.set_uniform("_delta_time", system_values.delta_time.as_seconds_float());

if (depends_on.audio_volume)
shader.set_uniform("_audio_volume", system_values.audio_manager.get().volume());
Expand Down

0 comments on commit 2faf6ee

Please sign in to comment.