Przeglądaj źródła

Do a deep comparison before submitting new transforms through the interface, see #55.

Michael Ragazzon 6 lat temu
rodzic
commit
b4f370b5d2
2 zmienionych plików z 25 dodań i 5 usunięć
  1. 24 4
      Source/Core/ElementUtilities.cpp
  2. 1 1
      readme.md

+ 24 - 4
Source/Core/ElementUtilities.cpp

@@ -338,18 +338,38 @@ bool ElementUtilities::ApplyTransform(Element &element)
 	if (!render_interface)
 	if (!render_interface)
 		return false;
 		return false;
 
 
-	static SmallUnorderedMap<RenderInterface*, const Matrix4f*> previous_matrix;
+	struct PreviousMatrix {
+		const Matrix4f* pointer; // This may be expired, dereferencing not allowed!
+		Matrix4f value;
+	};
+	static SmallUnorderedMap<RenderInterface*, PreviousMatrix> previous_matrix;
 
 
-	const Matrix4f*& old_transform = previous_matrix.emplace(render_interface, nullptr).first->second;
+	auto it = previous_matrix.find(render_interface);
+	if (it == previous_matrix.end())
+		it = previous_matrix.emplace(render_interface, PreviousMatrix{ nullptr, Matrix4f::Identity() }).first;
+
+	RMLUI_ASSERT(it != previous_matrix.end());
+
+	const Matrix4f*& old_transform = it->second.pointer;
 	const Matrix4f* new_transform = nullptr;
 	const Matrix4f* new_transform = nullptr;
 
 
-	if (auto state = element.GetTransformState())
+	if (const TransformState* state = element.GetTransformState())
 		new_transform = state->GetTransform();
 		new_transform = state->GetTransform();
 
 
 	// Only changed transforms are submitted.
 	// Only changed transforms are submitted.
 	if (old_transform != new_transform)
 	if (old_transform != new_transform)
 	{
 	{
-		render_interface->SetTransform(new_transform);
+		Matrix4f& old_transform_value = it->second.value;
+
+		// Do a deep comparison as well to avoid submitting a new transform which is equal.
+		if(!old_transform || !new_transform || (old_transform_value != *new_transform))
+		{
+			render_interface->SetTransform(new_transform);
+
+			if(new_transform)
+				old_transform_value = *new_transform;
+		}
+
 		old_transform = new_transform;
 		old_transform = new_transform;
 	}
 	}
 
 

+ 1 - 1
readme.md

@@ -376,7 +376,7 @@ Three new CMake options added.
 - The debugger now has the ability to clear the log. Additionally, the displayed element information updates when the element changes.
 - The debugger now has the ability to clear the log. Additionally, the displayed element information updates when the element changes.
 - The `text-decoration` property can now also be used with `overline` and `line-through`.
 - The `text-decoration` property can now also be used with `overline` and `line-through`.
 - The text input and text area elements can be navigated word for word by holding the 'ctrl' key.
 - The text input and text area elements can be navigated word for word by holding the 'ctrl' key.
-- The `\<img\>` element can now take sprite names in its `src` attribute.
+- The `<img>` element can now take sprite names in its `src` attribute.
 
 
 
 
 ### Breaking changes
 ### Breaking changes