mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Add asset loading states per zone for the usecase of saving loaded menus and menu functions
This commit is contained in:
parent
b1e5fc70a6
commit
4552a4fe4a
@ -1,8 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <typeindex>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "IGdtQueryable.h"
|
#include "IGdtQueryable.h"
|
||||||
|
#include "IZoneAssetLoaderState.h"
|
||||||
#include "Obj/Gdt/Gdt.h"
|
#include "Obj/Gdt/Gdt.h"
|
||||||
#include "SearchPath/ISearchPath.h"
|
#include "SearchPath/ISearchPath.h"
|
||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
@ -10,6 +13,7 @@
|
|||||||
class AssetLoadingContext final : public IGdtQueryable
|
class AssetLoadingContext final : public IGdtQueryable
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, std::unordered_map<std::string, GdtEntry*>> m_entries_by_gdf_and_by_name;
|
std::unordered_map<std::string, std::unordered_map<std::string, GdtEntry*>> m_entries_by_gdf_and_by_name;
|
||||||
|
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
|
||||||
|
|
||||||
void BuildGdtEntryCache();
|
void BuildGdtEntryCache();
|
||||||
|
|
||||||
@ -21,4 +25,20 @@ public:
|
|||||||
|
|
||||||
AssetLoadingContext(Zone* zone, ISearchPath* rawSearchPath, std::vector<Gdt*> gdtFiles);
|
AssetLoadingContext(Zone* zone, ISearchPath* rawSearchPath, std::vector<Gdt*> gdtFiles);
|
||||||
GdtEntry* GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) override;
|
GdtEntry* GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) override;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* GetZoneAssetLoaderState()
|
||||||
|
{
|
||||||
|
static_assert(std::is_base_of_v<IZoneAssetLoaderState, T>, "T must inherit IZoneAssetLoaderState");
|
||||||
|
// T must also have a public default constructor
|
||||||
|
|
||||||
|
const auto foundEntry = m_zone_asset_loader_states.find(typeid(T));
|
||||||
|
if(foundEntry != m_zone_asset_loader_states.end())
|
||||||
|
return dynamic_cast<T*>(foundEntry->second.get());
|
||||||
|
|
||||||
|
auto newState = std::make_unique<T>();
|
||||||
|
auto* newStatePtr = newState.get();
|
||||||
|
m_zone_asset_loader_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetLoaderState>>(typeid(T), std::move(newState)));
|
||||||
|
return newStatePtr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,11 @@ bool AssetLoadingManager::LoadAssetFromLoader(const asset_type_t assetType, cons
|
|||||||
return LoadDependency(assetType, assetName) != nullptr;
|
return LoadDependency(assetType, assetName) != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AssetLoadingContext* AssetLoadingManager::GetAssetLoadingContext() const
|
||||||
|
{
|
||||||
|
return &m_context;
|
||||||
|
}
|
||||||
|
|
||||||
void AssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
|
void AssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
|
||||||
Zone* zone)
|
Zone* zone)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,9 @@ public:
|
|||||||
AssetLoadingManager(const std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>>& assetLoadersByType, AssetLoadingContext& context);
|
AssetLoadingManager(const std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>>& assetLoadersByType, AssetLoadingContext& context);
|
||||||
|
|
||||||
bool LoadAssetFromLoader(asset_type_t assetType, const std::string& assetName);
|
bool LoadAssetFromLoader(asset_type_t assetType, const std::string& assetName);
|
||||||
|
|
||||||
|
_NODISCARD AssetLoadingContext* GetAssetLoadingContext() const override;
|
||||||
|
|
||||||
void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override;
|
void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override;
|
||||||
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
|
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "AssetLoadingContext.h"
|
||||||
#include "Pool/XAssetInfo.h"
|
#include "Pool/XAssetInfo.h"
|
||||||
#include "Zone/ZoneTypes.h"
|
#include "Zone/ZoneTypes.h"
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
|
|
||||||
class IAssetLoadingManager
|
class IAssetLoadingManager
|
||||||
{
|
{
|
||||||
@ -14,6 +16,8 @@ public:
|
|||||||
IAssetLoadingManager& operator=(const IAssetLoadingManager& other) = default;
|
IAssetLoadingManager& operator=(const IAssetLoadingManager& other) = default;
|
||||||
IAssetLoadingManager& operator=(IAssetLoadingManager&& other) noexcept = default;
|
IAssetLoadingManager& operator=(IAssetLoadingManager&& other) noexcept = default;
|
||||||
|
|
||||||
|
_NODISCARD virtual AssetLoadingContext* GetAssetLoadingContext() const = 0;
|
||||||
|
|
||||||
virtual void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) = 0;
|
virtual void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) = 0;
|
||||||
void AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset)
|
void AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset)
|
||||||
{
|
{
|
||||||
|
14
src/ObjLoading/AssetLoading/IZoneAssetLoaderState.h
Normal file
14
src/ObjLoading/AssetLoading/IZoneAssetLoaderState.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class IZoneAssetLoaderState
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
IZoneAssetLoaderState() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~IZoneAssetLoaderState() = default;
|
||||||
|
IZoneAssetLoaderState(const IZoneAssetLoaderState& other) = default;
|
||||||
|
IZoneAssetLoaderState(IZoneAssetLoaderState&& other) noexcept = default;
|
||||||
|
IZoneAssetLoaderState& operator=(const IZoneAssetLoaderState& other) = default;
|
||||||
|
IZoneAssetLoaderState& operator=(IZoneAssetLoaderState&& other) noexcept = default;
|
||||||
|
};
|
@ -37,6 +37,8 @@ bool AssetLoaderMenuList::LoadFromRaw(const std::string& assetName, ISearchPath*
|
|||||||
return std::move(foundFileToInclude.m_stream);
|
return std::move(foundFileToInclude.m_stream);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
reader.IncludeZoneState(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<menu::MenuAssetZoneState>());
|
||||||
|
|
||||||
const auto menuFileResult = reader.ReadMenuFile();
|
const auto menuFileResult = reader.ReadMenuFile();
|
||||||
if(menuFileResult)
|
if(menuFileResult)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "CommonItemDef.h"
|
#include "CommonItemDef.h"
|
||||||
#include "CommonMenuTypes.h"
|
#include "CommonMenuTypes.h"
|
||||||
|
17
src/ObjLoading/Parsing/Menu/MenuAssetZoneState.h
Normal file
17
src/ObjLoading/Parsing/Menu/MenuAssetZoneState.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AssetLoading/IZoneAssetLoaderState.h"
|
||||||
|
#include "Domain/CommonFunctionDef.h"
|
||||||
|
#include "Domain/CommonMenuDef.h"
|
||||||
|
|
||||||
|
namespace menu
|
||||||
|
{
|
||||||
|
class MenuAssetZoneState final : public IZoneAssetLoaderState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::vector<std::unique_ptr<CommonFunctionDef>> m_functions;
|
||||||
|
std::vector<std::unique_ptr<CommonMenuDef>> m_menus;
|
||||||
|
|
||||||
|
MenuAssetZoneState() = default;
|
||||||
|
};
|
||||||
|
}
|
@ -15,6 +15,12 @@ MenuFileParser::MenuFileParser(SimpleLexer* lexer, const FeatureLevel featureLev
|
|||||||
CreateSequenceCollections();
|
CreateSequenceCollections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuFileParser::MenuFileParser(SimpleLexer* lexer, FeatureLevel featureLevel, const MenuAssetZoneState* zoneState)
|
||||||
|
: AbstractParser(lexer, std::make_unique<MenuFileParserState>(featureLevel, zoneState))
|
||||||
|
{
|
||||||
|
CreateSequenceCollections();
|
||||||
|
}
|
||||||
|
|
||||||
void MenuFileParser::AddSequence(std::vector<sequence_t*>& collection, std::unique_ptr<sequence_t> test)
|
void MenuFileParser::AddSequence(std::vector<sequence_t*>& collection, std::unique_ptr<sequence_t> test)
|
||||||
{
|
{
|
||||||
collection.push_back(test.get());
|
collection.push_back(test.get());
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "MenuAssetZoneState.h"
|
||||||
#include "Utils/ClassUtils.h"
|
#include "Utils/ClassUtils.h"
|
||||||
#include "MenuFileParserState.h"
|
#include "MenuFileParserState.h"
|
||||||
#include "Parsing/Simple/SimpleLexer.h"
|
#include "Parsing/Simple/SimpleLexer.h"
|
||||||
@ -26,6 +27,7 @@ namespace menu
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
MenuFileParser(SimpleLexer* lexer, FeatureLevel featureLevel);
|
MenuFileParser(SimpleLexer* lexer, FeatureLevel featureLevel);
|
||||||
|
MenuFileParser(SimpleLexer* lexer, FeatureLevel featureLevel, const MenuAssetZoneState* zoneState);
|
||||||
_NODISCARD MenuFileParserState* GetState() const;
|
_NODISCARD MenuFileParserState* GetState() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -18,3 +18,17 @@ MenuFileParserState::MenuFileParserState(const FeatureLevel featureLevel)
|
|||||||
m_current_nested_event_handler_set(nullptr)
|
m_current_nested_event_handler_set(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuFileParserState::MenuFileParserState(const FeatureLevel featureLevel, const MenuAssetZoneState* zoneState)
|
||||||
|
: MenuFileParserState(featureLevel)
|
||||||
|
{
|
||||||
|
for(const auto& function : zoneState->m_functions)
|
||||||
|
{
|
||||||
|
m_functions_by_name.emplace(std::make_pair(function->m_name, function.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const auto& menu : zoneState->m_menus)
|
||||||
|
{
|
||||||
|
m_menus_by_name.emplace(std::make_pair(menu->m_name, menu.get()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
#include "MenuAssetZoneState.h"
|
||||||
#include "Domain/CommonFunctionDef.h"
|
#include "Domain/CommonFunctionDef.h"
|
||||||
#include "Domain/CommonMenuDef.h"
|
#include "Domain/CommonMenuDef.h"
|
||||||
#include "Domain/MenuFeatureLevel.h"
|
#include "Domain/MenuFeatureLevel.h"
|
||||||
|
#include "Domain/EventHandler/CommonEventHandlerSet.h"
|
||||||
#include "Domain/EventHandler/CommonEventHandlerCondition.h"
|
#include "Domain/EventHandler/CommonEventHandlerCondition.h"
|
||||||
|
|
||||||
namespace menu
|
namespace menu
|
||||||
@ -45,5 +47,6 @@ namespace menu
|
|||||||
CommonEventHandlerSet* m_current_nested_event_handler_set;
|
CommonEventHandlerSet* m_current_nested_event_handler_set;
|
||||||
|
|
||||||
explicit MenuFileParserState(FeatureLevel featureLevel);
|
explicit MenuFileParserState(FeatureLevel featureLevel);
|
||||||
|
MenuFileParserState(FeatureLevel featureLevel, const MenuAssetZoneState* zoneState);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@ using namespace menu;
|
|||||||
MenuFileReader::MenuFileReader(std::istream& stream, std::string fileName, const FeatureLevel featureLevel, include_callback_t includeCallback)
|
MenuFileReader::MenuFileReader(std::istream& stream, std::string fileName, const FeatureLevel featureLevel, include_callback_t includeCallback)
|
||||||
: m_feature_level(featureLevel),
|
: m_feature_level(featureLevel),
|
||||||
m_file_name(std::move(fileName)),
|
m_file_name(std::move(fileName)),
|
||||||
m_stream(nullptr)
|
m_stream(nullptr),
|
||||||
|
m_zone_state(nullptr)
|
||||||
{
|
{
|
||||||
OpenBaseStream(stream, std::move(includeCallback));
|
OpenBaseStream(stream, std::move(includeCallback));
|
||||||
SetupStreamProxies();
|
SetupStreamProxies();
|
||||||
@ -24,7 +25,8 @@ MenuFileReader::MenuFileReader(std::istream& stream, std::string fileName, const
|
|||||||
MenuFileReader::MenuFileReader(std::istream& stream, std::string fileName, const FeatureLevel featureLevel)
|
MenuFileReader::MenuFileReader(std::istream& stream, std::string fileName, const FeatureLevel featureLevel)
|
||||||
: m_feature_level(featureLevel),
|
: m_feature_level(featureLevel),
|
||||||
m_file_name(std::move(fileName)),
|
m_file_name(std::move(fileName)),
|
||||||
m_stream(nullptr)
|
m_stream(nullptr),
|
||||||
|
m_zone_state(nullptr)
|
||||||
{
|
{
|
||||||
OpenBaseStream(stream, nullptr);
|
OpenBaseStream(stream, nullptr);
|
||||||
SetupStreamProxies();
|
SetupStreamProxies();
|
||||||
@ -110,6 +112,11 @@ std::unique_ptr<ParsingResult> MenuFileReader::CreateParsingResult(MenuFileParse
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuFileReader::IncludeZoneState(const MenuAssetZoneState* zoneState)
|
||||||
|
{
|
||||||
|
m_zone_state = zoneState;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<ParsingResult> MenuFileReader::ReadMenuFile()
|
std::unique_ptr<ParsingResult> MenuFileReader::ReadMenuFile()
|
||||||
{
|
{
|
||||||
SimpleLexer::Config lexerConfig;
|
SimpleLexer::Config lexerConfig;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "Domain/MenuFeatureLevel.h"
|
#include "Domain/MenuFeatureLevel.h"
|
||||||
#include "Domain/MenuParsingResult.h"
|
#include "Domain/MenuParsingResult.h"
|
||||||
#include "Parsing/IParserLineStream.h"
|
#include "Parsing/IParserLineStream.h"
|
||||||
|
#include "MenuAssetZoneState.h"
|
||||||
|
|
||||||
namespace menu
|
namespace menu
|
||||||
{
|
{
|
||||||
@ -23,6 +24,8 @@ namespace menu
|
|||||||
IParserLineStream* m_stream;
|
IParserLineStream* m_stream;
|
||||||
std::vector<std::unique_ptr<IParserLineStream>> m_open_streams;
|
std::vector<std::unique_ptr<IParserLineStream>> m_open_streams;
|
||||||
|
|
||||||
|
const MenuAssetZoneState* m_zone_state;
|
||||||
|
|
||||||
bool OpenBaseStream(std::istream& stream, include_callback_t includeCallback);
|
bool OpenBaseStream(std::istream& stream, include_callback_t includeCallback);
|
||||||
void SetupDefinesProxy();
|
void SetupDefinesProxy();
|
||||||
void SetupStreamProxies();
|
void SetupStreamProxies();
|
||||||
@ -34,6 +37,8 @@ namespace menu
|
|||||||
MenuFileReader(std::istream& stream, std::string fileName, FeatureLevel featureLevel);
|
MenuFileReader(std::istream& stream, std::string fileName, FeatureLevel featureLevel);
|
||||||
MenuFileReader(std::istream& stream, std::string fileName, FeatureLevel featureLevel, include_callback_t includeCallback);
|
MenuFileReader(std::istream& stream, std::string fileName, FeatureLevel featureLevel, include_callback_t includeCallback);
|
||||||
|
|
||||||
|
void IncludeZoneState(const MenuAssetZoneState* zoneState);
|
||||||
|
|
||||||
std::unique_ptr<ParsingResult> ReadMenuFile();
|
std::unique_ptr<ParsingResult> ReadMenuFile();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user