Skip to content

Commit

Permalink
🔀 Merge remote-tracking branch 'origin/main' into Time-Speed
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Mar 12, 2024
2 parents 8a8f517 + 18fedbb commit 1ff7cfd
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
[submodule "lib/imgui_gradient"]
path = lib/imgui_gradient
url = https://github.com/CoolLibs/imgui_gradient.git
[submodule "lib/open_link"]
path = lib/open_link
url = https://github.com/CoolLibs/open_link
[submodule "lib/expected"]
path = lib/expected
url = https://github.com/TartanLlama/expected
Expand Down Expand Up @@ -112,3 +109,6 @@
[submodule "lib/oscpack"]
path = lib/oscpack
url = https://github.com/CoolLibs/oscpack
[submodule "lib/open"]
path = lib/open
url = https://github.com/CoolLibs/open
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ add_subdirectory(lib/wafl)
target_link_libraries(Cool-PublicProperties INTERFACE wafl::wafl)

# open_link
add_subdirectory(lib/open_link)
target_link_libraries(Cool-PublicProperties INTERFACE open_link::open_link)
add_subdirectory(lib/open)
target_link_libraries(Cool-PublicProperties INTERFACE Cool::open)

# os_name
add_subdirectory(lib/os_name)
Expand Down
1 change: 1 addition & 0 deletions lib/open
Submodule open added at 3cdf43
1 change: 0 additions & 1 deletion lib/open_link
Submodule open_link deleted from 881827
16 changes: 8 additions & 8 deletions src/Cool/AppManager/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ AppManager::AppManager(WindowManager& window_manager, ViewsManager& views, IApp&
void AppManager::run(std::function<void()> on_update)
{
auto const do_update = [&]() {
#if !DEBUG
try
#endif
{
update();
on_update();
}
#if !DEBUG
catch (std::exception const& e)
{
Cool::Log::ToUser::error("UNKNOWN ERROR 1", e.what());
#if DEBUG
std::cerr << e.what() << '\n';
assert(false); // Please catch the error where appropriate, and handle it properly.
#endif
}
#endif
};
#if defined(COOL_UPDATE_APP_ON_SEPARATE_THREAD)
auto should_stop = false;
Expand Down Expand Up @@ -144,18 +144,18 @@ void AppManager::update()
_app.request_rerender();
if (TextureLibrary_FromFile::instance().update()) // update() needs to be called because update has side effect
_app.request_rerender();
#if !DEBUG
try
#endif
{
_app.update();
}
#if !DEBUG
catch (std::exception const& e)
{
Cool::Log::ToUser::error("UNKNOWN ERROR 2", e.what());
#if DEBUG
std::cerr << e.what() << '\n';
assert(false); // Please catch the error where appropriate, and handle it properly.
#endif
}
#endif
restore_imgui_ini_state_ifn(); // Must be before `imgui_new_frame()` (this is a constraint from Dear ImGui (https://github.com/ocornut/imgui/issues/6263#issuecomment-1479727227))
imgui_new_frame();
check_for_imgui_item_picker_request();
Expand Down
17 changes: 17 additions & 0 deletions src/Cool/Expected/RETURN_IF_ERROR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

/// x should be a std::optional<std::string> representing an optional error message
#define RETURN_IF_ERROR(x) \
{ \
auto maybe_error = x; \
if (maybe_error) \
return tl::make_unexpected(std::move(*maybe_error)); \
}

/// x should be a std::optional<std::string> representing an optional error message
#define RETURN_IF_ERR(x) \
{ \
auto maybe_error = x; \
if (maybe_error) \
return maybe_error; \
}
1 change: 1 addition & 0 deletions src/Cool/Gpu/OpenGL/preprocess_shader_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static auto preprocess_shader_source_impl(std::string_view source, std::vector<s
{
String::replace_all_inplace(line, "_COOL_RES_", Path::cool_res().string());
String::replace_all_inplace(line, "_ROOT_FOLDER_", Path::root().string());
String::replace_all_inplace(line, "_USER_DATA_", Path::user_data().string());
auto const content = line_or_include(line, included_paths);
if (!content)
return content;
Expand Down
1 change: 0 additions & 1 deletion src/Cool/ImGui/ImGuiExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <Cool/Icons/Icons.h>
#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <open_link/open_link.hpp>
#include <ostream>
#include "Cool/ImGui/Fonts.h"
#include "Cool/ImGui/IcoMoonCodepoints.h"
Expand Down
4 changes: 2 additions & 2 deletions src/Cool/ImGui/markdown.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "markdown.h"
#include <imgui_markdown/imgui_markdown.h>
#include <open_link/open_link.hpp>
#include <open/open.hpp>
#include "Cool/ImGui/Fonts.h"
#include "Cool/ImGui/ImGuiExtrasStyle.h"
#include "Fonts.h"
Expand All @@ -12,7 +12,7 @@ static void link_clicked_callback(ImGui::MarkdownLinkCallbackData data)
{
if (data.isImage)
return;
open_link(std::string{data.link, static_cast<size_t>(data.linkLength)}.c_str()); // `link` is not a zero-terminated string, so we must construct a string from the pointer and the length.
open(std::string{data.link, static_cast<size_t>(data.linkLength)}.c_str()); // `link` is not a zero-terminated string, so we must construct a string from the pointer and the length.
}

static void format_callback(ImGui::MarkdownFormatInfo const& info, bool is_beginning);
Expand Down
10 changes: 10 additions & 0 deletions src/Cool/Nodes/EditorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ auto NodesEditorImpl::process_link_creation(NodesConfig& nodes_cfg) -> bool
.from_pin_id = begin_pin->id(),
.to_pin_id = end_pin->id(),
};
{
// Remove all links going into the same pin as the new link
// Must be done before adding the link, otherwise we would remove it too
auto links_to_remove = std::vector<std::pair<LinkId, Link>>{}; // Can't remove while iterating, so we delay it
_graph.for_each_link_connected_to_input_pin(link.to_pin_id, [&](LinkId const& old_link_id, Link const& old_link) {
links_to_remove.emplace_back(old_link_id, old_link);
});
for (auto const& [old_link_id, old_link] : links_to_remove)
nodes_cfg.remove_link(old_link_id, old_link);
}
auto const link_id = nodes_cfg.add_link(link);
nodes_cfg.on_link_created_between_existing_nodes(link, link_id);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Cool/Nodes/NodesDefinitionUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void NodesDefinitionUpdater::add_definition(

{
auto const category_folder = File::without_file_name(path).string();
_library.add_definition(*definition, category_name, make_category_config(category_folder), get_category_order(path, root));
_library.add_definition(*definition, category_name, [&]() { return NodesCategory{category_name, make_category_config(category_folder), get_category_order(path, root)}; });
}

{
Expand Down
7 changes: 0 additions & 7 deletions src/Cool/Nodes/NodesFolderWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ auto NodesFolderWatcher::update(
std::function<NodesCategoryConfig(std::filesystem::path const&)> const& make_category_config
) -> bool
{
// If not in nodes dev mode, we disable hot reloading. We only update the folder watcher once, when the library is empty, to fill it.
if (!Cool::user_settings().nodes_developer_mode
&& !updater.library_is_empty())
{
return false;
}

bool has_changed = false;
auto const clear_errors_and_check_extension = [&](std::filesystem::path const& path) {
Cool::Log::ToUser::console().remove(_error_message_id);
Expand Down
10 changes: 10 additions & 0 deletions src/Cool/Nodes/NodesGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,14 @@ void NodesGraph::for_each_link_connected_to_pin(PinId const& pin_id, std::functi
}
}

void NodesGraph::for_each_link_connected_to_input_pin(PinId const& pin_id, std::function<void(LinkId const&, Link const&)> const& callback) const
{
std::shared_lock lock{_links.mutex()};
for (auto const& [id, link] : _links)
{
if (link.to_pin_id == pin_id)
callback(id, link);
}
}

} // namespace Cool
1 change: 1 addition & 0 deletions src/Cool/Nodes/NodesGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class NodesGraph {
}
void for_each_link_connected_to_node(Node const&, std::function<void(LinkId const&, Link const&, bool is_connected_to_input_pin)> const&) const;
void for_each_link_connected_to_pin(PinId const&, std::function<void(LinkId const&, Link const&, bool is_connected_to_input_pin)> const&) const;
void for_each_link_connected_to_input_pin(PinId const&, std::function<void(LinkId const&, Link const&)> const&) const;

private:
reg::RawRegistry<Node> _nodes;
Expand Down
9 changes: 4 additions & 5 deletions src/Cool/Nodes/NodesLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ auto NodesLibrary::imgui_nodes_menu(std::string const& nodes_filter, MaybeDisabl
}

void NodesLibrary::add_definition(
NodeDefinition const& definition,
std::string category_name,
NodesCategoryConfig const& category_config,
int category_order
NodeDefinition const& definition,
std::string const& category_name,
std::function<NodesCategory()> const& make_category // We take a function because we want to delay the creation of the category until we are sure we need to create one, which is rare (and otherwise would cause warning when two folders correspond to the same category, but only one of them contains the _category_config.json, which happens when reading nodes from both the app's root folder and the user-data folder)
)
{
// Add definition to the corresponding category if it exists
Expand All @@ -108,7 +107,7 @@ void NodesLibrary::add_definition(
}

// Add new category if not found
_categories.push_back(NodesCategory{category_name, category_config, category_order});
_categories.push_back(make_category());
_categories.back().definitions().push_back(definition);
std::sort(
_categories.begin(), _categories.end(),
Expand Down
2 changes: 1 addition & 1 deletion src/Cool/Nodes/NodesLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class NodesLibrary {

auto imgui_nodes_menu(std::string const& nodes_filter, MaybeDisableNodeDefinition const&, bool select_first, bool open_all_categories, bool menu_just_opened) const -> std::optional<NodeDefinitionAndCategoryName>;

void add_definition(NodeDefinition const&, std::string category_name, NodesCategoryConfig const&, int category_order);
void add_definition(NodeDefinition const& definition, std::string const& category_name, std::function<NodesCategory()> const& make_category);

void remove_definition(NodeDefinitionIdentifier const&);

Expand Down
18 changes: 18 additions & 0 deletions src/Cool/String/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ auto substring(
return substring_impl(text, begin, end);
}

void remove_substring(std::string& string, size_t start, size_t end)
{
string.erase(start, end - start);
}

auto find_next_word_position(
std::string_view text,
size_t starting_pos,
Expand Down Expand Up @@ -328,6 +333,19 @@ auto find_previous_word_position(
return std::make_pair(idx1, idx2 + 1);
}

auto find_previous_word(
std::string_view text,
size_t ending_pos,
std::string_view delimiters
) -> std::optional<std::string>
{
auto const position = find_previous_word_position(text, ending_pos, delimiters);
if (!position)
return std::nullopt;

return std::string{substring(text, *position)};
}

auto next_word(
std::string_view text,
size_t starting_pos,
Expand Down
11 changes: 11 additions & 0 deletions src/Cool/String/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ auto substring(
std::pair<size_t, size_t> begin_end
) -> std::string_view;

/// Removes all characters in `string` between `start` (included) and `end` (excluded).
void remove_substring(std::string& string, size_t start, size_t end);

/// Returns the indices of the beginning and end of the next word in "text" after position "starting_pos".
/// Words are considered to be separated by one or more characters of "delimiters".
auto find_next_word_position(
Expand All @@ -170,6 +173,14 @@ auto find_previous_word_position(
std::string_view delimiters = default_word_delimiters
) -> std::optional<std::pair<size_t, size_t>>;

/// Returns the word in "text" before the position "ending_pos". Or nullopt if there is no such word.
/// Words are considered to be separated by one or more characters of "delimiters".
auto find_previous_word(
std::string_view text,
size_t ending_pos,
std::string_view delimiters = default_word_delimiters
) -> std::optional<std::string>;

/// /!\ The returned string_view is only valid as long as the input string_view is valid!
/// Returns the next word after `startingPos`. A word is a block of characters that doesn't contain any of the `delimiters`.
auto next_word(
Expand Down
5 changes: 5 additions & 0 deletions src/Cool/StrongTypes/Camera2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ auto Camera2D::view_matrix() const -> glm::mat3
return res;
}

auto Camera2D::view_projection_matrix(float inverse_aspect_ratio) const -> glm::mat3
{
return glm::scale(glm::mat3{1.f}, glm::vec2{inverse_aspect_ratio, 1.f}) * view_matrix();
}

auto to_string(Camera2D const& cam) -> std::string
{
return fmt::format(
Expand Down
1 change: 1 addition & 0 deletions src/Cool/StrongTypes/Camera2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct Camera2D {
auto transform_matrix() const -> glm::mat3;
/// Inverse of transform_matrix().
auto view_matrix() const -> glm::mat3;
auto view_projection_matrix(float inverse_aspect_ratio) const -> glm::mat3;

friend auto operator==(Camera2D const& a, Camera2D const& b) -> bool = default;

Expand Down
10 changes: 0 additions & 10 deletions src/Cool/UserSettings/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ auto UserSettings::imgui() -> bool
ImGuiExtras::separator_text("Miscellaneous");
b |= imgui_single_click_to_input_in_drag_widgets();
b |= imgui_enable_multi_viewport();
ImGui::NewLine();
ImGuiExtras::separator_text("Advanced");
b |= imgui_nodes_developer_mode();

return b;
}
Expand Down Expand Up @@ -78,13 +75,6 @@ void UserSettings::apply_multi_viewport_setting() const
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_ViewportsEnable;
}

auto UserSettings::imgui_nodes_developer_mode() -> bool
{
bool const b = ImGuiExtras::toggle("Nodes developer mode", &nodes_developer_mode);
ImGuiExtras::help_marker("If you want to write your own nodes, enable this. It will enable hot reloading of the nodes files.");
return b;
}

auto should_enable_multi_viewport_by_default() -> bool
{
#if !defined(__linux__)
Expand Down
13 changes: 1 addition & 12 deletions src/Cool/UserSettings/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@ struct UserSettings {
bool enable_multi_viewport{should_enable_multi_viewport_by_default()};
void apply_multi_viewport_setting() const;

bool nodes_developer_mode
{
#if DEBUG
true
#else
false
#endif
};

auto imgui() -> bool;
auto imgui_autosave() -> bool;
auto imgui_extra_icons() -> bool;
auto imgui_camera2D_zoom_sensitivity() -> bool;
auto imgui_single_click_to_input_in_drag_widgets() -> bool;
auto imgui_enable_multi_viewport() -> bool;
auto imgui_nodes_developer_mode() -> bool;

private:
// Serialization
Expand All @@ -51,8 +41,7 @@ struct UserSettings {
cereal::make_nvp("Camera 2D zoom sensitivity", camera2D_zoom_sensitivity),
cereal::make_nvp("Use OS color theme", color_themes),
cereal::make_nvp("Single click to input in drag widgets", single_click_to_input_in_drag_widgets),
cereal::make_nvp("Enable multi-viewport", enable_multi_viewport),
cereal::make_nvp("Nodes developer mode", nodes_developer_mode)
cereal::make_nvp("Enable multi-viewport", enable_multi_viewport)
);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/Cool/View/GizmoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void GizmoManager::on_drag_update(MouseDragUpdateEvent<ViewCoordinates> const& e
{
with_dragged_gizmo([&](Gizmo_Point2D const& gizmo) {
gizmo.set_position(ViewCoordinates{gizmo.get_position() + event.delta});
ImGui::WrapMousePos(ImGuiAxesMask_All);
});
}

Expand Down

0 comments on commit 1ff7cfd

Please sign in to comment.