diff --git a/source/Engine/Application.cpp b/source/Engine/Application.cpp index 3a7b7da6..8278f1ab 100644 --- a/source/Engine/Application.cpp +++ b/source/Engine/Application.cpp @@ -889,21 +889,24 @@ PRIVATE STATIC void Application::RunFrame(void* p) { DEBUG_fontSprite = new ISprite(); int cols, rows; - DEBUG_fontSprite->SpritesheetCount = 1; - DEBUG_fontSprite->Spritesheets[0] = DEBUG_fontSprite->AddSpriteSheet("Debug/Font.png"); - if (!DEBUG_fontSprite->Spritesheets[0]) - DEBUG_fontSprite->Spritesheets[0] = DEBUG_fontSprite->AddSpriteSheet("Sprites/Fonts/Font.png"); - cols = DEBUG_fontSprite->Spritesheets[0]->Width / 32; - rows = DEBUG_fontSprite->Spritesheets[0]->Height / 32; - - DEBUG_fontSprite->ReserveAnimationCount(1); - DEBUG_fontSprite->AddAnimation("Font?", 0, 0, cols * rows); - for (int i = 0; i < cols * rows; i++) { - DEBUG_fontSprite->AddFrame(0, - (i % cols) * 32, - (i / cols) * 32, - 32, 32, 0, 0, - 14); + Texture* spriteSheet = DEBUG_fontSprite->AddSpriteSheet("Debug/Font.png"); + if (!spriteSheet) + spriteSheet = DEBUG_fontSprite->AddSpriteSheet("Sprites/Fonts/DebugFont.png"); + if (spriteSheet) { + DEBUG_fontSprite->Spritesheets.push_back(spriteSheet); + + cols = spriteSheet->Width / 32; + rows = spriteSheet->Height / 32; + + DEBUG_fontSprite->ReserveAnimationCount(1); + DEBUG_fontSprite->AddAnimation("Font", 0, 0, cols * rows); + for (int i = 0; i < cols * rows; i++) { + DEBUG_fontSprite->AddFrame(0, + (i % cols) * 32, + (i / cols) * 32, + 32, 32, 0, 0, + 14); + } } Graphics::SetTextureInterpolation(original); diff --git a/source/Engine/FontFace.cpp b/source/Engine/FontFace.cpp index 988cf247..3d6de6d6 100644 --- a/source/Engine/FontFace.cpp +++ b/source/Engine/FontFace.cpp @@ -216,9 +216,9 @@ PUBLIC STATIC ISprite* FontFace::SpriteFromFont(Stream* stream, int pixelSize, c } } - sprite->Spritesheets[0] = Graphics::CreateTextureFromPixels(package->Width, package->Height, pixelData, package->Width * sizeof(Uint32)); - sprite->SpritesheetsBorrowed[0] = false; - sprite->SpritesheetCount = 1; + Texture* spriteSheet = Graphics::CreateTextureFromPixels(package->Width, package->Height, pixelData, package->Width * sizeof(Uint32)); + if (spriteSheet) + sprite->Spritesheets.push_back(spriteSheet); // Add preliminary chars sprite->AddAnimation("Font", offsetBaseline & 0xFFFF, pixelSize, 0x100); @@ -248,9 +248,9 @@ PUBLIC STATIC ISprite* FontFace::SpriteFromFont(Stream* stream, int pixelSize, c } } - char testFilename[256]; + char testFilename[4096]; snprintf(testFilename, sizeof testFilename, "Fonts/%s_%d.bmp", filenameJustName, pixelSize); - strncpy(sprite->SpritesheetsFilenames[0], testFilename, 32); + sprite->SpritesheetsFilenames.push_back(StringUtils::Duplicate(testFilename)); SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(pixelData, package->Width, package->Height, 32, package->Width * 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); diff --git a/source/Engine/Rendering/GL/GLRenderer.cpp b/source/Engine/Rendering/GL/GLRenderer.cpp index f78bfecd..273daf89 100644 --- a/source/Engine/Rendering/GL/GLRenderer.cpp +++ b/source/Engine/Rendering/GL/GLRenderer.cpp @@ -2087,7 +2087,7 @@ PUBLIC STATIC void GLRenderer::MakeFrameBufferID(ISprite* sprite, AnimFrame* GL_AnimFrameVert vertices[16]; GL_AnimFrameVert* vert = &vertices[0]; - if (frame->SheetNumber >= sprite->SpritesheetCount) + if (frame->SheetNumber >= sprite->Spritesheets.size()) return; if (!sprite->Spritesheets[frame->SheetNumber]) return; diff --git a/source/Engine/ResourceTypes/ISprite.cpp b/source/Engine/ResourceTypes/ISprite.cpp index f919bac0..385a2750 100644 --- a/source/Engine/ResourceTypes/ISprite.cpp +++ b/source/Engine/ResourceTypes/ISprite.cpp @@ -5,22 +5,18 @@ class ISprite { public: - char Filename[256]; + char* Filename = nullptr; - bool LoadFailed; + bool LoadFailed = true; - Texture* Spritesheets[32]; - bool SpritesheetsBorrowed[32]; - char SpritesheetsFilenames[128][32]; - int SpritesheetCount = 0; + vector Spritesheets; + vector SpritesheetsFilenames; int CollisionBoxCount = 0; vector Animations; }; #endif -#define MAX_SPRITESHEETS 32 - #include #include @@ -40,17 +36,19 @@ class ISprite { #include PUBLIC ISprite::ISprite() { - memset(Spritesheets, 0, sizeof(Spritesheets)); - memset(SpritesheetsBorrowed, 0, sizeof(SpritesheetsBorrowed)); - memset(Filename, 0, 256); + Spritesheets.clear(); + Spritesheets.shrink_to_fit(); + SpritesheetsFilenames.clear(); + SpritesheetsFilenames.shrink_to_fit(); LoadFailed = true; + Filename = nullptr; } PUBLIC ISprite::ISprite(const char* filename) { - memset(Spritesheets, 0, sizeof(Spritesheets)); - memset(SpritesheetsBorrowed, 0, sizeof(SpritesheetsBorrowed)); - memset(Filename, 0, 256); - - strncpy(Filename, filename, 255); + Spritesheets.clear(); + Spritesheets.shrink_to_fit(); + SpritesheetsFilenames.clear(); + SpritesheetsFilenames.shrink_to_fit(); + Filename = StringUtils::Duplicate(filename); LoadFailed = !LoadAnimation(Filename); } @@ -213,20 +211,20 @@ PUBLIC void ISprite::RemoveFrames(int animID) { } PUBLIC void ISprite::ConvertToRGBA() { - for (int a = 0; a < SpritesheetCount; a++) { + for (int a = 0; a < Spritesheets.size(); a++) { if (Spritesheets[a]) Graphics::ConvertTextureToRGBA(Spritesheets[a]); } } PUBLIC void ISprite::ConvertToPalette(unsigned paletteNumber) { - for (int a = 0; a < SpritesheetCount; a++) { + for (int a = 0; a < Spritesheets.size(); a++) { if (Spritesheets[a]) Graphics::ConvertTextureToPalette(Spritesheets[a], paletteNumber); } } PUBLIC bool ISprite::LoadAnimation(const char* filename) { - char* str, altered[4096]; + char* str; int animationCount, previousAnimationCount; Stream* reader = ResourceStream::New(filename); @@ -253,30 +251,58 @@ PUBLIC bool ISprite::LoadAnimation(const char* filename) { reader->ReadUInt32(); // Get texture count - this->SpritesheetCount = reader->ReadByte(); + unsigned spritesheetCount = reader->ReadByte(); // Load textures - for (int i = 0; i < this->SpritesheetCount; i++) { - if (i >= MAX_SPRITESHEETS) { - Log::Print(Log::LOG_ERROR, "Too many spritesheets in sprite %s!", filename); - exit(-1); - } + for (int i = 0; i < spritesheetCount; i++) { + char fullPath[4096]; str = reader->ReadHeaderedString(); + + // Spritesheet path is relative to where the animation file is + if (StringUtils::StartsWith(str, "./")) { + char *parentPath = StringUtils::GetPath(filename); + if (parentPath) { + snprintf(fullPath, sizeof fullPath, "%s/%s", parentPath, str + 2); + Memory::Free(parentPath); + } + else + snprintf(fullPath, sizeof fullPath, "%s", str + 2); + } + else + StringUtils::Copy(fullPath, str, sizeof fullPath); + + Memory::Free(str); + + // Replace '\' with '/' + StringUtils::ReplacePathSeparatorsInPlace(fullPath); + + char* sheetName = StringUtils::Duplicate(fullPath); + #ifdef ISPRITE_DEBUG - Log::Print(Log::LOG_VERBOSE, " - %s", str); + Log::Print(Log::LOG_VERBOSE, " - %s", sheetName); #endif - strcpy(SpritesheetsFilenames[i], str); + SpritesheetsFilenames.push_back(sheetName); - snprintf(altered, sizeof altered, "Sprites/%s", str); - Memory::Free(str); + bool shouldConcatSpritesPath = true; + if (StringUtils::StartsWith(sheetName, "Sprites/")) { + // don't need to concat "Sprites/" if the path already begins with that + shouldConcatSpritesPath = false; + } + + if (shouldConcatSpritesPath) { + char* altered = StringUtils::ConcatPaths("Sprites", sheetName); + if (!altered) + abort(); - if (Graphics::SpriteSheetTextureMap->Exists(altered)) - SpritesheetsBorrowed[i] = true; + Spritesheets.push_back(AddSpriteSheet(altered)); - Spritesheets[i] = AddSpriteSheet(altered); - // Spritesheets[i] = Image::LoadTextureFromResource(altered); + Memory::Free(altered); + } + else { + Spritesheets.push_back(AddSpriteSheet(sheetName)); + } } // Get collision group count @@ -310,8 +336,9 @@ PUBLIC bool ISprite::LoadAnimation(const char* filename) { an.Flags = reader->ReadByte(); #ifdef ISPRITE_DEBUG - Log::Print(Log::LOG_VERBOSE, " \"%s\" (%d) (Flags: %02X, FtL: %d, Spd: %d, Frames: %d)", an.Name, a, an.Flags, an.FrameToLoop, an.AnimationSpeed, frameCount); + Log::Print(Log::LOG_VERBOSE, " \"%s\" (%d) (Flags: %02X, FtL: %d, Spd: %d, Frames: %d)", an.Name, a, an.Flags, an.FrameToLoop, an.AnimationSpeed, an.FrameCount); #endif + an.Frames.resize(an.FrameCount); for (int i = 0; i < an.FrameCount; i++) { @@ -319,8 +346,8 @@ PUBLIC bool ISprite::LoadAnimation(const char* filename) { anfrm.SheetNumber = reader->ReadByte(); frameID++; - if (anfrm.SheetNumber >= SpritesheetCount) - Log::Print(Log::LOG_ERROR, "Sheet number %d outside of range of sheet count %d! (Animation %d, Frame %d)", anfrm.SheetNumber, SpritesheetCount, a, i); + if (anfrm.SheetNumber >= Spritesheets.size()) + Log::Print(Log::LOG_ERROR, "Sheet number %d outside of range of sheet count %d! (Animation %d, Frame %d)", anfrm.SheetNumber, Spritesheets.size(), a, i); anfrm.Duration = reader->ReadInt16(); anfrm.Advance = reader->ReadUInt16(); @@ -388,10 +415,10 @@ PUBLIC bool ISprite::SaveAnimation(const char* filename) { stream->WriteUInt32(totalFrameCount); // Get texture count - stream->WriteByte(this->SpritesheetCount); + stream->WriteByte(this->Spritesheets.size()); // Load textures - for (int i = 0; i < this->SpritesheetCount; i++) { + for (int i = 0; i < this->Spritesheets.size(); i++) { stream->WriteHeaderedString(SpritesheetsFilenames[i]); } @@ -470,13 +497,24 @@ PUBLIC void ISprite::Dispose() { Animations.clear(); Animations.shrink_to_fit(); - for (int a = 0; a < SpritesheetCount; a++) { + for (int a = 0; a < Spritesheets.size(); a++) { if (Spritesheets[a]) { - // if (!SpritesheetsBorrowed[a]) - // Graphics::DisposeTexture(Spritesheets[a]); Spritesheets[a] = NULL; } } + + Spritesheets.clear(); + Spritesheets.shrink_to_fit(); + + for (int a = 0; a < SpritesheetsFilenames.size(); a++) { + Memory::Free(SpritesheetsFilenames[a]); + } + + SpritesheetsFilenames.clear(); + SpritesheetsFilenames.shrink_to_fit(); + + Memory::Free(Filename); + Filename = nullptr; } PUBLIC ISprite::~ISprite() { diff --git a/source/Engine/ResourceTypes/ResourceManager.cpp b/source/Engine/ResourceTypes/ResourceManager.cpp index cfc5c1b1..eda7fc1c 100644 --- a/source/Engine/ResourceTypes/ResourceManager.cpp +++ b/source/Engine/ResourceTypes/ResourceManager.cpp @@ -24,8 +24,6 @@ class ResourceManager { #include #include -#define KEEP_DATA_PACKS_IN_MEMORY - struct StreamNode { Stream* Table; struct StreamNode* Next; @@ -75,7 +73,6 @@ PUBLIC STATIC void ResourceManager::Init(const char* filename) { char modpacksString[1024]; if (Application::Settings->GetString("game", "modpacks", modpacksString, sizeof modpacksString)) { if (File::Exists(modpacksString)) { - // ResourceManager::UsingDataFolder = false; ResourceManager::UsingModPack = true; Log::Print(Log::LOG_IMPORTANT, "Using \"%s\"", modpacksString); @@ -134,6 +131,7 @@ PUBLIC STATIC void ResourceManager::Load(const char* filename) { PUBLIC STATIC bool ResourceManager::LoadResource(const char* filename, Uint8** out, size_t* size) { Uint8* memory; char resourcePath[4096]; + char *pathToLoad = StringUtils::ReplacePathSeparators(filename); ResourceRegistryItem item; if (ResourceManager::UsingDataFolder && !ResourceManager::UsingModPack) @@ -142,10 +140,10 @@ PUBLIC STATIC bool ResourceManager::LoadResource(const char* filename, Uint8** if (!ResourceRegistry) goto DATA_FOLDER; - if (!ResourceRegistry->Exists(filename)) + if (!ResourceRegistry->Exists(pathToLoad)) goto DATA_FOLDER; - item = ResourceRegistry->Get(filename); + item = ResourceRegistry->Get(pathToLoad); memory = (Uint8*)Memory::Malloc(item.Size + 1); if (!memory) @@ -172,7 +170,7 @@ PUBLIC STATIC bool ResourceManager::LoadResource(const char* filename, Uint8** if (item.DataFlag == 2) { Uint8 keyA[16]; Uint8 keyB[16]; - Uint32 filenameHash = CRC32::EncryptString(filename); + Uint32 filenameHash = CRC32::EncryptString(pathToLoad); Uint32 sizeHash = CRC32::EncryptData(&item.Size, sizeof(item.Size)); // Populate Key A @@ -231,12 +229,16 @@ PUBLIC STATIC bool ResourceManager::LoadResource(const char* filename, Uint8** } } + Memory::Free(pathToLoad); + *out = memory; *size = (size_t)item.Size; return true; DATA_FOLDER: - ResourceManager::PrefixResourcePath(resourcePath, sizeof resourcePath, filename); + ResourceManager::PrefixResourcePath(resourcePath, sizeof resourcePath, pathToLoad); + + Memory::Free(pathToLoad); SDL_RWops* rw = SDL_RWFromFile(resourcePath, "rb"); if (!rw) { @@ -263,6 +265,8 @@ PUBLIC STATIC bool ResourceManager::LoadResource(const char* filename, Uint8** return true; } PUBLIC STATIC bool ResourceManager::ResourceExists(const char* filename) { + char *pathToLoad = StringUtils::ReplacePathSeparators(filename); + char resourcePath[4096]; if (ResourceManager::UsingDataFolder && !ResourceManager::UsingModPack) goto DATA_FOLDER; @@ -270,13 +274,17 @@ PUBLIC STATIC bool ResourceManager::ResourceExists(const char* filename) { if (!ResourceRegistry) goto DATA_FOLDER; - if (!ResourceRegistry->Exists(filename)) + if (!ResourceRegistry->Exists(pathToLoad)) goto DATA_FOLDER; + Memory::Free(pathToLoad); + return true; DATA_FOLDER: - ResourceManager::PrefixResourcePath(resourcePath, sizeof resourcePath, filename); + ResourceManager::PrefixResourcePath(resourcePath, sizeof resourcePath, pathToLoad); + + Memory::Free(pathToLoad); SDL_RWops* rw = SDL_RWFromFile(resourcePath, "rb"); if (!rw) { diff --git a/source/Engine/ResourceTypes/SceneFormats/HatchSceneReader.cpp b/source/Engine/ResourceTypes/SceneFormats/HatchSceneReader.cpp index caf61224..37d8add2 100644 --- a/source/Engine/ResourceTypes/SceneFormats/HatchSceneReader.cpp +++ b/source/Engine/ResourceTypes/SceneFormats/HatchSceneReader.cpp @@ -328,17 +328,23 @@ PRIVATE STATIC void HatchSceneReader::FreeClasses() { SceneClasses.clear(); } -PRIVATE STATIC void HatchSceneReader::LoadTileset(const char* parentFolder) { +PRIVATE STATIC bool HatchSceneReader::LoadTileset(const char* parentFolder) { int curTileCount = (int)Scene::TileSpriteInfos.size(); char tilesetFile[4096]; snprintf(tilesetFile, sizeof(tilesetFile), "%s/Tileset.png", parentFolder); ISprite* tileSprite = new ISprite(); - tileSprite->Spritesheets[0] = tileSprite->AddSpriteSheet(tilesetFile); + Texture* spriteSheet = tileSprite->AddSpriteSheet(tilesetFile); + if (!spriteSheet) { + delete tileSprite; + return false; + } + + tileSprite->Spritesheets.push_back(spriteSheet); - int cols = tileSprite->Spritesheets[0]->Width / Scene::TileWidth; - int rows = tileSprite->Spritesheets[0]->Height / Scene::TileHeight; + int cols = spriteSheet->Width / Scene::TileWidth; + int rows = spriteSheet->Height / Scene::TileHeight; tileSprite->ReserveAnimationCount(1); tileSprite->AddAnimation("TileSprite", 0, 0, cols * rows); @@ -371,6 +377,8 @@ PRIVATE STATIC void HatchSceneReader::LoadTileset(const char* parentFolder) { Tileset sceneTileset(tileSprite, Scene::TileWidth, Scene::TileHeight, 0, curTileCount, Scene::TileSpriteInfos.size(), tilesetFile); Scene::Tilesets.push_back(sceneTileset); + + return true; } PRIVATE STATIC void HatchSceneReader::ReadEntities(Stream *r) { diff --git a/source/Engine/ResourceTypes/SceneFormats/RSDKSceneReader.cpp b/source/Engine/ResourceTypes/SceneFormats/RSDKSceneReader.cpp index b24fc72b..dcb4fd4b 100644 --- a/source/Engine/ResourceTypes/SceneFormats/RSDKSceneReader.cpp +++ b/source/Engine/ResourceTypes/SceneFormats/RSDKSceneReader.cpp @@ -572,7 +572,7 @@ PUBLIC STATIC bool RSDKSceneReader::Read(Stream* r, const char* parentFolder) { return true; } -PRIVATE STATIC void RSDKSceneReader::LoadTileset(const char* parentFolder) { +PRIVATE STATIC bool RSDKSceneReader::LoadTileset(const char* parentFolder) { Graphics::UsePalettes = true; char filename16x16Tiles[4096]; @@ -596,10 +596,16 @@ PRIVATE STATIC void RSDKSceneReader::LoadTileset(const char* parentFolder) { } ISprite* tileSprite = new ISprite(); - tileSprite->Spritesheets[0] = tileSprite->AddSpriteSheet(filename16x16Tiles); + Texture* spriteSheet = tileSprite->AddSpriteSheet(filename16x16Tiles); + if (!spriteSheet) { + delete tileSprite; + return false; + } + + tileSprite->Spritesheets.push_back(spriteSheet); - int cols = tileSprite->Spritesheets[0]->Width / Scene::TileWidth; - int rows = tileSprite->Spritesheets[0]->Height / Scene::TileHeight; + int cols = spriteSheet->Width / Scene::TileWidth; + int rows = spriteSheet->Height / Scene::TileHeight; tileSprite->ReserveAnimationCount(1); tileSprite->AddAnimation("TileSprite", 0, 0, cols * rows); @@ -622,4 +628,6 @@ PRIVATE STATIC void RSDKSceneReader::LoadTileset(const char* parentFolder) { Tileset sceneTileset(tileSprite, Scene::TileWidth, Scene::TileHeight, 0, 0, Scene::TileSpriteInfos.size(), filename16x16Tiles); Scene::Tilesets.push_back(sceneTileset); + + return true; } diff --git a/source/Engine/ResourceTypes/SceneFormats/TiledMapReader.cpp b/source/Engine/ResourceTypes/SceneFormats/TiledMapReader.cpp index a1180433..4f1d531f 100644 --- a/source/Engine/ResourceTypes/SceneFormats/TiledMapReader.cpp +++ b/source/Engine/ResourceTypes/SceneFormats/TiledMapReader.cpp @@ -223,10 +223,17 @@ PRIVATE STATIC Tileset* TiledMapReader::ParseTilesetImage(XMLNode* node, int fir snprintf(imagePath, sizeof(imagePath), "%s%.*s", parentFolder, (int)image_source.Length, image_source.Start); ISprite* tileSprite = new ISprite(); - tileSprite->Spritesheets[0] = tileSprite->AddSpriteSheet(imagePath); + Texture* spriteSheet = tileSprite->AddSpriteSheet(imagePath); - int cols = tileSprite->Spritesheets[0]->Width / Scene::TileWidth; - int rows = tileSprite->Spritesheets[0]->Height / Scene::TileHeight; + if (!spriteSheet) { + delete tileSprite; + return nullptr; + } + + tileSprite->Spritesheets.push_back(spriteSheet); + + int cols = spriteSheet->Width / Scene::TileWidth; + int rows = spriteSheet->Height / Scene::TileHeight; tileSprite->ReserveAnimationCount(1); tileSprite->AddAnimation("TileSprite", 0, 0, cols * rows); @@ -289,8 +296,11 @@ PRIVATE STATIC void TiledMapReader::ParseTileAnimation(int tileID, int firstgid, } PRIVATE STATIC void TiledMapReader::ParseTile(Tileset* tilesetPtr, XMLNode* node) { + if (!tilesetPtr) + return; + for (size_t e = 0; e < node->children.size(); e++) { - if (tilesetPtr && XMLParser::MatchToken(node->children[e]->name, "animation")) { + if (XMLParser::MatchToken(node->children[e]->name, "animation")) { int firstgid = tilesetPtr->FirstGlobalTileID; int tileID = (int)XMLParser::TokenToNumber(node->attributes.Get("id")) + firstgid; if ((size_t)tileID < Scene::TileSpriteInfos.size()) diff --git a/source/Engine/Scene.cpp b/source/Engine/Scene.cpp index 8c8714a2..61b13069 100644 --- a/source/Engine/Scene.cpp +++ b/source/Engine/Scene.cpp @@ -2272,14 +2272,16 @@ PRIVATE STATIC void Scene::ClearTileCollisions(TileConfig* cfg, size_t numTiles) } PUBLIC STATIC bool Scene::AddTileset(char* path) { ISprite* tileSprite = new ISprite(); - tileSprite->Spritesheets[0] = tileSprite->AddSpriteSheet(path); - if (!tileSprite->Spritesheets[0]) { + Texture* spriteSheet = tileSprite->AddSpriteSheet(path); + if (!spriteSheet) { delete tileSprite; return false; } - int cols = tileSprite->Spritesheets[0]->Width / Scene::TileWidth; - int rows = tileSprite->Spritesheets[0]->Height / Scene::TileHeight; + tileSprite->Spritesheets.push_back(spriteSheet); + + int cols = spriteSheet->Width / Scene::TileWidth; + int rows = spriteSheet->Height / Scene::TileHeight; tileSprite->ReserveAnimationCount(1); tileSprite->AddAnimation("TileSprite", 0, 0, cols * rows); @@ -2445,7 +2447,6 @@ PUBLIC STATIC void Scene::DisposeInScope(Uint32 scope) { if (!Scene::SpriteList[i]) continue; if (Scene::SpriteList[i]->UnloadPolicy > scope) continue; - Scene::SpriteList[i]->AsSprite->Dispose(); delete Scene::SpriteList[i]->AsSprite; delete Scene::SpriteList[i]; Scene::SpriteList[i] = NULL; diff --git a/source/Engine/Types/Tileset.cpp b/source/Engine/Types/Tileset.cpp index ba3fe851..d3939904 100644 --- a/source/Engine/Types/Tileset.cpp +++ b/source/Engine/Types/Tileset.cpp @@ -23,6 +23,9 @@ class Tileset { #include PUBLIC Tileset::Tileset(ISprite* sprite, int tileWidth, int tileHeight, size_t firstgid, size_t startTile, size_t tileCount, char* filename) { + if (sprite->Spritesheets.size() < 1) + return; + Sprite = sprite; NumCols = Sprite->Spritesheets[0]->Width / tileWidth; NumRows = Sprite->Spritesheets[0]->Height / tileHeight; @@ -52,6 +55,8 @@ PUBLIC void Tileset::RestartAnimations() { PUBLIC void Tileset::AddTileAnimSequence(int tileID, TileSpriteInfo* tileSpriteInfo, vector& tileIDs, vector& durations) { ISprite* tileSprite = Sprite; + if (!tileSprite) + return; if (tileSprite->Animations.size() == 1) tileSprite->AddAnimation("TileAnimation", 1, 0); @@ -65,6 +70,9 @@ PUBLIC void Tileset::AddTileAnimSequence(int tileID, TileSpriteInfo* tileSpriteI return; } + if (!NumCols) + return; + for (size_t i = 0; i < tileIDs.size(); i++) { int otherTileID = tileIDs[i]; tileSprite->AddFrame(animID, durations[i], diff --git a/source/Engine/Utilities/StringUtils.cpp b/source/Engine/Utilities/StringUtils.cpp index 980d45ee..71549c39 100644 --- a/source/Engine/Utilities/StringUtils.cpp +++ b/source/Engine/Utilities/StringUtils.cpp @@ -211,3 +211,35 @@ PUBLIC STATIC char* StringUtils::ConcatPaths(const char* pathA, const char* path memcpy(newPath, pathB, lenB); return out; } +PUBLIC STATIC char* StringUtils::ReplacePathSeparators(const char* path) { + if (!path) + return nullptr; + + char* newPath = (char*)Memory::Malloc(strlen(path) + 1); + if (!newPath) + return nullptr; + + char* out = newPath; + while (*path) { + char c = *path; + if (c == '\\') + *out = '/'; + else + *out = c; + out++; + path++; + } + *out = '\0'; + + return newPath; +} +PUBLIC STATIC void StringUtils::ReplacePathSeparatorsInPlace(char* path) { + if (!path) + return; + + while (*path) { + if (*path == '\\') + *path = '/'; + path++; + } +} diff --git a/tools/Animation Editor/Animation Editor.exe b/tools/Animation Editor/Animation Editor.exe deleted file mode 100644 index 88cc037a..00000000 Binary files a/tools/Animation Editor/Animation Editor.exe and /dev/null differ diff --git a/tools/Animation Editor/HatchAnimEditor.exe b/tools/Animation Editor/HatchAnimEditor.exe new file mode 100644 index 00000000..20c920fb Binary files /dev/null and b/tools/Animation Editor/HatchAnimEditor.exe differ diff --git a/tools/Animation Editor/INIFileParser.dll b/tools/Animation Editor/INIFileParser.dll deleted file mode 100644 index d19e920f..00000000 Binary files a/tools/Animation Editor/INIFileParser.dll and /dev/null differ diff --git a/tools/Animation Editor/RSDKv5.dll b/tools/Animation Editor/RSDKv5.dll deleted file mode 100644 index a43f5b9f..00000000 Binary files a/tools/Animation Editor/RSDKv5.dll and /dev/null differ diff --git a/tools/Animation Editor/SharpDX.Desktop.dll b/tools/Animation Editor/SharpDX.Desktop.dll deleted file mode 100644 index c0da6fce..00000000 Binary files a/tools/Animation Editor/SharpDX.Desktop.dll and /dev/null differ diff --git a/tools/Animation Editor/SharpDX.Direct3D9.dll b/tools/Animation Editor/SharpDX.Direct3D9.dll deleted file mode 100644 index 54d16343..00000000 Binary files a/tools/Animation Editor/SharpDX.Direct3D9.dll and /dev/null differ diff --git a/tools/Animation Editor/SharpDX.Mathematics.dll b/tools/Animation Editor/SharpDX.Mathematics.dll deleted file mode 100644 index 407083e7..00000000 Binary files a/tools/Animation Editor/SharpDX.Mathematics.dll and /dev/null differ diff --git a/tools/Animation Editor/SharpDX.dll b/tools/Animation Editor/SharpDX.dll deleted file mode 100644 index d4163a84..00000000 Binary files a/tools/Animation Editor/SharpDX.dll and /dev/null differ diff --git a/tools/Animation Editor/SonLVLAPI.dll b/tools/Animation Editor/SonLVLAPI.dll deleted file mode 100644 index 56d3fdc8..00000000 Binary files a/tools/Animation Editor/SonLVLAPI.dll and /dev/null differ diff --git a/tools/Animation Editor/SonicRetro.KensSharp.Common.dll b/tools/Animation Editor/SonicRetro.KensSharp.Common.dll deleted file mode 100644 index b9fe3d2a..00000000 Binary files a/tools/Animation Editor/SonicRetro.KensSharp.Common.dll and /dev/null differ diff --git a/tools/Animation Editor/SonicRetro.KensSharp.Enigma.dll b/tools/Animation Editor/SonicRetro.KensSharp.Enigma.dll deleted file mode 100644 index 9e8c3265..00000000 Binary files a/tools/Animation Editor/SonicRetro.KensSharp.Enigma.dll and /dev/null differ diff --git a/tools/Animation Editor/SonicRetro.KensSharp.Kosinski.dll b/tools/Animation Editor/SonicRetro.KensSharp.Kosinski.dll deleted file mode 100644 index 9c8afb90..00000000 Binary files a/tools/Animation Editor/SonicRetro.KensSharp.Kosinski.dll and /dev/null differ diff --git a/tools/Animation Editor/SonicRetro.KensSharp.Nemesis.dll b/tools/Animation Editor/SonicRetro.KensSharp.Nemesis.dll deleted file mode 100644 index 77e4d2b7..00000000 Binary files a/tools/Animation Editor/SonicRetro.KensSharp.Nemesis.dll and /dev/null differ diff --git a/tools/Animation Editor/zlib.net.dll b/tools/Animation Editor/zlib.net.dll deleted file mode 100644 index c156f8e7..00000000 Binary files a/tools/Animation Editor/zlib.net.dll and /dev/null differ