Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/AnimationLegacy.cpp
1163 views
1
2
3
RSDK::Legacy::AnimationFile RSDK::Legacy::animationFileList[LEGACY_ANIFILE_COUNT];
4
int32 RSDK::Legacy::animationFileCount = 0;
5
6
RSDK::Legacy::SpriteFrame RSDK::Legacy::scriptFrames[LEGACY_SPRITEFRAME_COUNT];
7
int32 RSDK::Legacy::scriptFrameCount = 0;
8
9
RSDK::Legacy::SpriteFrame RSDK::Legacy::animFrames[LEGACY_SPRITEFRAME_COUNT];
10
int32 RSDK::Legacy::animFrameCount = 0;
11
RSDK::Legacy::SpriteAnimation RSDK::Legacy::animationList[LEGACY_ANIMATION_COUNT];
12
int32 RSDK::Legacy::animationCount = 0;
13
RSDK::Legacy::Hitbox RSDK::Legacy::hitboxList[LEGACY_HITBOX_COUNT];
14
int32 RSDK::Legacy::hitboxCount = 0;
15
16
void RSDK::Legacy::LoadAnimationFile(char *filePath)
17
{
18
FileInfo info;
19
InitFileInfo(&info);
20
21
if (LoadFile(&info, filePath, FMODE_RB)) {
22
uint8 sheetIDs[24];
23
sheetIDs[0] = 0;
24
25
uint8 sheetCount = ReadInt8(&info);
26
27
for (int32 s = 0; s < sheetCount; ++s) {
28
char sheetPath[0x21];
29
ReadString(&info, sheetPath);
30
sheetIDs[s] = AddGraphicsFile(sheetPath);
31
}
32
33
AnimationFile *animFile = &animationFileList[animationFileCount];
34
animFile->animCount = ReadInt8(&info);
35
animFile->aniListOffset = animationCount;
36
37
for (int32 a = 0; a < animFile->animCount; ++a) {
38
SpriteAnimation *anim = &animationList[animationCount++];
39
anim->frameListOffset = animFrameCount;
40
41
ReadString(&info, anim->name);
42
anim->frameCount = ReadInt8(&info);
43
anim->speed = ReadInt8(&info);
44
anim->loopPoint = ReadInt8(&info);
45
anim->rotationStyle = ReadInt8(&info);
46
47
for (int32 f = 0; f < anim->frameCount; ++f) {
48
SpriteFrame *frame = &animFrames[animFrameCount++];
49
frame->sheetID = sheetIDs[ReadInt8(&info)];
50
frame->hitboxID = ReadInt8(&info);
51
frame->sprX = ReadInt8(&info);
52
frame->sprY = ReadInt8(&info);
53
frame->width = ReadInt8(&info);
54
frame->height = ReadInt8(&info);
55
frame->pivotX = (int8)ReadInt8(&info);
56
frame->pivotY = (int8)ReadInt8(&info);
57
}
58
59
// 90 Degree (Extra rotation Frames) rotation
60
if (anim->rotationStyle == ROTSTYLE_STATICFRAMES)
61
anim->frameCount >>= 1;
62
}
63
64
animFile->hitboxListOffset = hitboxCount;
65
int32 hbCount = ReadInt8(&info);
66
for (int32 h = 0; h < hbCount; ++h) {
67
Hitbox *hitbox = &hitboxList[hitboxCount++];
68
for (int32 d = 0; d < LEGACY_HITBOX_DIR_COUNT; ++d) {
69
hitbox->left[d] = ReadInt8(&info);
70
hitbox->top[d] = ReadInt8(&info);
71
hitbox->right[d] = ReadInt8(&info);
72
hitbox->bottom[d] = ReadInt8(&info);
73
}
74
}
75
76
CloseFile(&info);
77
}
78
}
79
void RSDK::Legacy::ClearAnimationData()
80
{
81
for (int32 f = 0; f < LEGACY_SPRITEFRAME_COUNT; ++f) MEM_ZERO(scriptFrames[f]);
82
for (int32 f = 0; f < LEGACY_SPRITEFRAME_COUNT; ++f) MEM_ZERO(animFrames[f]);
83
for (int32 h = 0; h < LEGACY_HITBOX_COUNT; ++h) MEM_ZERO(hitboxList[h]);
84
for (int32 a = 0; a < LEGACY_ANIMATION_COUNT; ++a) MEM_ZERO(animationList[a]);
85
for (int32 a = 0; a < LEGACY_ANIFILE_COUNT; ++a) MEM_ZERO(animationFileList[a]);
86
87
scriptFrameCount = 0;
88
animFrameCount = 0;
89
animationCount = 0;
90
animationFileCount = 0;
91
hitboxCount = 0;
92
}
93
94
RSDK::Legacy::AnimationFile *RSDK::Legacy::AddAnimationFile(char *filePath)
95
{
96
char path[0x80];
97
StrCopy(path, "Data/Animations/");
98
StrAdd(path, filePath);
99
100
for (int32 a = 0; a < LEGACY_ANIFILE_COUNT; ++a) {
101
if (StrLength(animationFileList[a].fileName) <= 0) {
102
StrCopy(animationFileList[a].fileName, filePath);
103
LoadAnimationFile(path);
104
++animationFileCount;
105
return &animationFileList[a];
106
}
107
108
if (StrComp(animationFileList[a].fileName, filePath))
109
return &animationFileList[a];
110
}
111
112
return NULL;
113
}
114
115
void RSDK::Legacy::v3::ProcessObjectAnimation(void *objScr, void *ent)
116
{
117
Legacy::v3::ObjectScript *objectScript = (Legacy::v3::ObjectScript *)objScr;
118
Legacy::v3::Entity *entity = (Legacy::v3::Entity *)ent;
119
Legacy::SpriteAnimation *sprAnim = &Legacy::animationList[objectScript->animFile->aniListOffset + entity->animation];
120
121
if (entity->animationSpeed <= 0) {
122
entity->animationTimer += sprAnim->speed;
123
}
124
else {
125
if (entity->animationSpeed > 0xF0)
126
entity->animationSpeed = 0xF0;
127
entity->animationTimer += entity->animationSpeed;
128
}
129
130
if (entity->animation != entity->prevAnimation) {
131
entity->prevAnimation = entity->animation;
132
entity->frame = 0;
133
entity->animationTimer = 0;
134
entity->animationSpeed = 0;
135
}
136
137
if (entity->animationTimer >= 0xF0) {
138
entity->animationTimer -= 0xF0;
139
++entity->frame;
140
}
141
142
if (entity->frame >= sprAnim->frameCount)
143
entity->frame = sprAnim->loopPoint;
144
}
145
146
void RSDK::Legacy::v4::ProcessObjectAnimation(void *objScr, void *ent)
147
{
148
Legacy::v4::ObjectScript *objectScript = (Legacy::v4::ObjectScript *)objScr;
149
Legacy::v4::Entity *entity = (Legacy::v4::Entity *)ent;
150
Legacy::SpriteAnimation *sprAnim = &Legacy::animationList[objectScript->animFile->aniListOffset + entity->animation];
151
152
if (entity->animationSpeed <= 0) {
153
entity->animationTimer += sprAnim->speed;
154
}
155
else {
156
if (entity->animationSpeed > 0xF0)
157
entity->animationSpeed = 0xF0;
158
entity->animationTimer += entity->animationSpeed;
159
}
160
161
if (entity->animation != entity->prevAnimation) {
162
entity->prevAnimation = entity->animation;
163
entity->frame = 0;
164
entity->animationTimer = 0;
165
entity->animationSpeed = 0;
166
}
167
168
if (entity->animationTimer >= 0xF0) {
169
entity->animationTimer -= 0xF0;
170
++entity->frame;
171
}
172
173
if (entity->frame >= sprAnim->frameCount)
174
entity->frame = sprAnim->loopPoint;
175
}
176