mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Add ZoneScriptString class to store zone script strings
This commit is contained in:
@ -260,7 +260,7 @@ void GameAssetPoolIW4::InitPoolDynamic(const asset_type_t type)
|
||||
#undef CASE_INIT_POOL_STATIC
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
|
||||
XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone)
|
||||
{
|
||||
XAsset xAsset{};
|
||||
|
||||
@ -271,7 +271,7 @@ XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::stri
|
||||
case assetType: \
|
||||
{ \
|
||||
assert((poolName) != nullptr); \
|
||||
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, m_zone, dependencies); \
|
||||
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, zone, std::move(dependencies), std::move(usedScriptStrings)); \
|
||||
}
|
||||
|
||||
switch (xAsset.type)
|
||||
|
@ -14,7 +14,7 @@ class GameAssetPoolIW4 final : public ZoneAssetPools
|
||||
static const char* ASSET_TYPE_NAMES[];
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
|
||||
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone) override;
|
||||
|
||||
public:
|
||||
std::unique_ptr<AssetPool<IW4::PhysPreset>> m_phys_preset;
|
||||
|
@ -329,7 +329,8 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
|
||||
#undef CASE_INIT_POOL_STATIC
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
|
||||
XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
|
||||
Zone* zone)
|
||||
{
|
||||
XAsset xAsset{};
|
||||
|
||||
@ -340,7 +341,7 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::strin
|
||||
case assetType: \
|
||||
{ \
|
||||
assert((poolName) != nullptr); \
|
||||
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, m_zone, dependencies); \
|
||||
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, zone, std::move(dependencies), std::move(usedScriptStrings)); \
|
||||
}
|
||||
|
||||
switch (xAsset.type)
|
||||
|
@ -12,7 +12,7 @@ class GameAssetPoolT6 final : public ZoneAssetPools
|
||||
static const char* ASSET_TYPE_NAMES[];
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
|
||||
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone) override;
|
||||
|
||||
public:
|
||||
AssetPool<T6::PhysPreset>* m_phys_preset;
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
|
||||
virtual ~AssetPool() = default;
|
||||
|
||||
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
|
||||
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) = 0;
|
||||
|
||||
XAssetInfo<T>* GetAsset(const std::string& name)
|
||||
{
|
||||
|
@ -40,13 +40,14 @@ public:
|
||||
m_asset_lookup.clear();
|
||||
}
|
||||
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*>& dependencies) override
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override
|
||||
{
|
||||
auto* newInfo = new XAssetInfo<T>();
|
||||
newInfo->m_type = m_type;
|
||||
newInfo->m_name = std::move(name);
|
||||
newInfo->m_zone = zone;
|
||||
newInfo->m_dependencies = std::move(dependencies);
|
||||
newInfo->m_used_script_strings = std::move(usedScriptStrings);
|
||||
|
||||
T* newAsset = new T();
|
||||
memcpy(newAsset, asset, sizeof(T));
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
m_capacity = 0;
|
||||
}
|
||||
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*>& dependencies) override
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override
|
||||
{
|
||||
if(m_free == nullptr)
|
||||
{
|
||||
@ -99,6 +99,7 @@ public:
|
||||
poolSlot->m_info->m_ptr = &poolSlot->m_entry;
|
||||
poolSlot->m_info->m_zone = zone;
|
||||
poolSlot->m_info->m_dependencies = std::move(dependencies);
|
||||
poolSlot->m_info->m_used_script_strings = std::move(usedScriptStrings);
|
||||
|
||||
m_asset_lookup[poolSlot->m_info->m_name] = poolSlot->m_info;
|
||||
|
||||
|
@ -13,6 +13,7 @@ public:
|
||||
std::string m_name;
|
||||
Zone* m_zone;
|
||||
std::vector<XAssetInfoGeneric*> m_dependencies;
|
||||
std::vector<scr_string_t> m_used_script_strings;
|
||||
void* m_ptr;
|
||||
};
|
||||
|
||||
|
@ -5,10 +5,15 @@ ZoneAssetPools::ZoneAssetPools(Zone* zone)
|
||||
{
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings)
|
||||
{
|
||||
auto* assetInfo = AddAssetToPool(type, std::move(name), asset, dependencies);
|
||||
if(assetInfo)
|
||||
return AddAsset(type, std::move(name), asset, std::move(dependencies), std::move(usedScriptStrings), m_zone);
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone)
|
||||
{
|
||||
auto* assetInfo = AddAssetToPool(type, std::move(name), asset, std::move(dependencies), std::move(usedScriptStrings), zone);
|
||||
if (assetInfo)
|
||||
{
|
||||
m_assets_in_order.push_back(assetInfo);
|
||||
}
|
||||
|
@ -17,17 +17,23 @@ protected:
|
||||
Zone* m_zone;
|
||||
std::vector<XAssetInfoGeneric*> m_assets_in_order;
|
||||
|
||||
virtual XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
|
||||
virtual XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
|
||||
Zone* zone) = 0;
|
||||
|
||||
public:
|
||||
using iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
|
||||
|
||||
explicit ZoneAssetPools(Zone* zone);
|
||||
virtual ~ZoneAssetPools() = default;
|
||||
ZoneAssetPools(const ZoneAssetPools& other) = delete;
|
||||
ZoneAssetPools(ZoneAssetPools&& other) noexcept = default;
|
||||
ZoneAssetPools& operator=(const ZoneAssetPools& other) = delete;
|
||||
ZoneAssetPools& operator=(ZoneAssetPools&& other) noexcept = default;
|
||||
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies);
|
||||
virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const = 0;
|
||||
virtual const char* GetAssetTypeName(asset_type_t assetType) const = 0;
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings);
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone);
|
||||
_NODISCARD virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const = 0;
|
||||
_NODISCARD virtual const char* GetAssetTypeName(asset_type_t assetType) const = 0;
|
||||
|
||||
virtual void InitPoolStatic(asset_type_t type, size_t capacity) = 0;
|
||||
virtual void InitPoolDynamic(asset_type_t type) = 0;
|
||||
|
@ -2,13 +2,14 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "ZoneMemory.h"
|
||||
#include "ZoneScriptStrings.h"
|
||||
|
||||
class IGame;
|
||||
class ZoneAssetPools;
|
||||
@ -24,7 +25,7 @@ public:
|
||||
zone_priority_t m_priority;
|
||||
GameLanguage m_language;
|
||||
IGame* m_game;
|
||||
std::vector<std::string> m_script_strings;
|
||||
ZoneScriptStrings m_script_strings;
|
||||
std::unique_ptr<ZoneAssetPools> m_pools;
|
||||
|
||||
Zone(std::string name, zone_priority_t priority, IGame* game);
|
||||
@ -36,5 +37,5 @@ public:
|
||||
|
||||
void Register();
|
||||
|
||||
ZoneMemory* GetMemory() const;
|
||||
_NODISCARD ZoneMemory* GetMemory() const;
|
||||
};
|
||||
|
57
src/ZoneCommon/Zone/ZoneScriptStrings.cpp
Normal file
57
src/ZoneCommon/Zone/ZoneScriptStrings.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "ZoneScriptStrings.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
scr_string_t ZoneScriptStrings::AddScriptString(const std::string& value)
|
||||
{
|
||||
if(m_scr_strings.empty())
|
||||
{
|
||||
m_scr_strings.emplace_back("");
|
||||
m_scr_string_lookup[""] = static_cast<scr_string_t>(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto existingScriptString = m_scr_string_lookup.find(value);
|
||||
if (existingScriptString != m_scr_string_lookup.end())
|
||||
return existingScriptString->second;
|
||||
}
|
||||
|
||||
const auto newScrStringIndex = static_cast<scr_string_t>(m_scr_strings.size());
|
||||
m_scr_strings.emplace_back(value);
|
||||
m_scr_string_lookup[value] = newScrStringIndex;
|
||||
|
||||
return newScrStringIndex;
|
||||
}
|
||||
|
||||
size_t ZoneScriptStrings::Count() const
|
||||
{
|
||||
return m_scr_strings.size();
|
||||
}
|
||||
|
||||
bool ZoneScriptStrings::Empty() const
|
||||
{
|
||||
return m_scr_strings.empty();
|
||||
}
|
||||
|
||||
const std::string& ZoneScriptStrings::operator[](const size_t index) const
|
||||
{
|
||||
if(index > m_scr_strings.size())
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Script string index '" << index << "' is not inside range of zone script strings (count: " << m_scr_strings.size() << ")";
|
||||
throw std::runtime_error(str.str());
|
||||
}
|
||||
|
||||
return m_scr_strings[index];
|
||||
}
|
||||
|
||||
std::vector<std::string>::const_iterator ZoneScriptStrings::begin() const
|
||||
{
|
||||
return m_scr_strings.cbegin();
|
||||
}
|
||||
|
||||
std::vector<std::string>::const_iterator ZoneScriptStrings::end() const
|
||||
{
|
||||
return m_scr_strings.end();
|
||||
}
|
24
src/ZoneCommon/Zone/ZoneScriptStrings.h
Normal file
24
src/ZoneCommon/Zone/ZoneScriptStrings.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
class ZoneScriptStrings
|
||||
{
|
||||
std::vector<std::string> m_scr_strings;
|
||||
std::unordered_map<std::string, scr_string_t> m_scr_string_lookup;
|
||||
|
||||
public:
|
||||
scr_string_t AddScriptString(const std::string& value);
|
||||
_NODISCARD size_t Count() const;
|
||||
_NODISCARD bool Empty() const;
|
||||
|
||||
_NODISCARD const std::string& operator[](size_t index) const;
|
||||
_NODISCARD std::vector<std::string>::const_iterator begin() const;
|
||||
_NODISCARD std::vector<std::string>::const_iterator end() const;
|
||||
};
|
Reference in New Issue
Block a user