Bläddra i källkod

Avoid property copy and unnecessary compare (thanks @viciious, see #8)

Michael Ragazzon 6 år sedan
förälder
incheckning
ffccffd759

+ 9 - 9
Source/Core/ElementAnimation.cpp

@@ -301,7 +301,6 @@ static bool PrepareTransforms(std::vector<AnimationKey>& keys, Element& element,
 
 	int count_iterations = -1;
 	const int max_iterations = 3 * N;
-	if (start_index < 1) start_index = 1;
 
 	std::vector<bool> dirty_list(N + 1, false);
 	dirty_list[start_index] = true;
@@ -355,27 +354,28 @@ ElementAnimation::ElementAnimation(PropertyId property_id, const Property& curre
 	{
 		Log::Message(Log::LT_WARNING, "Property in animation key did not have a definition (while adding key '%s').", current_value.ToString().c_str());
 	}
-	InternalAddKey(AnimationKey{ 0.0f, current_value, Tween{} });
+	InternalAddKey(0.0f, current_value, Tween{});
 }
 
-bool ElementAnimation::InternalAddKey(AnimationKey key)
+bool ElementAnimation::InternalAddKey(float time, const Property& property, Tween tween)
 {
 	int valid_properties = (Property::NUMBER_LENGTH_PERCENT | Property::ANGLE | Property::COLOUR | Property::TRANSFORM);
 
-	if (!(key.property.unit & valid_properties))
+	if (!(property.unit & valid_properties))
 	{
-		Log::Message(Log::LT_WARNING, "Property '%s' is not a valid target for interpolation.", key.property.ToString().c_str());
+		Log::Message(Log::LT_WARNING, "Property '%s' is not a valid target for interpolation.", property.ToString().c_str());
 		return false;
 	}
 
+	keys.emplace_back(time, property, tween);
+	AnimationKey& key = keys.back();
+
 	if (key.property.unit == Property::TRANSFORM)
 	{
 		if (!key.property.value.Get<TransformRef>())
 			key.property.value.Reset(TransformRef(new Transform));
 	}
 
-	keys.push_back(key);
-
 	return true;
 }
 
@@ -387,7 +387,7 @@ bool ElementAnimation::AddKey(float target_time, const Property & in_property, E
 		Log::Message(Log::LT_WARNING, "Element animation was not initialized properly, can't add key.");
 		return false;
 	}
-	if (!InternalAddKey(AnimationKey{ target_time, in_property, tween }))
+	if (!InternalAddKey(target_time, in_property, tween))
 	{
 		return false;
 	}
@@ -398,7 +398,7 @@ bool ElementAnimation::AddKey(float target_time, const Property & in_property, E
 	if (property.unit == Property::TRANSFORM)
 	{
 		bool must_decompose = false;
-		auto& transform = *property.value.Get<TransformRef>();
+		Transform& transform = *property.value.Get<TransformRef>();
 
 		for (auto& primitive : transform.GetPrimitives())
 		{

+ 2 - 1
Source/Core/ElementAnimation.h

@@ -37,6 +37,7 @@ namespace Core {
 
 
 struct AnimationKey {
+	AnimationKey(float time, const Property& property, Tween tween) : time(time), property(property), tween(tween) {}
 	float time;   // Local animation time (Zero means the time when the animation iteration starts)
 	Property property;
 	Tween tween;  // Tweening between the previous and this key. Ignored for the first animation key.
@@ -63,7 +64,7 @@ private:
 	bool animation_complete;
 	bool is_transition;
 
-	bool InternalAddKey(AnimationKey key);
+	bool InternalAddKey(float time, const Property& property, Tween tween);
 
 	float GetInterpolationFactorAndKeys(int* out_key0, int* out_key1) const;
 public:

+ 1 - 1
Source/Core/TransformPrimitive.cpp

@@ -509,7 +509,7 @@ struct PrepareVisitor
 	}
 	bool operator()(Matrix3D& p)
 	{
-		// Matrices must be decomposed for interpolatino
+		// Matrices must be decomposed for interpolation
 		return false;
 	}
 	bool operator()(Matrix2D& p)