summaryrefslogtreecommitdiff
path: root/ZAPD/ZAnimation.h
blob: 643842b891ab3b83837033c6639607a4afdfdc0a (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#pragma once

#include <cstdint>
#include <string>
#include <vector>
#include "Vec3s.h"
#include "ZResource.h"
#include "ZSkeleton.h"
#include "tinyxml2.h"

struct RotationIndex
{
	// uint16_t transX, transY, transZ;
	uint16_t x, y, z;

	RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) {}
};

class ZAnimation : public ZResource
{
public:
	int16_t frameCount;

	ZAnimation(ZFile* nParent);

	ZResourceType GetResourceType() const override;

protected:
	void ParseRawData() override;
};

class ZNormalAnimation : public ZAnimation
{
public:
	std::vector<uint16_t> rotationValues;
	std::vector<RotationIndex> rotationIndices;
	segptr_t rotationValuesSeg = 0;
	segptr_t rotationIndicesSeg = 0;
	offset_t rotationValuesOffset = 0;
	offset_t rotationIndicesOffset = 0;
	int16_t limit = 0;

	ZNormalAnimation(ZFile* nParent);

	void DeclareReferences(const std::string& prefix) override;

	std::string GetBodySourceCode() const override;

	size_t GetRawDataSize() const override;
	std::string GetSourceTypeName() const override;

	void ParseRawData() override;
};

class ZLinkAnimation : public ZAnimation
{
public:
	segptr_t segmentAddress;

	ZLinkAnimation(ZFile* nParent);

	std::string GetBodySourceCode() const override;

	size_t GetRawDataSize() const override;
	std::string GetSourceTypeName() const override;

	void ParseRawData() override;
};

class CurveInterpKnot
{
protected:
	ZFile* parent;

	///* 0x0000 */ u16 unk_00; // appears to be flags
	uint16_t unk_00;
	///* 0x0002 */ s16 unk_02;
	int16_t unk_02;
	///* 0x0004 */ s16 unk_04;
	int16_t unk_04;
	///* 0x0006 */ s16 unk_06;
	int16_t unk_06;
	///* 0x0008 */ f32 unk_08;
	float unk_08;

public:
	CurveInterpKnot() = default;
	CurveInterpKnot(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
	CurveInterpKnot(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
	                size_t index);

	[[nodiscard]] std::string GetBody(const std::string& prefix) const;

	size_t GetRawDataSize() const;
	std::string GetSourceTypeName();
};

class ZCurveAnimation : public ZAnimation
{
protected:
	segptr_t skelOffset = 0;

	///* 0x0000 */ u8* refIndex;
	segptr_t refIndex = 0;
	///* 0x0004 */ CurveInterpKnot* transformData;
	segptr_t transformData = 0;
	///* 0x0008 */ s16* copyValues;
	segptr_t copyValues = 0;
	///* 0x000C */ s16 unk_0C;
	int16_t unk_0C;
	///* 0x000E */ s16 unk_10;
	int16_t unk_10;

	uint8_t limbCount = 0;

	std::vector<uint8_t> refIndexArr;
	std::vector<CurveInterpKnot> transformDataArr;
	std::vector<int16_t> copyValuesArr;

public:
	ZCurveAnimation(ZFile* nParent);

	void ParseXML(tinyxml2::XMLElement* reader) override;
	void ParseRawData() override;

	void DeclareReferences(const std::string& prefix) override;

	std::string GetBodySourceCode() const override;

	size_t GetRawDataSize() const override;
	DeclarationAlignment GetDeclarationAlignment() const override;

	std::string GetSourceTypeName() const override;
};
// CurveAnimationHeader

/* ZLegacyAnimation */

class LegacyJointKey : public ZResource
{
public:
	LegacyJointKey(ZFile* nParent);

	void ParseRawData() override;
	std::string GetBodySourceCode() const override;

	std::string GetSourceTypeName() const override;
	ZResourceType GetResourceType() const override;

	size_t GetRawDataSize() const override;

protected:
	int16_t xMax, x;
	int16_t yMax, y;
	int16_t zMax, z;
};

class ZLegacyAnimation : public ZAnimation
{
public:
	ZLegacyAnimation(ZFile* nParent);

	void ParseRawData() override;
	void DeclareReferences(const std::string& prefix) override;

	std::string GetBodySourceCode() const override;

	std::string GetSourceTypeName() const override;

	size_t GetRawDataSize() const override;

protected:
	int16_t limbCount;
	segptr_t frameData;  // s16*
	segptr_t jointKey;   // LegacyJointKey*

	std::vector<uint16_t> frameDataArray;
	std::vector<LegacyJointKey> jointKeyArray;
};