From b952a2bd8feef58edeaa1b79888d44616b0e50cf Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Mon, 29 Jan 2024 10:29:38 -0300 Subject: [PATCH] fix: build and other adjusts --- CMakePresets.json | 12 ++++ source/graphics.cpp | 138 +++++++++++++++++++---------------------- source/graphics.h | 10 +-- source/gui.cpp | 38 ------------ source/gui.h | 1 - source/item.cpp | 3 +- source/items.cpp | 9 ++- source/map_drawer.cpp | 2 +- source/preferences.cpp | 2 +- 9 files changed, 85 insertions(+), 130 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index fe8e351e..fd575106 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -128,6 +128,18 @@ } ], "buildPresets": [ + { + "name": "1-windows-release", + "configurePreset": "windows-release" + }, + { + "name": "2-windows-asan", + "configurePreset": "windows-release-asan" + }, + { + "name": "3-windows-debug", + "configurePreset": "windows-debug" + }, { "name": "linux-release", "configurePreset": "linux-release" diff --git a/source/graphics.cpp b/source/graphics.cpp index ff270447..dc6ca139 100644 --- a/source/graphics.cpp +++ b/source/graphics.cpp @@ -915,8 +915,7 @@ bool GraphicManager::loadOutfitSpriteMetadata(canary::protobuf::appearances::App sType->minimap_color = outfit.flags().has_automap() ? static_cast(outfit.flags().automap().color()) : 0; sType->draw_height = outfit.flags().has_height() ? static_cast(outfit.flags().height().elevation()) : 0; if (outfit.flags().has_shift()) { - sType->drawoffset_x = static_cast(outfit.flags().shift().x()); - sType->drawoffset_y = static_cast(outfit.flags().shift().y()); + sType->draw_offset = wxPoint(outfit.flags().shift().x(), outfit.flags().shift().y()); sType->isDrawOffsetLoaded = true; } @@ -1012,8 +1011,6 @@ GameSprite::GameSprite() : numsprites(0), animator(nullptr), draw_height(0), - drawoffset_x(0), - drawoffset_y(0), minimap_color(0) { m_wxMemoryDc[SPRITE_SIZE_16x16] = nullptr; m_wxMemoryDc[SPRITE_SIZE_32x32] = nullptr; @@ -1025,13 +1022,6 @@ GameSprite::~GameSprite() { animator = nullptr; } -void GameSprite::unloadDC() { - delete m_wxMemoryDc[SPRITE_SIZE_16x16]; - delete m_wxMemoryDc[SPRITE_SIZE_32x32]; - m_wxMemoryDc[SPRITE_SIZE_16x16] = nullptr; - m_wxMemoryDc[SPRITE_SIZE_32x32] = nullptr; -} - uint16_t GameSprite::getDrawHeight() const { return draw_height; } @@ -1043,12 +1033,43 @@ wxPoint GameSprite::getDrawOffset() { return wxPoint(0, 0); } - drawoffset_x += sheet->getSpriteSize().width - 32; - drawoffset_y += sheet->getSpriteSize().height - 32; + draw_offset.x += sheet->getSpriteSize().width - 32; + draw_offset.y += sheet->getSpriteSize().height - 32; isDrawOffsetLoaded = true; } - return wxPoint(drawoffset_x, drawoffset_y); + return draw_offset; +} + +uint8_t GameSprite::getWidth() { + if (width <= 0) { + const auto &sheet = g_spriteAppearances.getSheetBySpriteId(spriteList[0]->getHardwareID(), false); + if (sheet) { + width = sheet->getSpriteSize().width; + height = sheet->getSpriteSize().height; + } + } + + return width; +} + +uint8_t GameSprite::getHeight() { + if (height <= 0) { + const auto &sheet = g_spriteAppearances.getSheetBySpriteId(spriteList[0]->getHardwareID(), false); + if (sheet) { + width = sheet->getSpriteSize().width; + height = sheet->getSpriteSize().height; + } + } + + return height; +} + +void GameSprite::unloadDC() { + delete m_wxMemoryDc[SPRITE_SIZE_16x16]; + delete m_wxMemoryDc[SPRITE_SIZE_32x32]; + m_wxMemoryDc[SPRITE_SIZE_16x16] = nullptr; + m_wxMemoryDc[SPRITE_SIZE_32x32] = nullptr; } uint8_t GameSprite::getMiniMapColor() const { @@ -1059,23 +1080,6 @@ int GameSprite::getIndex(int width, int height, int layer, int pattern_x, int pa return ((((frame % this->sprite_phase_size) * this->pattern_z + pattern_z) * this->pattern_y + pattern_y) * this->pattern_x + pattern_x) * this->layers + layer; } -GLuint GameSprite::getHardwareID(int _layer, int _count, int _pattern_x, int _pattern_y, int _pattern_z, int _frame) { - uint32_t v; - if (_count >= 0) { - v = _count; - } else { - v = (((_frame)*pattern_y + _pattern_y) * pattern_x + _pattern_x) * layers + _layer; - } - if (v >= numsprites) { - if (numsprites == 1) { - v = 0; - } else { - v %= numsprites; - } - } - return spriteList[v]->getHardwareID(); -} - std::shared_ptr GameSprite::getOutfitImage(int spriteId, Direction direction, const Outfit &outfit) { uint32_t spriteIndex = direction * layers; if (layers > 1 && spriteIndex >= numsprites) { @@ -1086,17 +1090,7 @@ std::shared_ptr GameSprite::getOutfitImage(int spriteId } } - if (instanced_templates.empty()) { - auto img = std::make_shared(this, spriteIndex, spriteId, outfit); - if (!img) { - return nullptr; - } - instanced_templates.push_back(img); - return img; - } - // While this is linear lookup, it is very rare for the list to contain more than 4-8 entries, so it's faster than a hashmap anyways. - for (auto iter = instanced_templates.begin(); iter != instanced_templates.end(); ++iter) { - auto img = *iter; + for (auto &img : instanced_templates) { if (img->m_spriteId == spriteId) { uint32_t lookHash = img->m_lookHead << 24 | img->m_lookBody << 16 | img->m_lookLegs << 8 | img->m_lookFeet; if (outfit.getColorHash() == lookHash) { @@ -1110,6 +1104,23 @@ std::shared_ptr GameSprite::getOutfitImage(int spriteId return img; } +GLuint GameSprite::getHardwareID(int _layer, int _count, int _pattern_x, int _pattern_y, int _pattern_z, int _frame) { + uint32_t v; + if (_count >= 0) { + v = _count; + } else { + v = (((_frame)*pattern_y + _pattern_y) * pattern_x + _pattern_x) * layers + _layer; + } + if (v >= numsprites) { + if (numsprites == 1) { + v = 0; + } else { + v %= numsprites; + } + } + return spriteList[v]->getHardwareID(); +} + wxMemoryDC* GameSprite::getDC(SpriteSize spriteSize) { if (!m_wxMemoryDc[spriteSize]) { const int bgshade = g_settings.getInteger(Config::ICON_BACKGROUND); @@ -1182,7 +1193,7 @@ GameSprite::Image::~Image() { unloadGLTexture(0); } -void GameSprite::Image::createGLTexture(GLuint whatid) { +void GameSprite::Image::createGLTexture(GLuint textureId) { ASSERT(!isGLLoaded); uint8_t* rgba = getRGBAData(); @@ -1190,7 +1201,7 @@ void GameSprite::Image::createGLTexture(GLuint whatid) { return; } - const auto &sheet = g_spriteAppearances.getSheetBySpriteId(whatid); + const auto &sheet = g_spriteAppearances.getSheetBySpriteId(textureId); if (!sheet) { return; } @@ -1202,7 +1213,7 @@ void GameSprite::Image::createGLTexture(GLuint whatid) { isGLLoaded = true; g_gui.gfx.loaded_textures += 1; - glBindTexture(GL_TEXTURE_2D, whatid); + glBindTexture(GL_TEXTURE_2D, textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812F); // GL_CLAMP_TO_EDGE @@ -1210,10 +1221,10 @@ void GameSprite::Image::createGLTexture(GLuint whatid) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, spriteWidth, spriteHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, invertedBuffer); } -void GameSprite::Image::unloadGLTexture(GLuint whatid) { +void GameSprite::Image::unloadGLTexture(GLuint textureId) { isGLLoaded = false; g_gui.gfx.loaded_textures -= 1; - glDeleteTextures(1, &whatid); + glDeleteTextures(1, &textureId); } void GameSprite::Image::visit() { @@ -1264,11 +1275,11 @@ GLuint GameSprite::NormalImage::getHardwareID() { return id; } -void GameSprite::NormalImage::createGLTexture(GLuint ignored) { +void GameSprite::NormalImage::createGLTexture(GLuint) { Image::createGLTexture(id); } -void GameSprite::NormalImage::unloadGLTexture(GLuint ignored) { +void GameSprite::NormalImage::unloadGLTexture(GLuint) { Image::unloadGLTexture(id); } @@ -1324,36 +1335,13 @@ void GameSprite::EditorImage::createGLTexture(GLuint textureId) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812F); // GL_CLAMP_TO_EDGE glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 0x812F); // GL_CLAMP_TO_EDGE glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rme::SpritePixels, rme::SpritePixels, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); + delete[] imageData; } void GameSprite::EditorImage::unloadGLTexture(GLuint textureId) { Image::unloadGLTexture(id); } -uint8_t GameSprite::getWidth() { - if (width <= 0) { - const auto &sheet = g_spriteAppearances.getSheetBySpriteId(spriteList[0]->getHardwareID(), false); - if (sheet) { - width = sheet->getSpriteSize().width; - height = sheet->getSpriteSize().height; - } - } - - return width; -} - -uint8_t GameSprite::getHeight() { - if (height <= 0) { - const auto &sheet = g_spriteAppearances.getSheetBySpriteId(spriteList[0]->getHardwareID(), false); - if (sheet) { - width = sheet->getSpriteSize().width; - height = sheet->getSpriteSize().height; - } - } - - return height; -} - // OutfitImage GameSprite::OutfitImage::OutfitImage(GameSprite* initParent, int initSpriteIndex, GLuint initSpriteId, const Outfit &initOutfit) : m_spriteId(initSpriteId), @@ -1371,7 +1359,7 @@ GameSprite::OutfitImage::~OutfitImage() { m_cachedOutfitData = nullptr; } -void GameSprite::OutfitImage::unloadGLTexture(GLuint ignored) { +void GameSprite::OutfitImage::unloadGLTexture(GLuint) { Image::unloadGLTexture(m_spriteId); } @@ -1441,7 +1429,7 @@ uint8_t* GameSprite::OutfitImage::getRGBAData() { } } - spdlog::debug("outfit name: {}, pattern_x: {}, pattern_y: {}, pattern_z: {}, sprite_phase_size: {}, layers: {}, draw height: {}, drawx: {}, drawy: {}", m_name, m_parent->pattern_x, m_parent->pattern_y, m_parent->pattern_z, m_parent->sprite_phase_size, m_parent->layers, m_parent->draw_height, m_parent->drawoffset_x, m_parent->drawoffset_y); + spdlog::debug("outfit name: {}, pattern_x: {}, pattern_y: {}, pattern_z: {}, sprite_phase_size: {}, layers: {}, draw height: {}, drawx: {}, drawy: {}", m_name, m_parent->pattern_x, m_parent->pattern_y, m_parent->pattern_z, m_parent->sprite_phase_size, m_parent->layers, m_parent->draw_height, m_parent->getDrawOffset().x, m_parent->getDrawOffset().y); m_cachedOutfitData = rgbadata; return m_cachedOutfitData; diff --git a/source/graphics.h b/source/graphics.h index b5a14362..ece5eb96 100644 --- a/source/graphics.h +++ b/source/graphics.h @@ -192,8 +192,8 @@ class GameSprite : public Sprite { void colorizePixel(uint8_t color, uint8_t &r, uint8_t &b, uint8_t &g); uint8_t* getOutfitData(int spriteId); - virtual void createGLTexture(GLuint spriteId = 0); - virtual void unloadGLTexture(GLuint ignored = 0); + virtual void createGLTexture(GLuint); + virtual void unloadGLTexture(GLuint); }; uint32_t id; @@ -223,8 +223,6 @@ class GameSprite : public Sprite { uint16_t ground_speed; uint16_t draw_height; wxPoint draw_offset; - uint16_t drawoffset_x; - uint16_t drawoffset_y; uint16_t minimap_color; @@ -344,9 +342,6 @@ class GraphicManager { return sprites_file; } - bool hasTransparency() const; - bool isUnloaded() const; - private: bool unloaded; // This is used if memcaching is NOT on @@ -363,7 +358,6 @@ class GraphicManager { uint16_t creature_count; bool otfi_found; bool is_extended; - bool has_transparency; bool has_frame_durations; bool has_frame_groups; wxFileName metadata_file; diff --git a/source/gui.cpp b/source/gui.cpp index 11025dc5..1936dc0d 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -239,9 +239,6 @@ bool GUI::LoadVersion(wxString &error, wxArrayString &warnings) { DestroyPalettes(); DestroyMinimap(); - // Destroy the previous version - UnloadVersion(); - bool ret = LoadDataFiles(error, warnings); if (ret) { g_gui.LoadPerspective(); @@ -289,7 +286,6 @@ bool GUI::LoadDataFiles(wxString &error, wxArrayString &warnings) { error = "Couldn't load catalog-content.json, error: " + error; spdlog::error("[GUI::LoadDataFiles] {}", error.ToStdString()); g_gui.DestroyLoadBar(); - UnloadVersion(); return false; } @@ -354,40 +350,6 @@ bool GUI::LoadDataFiles(wxString &error, wxArrayString &warnings) { return true; } -void GUI::UnloadVersion() { - UnnamedRenderingLock(); - gfx.clear(); - current_brush = nullptr; - previous_brush = nullptr; - - house_brush = nullptr; - house_exit_brush = nullptr; - waypoint_brush = nullptr; - optional_brush = nullptr; - eraser = nullptr; - normal_door_brush = nullptr; - locked_door_brush = nullptr; - magic_door_brush = nullptr; - quest_door_brush = nullptr; - hatch_door_brush = nullptr; - window_door_brush = nullptr; - - // g_gui.UnloadVersion(); - g_materials.clear(); - g_brushes.clear(); - g_items.clear(); - gfx.clear(); - - FileName cdb = ClientAssets::getLocalPath(); - cdb.SetFullName("monsters.xml"); - g_monsters.saveToXML(cdb); - g_monsters.clear(); - - cdb.SetFullName("npcs.xml"); - g_npcs.saveToXML(cdb); - g_npcs.clear(); -} - void GUI::SaveCurrentMap(FileName filename, bool showdialog) { MapTab* mapTab = GetCurrentMapTab(); if (mapTab) { diff --git a/source/gui.h b/source/gui.h index 364d0e8f..adebf5ff 100644 --- a/source/gui.h +++ b/source/gui.h @@ -367,7 +367,6 @@ class GUI { protected: bool LoadDataFiles(wxString &error, wxArrayString &warnings); - void UnloadVersion(); //========================================================================= // Palette Interface diff --git a/source/item.cpp b/source/item.cpp index 7f8b1bad..7001996e 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -228,8 +228,9 @@ bool Item::hasProperty(enum ITEMPROPERTY prop) const { wxPoint Item::getDrawOffset() const { const ItemType &type = g_items.getItemType(id); if (type.sprite) { - return wxPoint(type.sprite->getDrawOffset().x, type.sprite->getDrawOffset().y); + return type.sprite->getDrawOffset(); } + return wxPoint(0, 0); } diff --git a/source/items.cpp b/source/items.cpp index a5c7e657..da8f8eee 100644 --- a/source/items.cpp +++ b/source/items.cpp @@ -100,7 +100,7 @@ bool ItemDatabase::loadFromOtbVer1(BinaryNode* itemNode, wxString &error, wxArra if (itemNode->getU32(flags)) { item->unpassable = ((flags & FLAG_UNPASSABLE) == FLAG_UNPASSABLE); item->blockMissiles = ((flags & FLAG_BLOCK_MISSILES) == FLAG_BLOCK_MISSILES); - item->blockPathfinderer = ((flags & FLAG_BLOCK_PATHFINDER) == FLAG_BLOCK_PATHFINDER); + item->blockPathfinder = ((flags & FLAG_BLOCK_PATHFINDER) == FLAG_BLOCK_PATHFINDER); item->hasElevation = ((flags & FLAG_HAS_ELEVATION) == FLAG_HAS_ELEVATION); // t->useable = ((flags & FLAG_USEABLE) == FLAG_USEABLE); item->pickupable = ((flags & FLAG_PICKUPABLE) == FLAG_PICKUPABLE); @@ -373,7 +373,7 @@ bool ItemDatabase::loadFromOtbVer2(BinaryNode* itemNode, wxString &error, wxArra if (itemNode->getU32(flags)) { item->unpassable = ((flags & FLAG_UNPASSABLE) == FLAG_UNPASSABLE); item->blockMissiles = ((flags & FLAG_BLOCK_MISSILES) == FLAG_BLOCK_MISSILES); - item->blockPathfinderer = ((flags & FLAG_BLOCK_PATHFINDER) == FLAG_BLOCK_PATHFINDER); + item->blockPathfinder = ((flags & FLAG_BLOCK_PATHFINDER) == FLAG_BLOCK_PATHFINDER); item->hasElevation = ((flags & FLAG_HAS_ELEVATION) == FLAG_HAS_ELEVATION); item->pickupable = ((flags & FLAG_PICKUPABLE) == FLAG_PICKUPABLE); item->moveable = ((flags & FLAG_MOVEABLE) == FLAG_MOVEABLE); @@ -528,7 +528,7 @@ bool ItemDatabase::loadFromOtbVer3(BinaryNode* itemNode, wxString &error, wxArra if (itemNode->getU32(flags)) { item->unpassable = ((flags & FLAG_UNPASSABLE) == FLAG_UNPASSABLE); item->blockMissiles = ((flags & FLAG_BLOCK_MISSILES) == FLAG_BLOCK_MISSILES); - item->blockPathfinderer = ((flags & FLAG_BLOCK_PATHFINDER) == FLAG_BLOCK_PATHFINDER); + item->blockPathfinder = ((flags & FLAG_BLOCK_PATHFINDER) == FLAG_BLOCK_PATHFINDER); item->hasElevation = ((flags & FLAG_HAS_ELEVATION) == FLAG_HAS_ELEVATION); item->pickupable = ((flags & FLAG_PICKUPABLE) == FLAG_PICKUPABLE); item->moveable = ((flags & FLAG_MOVEABLE) == FLAG_MOVEABLE); @@ -820,8 +820,7 @@ bool ItemDatabase::loadFromProtobuf(wxString &error, wxArrayString &warnings, ca t->sprite->minimap_color = object.flags().has_automap() ? static_cast(object.flags().automap().color()) : 0; t->sprite->draw_height = object.flags().has_height() ? static_cast(object.flags().height().elevation()) : 0; if (object.flags().has_shift()) { - t->sprite->drawoffset_x = static_cast(object.flags().shift().x()); - t->sprite->drawoffset_y = static_cast(object.flags().shift().y()); + t->sprite->draw_offset = wxPoint(object.flags().shift().x(), object.flags().shift().y()); } } diff --git a/source/map_drawer.cpp b/source/map_drawer.cpp index e31ceae0..1f0f9513 100644 --- a/source/map_drawer.cpp +++ b/source/map_drawer.cpp @@ -1952,7 +1952,7 @@ void MapDrawer::glBlitTexture(int sx, int sy, int texture_number, int red, int g // Fix the outfit offset 8x8 sprites being drawn offset if (spriteWidth == 64 && spriteHeight == 64 && (outfit.lookType > 0 || outfit.lookItem > 0)) { GameSprite* spr = g_gui.gfx.getCreatureSprite(outfit.lookType); - if (spr && spr->drawoffset_x == 8 && spr->drawoffset_y == 8) { + if (spr && spr->getDrawOffset().x == 8 && spr->getDrawOffset().y == 8) { sx -= spriteWidth / 2; sy -= spriteWidth / 2; } diff --git a/source/preferences.cpp b/source/preferences.cpp index c4a2a2e1..80f6c88d 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -547,7 +547,7 @@ void PreferencesWindow::SelectNewAssetsFolder(wxCommandEvent &event) { wxString path = dir_picker->GetPath(); if (!path.IsEmpty()) { ClientAssets::setPath(path); - // spdlog::info("New directory selected: {}", path.ToStdString()); + spdlog::debug("New directory selected: {}", path.ToStdString()); } else { wxMessageDialog dialog(this, "Directory is empty, please, select a valid directory", "Error", wxOK | wxICON_ERROR); dialog.ShowModal();