From ad334f2e7e2398021d2ea80ed8cb73c8197b5da1 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Thu, 29 Jun 2023 23:39:11 -0400 Subject: [PATCH 01/13] Add method to load a texture from a memory buffer --- OP2-Landlord/Graphics.cpp | 32 +++++++++++++++++++++++++++++++- OP2-Landlord/Graphics.h | 3 ++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index e02da2e..f9eec2f 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -41,7 +41,7 @@ void Graphics::present() } -Graphics::Texture Graphics::loadTexture(const std::string& filename) +Graphics::Texture Graphics::loadTexture(const std::string& filename) const { SDL_Surface* temp = IMG_Load(filename.c_str()); if (!temp) @@ -66,6 +66,36 @@ Graphics::Texture Graphics::loadTexture(const std::string& filename) } +Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferSize) const +{ + auto rwops = SDL_RWFromConstMem(buffer, static_cast(bufferSize)); + SDL_Surface* temp = IMG_LoadBMP_RW(rwops); + SDL_RWclose(rwops); + + if (!temp) + { + const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; + std::cout << msg << std::endl; + throw std::runtime_error(msg + SDL_GetError()); + } + + SDL_Texture* out = SDL_CreateTextureFromSurface(mRenderer, temp); + SDL_FreeSurface(temp); + + if (!out) + { + const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; + std::cout << msg << std::endl; + throw std::runtime_error(msg + SDL_GetError()); + } + + int width = 0, height = 0; + SDL_QueryTexture(out, nullptr, nullptr, &width, &height); + + return Texture{ out, SDL_Rect{ 0, 0, width, height }, { static_cast(width), static_cast(height) } }; +} + + void Graphics::init() { if (SDL_Init(SDL_INIT_VIDEO)) diff --git a/OP2-Landlord/Graphics.h b/OP2-Landlord/Graphics.h index 1550a90..7dd872e 100644 --- a/OP2-Landlord/Graphics.h +++ b/OP2-Landlord/Graphics.h @@ -28,7 +28,8 @@ class Graphics void clear(); void present(); - Texture loadTexture(const std::string& filename); + Texture loadTexture(const std::string& filename) const; + Texture loadTexture(const void* buffer, const size_t bufferSize) const; SDL_Window* window() { return mWindow; } SDL_Renderer* renderer() { return mRenderer; } From 6a92cf5c622bdc26e4686d1311159db231de03f5 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Thu, 29 Jun 2023 23:39:28 -0400 Subject: [PATCH 02/13] Fix include paths in project settings --- OP2-Landlord/OP2-Landlord.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OP2-Landlord/OP2-Landlord.vcxproj b/OP2-Landlord/OP2-Landlord.vcxproj index 157f62b..7f47375 100644 --- a/OP2-Landlord/OP2-Landlord.vcxproj +++ b/OP2-Landlord/OP2-Landlord.vcxproj @@ -71,11 +71,11 @@ - ../nas2d-core/;../OP2Utility/header/;../json/include;$(IncludePath) + ../nas2d-core/;../OP2Utility/include/;../json/include;$(IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath) - ../nas2d-core/;../OP2Utility/header/;../json/include;$(IncludePath) + ../nas2d-core/;../OP2Utility/include/;../json/include;$(IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath) From a9b0839d5278880b3d3c6d1e894ba8740ad16e37 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Thu, 29 Jun 2023 23:44:03 -0400 Subject: [PATCH 03/13] Load tileset data from art.vol and store as Graphics::Texture objects --- OP2-Landlord/main.cpp | 66 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/OP2-Landlord/main.cpp b/OP2-Landlord/main.cpp index d7866f2..23878bc 100644 --- a/OP2-Landlord/main.cpp +++ b/OP2-Landlord/main.cpp @@ -8,6 +8,7 @@ #include #if defined(_WIN32) +#define NOMINMAX #include #endif @@ -23,6 +24,11 @@ #include "StringTable.h" #include "Utility.h" +#include "OP2Utility.h" + + +using namespace OP2Utility; + namespace { @@ -33,12 +39,14 @@ namespace using StateGuiFunction = std::function; std::map StateFunctionTable; - using StateTransitionFunction = std::function; + using StateTransitionFunction = std::function; std::map StateTransitionFunctionTable; + + std::vector TileSets; }; -void mainLoop(Graphics& graphics, Gui& gui) +void mainLoop(EditorConfig& config, Graphics& graphics, Gui& gui) { std::string pathToOutpost2{}; @@ -56,7 +64,7 @@ void mainLoop(Graphics& graphics, Gui& gui) { try { - StateTransitionFunctionTable.at(ApplicationState)(gui); + StateTransitionFunctionTable.at(ApplicationState)(config, graphics, gui); } catch (std::out_of_range) { @@ -76,8 +84,54 @@ void checkConfig(EditorConfig& config) } -void loadOrCreateTransition(Gui& gui) +Graphics::Texture bmpToSurface(Graphics& graphics, EditorConfig& config, BitmapFile& bmp) +{ + std::size_t pixelOffset = sizeof(BmpHeader) + sizeof(ImageHeader) + bmp.palette.size() * sizeof(Color); + std::size_t bufferSize = pixelOffset + ImageHeader::CalculatePitch(bmp.imageHeader.bitCount, bmp.imageHeader.width) * std::abs(bmp.imageHeader.height); + + auto buffer = new uint8_t[bufferSize]; + memset(buffer, 0, bufferSize); + + Stream::MemoryWriter writer(buffer, bufferSize); + + bmp.WriteIndexed(writer); + + Graphics::Texture tileset = graphics.loadTexture(buffer, bufferSize); + + return tileset; +} + + +void loadOrCreateTransition(EditorConfig& config, Graphics& graphics, Gui& gui) { + Archive::VolFile artVol(config["Op2FilePath"] + "/" + "art.vol"); + const auto indexCount = artVol.GetCount(); + + std::vector tilesetIndicies; + for (size_t i = 0; i < indexCount; ++i) + { + const auto artName{ StringUtility::ConvertToUpper(artVol.GetName(i)) }; + + if (artName.find("WELL") != std::string::npos) + { + tilesetIndicies.push_back(i); + } + } + + for (size_t i = 0; i < tilesetIndicies.size(); ++i) + { + const auto tsetIndex = tilesetIndicies[i]; + + try + { + auto bitmap = Tileset::ReadTileset(*artVol.OpenStream(tsetIndex)); + TileSets.push_back(bmpToSurface(graphics, config, bitmap)); + } + catch(std::runtime_error e) + { + std::cout << "[Warning] Unable to load tilset '" << artVol.GetName(tsetIndex) << "' : " << e.what() << std::endl; + } + } } @@ -107,10 +161,10 @@ int main(int argc, char* argv[]) if (ApplicationState != Gui::AppState::InitialSetup) { - loadOrCreateTransition(gui); + loadOrCreateTransition(config, graphics, gui); } - mainLoop(graphics, gui); + mainLoop(config, graphics, gui); SDL_Quit(); } From 877b30b984b22aae1d102935a92fc44254d54b99 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Fri, 30 Jun 2023 16:17:55 -0400 Subject: [PATCH 04/13] Draw loaded tilesets Note: test to ensure proper loading of tileset image data --- OP2-Landlord/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/OP2-Landlord/main.cpp b/OP2-Landlord/main.cpp index 23878bc..0757df6 100644 --- a/OP2-Landlord/main.cpp +++ b/OP2-Landlord/main.cpp @@ -72,6 +72,24 @@ void mainLoop(EditorConfig& config, Graphics& graphics, Gui& gui) } } + if (!TileSets.empty()) + { + const auto& tset = TileSets.back(); + + int offset = 250; + for (const auto& tset : TileSets) + { + const SDL_Rect destRect{ + offset, 100, + static_cast(tset.dimensions.x), + static_cast(tset.dimensions.y) + }; + + SDL_RenderCopy(graphics.renderer(), tset.texture, nullptr, &destRect); + offset += 40; + } + } + gui.endFrame(); graphics.present(); } From 83fece8634a540c5525b4c1cda5ee4cfd0fe8336 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 10:46:38 -0400 Subject: [PATCH 05/13] Remove superfluous cout calls --- OP2-Landlord/Graphics.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index f9eec2f..23eafae 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -75,8 +75,8 @@ Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferS if (!temp) { const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; - std::cout << msg << std::endl; - throw std::runtime_error(msg + SDL_GetError()); + //std::cout << msg << std::endl; + throw std::runtime_error(msg); } SDL_Texture* out = SDL_CreateTextureFromSurface(mRenderer, temp); @@ -85,8 +85,8 @@ Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferS if (!out) { const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; - std::cout << msg << std::endl; - throw std::runtime_error(msg + SDL_GetError()); + //std::cout << msg << std::endl; + throw std::runtime_error(msg); } int width = 0, height = 0; From 97d02876dbabe3536cd6ac1d9f8b9150d52a6d68 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 10:46:48 -0400 Subject: [PATCH 06/13] Rename bmpToSurface --- OP2-Landlord/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OP2-Landlord/main.cpp b/OP2-Landlord/main.cpp index 0757df6..f1bbf64 100644 --- a/OP2-Landlord/main.cpp +++ b/OP2-Landlord/main.cpp @@ -102,7 +102,7 @@ void checkConfig(EditorConfig& config) } -Graphics::Texture bmpToSurface(Graphics& graphics, EditorConfig& config, BitmapFile& bmp) +Graphics::Texture bmpToTexture(Graphics& graphics, EditorConfig& config, BitmapFile& bmp) { std::size_t pixelOffset = sizeof(BmpHeader) + sizeof(ImageHeader) + bmp.palette.size() * sizeof(Color); std::size_t bufferSize = pixelOffset + ImageHeader::CalculatePitch(bmp.imageHeader.bitCount, bmp.imageHeader.width) * std::abs(bmp.imageHeader.height); @@ -143,7 +143,7 @@ void loadOrCreateTransition(EditorConfig& config, Graphics& graphics, Gui& gui) try { auto bitmap = Tileset::ReadTileset(*artVol.OpenStream(tsetIndex)); - TileSets.push_back(bmpToSurface(graphics, config, bitmap)); + TileSets.push_back(bmpToTexture(graphics, config, bitmap)); } catch(std::runtime_error e) { From 5758dedc0e2691dda26f404d5f13999e1a4aac1d Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 10:59:20 -0400 Subject: [PATCH 07/13] Add stub function to load a texture packed into a texture atlas that plays nice with GPU's --- OP2-Landlord/Graphics.cpp | 6 ++++++ OP2-Landlord/Graphics.h | 1 + 2 files changed, 7 insertions(+) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index 23eafae..dcfd543 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -96,6 +96,12 @@ Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferS } +Graphics::Texture Graphics::loadTexturePacked(const void* buffer, const size_t buffersize) const +{ + return Texture(); +} + + void Graphics::init() { if (SDL_Init(SDL_INIT_VIDEO)) diff --git a/OP2-Landlord/Graphics.h b/OP2-Landlord/Graphics.h index 7dd872e..d314a16 100644 --- a/OP2-Landlord/Graphics.h +++ b/OP2-Landlord/Graphics.h @@ -30,6 +30,7 @@ class Graphics Texture loadTexture(const std::string& filename) const; Texture loadTexture(const void* buffer, const size_t bufferSize) const; + Texture loadTexturePacked(const void* buffer, const size_t buffersize) const; SDL_Window* window() { return mWindow; } SDL_Renderer* renderer() { return mRenderer; } From a85be59477b2a367f8ad28755572570631d53da9 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 11:08:51 -0400 Subject: [PATCH 08/13] Extract to function --- OP2-Landlord/Graphics.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index dcfd543..808ca92 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -6,6 +6,25 @@ #include +namespace +{ + SDL_Surface* createSurfaceFromBuffer(const void* buffer, const size_t bufferSize) + { + auto rwops = SDL_RWFromConstMem(buffer, static_cast(bufferSize)); + SDL_Surface* surface = IMG_LoadBMP_RW(rwops); + SDL_RWclose(rwops); + + if (!surface) + { + const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; + throw std::runtime_error(msg); + } + + return surface; + } +}; + + Graphics::Graphics(ImVec2 windowSize) : mWindowSize{windowSize} { @@ -68,19 +87,9 @@ Graphics::Texture Graphics::loadTexture(const std::string& filename) const Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferSize) const { - auto rwops = SDL_RWFromConstMem(buffer, static_cast(bufferSize)); - SDL_Surface* temp = IMG_LoadBMP_RW(rwops); - SDL_RWclose(rwops); - - if (!temp) - { - const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; - //std::cout << msg << std::endl; - throw std::runtime_error(msg); - } - - SDL_Texture* out = SDL_CreateTextureFromSurface(mRenderer, temp); - SDL_FreeSurface(temp); + auto surface = createSurfaceFromBuffer(buffer, bufferSize); + auto out = SDL_CreateTextureFromSurface(mRenderer, surface); + SDL_FreeSurface(surface); if (!out) { From dcc45f3dc7ee23bcefa702cb71665431d14809d4 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 11:09:13 -0400 Subject: [PATCH 09/13] Remove dead code --- OP2-Landlord/Graphics.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index 808ca92..3c8177d 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -94,7 +94,6 @@ Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferS if (!out) { const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; - //std::cout << msg << std::endl; throw std::runtime_error(msg); } From 89decb7e45c169c7c4ac57f8e4d120a24a61c4c7 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 11:25:12 -0400 Subject: [PATCH 10/13] Use unique_ptr to embrace RAII --- OP2-Landlord/Graphics.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index 3c8177d..e1f2b07 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -3,12 +3,15 @@ #include +#include #include namespace { - SDL_Surface* createSurfaceFromBuffer(const void* buffer, const size_t bufferSize) + using SdlSurface = std::unique_ptr < SDL_Surface, std::function> ; + + SdlSurface createSurfaceFromBuffer(const void* buffer, const size_t bufferSize) { auto rwops = SDL_RWFromConstMem(buffer, static_cast(bufferSize)); SDL_Surface* surface = IMG_LoadBMP_RW(rwops); @@ -20,7 +23,7 @@ namespace throw std::runtime_error(msg); } - return surface; + return SdlSurface{ surface, [](SDL_Surface* srf) { SDL_FreeSurface(srf); } }; } }; @@ -87,9 +90,7 @@ Graphics::Texture Graphics::loadTexture(const std::string& filename) const Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferSize) const { - auto surface = createSurfaceFromBuffer(buffer, bufferSize); - auto out = SDL_CreateTextureFromSurface(mRenderer, surface); - SDL_FreeSurface(surface); + auto out = SDL_CreateTextureFromSurface(mRenderer, createSurfaceFromBuffer(buffer, bufferSize).get()); if (!out) { From b3dd854cb09408e183f8fa2286612291c40b1754 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 12:15:13 -0400 Subject: [PATCH 11/13] Normalize naming --- OP2-Landlord/Graphics.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index e1f2b07..1687375 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -11,9 +11,9 @@ namespace { using SdlSurface = std::unique_ptr < SDL_Surface, std::function> ; - SdlSurface createSurfaceFromBuffer(const void* buffer, const size_t bufferSize) + SdlSurface createSurfaceFromBuffer(const void* buffer, const size_t buffersize) { - auto rwops = SDL_RWFromConstMem(buffer, static_cast(bufferSize)); + auto rwops = SDL_RWFromConstMem(buffer, static_cast(buffersize)); SDL_Surface* surface = IMG_LoadBMP_RW(rwops); SDL_RWclose(rwops); @@ -88,9 +88,9 @@ Graphics::Texture Graphics::loadTexture(const std::string& filename) const } -Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t bufferSize) const +Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t buffersize) const { - auto out = SDL_CreateTextureFromSurface(mRenderer, createSurfaceFromBuffer(buffer, bufferSize).get()); + auto out = SDL_CreateTextureFromSurface(mRenderer, createSurfaceFromBuffer(buffer, buffersize).get()); if (!out) { From ea0d9d4fdedddc70dde26a85a6398fd244899d69 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 15:43:28 -0400 Subject: [PATCH 12/13] Flesh out loadTexturePacked --- OP2-Landlord/Graphics.cpp | 55 +++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index 1687375..37fc3e1 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -5,11 +5,21 @@ #include #include +#include namespace { - using SdlSurface = std::unique_ptr < SDL_Surface, std::function> ; + + struct SurfaceDeleter + { + void operator()(SDL_Surface* srf) + { + SDL_FreeSurface(srf); + } + }; + + using SdlSurface = std::unique_ptr ; SdlSurface createSurfaceFromBuffer(const void* buffer, const size_t buffersize) { @@ -19,11 +29,11 @@ namespace if (!surface) { - const std::string msg{ std::string("loadTexture(): Unable to load from memory buffer: ") + SDL_GetError() }; + const std::string msg{ "createSurfaceFromBuffer(): Unable to load from memory buffer: " + std::string(SDL_GetError()) }; throw std::runtime_error(msg); } - return SdlSurface{ surface, [](SDL_Surface* srf) { SDL_FreeSurface(srf); } }; + return SdlSurface{ surface }; } }; @@ -106,8 +116,43 @@ Graphics::Texture Graphics::loadTexture(const void* buffer, const size_t buffers Graphics::Texture Graphics::loadTexturePacked(const void* buffer, const size_t buffersize) const -{ - return Texture(); +{ + SdlSurface src{ SDL_ConvertSurfaceFormat(createSurfaceFromBuffer(buffer, buffersize).get(), SDL_PIXELFORMAT_RGB888, 0) }; + + SdlSurface destinationSurface(SDL_CreateRGBSurface( + src.get()->flags, + 1024, 1024, + src->format->BitsPerPixel, + src->format->Rmask, + src->format->Gmask, + src->format->Bmask, + src->format->Amask)); + + if (!destinationSurface.get()) + { + throw std::runtime_error("loadTexturePacked(): Unable to create new surface: " + std::string(SDL_GetError())); + } + + SDL_Rect sourceRect{ 0, 0, 32, 32 }; + SDL_Rect destRect{ 0, 0, 32, 32 }; + for (size_t i = 0; i < src->h / 32; ++i) + { + destRect = { (static_cast(i) % 32) * 32, (static_cast(i) / 32) * 32, 32, 32 }; + SDL_BlitSurface(src.get(), &sourceRect, destinationSurface.get(), &destRect); + sourceRect.y += 32; + } + + auto out = SDL_CreateTextureFromSurface(mRenderer, destinationSurface.get()); + if (!out) + { + const std::string msg{ std::string("loadTexturePacked(): Unable to load from memory buffer: ") + SDL_GetError() }; + throw std::runtime_error(msg); + } + + int width = 0, height = 0; + SDL_QueryTexture(out, nullptr, nullptr, &width, &height); + + return Texture{ out, SDL_Rect{ 0, 0, width, height }, { static_cast(width), static_cast(height) } }; } From b7723c0d67c454e2b663c221751020e8a80762f6 Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Sat, 1 Jul 2023 15:43:49 -0400 Subject: [PATCH 13/13] Use packed texture loader --- OP2-Landlord/main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OP2-Landlord/main.cpp b/OP2-Landlord/main.cpp index f1bbf64..868e9c9 100644 --- a/OP2-Landlord/main.cpp +++ b/OP2-Landlord/main.cpp @@ -114,9 +114,7 @@ Graphics::Texture bmpToTexture(Graphics& graphics, EditorConfig& config, BitmapF bmp.WriteIndexed(writer); - Graphics::Texture tileset = graphics.loadTexture(buffer, bufferSize); - - return tileset; + return graphics.loadTexturePacked(buffer, bufferSize); }