From ded1b0fe538c248eea516a6e20df1e9c383a1dcf Mon Sep 17 00:00:00 2001 From: Michael Ragazzon Date: Sun, 6 Oct 2024 16:59:06 +0200 Subject: [PATCH] Code cleanup: Fix some always true/false conditions --- Backends/RmlUi_Renderer_GL3.cpp | 8 +++----- Include/RmlUi/Core/PropertySpecification.h | 2 +- Samples/invaders/src/ElementGame.cpp | 2 +- Samples/lua_invaders/src/ElementGame.cpp | 2 +- Source/Core/DataViewDefault.cpp | 2 +- Source/Core/Elements/WidgetSlider.cpp | 17 +++++++---------- Source/Core/PropertySpecification.cpp | 10 +++++----- Source/Core/WidgetScroll.cpp | 2 +- 8 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Backends/RmlUi_Renderer_GL3.cpp b/Backends/RmlUi_Renderer_GL3.cpp index 51f331701..183682353 100644 --- a/Backends/RmlUi_Renderer_GL3.cpp +++ b/Backends/RmlUi_Renderer_GL3.cpp @@ -480,7 +480,7 @@ struct FramebufferData { bool owns_depth_stencil_buffer; }; -enum class FramebufferAttachment { None, Depth, DepthStencil }; +enum class FramebufferAttachment { None, DepthStencil }; static void CheckGLError(const char* operation_name) { @@ -670,12 +670,10 @@ static bool CreateFramebuffer(FramebufferData& out_fb, int width, int height, in glGenRenderbuffers(1, &depth_stencil_buffer); glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_buffer); - const GLenum internal_format = (attachment == FramebufferAttachment::DepthStencil ? GL_DEPTH24_STENCIL8 : GL_DEPTH_COMPONENT24); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, internal_format, width, height); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH24_STENCIL8, width, height); } - const GLenum attachment_type = (attachment == FramebufferAttachment::DepthStencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment_type, GL_RENDERBUFFER, depth_stencil_buffer); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_buffer); } const GLuint framebuffer_status = glCheckFramebufferStatus(GL_FRAMEBUFFER); diff --git a/Include/RmlUi/Core/PropertySpecification.h b/Include/RmlUi/Core/PropertySpecification.h index 1b0f7518b..d0871e6e4 100644 --- a/Include/RmlUi/Core/PropertySpecification.h +++ b/Include/RmlUi/Core/PropertySpecification.h @@ -137,7 +137,7 @@ class RMLUICORE_API PropertySpecification { PropertyIdSet property_ids_forcing_layout; enum class SplitOption { None, Whitespace, Comma }; - bool ParsePropertyValues(StringList& values_list, const String& values, SplitOption split_option) const; + void ParsePropertyValues(StringList& values_list, const String& values, SplitOption split_option) const; friend class Rml::StyleSheetSpecification; friend class TestPropertySpecification; diff --git a/Samples/invaders/src/ElementGame.cpp b/Samples/invaders/src/ElementGame.cpp index a6b19410f..cdb74981d 100644 --- a/Samples/invaders/src/ElementGame.cpp +++ b/Samples/invaders/src/ElementGame.cpp @@ -63,7 +63,7 @@ void ElementGame::ProcessEvent(Rml::Event& event) if (key_identifier == Rml::Input::KI_SPACE) game->GetDefender()->Fire(); } - else if (!key_down) + else { if (key_identifier == Rml::Input::KI_LEFT) game->GetDefender()->StopMove(-1.0f); diff --git a/Samples/lua_invaders/src/ElementGame.cpp b/Samples/lua_invaders/src/ElementGame.cpp index 27ff353f6..7b2bced7e 100644 --- a/Samples/lua_invaders/src/ElementGame.cpp +++ b/Samples/lua_invaders/src/ElementGame.cpp @@ -63,7 +63,7 @@ void ElementGame::ProcessEvent(Rml::Event& event) if (key_identifier == Rml::Input::KI_SPACE) game->GetDefender()->Fire(); } - else if (!key_down) + else { if (key_identifier == Rml::Input::KI_LEFT) game->GetDefender()->StopMove(-1.0f); diff --git a/Source/Core/DataViewDefault.cpp b/Source/Core/DataViewDefault.cpp index 42766097f..1200ee6b0 100644 --- a/Source/Core/DataViewDefault.cpp +++ b/Source/Core/DataViewDefault.cpp @@ -104,7 +104,7 @@ bool DataViewAttribute::Update(DataModel& model) const String value = variant.Get(); const Variant* attribute = element->GetAttribute(attribute_name); - if (!attribute || (attribute && attribute->Get() != value)) + if (!attribute || attribute->Get() != value) { element->SetAttribute(attribute_name, value); result = true; diff --git a/Source/Core/Elements/WidgetSlider.cpp b/Source/Core/Elements/WidgetSlider.cpp index df29b1967..9256235d3 100644 --- a/Source/Core/Elements/WidgetSlider.cpp +++ b/Source/Core/Elements/WidgetSlider.cpp @@ -127,20 +127,17 @@ bool WidgetSlider::Initialise() void WidgetSlider::Update() { + if (!std::any_of(std::begin(arrow_timers), std::end(arrow_timers), [](float timer) { return timer > 0; })) + return; + + const double current_time = Clock::GetElapsedTime(); + const float delta_time = float(current_time - last_update_time); + last_update_time = current_time; + for (int i = 0; i < 2; i++) { - bool updated_time = false; - float delta_time = 0; - if (arrow_timers[i] > 0) { - if (!updated_time) - { - double current_time = Clock::GetElapsedTime(); - delta_time = float(current_time - last_update_time); - last_update_time = current_time; - } - arrow_timers[i] -= delta_time; while (arrow_timers[i] <= 0) { diff --git a/Source/Core/PropertySpecification.cpp b/Source/Core/PropertySpecification.cpp index 13e76e44a..bf9b7a921 100644 --- a/Source/Core/PropertySpecification.cpp +++ b/Source/Core/PropertySpecification.cpp @@ -248,7 +248,8 @@ bool PropertySpecification::ParsePropertyDeclaration(PropertyDictionary& diction return false; StringList property_values; - if (!ParsePropertyValues(property_values, property_value, SplitOption::None) || property_values.empty()) + ParsePropertyValues(property_values, property_value, SplitOption::None); + if (property_values.empty()) return false; Property new_property; @@ -269,7 +270,8 @@ bool PropertySpecification::ParseShorthandDeclaration(PropertyDictionary& dictio (shorthand_definition->type == ShorthandType::RecursiveCommaSeparated ? SplitOption::Comma : SplitOption::Whitespace); StringList property_values; - if (!ParsePropertyValues(property_values, property_value, split_option) || property_values.empty()) + ParsePropertyValues(property_values, property_value, split_option); + if (property_values.empty()) return false; // Handle the special behavior of the flex shorthand first, otherwise it acts like 'FallThrough'. @@ -475,7 +477,7 @@ String PropertySpecification::PropertiesToString(const PropertyDictionary& dicti return result; } -bool PropertySpecification::ParsePropertyValues(StringList& values_list, const String& values, const SplitOption split_option) const +void PropertySpecification::ParsePropertyValues(StringList& values_list, const String& values, const SplitOption split_option) const { const bool split_values = (split_option != SplitOption::None); const bool split_by_comma = (split_option == SplitOption::Comma); @@ -609,8 +611,6 @@ bool PropertySpecification::ParsePropertyValues(StringList& values_list, const S if (state == VALUE) SubmitValue(); - - return true; } } // namespace Rml diff --git a/Source/Core/WidgetScroll.cpp b/Source/Core/WidgetScroll.cpp index 4a0c844d7..74f3cd94a 100644 --- a/Source/Core/WidgetScroll.cpp +++ b/Source/Core/WidgetScroll.cpp @@ -148,7 +148,7 @@ void WidgetScroll::Update() if (!std::any_of(std::begin(arrow_timers), std::end(arrow_timers), [](float timer) { return timer > 0; })) return; - double current_time = Clock::GetElapsedTime(); + const double current_time = Clock::GetElapsedTime(); const float delta_time = float(current_time - last_update_time); last_update_time = current_time;