Skip to content

Commit

Permalink
⚡️ Fix lag when editing the color gradient on a Color Ramp node
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Nov 8, 2023
1 parent acc0db6 commit 9df9435
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- ✨ Added "Load Backup" in case you accidentally refused to save your unsaved changes.
- 🐛 Fix: the transparency information was sometimes getting lost between nodes.
- 🐛 Fix: crash on Linux "Too many open files".
- ⚡️ Fix lag when editing the color gradient on a Color Ramp node.
- 👩‍💻 Replaced CIELAB with Oklab
- 👩‍💻 Replaced HSLuv with Okhsl

Expand Down
4 changes: 2 additions & 2 deletions src/CommandCore/CommandExecutionContext_Ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class CommandExecutionContext_Ref {
_data.executor.execute(command, *this);
}
template<typename T>
void set_dirty(Cool::VariableId<T> const& id) const
void set_dirty(Cool::VariableId<T> const& id, bool use_secondary_dirty_flag = false) const
{
_data.set_dirty(id);
_data.set_dirty(id, use_secondary_dirty_flag);
}

struct Data { // We wrap our members in a struct to get a constructor automatically
Expand Down
9 changes: 8 additions & 1 deletion src/Commands/Command_SetVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ namespace internal {
template<typename T>
void set_value_default_impl(CommandExecutionContext_Ref const& ctx, const Cool::VariableId<T>& id, const T& value)
{
bool use_secondary_flag{false};
ctx.registries().with_mutable_ref<Cool::Variable<T>>(id, [&](Cool::Variable<T>& variable) {
if constexpr (std::is_same_v<T, Cool::Gradient>)
{
// Request shader code generation only if the number of marks has changed.
use_secondary_flag = variable.value().value.gradient().get_marks().size()
!= value.value.gradient().get_marks().size();
}
variable.value() = value;
});
ctx.set_dirty(id);
ctx.set_dirty(id, use_secondary_flag);
}

} // namespace internal
Expand Down
5 changes: 3 additions & 2 deletions src/Module_Nodes/NodesConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "NodesConfig.h"
#include <Cool/Dependencies/requires_shader_code_generation.h>
#include <Cool/Dependencies/always_requires_shader_code_generation.h>
#include <Module_Nodes/NodeColor.h>
#include <algorithm>
#include <string>
Expand Down Expand Up @@ -319,7 +319,8 @@ auto NodesConfig::make_node(Cool::NodeDefinitionAndCategoryName const& cat_id) -
{
node.value_inputs().push_back(_input_factory.make(
value_input_def,
Cool::requires_shader_code_generation(value_input_def) ? _regenerate_code_flag : _rerender_flag
Cool::always_requires_shader_code_generation(value_input_def) ? _regenerate_code_flag : _rerender_flag,
_regenerate_code_flag // At the moment only used by Gradient variable when we detect that the number of marks has changed. See `set_value_default_impl()` of Command_SetVariable.h
));
node.input_pins().push_back(Cool::InputPin{std::visit([](auto&& value_input_def) { return value_input_def.name; }, value_input_def)});
}
Expand Down

0 comments on commit 9df9435

Please sign in to comment.