mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 05:27:19 +00:00
Convert BrickDatabase to namespace (#1142)
* Convert BrickDatabase to namespace This did not need to be a class. * Fix linker errors * convert to anonymous namespace so the cache is unmodifiable outside the brickcache * Move to lower scope level and remove log
This commit is contained in:
parent
455f9470a5
commit
080a833144
@ -236,7 +236,7 @@ void PetComponent::OnUse(Entity* originator) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& bricks = BrickDatabase::Instance()->GetBricks(buildFile);
|
const auto& bricks = BrickDatabase::GetBricks(buildFile);
|
||||||
|
|
||||||
if (bricks.empty()) {
|
if (bricks.empty()) {
|
||||||
ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to load the puzzle minigame for this pet.");
|
ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to load the puzzle minigame for this pet.");
|
||||||
|
@ -3471,7 +3471,7 @@ void GameMessages::SendNotifyTamingModelLoadedOnServer(LWOOBJID objectId, const
|
|||||||
SEND_PACKET;
|
SEND_PACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMessages::SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, std::vector<Brick>& bricks, const SystemAddress& sysAddr) {
|
void GameMessages::SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, const std::vector<Brick>& bricks, const SystemAddress& sysAddr) {
|
||||||
CBITSTREAM;
|
CBITSTREAM;
|
||||||
CMSGHEADER;
|
CMSGHEADER;
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ namespace GameMessages {
|
|||||||
//Pets:
|
//Pets:
|
||||||
void SendNotifyPetTamingMinigame(LWOOBJID objectId, LWOOBJID petId, LWOOBJID playerTamingId, bool bForceTeleport, ePetTamingNotifyType notifyType, NiPoint3 petsDestPos, NiPoint3 telePos, NiQuaternion teleRot, const SystemAddress& sysAddr);
|
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<Brick>& bricks, const SystemAddress& sysAddr);
|
void SendNotifyPetTamingPuzzleSelected(LWOOBJID objectId, const std::vector<Brick>& bricks, const SystemAddress& sysAddr);
|
||||||
|
|
||||||
void SendNotifyTamingModelLoadedOnServer(LWOOBJID objectId, const SystemAddress& sysAddr);
|
void SendNotifyTamingModelLoadedOnServer(LWOOBJID objectId, const SystemAddress& sysAddr);
|
||||||
|
|
||||||
|
@ -5,14 +5,12 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
#include "Brick.h"
|
||||||
|
|
||||||
std::vector<Brick> BrickDatabase::emptyCache{};
|
const BrickList& BrickDatabase::GetBricks(const LxfmlPath& lxfmlPath) {
|
||||||
BrickDatabase* BrickDatabase::m_Address = nullptr;
|
static std::unordered_map<LxfmlPath, BrickList> m_Cache;
|
||||||
|
static const BrickList emptyCache;
|
||||||
|
|
||||||
BrickDatabase::BrickDatabase() = default;
|
|
||||||
BrickDatabase::~BrickDatabase() = default;
|
|
||||||
|
|
||||||
std::vector<Brick>& BrickDatabase::GetBricks(const std::string& lxfmlPath) {
|
|
||||||
const auto cached = m_Cache.find(lxfmlPath);
|
const auto cached = m_Cache.find(lxfmlPath);
|
||||||
|
|
||||||
if (cached != m_Cache.end()) {
|
if (cached != m_Cache.end()) {
|
||||||
@ -45,7 +43,7 @@ std::vector<Brick>& BrickDatabase::GetBricks(const std::string& lxfmlPath) {
|
|||||||
return emptyCache;
|
return emptyCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Brick> parts;
|
BrickList parts;
|
||||||
|
|
||||||
auto* lxfml = doc->FirstChildElement("LXFML");
|
auto* lxfml = doc->FirstChildElement("LXFML");
|
||||||
auto* bricks = lxfml->FirstChildElement("Bricks");
|
auto* bricks = lxfml->FirstChildElement("Bricks");
|
||||||
|
@ -1,29 +1,16 @@
|
|||||||
|
#ifndef __BRICKDATABASE__H__
|
||||||
|
#define __BRICKDATABASE__H__
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
class BrickDatabase
|
class Brick;
|
||||||
{
|
using BrickList = std::vector<Brick>;
|
||||||
public:
|
using LxfmlPath = std::string;
|
||||||
static BrickDatabase* Instance() {
|
|
||||||
if (m_Address == nullptr) {
|
|
||||||
m_Address = new BrickDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_Address;
|
namespace BrickDatabase {
|
||||||
}
|
const BrickList& GetBricks(const LxfmlPath& lxfmlPath);
|
||||||
|
|
||||||
std::vector<Brick>& GetBricks(const std::string& lxfmlPath);
|
|
||||||
|
|
||||||
explicit BrickDatabase();
|
|
||||||
|
|
||||||
~BrickDatabase();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unordered_map<std::string, std::vector<Brick>> m_Cache;
|
|
||||||
|
|
||||||
static std::vector<Brick> emptyCache;
|
|
||||||
|
|
||||||
static BrickDatabase* m_Address; //For singleton method
|
|
||||||
|
|
||||||
/* data */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif //!__BRICKDATABASE__H__
|
||||||
|
Loading…
Reference in New Issue
Block a user