Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/SpriteLegacy.cpp
1163 views
1int32 RSDK::Legacy::AddGraphicsFile(const char *filePath)2{3char sheetPath[0x100];45StrCopy(sheetPath, "Data/Sprites/");6StrAdd(sheetPath, filePath);78int32 sheetID = 0;9while (StrLength(gfxSurface[sheetID].fileName) > 0) {10if (StrComp(gfxSurface[sheetID].fileName, sheetPath))11return sheetID;12if (++sheetID == LEGACY_SURFACE_COUNT)13return 0;14}1516ImageGIF image;17if (image.Load(sheetPath, true)) {18GFXSurface *surface = &gfxSurface[sheetID];1920StrCopy(surface->fileName, sheetPath);21surface->width = image.width;22surface->height = image.height;2324surface->dataPosition = gfxDataPosition;25gfxDataPosition += surface->width * surface->height;2627if (gfxDataPosition < LEGACY_GFXDATA_SIZE) {28image.pixels = &graphicData[surface->dataPosition];29image.Load(NULL, false);30}31else {32gfxDataPosition = 0;33PrintLog(PRINT_NORMAL, "WARNING: Exceeded max gfx size!");34}3536surface->widthShift = 0;37int32 w = surface->width;38while (w > 1) {39w >>= 1;40++surface->widthShift;41}42}4344return sheetID;45}4647void RSDK::Legacy::RemoveGraphicsFile(const char *filePath, int32 sheetID)48{49if (sheetID < 0) {50for (int32 i = 0; i < LEGACY_SURFACE_COUNT; ++i) {51if (StrLength(gfxSurface[i].fileName) > 0 && StrComp(gfxSurface[i].fileName, filePath))52sheetID = i;53}54}5556if (sheetID >= 0 && StrLength(gfxSurface[sheetID].fileName)) {57StrCopy(gfxSurface[sheetID].fileName, "");58int32 dataPosStart = gfxSurface[sheetID].dataPosition;59int32 dataPosEnd = gfxSurface[sheetID].dataPosition + gfxSurface[sheetID].height * gfxSurface[sheetID].width;6061for (int32 i = LEGACY_GFXDATA_SIZE - dataPosEnd; i > 0; --i) graphicData[dataPosStart++] = graphicData[dataPosEnd++];62gfxDataPosition -= gfxSurface[sheetID].height * gfxSurface[sheetID].width;6364for (int32 i = 0; i < LEGACY_SURFACE_COUNT; ++i) {65if (gfxSurface[i].dataPosition > gfxSurface[sheetID].dataPosition)66gfxSurface[i].dataPosition -= gfxSurface[sheetID].height * gfxSurface[sheetID].width;67}68}69}7071