Browse Source

Code cleanup: Fix some always true/false conditions

Michael Ragazzon 1 year ago
parent
commit
ded1b0fe53

+ 3 - 5
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);

+ 1 - 1
Include/RmlUi/Core/PropertySpecification.h

@@ -137,7 +137,7 @@ private:
 	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;

+ 1 - 1
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);

+ 1 - 1
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);

+ 1 - 1
Source/Core/DataViewDefault.cpp

@@ -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;

+ 7 - 10
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)
 			{

+ 5 - 5
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

+ 1 - 1
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;