Skip to content

Commit

Permalink
Code cleanup: Fix some always true/false conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Oct 6, 2024
1 parent 14b0618 commit ded1b0f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 25 deletions.
8 changes: 3 additions & 5 deletions Backends/RmlUi_Renderer_GL3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Include/RmlUi/Core/PropertySpecification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Samples/invaders/src/ElementGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Samples/lua_invaders/src/ElementGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DataViewDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool DataViewAttribute::Update(DataModel& model)
const String value = variant.Get<String>();
const Variant* attribute = element->GetAttribute(attribute_name);

if (!attribute || (attribute && attribute->Get<String>() != value))
if (!attribute || attribute->Get<String>() != value)
{
element->SetAttribute(attribute_name, value);
result = true;
Expand Down
17 changes: 7 additions & 10 deletions Source/Core/Elements/WidgetSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/PropertySpecification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -609,8 +611,6 @@ bool PropertySpecification::ParsePropertyValues(StringList& values_list, const S

if (state == VALUE)
SubmitValue();

return true;
}

} // namespace Rml
2 changes: 1 addition & 1 deletion Source/Core/WidgetScroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ded1b0f

Please sign in to comment.