diff --git a/source/graphics.cpp b/source/graphics.cpp index c3af8e9e..8310922a 100644 --- a/source/graphics.cpp +++ b/source/graphics.cpp @@ -195,6 +195,9 @@ GraphicManager::~GraphicManager() { iter->second = nullptr; } + sprite_space.clear(); + image_space.clear(); + delete animation_timer; animation_timer = nullptr; } @@ -416,7 +419,6 @@ bool GraphicManager::loadEditorSprites() { sprite_space[EDITOR_SPRITE_PICKUPABLE_ITEM] = GameSprite::createFromBitmap(ART_PICKUPABLE); sprite_space[EDITOR_SPRITE_MOVEABLE_ITEM] = GameSprite::createFromBitmap(ART_MOVEABLE); sprite_space[EDITOR_SPRITE_PICKUPABLE_MOVEABLE_ITEM] = GameSprite::createFromBitmap(ART_PICKUPABLE_MOVEABLE); - return true; } diff --git a/source/map_drawer.cpp b/source/map_drawer.cpp index 1f0f9513..e0d1c319 100644 --- a/source/map_drawer.cpp +++ b/source/map_drawer.cpp @@ -1366,7 +1366,7 @@ void MapDrawer::BlitCreature(int screenx, int screeny, const Outfit &outfit, Dir auto spriteId = spr->spriteList[0]->getHardwareID(); auto outfitImage = spr->getOutfitImage(spriteId, dir, outfit); if (outfitImage) { - glBlitTexture(screenx, screeny, outfitImage->getHardwareID(), red, green, blue, alpha, false, outfit); + glBlitTexture(screenx, screeny, outfitImage->getHardwareID(), red, green, blue, alpha, false, false, outfit); } } @@ -1727,11 +1727,12 @@ void MapDrawer::DrawTileIndicators(TileLocation* location) { void MapDrawer::DrawIndicator(int x, int y, int indicator, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { GameSprite* sprite = g_gui.gfx.getEditorSprite(indicator); if (sprite == nullptr) { + spdlog::error("MapDrawer::DrawIndicator: sprite is nullptr"); return; } int textureId = sprite->getHardwareID(0, 0, 0, -1, 0, 0); - glBlitTexture(x, y, textureId, r, g, b, a, true); + glBlitTexture(x, y, textureId, r, g, b, a, true, true); } void MapDrawer::DrawPositionIndicator(int z) { @@ -1940,39 +1941,66 @@ void MapDrawer::ShowPositionIndicator(const Position &position) { pos_indicator_timer.Start(); } -void MapDrawer::glBlitTexture(int sx, int sy, int texture_number, int red, int green, int blue, int alpha, bool adjustZoom /* = false*/, const Outfit &outfit /* = {}*/) { - if (texture_number != 0) { - SpriteSheetPtr sheet = g_spriteAppearances.getSheetBySpriteId(texture_number); +void MapDrawer::glBlitTexture(int sx, int sy, int textureId, int red, int green, int blue, int alpha, bool adjustZoom, bool isEditorSprite, const Outfit &outfit) { + if (textureId <= 0) { + return; + } + + auto width = rme::TileSize; + auto height = rme::TileSize; + // Adjusts the offset of normal sprites + if (!isEditorSprite) { + SpriteSheetPtr sheet = g_spriteAppearances.getSheetBySpriteId(textureId); if (!sheet) { return; } - auto spriteWidth = sheet->getSpriteSize().width; - auto spriteHeight = sheet->getSpriteSize().height; - // Fix the outfit offset 8x8 sprites being drawn offset - if (spriteWidth == 64 && spriteHeight == 64 && (outfit.lookType > 0 || outfit.lookItem > 0)) { + width = sheet->getSpriteSize().width; + height = sheet->getSpriteSize().height; + + // If the sprite is an outfit and the size is 64x64, adjust the offset + if (width == 64 && height == 64 && (outfit.lookType > 0 || outfit.lookItem > 0)) { GameSprite* spr = g_gui.gfx.getCreatureSprite(outfit.lookType); if (spr && spr->getDrawOffset().x == 8 && spr->getDrawOffset().y == 8) { - sx -= spriteWidth / 2; - sy -= spriteWidth / 2; + sx -= width / 2; + sy -= height / 2; } } + } - spdlog::debug("Blitting outfit {} at ({}, {})", outfit.name, sx, sy); + // Adjust zoom if necessary + if (adjustZoom) { + if (zoom < 1.0f) { + float offset = 10 / (10 * zoom); + width = std::max(16, static_cast(width * zoom)); + height = std::max(16, static_cast(height * zoom)); + sx += offset; + sy += offset; + } else if (zoom > 1.f) { + float offset = (10 * zoom); + width += static_cast(offset); + height += static_cast(offset); + sx -= offset; + sy -= offset; + } + } - glBindTexture(GL_TEXTURE_2D, texture_number); - glColor4ub(uint8_t(red), uint8_t(green), uint8_t(blue), uint8_t(alpha)); - glBegin(GL_QUADS); - glTexCoord2f(0.f, 0.f); - glVertex2f(sx, sy); - glTexCoord2f(1.f, 0.f); - glVertex2f(sx + spriteWidth, sy); - glTexCoord2f(1.f, 1.f); - glVertex2f(sx + spriteWidth, sy + spriteHeight); - glTexCoord2f(0.f, 1.f); - glVertex2f(sx, sy + spriteHeight); - glEnd(); + if (outfit.lookType > 0) { + spdlog::debug("Blitting outfit {} at ({}, {})", outfit.name, sx, sy); } + + glBindTexture(GL_TEXTURE_2D, textureId); + glColor4ub(uint8_t(red), uint8_t(green), uint8_t(blue), uint8_t(alpha)); + glBegin(GL_QUADS); + glTexCoord2f(0.f, 0.f); + glVertex2f(sx, sy); + glTexCoord2f(1.f, 0.f); + glVertex2f(sx + width, sy); + glTexCoord2f(1.f, 1.f); + glVertex2f(sx + width, sy + height); + glTexCoord2f(0.f, 1.f); + glVertex2f(sx, sy + height); + glEnd(); } void MapDrawer::glBlitSquare(int x, int y, int red, int green, int blue, int alpha) { diff --git a/source/map_drawer.h b/source/map_drawer.h index 1d5b2572..55d72a6d 100644 --- a/source/map_drawer.h +++ b/source/map_drawer.h @@ -180,7 +180,7 @@ class MapDrawer { }; void getColor(Brush* brush, const Position &position, uint8_t &r, uint8_t &g, uint8_t &b); - void glBlitTexture(int sx, int sy, int texture_number, int red, int green, int blue, int alpha, bool adjustZoom = false, const Outfit &outfit = {}); + void glBlitTexture(int sx, int sy, int texture_number, int red, int green, int blue, int alpha, bool adjustZoom = false, bool isEditorSprite = false, const Outfit &outfit = {}); void glBlitSquare(int x, int y, int red, int green, int blue, int alpha); void glBlitSquare(int x, int y, const wxColor &color); void glColor(const wxColor &color); diff --git a/source/sprites.h b/source/sprites.h index 38579c80..6e87cb27 100644 --- a/source/sprites.h +++ b/source/sprites.h @@ -18,14 +18,6 @@ #ifndef RME_SPRITES_H_ #define RME_SPRITES_H_ -enum { - SPRITE_FLAME_BLUE = 775, - SPRITE_FLAG_GREY = 2889, - SPRITE_FLAG_GREEN = 2890, - SPRITE_SPAWN = 2138, - SPRITE_SPAWN_NPC = 2133 -}; - enum { EDITOR_SPRITE_SELECTION_MARKER = -1000, EDITOR_SPRITE_BRUSH_CD_1x1,