diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 762c4f85..c2843266 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -236,7 +236,7 @@ void PetComponent::OnUse(Entity* originator) { return; } - auto& bricks = BrickDatabase::Instance()->GetBricks(buildFile); + const auto& bricks = BrickDatabase::GetBricks(buildFile); if (bricks.empty()) { ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to load the puzzle minigame for this pet."); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 8f7b96e1..390699e4 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -3471,7 +3471,7 @@ void GameMessages::SendNotifyTamingModelLoadedOnServer(LWOOBJID objectId, const SEND_PACKET; } -void GameMessages::SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, std::vector& bricks, const SystemAddress& sysAddr) { +void GameMessages::SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, const std::vector& bricks, const SystemAddress& sysAddr) { CBITSTREAM; CMSGHEADER; diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 94bdd3ea..bd1224d3 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -364,7 +364,7 @@ namespace GameMessages { //Pets: void SendNotifyPetTamingMinigame(LWOOBJID objectId, LWOOBJID petId, LWOOBJID playerTamingId, bool bForceTeleport, ePetTamingNotifyType notifyType, NiPoint3 petsDestPos, NiPoint3 telePos, NiQuaternion teleRot, const SystemAddress& sysAddr); - void SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, std::vector& bricks, const SystemAddress& sysAddr); + void SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, const std::vector& bricks, const SystemAddress& sysAddr); void SendNotifyTamingModelLoadedOnServer(LWOOBJID objectId, const SystemAddress& sysAddr); diff --git a/dGame/dUtilities/BrickDatabase.cpp b/dGame/dUtilities/BrickDatabase.cpp index a6c43d52..e4a6a714 100644 --- a/dGame/dUtilities/BrickDatabase.cpp +++ b/dGame/dUtilities/BrickDatabase.cpp @@ -5,14 +5,12 @@ #include "Game.h" #include "AssetManager.h" #include "tinyxml2.h" +#include "Brick.h" -std::vector BrickDatabase::emptyCache{}; -BrickDatabase* BrickDatabase::m_Address = nullptr; +const BrickList& BrickDatabase::GetBricks(const LxfmlPath& lxfmlPath) { + static std::unordered_map m_Cache; + static const BrickList emptyCache; -BrickDatabase::BrickDatabase() = default; -BrickDatabase::~BrickDatabase() = default; - -std::vector& BrickDatabase::GetBricks(const std::string& lxfmlPath) { const auto cached = m_Cache.find(lxfmlPath); if (cached != m_Cache.end()) { @@ -45,7 +43,7 @@ std::vector& BrickDatabase::GetBricks(const std::string& lxfmlPath) { return emptyCache; } - std::vector parts; + BrickList parts; auto* lxfml = doc->FirstChildElement("LXFML"); auto* bricks = lxfml->FirstChildElement("Bricks"); diff --git a/dGame/dUtilities/BrickDatabase.h b/dGame/dUtilities/BrickDatabase.h index 589d46ae..11c64416 100644 --- a/dGame/dUtilities/BrickDatabase.h +++ b/dGame/dUtilities/BrickDatabase.h @@ -1,29 +1,16 @@ +#ifndef __BRICKDATABASE__H__ +#define __BRICKDATABASE__H__ + #pragma once + #include "Entity.h" -class BrickDatabase -{ -public: - static BrickDatabase* Instance() { - if (m_Address == nullptr) { - m_Address = new BrickDatabase(); - } +class Brick; +using BrickList = std::vector; +using LxfmlPath = std::string; - return m_Address; - } - - std::vector& GetBricks(const std::string& lxfmlPath); - - explicit BrickDatabase(); - - ~BrickDatabase(); - -private: - std::unordered_map> m_Cache; - - static std::vector emptyCache; - - static BrickDatabase* m_Address; //For singleton method - - /* data */ +namespace BrickDatabase { + const BrickList& GetBricks(const LxfmlPath& lxfmlPath); }; + +#endif //!__BRICKDATABASE__H__