2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-23 16:56:39 +00:00

refactor: only refer to game id in zone

This commit is contained in:
Jan Laupetin
2025-08-30 16:49:09 +02:00
parent 495e85f945
commit 734173066b
56 changed files with 145 additions and 193 deletions

View File

@@ -1,13 +1,14 @@
#include "Zone.h"
Zone::Zone(std::string name, const zone_priority_t priority, IGame* game)
#include "ZoneRegistry.h"
Zone::Zone(std::string name, const zone_priority_t priority, GameId gameId)
: m_name(std::move(name)),
m_priority(priority),
m_language(GameLanguage::LANGUAGE_NONE),
m_game(game),
m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority)),
m_memory(std::make_unique<ZoneMemory>()),
m_registered(false)
m_game_id(gameId),
m_pools(ZoneAssetPools::CreateForGame(gameId, this, priority)),
m_memory(std::make_unique<ZoneMemory>())
{
}
@@ -15,7 +16,7 @@ Zone::~Zone()
{
if (m_registered)
{
m_game->RemoveZone(this);
ZoneRegistry::GetRegistryForGame(m_game_id)->RemoveZone(this);
}
}
@@ -23,7 +24,7 @@ void Zone::Register()
{
if (!m_registered)
{
m_game->AddZone(this);
ZoneRegistry::GetRegistryForGame(m_game_id)->AddZone(this);
m_registered = true;
}
}

View File

@@ -10,20 +10,12 @@
#include <memory>
#include <string>
class IGame;
class ZoneAssetPools;
class Zone
{
public:
std::string m_name;
zone_priority_t m_priority;
GameLanguage m_language;
IGame* m_game;
ZoneScriptStrings m_script_strings;
std::unique_ptr<ZoneAssetPools> m_pools;
Zone(std::string name, zone_priority_t priority, IGame* game);
Zone(std::string name, zone_priority_t priority, GameId gameId);
~Zone();
Zone(const Zone& other) = delete;
Zone(Zone&& other) noexcept = default;
@@ -34,6 +26,13 @@ public:
[[nodiscard]] ZoneMemory& Memory() const;
std::string m_name;
zone_priority_t m_priority;
GameLanguage m_language;
GameId m_game_id;
ZoneScriptStrings m_script_strings;
std::unique_ptr<ZoneAssetPools> m_pools;
private:
std::unique_ptr<ZoneMemory> m_memory;

View File

@@ -0,0 +1,38 @@
#include "ZoneRegistry.h"
#include <algorithm>
#include <cassert>
#include <memory>
ZoneRegistry::ZoneRegistry() = default;
void ZoneRegistry::AddZone(Zone* zone)
{
assert(zone);
m_zones.emplace_back(zone);
}
void ZoneRegistry::RemoveZone(Zone* zone)
{
assert(zone);
std::erase_if(m_zones,
[zone](const Zone* existingZone)
{
return existingZone == zone;
});
}
const std::vector<Zone*>& ZoneRegistry::Zones() const
{
return m_zones;
}
ZoneRegistry* ZoneRegistry::GetRegistryForGame(GameId gameId)
{
static ZoneRegistry registries[static_cast<unsigned>(GameId::COUNT)];
assert(static_cast<unsigned>(gameId) < static_cast<unsigned>(GameId::COUNT));
return &registries[static_cast<unsigned>(gameId)];
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "Game/IGame.h"
#include "Zone.h"
#include <vector>
class ZoneRegistry
{
public:
void AddZone(Zone* zone);
void RemoveZone(Zone* zone);
const std::vector<Zone*>& Zones() const;
static ZoneRegistry* GetRegistryForGame(GameId gameId);
private:
ZoneRegistry();
std::vector<Zone*> m_zones;
};