Browse Source

Move element's main box outside of vector.

Michael Ragazzon 6 years ago
parent
commit
cf928b285e

+ 8 - 3
Include/Rocket/Core/Element.h

@@ -146,10 +146,13 @@ public:
 	/// Adds a box to the end of the list describing this element's geometry.
 	/// @param[in] box The auxiliary box for the element.
 	void AddBox(const Box& box);
+	/// Returns the main box describing the size of the element.
+	/// @return The box.
+	const Box& GetBox();
 	/// Returns one of the boxes describing the size of the element.
-	/// @param[in] index The index of the desired box. If this is outside of the bounds of the element's list of boxes, it will be clamped.
+	/// @param[in] index The index of the desired box, with 0 being the main box. If outside of bounds, the main box will be returned.
 	/// @return The requested box.
-	const Box& GetBox(int index = 0);
+	const Box& GetBox(int index);
 	/// Returns the number of boxes making up this element's geometry.
 	/// @return the number of boxes making up this element's geometry.
 	int GetNumBoxes();
@@ -751,7 +754,9 @@ private:
 
 	// The size of the element.
 	typedef std::vector< Box > BoxList;
-	BoxList boxes;
+	Box main_box;
+	BoxList additional_boxes;
+
 	// And of the element's internal content.
 	Vector2f content_offset;
 	Vector2f content_box;

+ 1 - 1
Samples/basic/benchmark/data/benchmark.rml

@@ -59,7 +59,7 @@
 			left: -200px;
 			width: 800px;
 			height: 300px;
-			transform: scale(0.6) rotate(-60deg);
+			/*transform: scale(0.6) rotate(-60deg);*/
 		}
 	</style>
 </head>

+ 2 - 0
Samples/basic/benchmark/src/main.cpp

@@ -78,6 +78,8 @@ public:
 		  Don't double create input elements: 58.0  [e162637]
 		  Memory pool for ElementMeta: 59.0  [ece191a]
 		  Include chobo flat containers: 65.0  [1696aa5]
+		  Move benchmark to its own sample (no code change, fps increase because of removal of animation elements): 68.0  [2433880]
+		  Keep the element's main sizing box local: 69.0 
 		
 		*/
 

+ 22 - 16
Source/Core/Element.cpp

@@ -114,7 +114,7 @@ struct alignas(ElementMeta) ElementMetaChunk
 
 
 /// Constructs a new libRocket element.
-Element::Element(const String& _tag) : relative_offset_base(0, 0), relative_offset_position(0, 0), absolute_offset(0, 0), scroll_offset(0, 0), boxes(1), content_offset(0, 0), content_box(0, 0), 
+Element::Element(const String& _tag) : relative_offset_base(0, 0), relative_offset_position(0, 0), absolute_offset(0, 0), scroll_offset(0, 0), content_offset(0, 0), content_box(0, 0), 
 transform_state(), transform_state_perspective_dirty(true), transform_state_transform_dirty(true), transform_state_parent_transform_dirty(true), dirty_animation(false)
 {
 	tag = ToLower(_tag);
@@ -460,11 +460,10 @@ void Element::SetContentBox(const Vector2f& _content_offset, const Vector2f& _co
 // Sets the box describing the size of the element.
 void Element::SetBox(const Box& box)
 {
-	if (box != boxes[0] ||
-		boxes.size() > 1)
+	if (box != main_box || additional_boxes.size() > 0)
 	{
-		boxes[0] = box;
-		boxes.resize(1);
+		main_box = box;
+		additional_boxes.clear();
 
 		box_dirty = true;
 		background->DirtyBackground();
@@ -476,7 +475,7 @@ void Element::SetBox(const Box& box)
 // Adds a box to the end of the list describing this element's geometry.
 void Element::AddBox(const Box& box)
 {
-	boxes.push_back(box);
+	additional_boxes.push_back(box);
 
 	box_dirty = true;
 	background->DirtyBackground();
@@ -484,21 +483,29 @@ void Element::AddBox(const Box& box)
 	decoration->DirtyDecorators(true);
 }
 
+// Returns one of the boxes describing the size of the element.
+const Box& Element::GetBox()
+{
+	return main_box;
+}
+
 // Returns one of the boxes describing the size of the element.
 const Box& Element::GetBox(int index)
 {
-	if (index < 0)
-		return boxes[0];
-	else if (index >= GetNumBoxes())
-		return boxes.back();
+	if (index < 1)
+		return main_box;
+	
+	int additional_box_index = index - 1;
+	if (additional_box_index >= (int)additional_boxes.size())
+		return main_box;
 
-	return boxes[index];
+	return additional_boxes[additional_box_index];
 }
 
 // Returns the number of boxes making up this element's geometry.
 int Element::GetNumBoxes()
 {
-	return (int) boxes.size();
+	return 1 + (int)additional_boxes.size();
 }
 
 // Returns the baseline of the element, in pixels offset from the bottom of the element's content area.
@@ -1376,11 +1383,10 @@ bool Element::DispatchEvent(const String& event, const Dictionary& parameters, b
 void Element::ScrollIntoView(bool align_with_top)
 {
 	Vector2f size(0, 0);
-	if (!align_with_top &&
-		!boxes.empty())
+	if (!align_with_top)
 	{
-		size.y = boxes.back().GetOffset().y +
-				 boxes.back().GetSize(Box::BORDER).y;
+		size.y = main_box.GetOffset().y +
+			main_box.GetSize(Box::BORDER).y;
 	}
 
 	Element* scroll_parent = parent;

+ 0 - 1
Source/Core/ElementStyle.cpp

@@ -366,7 +366,6 @@ bool ElementStyle::SetProperty(const String& name, const Property& property)
 	if (new_property.definition == NULL)
 		return false;
 
-	sizeof(ElementDefinition);
 	if (local_properties == NULL)
 		local_properties = new PropertyDictionary();
 

+ 1 - 1
Source/Core/LayoutEngine.cpp

@@ -442,7 +442,7 @@ bool LayoutEngine::FormatElementReplaced(Element* element)
 // Executes any special formatting for special elements.
 bool LayoutEngine::FormatElementSpecial(Element* element)
 {
-	static String br("br");
+	static const String br("br");
 	
 	// Check for a <br> tag.
 	if (element->GetTagName() == br)