Skip to content

Commit

Permalink
fix: build and other adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Jan 29, 2024
1 parent 454990b commit 23c6047
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 123 deletions.
12 changes: 12 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
124 changes: 56 additions & 68 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,7 @@ bool GraphicManager::loadOutfitSpriteMetadata(canary::protobuf::appearances::App
sType->minimap_color = outfit.flags().has_automap() ? static_cast<uint16_t>(outfit.flags().automap().color()) : 0;
sType->draw_height = outfit.flags().has_height() ? static_cast<uint16_t>(outfit.flags().height().elevation()) : 0;
if (outfit.flags().has_shift()) {
sType->drawoffset_x = static_cast<uint16_t>(outfit.flags().shift().x());
sType->drawoffset_y = static_cast<uint16_t>(outfit.flags().shift().y());
sType->draw_offset = wxPoint(outfit.flags().shift().x(), outfit.flags().shift().y());
sType->isDrawOffsetLoaded = true;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1043,12 +1040,36 @@ 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;
}

uint8_t GameSprite::getMiniMapColor() const {
Expand All @@ -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::OutfitImage> GameSprite::getOutfitImage(int spriteId, Direction direction, const Outfit &outfit) {
uint32_t spriteIndex = direction * layers;
if (layers > 1 && spriteIndex >= numsprites) {
Expand All @@ -1086,17 +1090,7 @@ std::shared_ptr<GameSprite::OutfitImage> GameSprite::getOutfitImage(int spriteId
}
}

if (instanced_templates.empty()) {
auto img = std::make_shared<GameSprite::OutfitImage>(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) {
Expand All @@ -1110,6 +1104,23 @@ std::shared_ptr<GameSprite::OutfitImage> 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);
Expand Down Expand Up @@ -1182,15 +1193,15 @@ GameSprite::Image::~Image() {
unloadGLTexture(0);
}

void GameSprite::Image::createGLTexture(GLuint whatid) {
void GameSprite::Image::createGLTexture(GLuint textureId) {
ASSERT(!isGLLoaded);

uint8_t* rgba = getRGBAData();
if (!rgba) {
return;
}

const auto &sheet = g_spriteAppearances.getSheetBySpriteId(whatid);
const auto &sheet = g_spriteAppearances.getSheetBySpriteId(textureId);
if (!sheet) {
return;
}
Expand All @@ -1202,18 +1213,18 @@ 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
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 0x812F); // GL_CLAMP_TO_EDGE
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() {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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),
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions source/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
38 changes: 0 additions & 38 deletions source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion source/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ class GUI {

protected:
bool LoadDataFiles(wxString &error, wxArrayString &warnings);
void UnloadVersion();

//=========================================================================
// Palette Interface
Expand Down
3 changes: 2 additions & 1 deletion source/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit 23c6047

Please sign in to comment.