summaryrefslogtreecommitdiff
path: root/Runtime/Animation/AnimationClipBindings.h
blob: b91362c41aa24853008b56ebaa02393479b0f2ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "Runtime/BaseClasses/BaseObject.h"

typedef UInt32 BindingHash;

namespace UnityEngine
{
namespace Animation
{

struct GenericBinding
{
	BindingHash    path;
	BindingHash    attribute;
	PPtr<Object>   script;
	UInt16         classID;
	UInt8          customType;
	UInt8          isPPtrCurve;
	
	GenericBinding () : path (0), attribute(0), classID(0), customType(0), isPPtrCurve(0)
	{
		
	}
	
	
	DECLARE_SERIALIZE (GenericBinding)
};

struct AnimationClipBindingConstant
{
	dynamic_array<GenericBinding>    genericBindings;
	dynamic_array<PPtr<Object> >     pptrCurveMapping;
	
	DECLARE_SERIALIZE (AnimationClipBindingConstant)
};

template<class TransferFunc> inline
void GenericBinding::Transfer (TransferFunc& transfer)
{
	TRANSFER(path);
	TRANSFER(attribute);
	TRANSFER(script);
	TRANSFER(classID);
	TRANSFER(customType);
	TRANSFER(isPPtrCurve);
}

template<class TransferFunc> inline
void AnimationClipBindingConstant::Transfer (TransferFunc& transfer)
{
	TRANSFER(genericBindings);
	TRANSFER(pptrCurveMapping);
}

inline bool operator < (const GenericBinding& lhs, const GenericBinding& rhs)
{
	// Transform components are sorted first by attribute, then by path.
	// This is because when creating the ValueArrayConstant.
	// We want scale curves at the end. This is because scale curves are most likely to not actually be changed
	// Thus more likely to be culled away by the constant clip optimization code.
	if (lhs.classID == ClassID (Transform) && rhs.classID == ClassID (Transform))
	{
		if (lhs.attribute != rhs.attribute)
			return lhs.attribute < rhs.attribute;
			
		return lhs.path < rhs.path;
	}
	 
	// All transform bindings always come first
	int lhsClassID = lhs.classID == ClassID (Transform) ? -1 : lhs.classID;
	int rhsClassID = rhs.classID == ClassID (Transform) ? -1 : rhs.classID;

	if (lhsClassID != rhsClassID)	
		return lhsClassID < rhsClassID;
	else if (lhs.isPPtrCurve != rhs.isPPtrCurve)	
		return lhs.isPPtrCurve < rhs.isPPtrCurve;
	else if (lhs.customType != rhs.customType)	
		return lhs.customType < rhs.customType;
	else if (lhs.path != rhs.path)
		return lhs.path < rhs.path;
	else if (lhs.script != rhs.script)
		return lhs.script < rhs.script;
	else
		return lhs.attribute < rhs.attribute;
}
	
}
}