mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-09 22:38:06 -05:00
Load state maps when loading techniques
This commit is contained in:
@ -29,7 +29,7 @@ namespace techset
|
||||
assert(state->m_in_pass == true);
|
||||
|
||||
std::string errorMessage;
|
||||
if(!state->m_acceptor->AcceptEndPass(errorMessage))
|
||||
if (!state->m_acceptor->AcceptEndPass(errorMessage))
|
||||
throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), errorMessage);
|
||||
|
||||
state->m_in_pass = false;
|
||||
@ -38,7 +38,8 @@ namespace techset
|
||||
|
||||
class SequenceStateMap final : public TechniqueParser::sequence_t
|
||||
{
|
||||
static constexpr auto CAPTURE_STATE_MAP_NAME = 1;
|
||||
static constexpr auto CAPTURE_START = 1;
|
||||
static constexpr auto CAPTURE_STATE_MAP_NAME = 2;
|
||||
|
||||
public:
|
||||
SequenceStateMap()
|
||||
@ -46,7 +47,7 @@ namespace techset
|
||||
const SimpleMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("stateMap"),
|
||||
create.Keyword("stateMap").Capture(CAPTURE_START),
|
||||
create.String().Capture(CAPTURE_STATE_MAP_NAME),
|
||||
create.Char(';')
|
||||
});
|
||||
@ -55,7 +56,13 @@ namespace techset
|
||||
protected:
|
||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||
{
|
||||
state->m_acceptor->AcceptStateMap(result.NextCapture(CAPTURE_STATE_MAP_NAME).StringValue());
|
||||
const auto& firstToken = result.NextCapture(CAPTURE_START);
|
||||
|
||||
std::string errorMessage;
|
||||
const auto acceptorResult = state->m_acceptor->AcceptStateMap(result.NextCapture(CAPTURE_STATE_MAP_NAME).StringValue(), errorMessage);
|
||||
|
||||
if (!acceptorResult)
|
||||
throw ParsingException(firstToken.GetPos(), std::move(errorMessage));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace techset
|
||||
virtual void AcceptNextPass() = 0;
|
||||
virtual bool AcceptEndPass(std::string& errorMessage) = 0;
|
||||
|
||||
virtual void AcceptStateMap(const std::string& stateMapName) = 0;
|
||||
virtual bool AcceptStateMap(const std::string& stateMapName, std::string& errorMessage) = 0;
|
||||
|
||||
virtual bool AcceptVertexShader(const std::string& vertexShaderName, std::string& errorMessage) = 0;
|
||||
virtual bool AcceptPixelShader(const std::string& pixelShaderName, std::string& errorMessage) = 0;
|
||||
|
@ -1,3 +1,33 @@
|
||||
#include "TechniqueStateMapCache.h"
|
||||
|
||||
using namespace techset;
|
||||
|
||||
const state_map::StateMapDefinition* TechniqueStateMapCache::GetCachedStateMap(const std::string& name) const
|
||||
{
|
||||
const auto foundStateMap = m_state_map_cache.find(name);
|
||||
|
||||
if (foundStateMap != m_state_map_cache.end())
|
||||
return foundStateMap->second.get();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TechniqueStateMapCache::AddStateMapToCache(std::unique_ptr<state_map::StateMapDefinition> stateMap)
|
||||
{
|
||||
m_state_map_cache.emplace(std::make_pair(stateMap->m_name, std::move(stateMap)));
|
||||
}
|
||||
|
||||
const state_map::StateMapDefinition* TechniqueStateMapCache::GetStateMapForTechnique(const std::string& techniqueName) const
|
||||
{
|
||||
const auto foundTechnique = m_state_map_per_technique.find(techniqueName);
|
||||
|
||||
if (foundTechnique != m_state_map_per_technique.end())
|
||||
return foundTechnique->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TechniqueStateMapCache::SetTechniqueUsesStateMap(std::string techniqueName, const state_map::StateMapDefinition* stateMap)
|
||||
{
|
||||
m_state_map_per_technique.emplace(std::make_pair(std::move(techniqueName), stateMap));
|
||||
}
|
||||
|
@ -1,10 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "AssetLoading/IZoneAssetLoaderState.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "StateMap/StateMapDefinition.h"
|
||||
|
||||
namespace techset
|
||||
{
|
||||
class TechniqueStateMapCache
|
||||
class TechniqueStateMapCache final : public IZoneAssetLoaderState
|
||||
{
|
||||
// TODO: Cache which state map is being used for which technique
|
||||
// TODO: Cache state map data
|
||||
public:
|
||||
_NODISCARD const state_map::StateMapDefinition* GetCachedStateMap(const std::string& name) const;
|
||||
void AddStateMapToCache(std::unique_ptr<state_map::StateMapDefinition> stateMap);
|
||||
|
||||
_NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const;
|
||||
void SetTechniqueUsesStateMap(std::string techniqueName, const state_map::StateMapDefinition* stateMap);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, const state_map::StateMapDefinition*> m_state_map_per_technique;
|
||||
std::unordered_map<std::string, std::unique_ptr<state_map::StateMapDefinition>> m_state_map_cache;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user