Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/SpriteLegacy.cpp
1163 views
1
2
int32 RSDK::Legacy::AddGraphicsFile(const char *filePath)
3
{
4
char sheetPath[0x100];
5
6
StrCopy(sheetPath, "Data/Sprites/");
7
StrAdd(sheetPath, filePath);
8
9
int32 sheetID = 0;
10
while (StrLength(gfxSurface[sheetID].fileName) > 0) {
11
if (StrComp(gfxSurface[sheetID].fileName, sheetPath))
12
return sheetID;
13
if (++sheetID == LEGACY_SURFACE_COUNT)
14
return 0;
15
}
16
17
ImageGIF image;
18
if (image.Load(sheetPath, true)) {
19
GFXSurface *surface = &gfxSurface[sheetID];
20
21
StrCopy(surface->fileName, sheetPath);
22
surface->width = image.width;
23
surface->height = image.height;
24
25
surface->dataPosition = gfxDataPosition;
26
gfxDataPosition += surface->width * surface->height;
27
28
if (gfxDataPosition < LEGACY_GFXDATA_SIZE) {
29
image.pixels = &graphicData[surface->dataPosition];
30
image.Load(NULL, false);
31
}
32
else {
33
gfxDataPosition = 0;
34
PrintLog(PRINT_NORMAL, "WARNING: Exceeded max gfx size!");
35
}
36
37
surface->widthShift = 0;
38
int32 w = surface->width;
39
while (w > 1) {
40
w >>= 1;
41
++surface->widthShift;
42
}
43
}
44
45
return sheetID;
46
}
47
48
void RSDK::Legacy::RemoveGraphicsFile(const char *filePath, int32 sheetID)
49
{
50
if (sheetID < 0) {
51
for (int32 i = 0; i < LEGACY_SURFACE_COUNT; ++i) {
52
if (StrLength(gfxSurface[i].fileName) > 0 && StrComp(gfxSurface[i].fileName, filePath))
53
sheetID = i;
54
}
55
}
56
57
if (sheetID >= 0 && StrLength(gfxSurface[sheetID].fileName)) {
58
StrCopy(gfxSurface[sheetID].fileName, "");
59
int32 dataPosStart = gfxSurface[sheetID].dataPosition;
60
int32 dataPosEnd = gfxSurface[sheetID].dataPosition + gfxSurface[sheetID].height * gfxSurface[sheetID].width;
61
62
for (int32 i = LEGACY_GFXDATA_SIZE - dataPosEnd; i > 0; --i) graphicData[dataPosStart++] = graphicData[dataPosEnd++];
63
gfxDataPosition -= gfxSurface[sheetID].height * gfxSurface[sheetID].width;
64
65
for (int32 i = 0; i < LEGACY_SURFACE_COUNT; ++i) {
66
if (gfxSurface[i].dataPosition > gfxSurface[sheetID].dataPosition)
67
gfxSurface[i].dataPosition -= gfxSurface[sheetID].height * gfxSurface[sheetID].width;
68
}
69
}
70
}
71