mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-24 08:53:04 +00:00
wip
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include "Game/IW4/CommonIW4.h"
|
#include "Game/IW4/CommonIW4.h"
|
||||||
#include "Game/IW4/IW4.h"
|
#include "Game/IW4/IW4.h"
|
||||||
#include "StateMap/StateMapLayout.h"
|
|
||||||
#include "Techset/CommonTechset.h"
|
#include "Techset/CommonTechset.h"
|
||||||
|
#include "Techset/StateMap/StateMapLayout.h"
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|||||||
@@ -190,6 +190,11 @@ namespace T6
|
|||||||
};
|
};
|
||||||
static_assert(std::extent_v<decltype(streamRoutingDestinations)> == STREAM_DST_COUNT);
|
static_assert(std::extent_v<decltype(streamRoutingDestinations)> == STREAM_DST_COUNT);
|
||||||
|
|
||||||
|
static inline techset::CommonStreamRoutingInfos commonRoutingInfos(streamRoutingSources,
|
||||||
|
std::extent_v<decltype(streamRoutingSources)>,
|
||||||
|
streamRoutingDestinations,
|
||||||
|
std::extent_v<decltype(streamRoutingDestinations)>);
|
||||||
|
|
||||||
static inline techset::CommonCodeConstSourceInfo commonCodeConstSources[]{
|
static inline techset::CommonCodeConstSourceInfo commonCodeConstSources[]{
|
||||||
{
|
{
|
||||||
.value = CONST_SRC_CODE_LIGHT_POSITION,
|
.value = CONST_SRC_CODE_LIGHT_POSITION,
|
||||||
@@ -1790,6 +1795,10 @@ namespace T6
|
|||||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
static inline techset::CommonCodeSourceInfos commonCodeSourceInfos(commonCodeConstSources,
|
||||||
|
std::extent_v<decltype(commonCodeConstSources)>,
|
||||||
|
commonCodeSamplerSources,
|
||||||
|
std::extent_v<decltype(commonCodeSamplerSources)>);
|
||||||
|
|
||||||
static inline MaterialTypeInfo g_materialTypeInfo[]{
|
static inline MaterialTypeInfo g_materialTypeInfo[]{
|
||||||
{"", "" },
|
{"", "" },
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ namespace techset
|
|||||||
{
|
{
|
||||||
std::copy(sourceInfos, &sourceInfos[sourceCount], m_sources.data());
|
std::copy(sourceInfos, &sourceInfos[sourceCount], m_sources.data());
|
||||||
std::copy(destinationNames, &destinationNames[destinationCount], m_destinations.data());
|
std::copy(destinationNames, &destinationNames[destinationCount], m_destinations.data());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sourceCount; i++)
|
||||||
|
m_source_lookup[sourceInfos[i].name] = static_cast<CommonStreamSource>(i);
|
||||||
|
for (size_t i = 0; i < destinationCount; i++)
|
||||||
|
m_destination_lookup[destinationNames[i].name] = static_cast<CommonStreamDestination>(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CommonStreamRoutingInfos::GetSourceName(const CommonStreamSource source) const
|
const char* CommonStreamRoutingInfos::GetSourceName(const CommonStreamSource source) const
|
||||||
@@ -105,4 +110,44 @@ namespace techset
|
|||||||
|
|
||||||
return m_destinations[destination].abbreviation;
|
return m_destinations[destination].abbreviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<CommonStreamSource> CommonStreamRoutingInfos::GetSourceByName(const std::string& name) const
|
||||||
|
{
|
||||||
|
const auto foundSource = m_source_lookup.find(name);
|
||||||
|
if (foundSource != m_source_lookup.end())
|
||||||
|
return foundSource->second;
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<CommonStreamDestination> CommonStreamRoutingInfos::GetDestinationByName(const std::string& name) const
|
||||||
|
{
|
||||||
|
const auto foundDestination = m_destination_lookup.find(name);
|
||||||
|
if (foundDestination != m_destination_lookup.end())
|
||||||
|
return foundDestination->second;
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonStreamRouting::CommonStreamRouting(const CommonStreamSource source, const CommonStreamDestination destination)
|
||||||
|
: m_source(source),
|
||||||
|
m_destination(destination)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonTechniqueShader::CommonTechniqueShader(std::string name)
|
||||||
|
: m_name(std::move(name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonTechnique::CommonTechnique()
|
||||||
|
: m_flags(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonTechnique::CommonTechnique(std::string name)
|
||||||
|
: m_name(std::move(name)),
|
||||||
|
m_flags(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
} // namespace techset
|
} // namespace techset
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace techset
|
namespace techset
|
||||||
@@ -79,10 +80,14 @@ namespace techset
|
|||||||
[[nodiscard]] bool IsSourceOptional(CommonStreamSource source) const;
|
[[nodiscard]] bool IsSourceOptional(CommonStreamSource source) const;
|
||||||
[[nodiscard]] const char* GetDestinationName(CommonStreamDestination destination) const;
|
[[nodiscard]] const char* GetDestinationName(CommonStreamDestination destination) const;
|
||||||
[[nodiscard]] const char* GetDestinationAbbreviation(CommonStreamDestination destination) const;
|
[[nodiscard]] const char* GetDestinationAbbreviation(CommonStreamDestination destination) const;
|
||||||
|
[[nodiscard]] std::optional<CommonStreamSource> GetSourceByName(const std::string& name) const;
|
||||||
|
[[nodiscard]] std::optional<CommonStreamDestination> GetDestinationByName(const std::string& name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<CommonStreamRoutingSourceInfo> m_sources;
|
std::vector<CommonStreamRoutingSourceInfo> m_sources;
|
||||||
std::vector<CommonStreamRoutingDestinationInfo> m_destinations;
|
std::vector<CommonStreamRoutingDestinationInfo> m_destinations;
|
||||||
|
std::unordered_map<std::string, CommonStreamSource> m_source_lookup;
|
||||||
|
std::unordered_map<std::string, CommonStreamDestination> m_destination_lookup;
|
||||||
};
|
};
|
||||||
|
|
||||||
union CommonShaderArgValue
|
union CommonShaderArgValue
|
||||||
@@ -132,6 +137,8 @@ namespace techset
|
|||||||
class CommonShaderArg
|
class CommonShaderArg
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CommonShaderArg() = default;
|
||||||
|
|
||||||
CommonShaderArgType m_type;
|
CommonShaderArgType m_type;
|
||||||
CommonShaderArgDestination m_destination;
|
CommonShaderArgDestination m_destination;
|
||||||
CommonShaderArgValue m_value;
|
CommonShaderArgValue m_value;
|
||||||
@@ -140,6 +147,9 @@ namespace techset
|
|||||||
class CommonStreamRouting
|
class CommonStreamRouting
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CommonStreamRouting() = default;
|
||||||
|
CommonStreamRouting(CommonStreamSource source, CommonStreamDestination destination);
|
||||||
|
|
||||||
CommonStreamSource m_source;
|
CommonStreamSource m_source;
|
||||||
CommonStreamDestination m_destination;
|
CommonStreamDestination m_destination;
|
||||||
};
|
};
|
||||||
@@ -147,15 +157,26 @@ namespace techset
|
|||||||
class CommonVertexDeclaration
|
class CommonVertexDeclaration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CommonVertexDeclaration() = default;
|
||||||
|
|
||||||
std::vector<CommonStreamRouting> m_routing;
|
std::vector<CommonStreamRouting> m_routing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CommonTechniqueShaderBin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const void* m_shader_bin;
|
||||||
|
size_t m_shader_bin_size;
|
||||||
|
};
|
||||||
|
|
||||||
class CommonTechniqueShader
|
class CommonTechniqueShader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CommonTechniqueShader() = default;
|
||||||
|
explicit CommonTechniqueShader(std::string name);
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
const void* m_shader_bin;
|
std::optional<CommonTechniqueShaderBin> m_bin;
|
||||||
size_t m_shader_bin_size;
|
|
||||||
std::vector<CommonShaderArg> m_args;
|
std::vector<CommonShaderArg> m_args;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,7 +189,10 @@ namespace techset
|
|||||||
class CommonPass
|
class CommonPass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CommonPass() = default;
|
||||||
|
|
||||||
uint32_t m_sampler_flags;
|
uint32_t m_sampler_flags;
|
||||||
|
std::string m_state_map;
|
||||||
DxVersion m_dx_version;
|
DxVersion m_dx_version;
|
||||||
CommonTechniqueShader m_vertex_shader;
|
CommonTechniqueShader m_vertex_shader;
|
||||||
CommonTechniqueShader m_pixel_shader;
|
CommonTechniqueShader m_pixel_shader;
|
||||||
@@ -178,6 +202,9 @@ namespace techset
|
|||||||
class CommonTechnique
|
class CommonTechnique
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CommonTechnique();
|
||||||
|
explicit CommonTechnique(std::string name);
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
uint64_t m_flags;
|
uint64_t m_flags;
|
||||||
std::vector<CommonPass> m_passes;
|
std::vector<CommonPass> m_passes;
|
||||||
|
|||||||
@@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
#include "Game/T6/Techset/TechsetConstantsT6.h"
|
#include "Game/T6/Techset/TechsetConstantsT6.h"
|
||||||
|
#include "Techset/CommonTechniqueLoader.h"
|
||||||
#include "Techset/CommonTechsetLoader.h"
|
#include "Techset/CommonTechsetLoader.h"
|
||||||
|
#include "Techset/TechniqueCache.h"
|
||||||
#include "Techset/TechsetCommon.h"
|
#include "Techset/TechsetCommon.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
using namespace T6;
|
using namespace T6;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -52,6 +56,30 @@ namespace
|
|||||||
return techset;
|
return techset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaterialTechnique* ConvertTechnique(const techset::CommonTechnique& commonTechnique, MemoryManager& memory)
|
||||||
|
{
|
||||||
|
const auto additionalPassCount = std::max(commonTechnique.m_passes.size(), 1u) - 1u;
|
||||||
|
auto* technique = static_cast<MaterialTechnique*>(memory.AllocRaw(sizeof(MaterialTechnique) + additionalPassCount * sizeof(MaterialPass)));
|
||||||
|
|
||||||
|
technique->name = memory.Dup(commonTechnique.m_name.c_str());
|
||||||
|
technique->passCount = static_cast<uint16_t>(commonTechnique.m_passes.size());
|
||||||
|
|
||||||
|
return technique;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialTechnique* LoadAndConvertTechnique(const std::string& techniqueName, techset::TechniqueCache& cache, MemoryManager& memory, ISearchPath& searchPath)
|
||||||
|
{
|
||||||
|
const auto commonTechnique = techset::LoadCommonTechnique(techniqueName, commonCodeSourceInfos, commonRoutingInfos, searchPath);
|
||||||
|
if (!commonTechnique)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto* convertedTechnique = ConvertTechnique(*commonTechnique, memory);
|
||||||
|
assert(convertedTechnique);
|
||||||
|
cache.AddTechniqueToCache(techniqueName, convertedTechnique);
|
||||||
|
|
||||||
|
return convertedTechnique;
|
||||||
|
}
|
||||||
|
|
||||||
class TechsetCompilerT6 final : public AssetCreator<AssetTechniqueSet>
|
class TechsetCompilerT6 final : public AssetCreator<AssetTechniqueSet>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -69,6 +97,23 @@ namespace
|
|||||||
return failure ? AssetCreationResult::Failure() : AssetCreationResult::NoAction();
|
return failure ? AssetCreationResult::Failure() : AssetCreationResult::NoAction();
|
||||||
|
|
||||||
auto* techset = ConvertTechniqueSet(*commonTechset, m_memory);
|
auto* techset = ConvertTechniqueSet(*commonTechset, m_memory);
|
||||||
|
auto& techniqueCache = context.GetZoneAssetCreationState<techset::TechniqueCache>();
|
||||||
|
|
||||||
|
for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v<decltype(MaterialTechniqueSet::techniques)>; techniqueIndex++)
|
||||||
|
{
|
||||||
|
const auto& techniqueName = commonTechset->m_technique_names[techniqueIndex];
|
||||||
|
if (techniqueName.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto* technique = techniqueCache.GetCachedTechnique<MaterialTechnique>(techniqueName);
|
||||||
|
if (!technique)
|
||||||
|
technique = LoadAndConvertTechnique(techniqueName, techniqueCache, m_memory, m_search_path);
|
||||||
|
|
||||||
|
if (!technique)
|
||||||
|
return AssetCreationResult::Failure();
|
||||||
|
|
||||||
|
techset->techniques[techniqueIndex] = technique;
|
||||||
|
}
|
||||||
|
|
||||||
return AssetCreationResult::Success(context.AddAsset(AssetRegistration<AssetTechniqueSet>(assetName, techset)));
|
return AssetCreationResult::Success(context.AddAsset(AssetRegistration<AssetTechniqueSet>(assetName, techset)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,42 @@
|
|||||||
#include "CommonTechniqueLoader.h"
|
#include "CommonTechniqueLoader.h"
|
||||||
|
|
||||||
|
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||||
|
#include "Parsing/Impl/ParserSingleInputStream.h"
|
||||||
|
#include "Parsing/Simple/SimpleLexer.h"
|
||||||
|
#include "Parsing/TechniqueFileParser.h"
|
||||||
|
#include "Techset/TechsetCommon.h"
|
||||||
|
#include "Utils/Logging/Log.h"
|
||||||
|
|
||||||
|
namespace techset
|
||||||
|
{
|
||||||
|
std::unique_ptr<CommonTechnique> LoadCommonTechnique(const std::string& techniqueName,
|
||||||
|
const CommonCodeSourceInfos& codeSourceInfos,
|
||||||
|
const CommonStreamRoutingInfos& routingInfos,
|
||||||
|
ISearchPath& searchPath)
|
||||||
|
{
|
||||||
|
const auto fileName = GetFileNameForTechniqueName(techniqueName);
|
||||||
|
const auto techniqueFile = searchPath.Open(fileName);
|
||||||
|
if (!techniqueFile.IsOpen())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
SimpleLexer::Config lexerConfig;
|
||||||
|
lexerConfig.m_emit_new_line_tokens = false;
|
||||||
|
lexerConfig.m_read_strings = true;
|
||||||
|
lexerConfig.m_string_escape_sequences = false;
|
||||||
|
lexerConfig.m_read_integer_numbers = true;
|
||||||
|
lexerConfig.m_read_floating_point_numbers = true;
|
||||||
|
|
||||||
|
const auto baseStream = std::make_unique<ParserSingleInputStream>(*techniqueFile.m_stream, fileName);
|
||||||
|
const auto commentProxy = std::make_unique<CommentRemovingStreamProxy>(baseStream.get());
|
||||||
|
const auto lexer = std::make_unique<SimpleLexer>(commentProxy.get(), std::move(lexerConfig));
|
||||||
|
|
||||||
|
const auto parser = std::make_unique<TechniqueParser>(*lexer, techniqueName, codeSourceInfos, routingInfos);
|
||||||
|
|
||||||
|
const auto success = parser->Parse();
|
||||||
|
if (success)
|
||||||
|
return parser->GetParsingResult();
|
||||||
|
|
||||||
|
con::error("Parsing technique file \"{}\" failed!", fileName);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} // namespace techset
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
namespace techset
|
namespace techset
|
||||||
{
|
{
|
||||||
std::unique_ptr<CommonTechnique>
|
std::unique_ptr<CommonTechnique> LoadCommonTechnique(const std::string& techniqueName,
|
||||||
LoadCommonTechnique(const AssetCreationContext& context, const CommonCodeSourceInfos& codeSourceInfos, const CommonStreamRoutingInfos& routingInfos);
|
const CommonCodeSourceInfos& codeSourceInfos,
|
||||||
|
const CommonStreamRoutingInfos& routingInfos,
|
||||||
|
ISearchPath& searchPath);
|
||||||
} // namespace techset
|
} // namespace techset
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
assert(state->m_in_pass == false);
|
assert(!state->m_current_pass);
|
||||||
state->m_in_pass = true;
|
state->m_current_pass = CommonPass();
|
||||||
|
|
||||||
state->m_acceptor->AcceptNextPass();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace techset
|
} // namespace techset
|
||||||
|
|||||||
@@ -26,20 +26,17 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
assert(state->m_in_pass == true);
|
assert(state->m_current_pass);
|
||||||
|
assert(state->m_technique);
|
||||||
|
|
||||||
std::string errorMessage;
|
state->m_technique->m_passes.emplace_back(std::move(*state->m_current_pass));
|
||||||
if (!state->m_acceptor->AcceptEndPass(errorMessage))
|
state->m_current_pass = std::nullopt;
|
||||||
throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), errorMessage);
|
|
||||||
|
|
||||||
state->m_in_pass = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SequenceStateMap final : public TechniqueParser::sequence_t
|
class SequenceStateMap final : public TechniqueParser::sequence_t
|
||||||
{
|
{
|
||||||
static constexpr auto CAPTURE_START = 1;
|
static constexpr auto CAPTURE_STATE_MAP_NAME = 1;
|
||||||
static constexpr auto CAPTURE_STATE_MAP_NAME = 2;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SequenceStateMap()
|
SequenceStateMap()
|
||||||
@@ -47,7 +44,7 @@ namespace techset
|
|||||||
const SimpleMatcherFactory create(this);
|
const SimpleMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Keyword("stateMap").Capture(CAPTURE_START),
|
create.Keyword("stateMap"),
|
||||||
create.String().Capture(CAPTURE_STATE_MAP_NAME),
|
create.String().Capture(CAPTURE_STATE_MAP_NAME),
|
||||||
create.Char(';'),
|
create.Char(';'),
|
||||||
});
|
});
|
||||||
@@ -56,13 +53,9 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
const auto& firstToken = result.NextCapture(CAPTURE_START);
|
assert(state->m_current_pass);
|
||||||
|
|
||||||
std::string errorMessage;
|
state->m_current_pass->m_state_map = result.NextCapture(CAPTURE_STATE_MAP_NAME).StringValue();
|
||||||
const auto acceptorResult = state->m_acceptor->AcceptStateMap(result.NextCapture(CAPTURE_STATE_MAP_NAME).StringValue(), errorMessage);
|
|
||||||
|
|
||||||
if (!acceptorResult)
|
|
||||||
throw ParsingException(firstToken.GetPos(), std::move(errorMessage));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,11 +64,10 @@ namespace techset
|
|||||||
static constexpr auto TAG_VERTEX_SHADER = 1;
|
static constexpr auto TAG_VERTEX_SHADER = 1;
|
||||||
static constexpr auto TAG_PIXEL_SHADER = 2;
|
static constexpr auto TAG_PIXEL_SHADER = 2;
|
||||||
|
|
||||||
static constexpr auto CAPTURE_START = 1;
|
static constexpr auto CAPTURE_VERSION = 1;
|
||||||
static constexpr auto CAPTURE_VERSION = 2;
|
static constexpr auto CAPTURE_VERSION_MAJOR = 2;
|
||||||
static constexpr auto CAPTURE_VERSION_MAJOR = 3;
|
static constexpr auto CAPTURE_VERSION_MINOR = 3;
|
||||||
static constexpr auto CAPTURE_VERSION_MINOR = 4;
|
static constexpr auto CAPTURE_SHADER_NAME = 4;
|
||||||
static constexpr auto CAPTURE_SHADER_NAME = 5;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SequenceShader()
|
SequenceShader()
|
||||||
@@ -83,12 +75,10 @@ namespace techset
|
|||||||
const SimpleMatcherFactory create(this);
|
const SimpleMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create
|
create.Or({
|
||||||
.Or({
|
|
||||||
create.Keyword("vertexShader").Tag(TAG_VERTEX_SHADER),
|
create.Keyword("vertexShader").Tag(TAG_VERTEX_SHADER),
|
||||||
create.Keyword("pixelShader").Tag(TAG_PIXEL_SHADER),
|
create.Keyword("pixelShader").Tag(TAG_PIXEL_SHADER),
|
||||||
})
|
}),
|
||||||
.Capture(CAPTURE_START),
|
|
||||||
create.Or({
|
create.Or({
|
||||||
create.And({
|
create.And({
|
||||||
create.Integer().Capture(CAPTURE_VERSION_MAJOR),
|
create.Integer().Capture(CAPTURE_VERSION_MAJOR),
|
||||||
@@ -106,31 +96,18 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
const auto& firstToken = result.NextCapture(CAPTURE_START);
|
|
||||||
|
|
||||||
// Don't care about shader version since it's stated in the shader bin anyway
|
// Don't care about shader version since it's stated in the shader bin anyway
|
||||||
|
|
||||||
const auto& shaderNameToken = result.NextCapture(CAPTURE_SHADER_NAME);
|
const auto& shaderNameToken = result.NextCapture(CAPTURE_SHADER_NAME);
|
||||||
|
|
||||||
bool acceptorResult;
|
|
||||||
std::string errorMessage;
|
|
||||||
const auto shaderTag = result.NextTag();
|
const auto shaderTag = result.NextTag();
|
||||||
assert(shaderTag == TAG_VERTEX_SHADER || shaderTag == TAG_PIXEL_SHADER);
|
assert(shaderTag == TAG_VERTEX_SHADER || shaderTag == TAG_PIXEL_SHADER);
|
||||||
|
|
||||||
|
state->m_current_shader = CommonTechniqueShader(shaderNameToken.StringValue());
|
||||||
if (shaderTag == TAG_VERTEX_SHADER)
|
if (shaderTag == TAG_VERTEX_SHADER)
|
||||||
{
|
state->m_current_shader_type = TechniqueParserShaderType::VERTEX;
|
||||||
acceptorResult = state->m_acceptor->AcceptVertexShader(shaderNameToken.StringValue(), errorMessage);
|
|
||||||
state->m_current_shader = ShaderSelector::VERTEX_SHADER;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
state->m_current_shader_type = TechniqueParserShaderType::PIXEL;
|
||||||
acceptorResult = state->m_acceptor->AcceptPixelShader(shaderNameToken.StringValue(), errorMessage);
|
|
||||||
state->m_current_shader = ShaderSelector::PIXEL_SHADER;
|
|
||||||
}
|
|
||||||
|
|
||||||
state->m_in_shader = true;
|
|
||||||
|
|
||||||
if (!acceptorResult)
|
|
||||||
throw ParsingException(firstToken.GetPos(), std::move(errorMessage));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -191,13 +168,23 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
const auto& firstToken = result.NextCapture(CAPTURE_FIRST_TOKEN);
|
assert(state->m_current_pass);
|
||||||
const std::string destinationString = CreateRoutingString(result, CAPTURE_STREAM_DESTINATION_NAME, CAPTURE_STREAM_DESTINATION_INDEX);
|
|
||||||
const std::string sourceString = CreateRoutingString(result, CAPTURE_STREAM_SOURCE_NAME, CAPTURE_STREAM_SOURCE_INDEX);
|
|
||||||
|
|
||||||
std::string errorMessage;
|
const auto& firstToken = result.NextCapture(CAPTURE_FIRST_TOKEN);
|
||||||
if (!state->m_acceptor->AcceptVertexStreamRouting(destinationString, sourceString, errorMessage))
|
|
||||||
throw ParsingException(firstToken.GetPos(), std::move(errorMessage));
|
const std::string destinationString = CreateRoutingString(result, CAPTURE_STREAM_DESTINATION_NAME, CAPTURE_STREAM_DESTINATION_INDEX);
|
||||||
|
const auto maybeDestination = state->m_routing_infos.GetDestinationByName(destinationString);
|
||||||
|
|
||||||
|
if (!maybeDestination.has_value())
|
||||||
|
throw ParsingException(firstToken.GetPos(), "Unknown routing destination");
|
||||||
|
|
||||||
|
const std::string sourceString = CreateRoutingString(result, CAPTURE_STREAM_SOURCE_NAME, CAPTURE_STREAM_SOURCE_INDEX);
|
||||||
|
const auto maybeSource = state->m_routing_infos.GetSourceByName(sourceString);
|
||||||
|
|
||||||
|
if (!maybeSource.has_value())
|
||||||
|
throw ParsingException(firstToken.GetPos(), "Unknown routing source");
|
||||||
|
|
||||||
|
state->m_current_pass->m_vertex_declaration.m_routing.emplace_back(*maybeSource, *maybeDestination);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace techset
|
} // namespace techset
|
||||||
|
|||||||
@@ -23,8 +23,15 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
assert(state->m_in_shader == true);
|
assert(state->m_current_pass);
|
||||||
state->m_in_shader = false;
|
assert(state->m_current_shader);
|
||||||
|
|
||||||
|
if (state->m_current_shader_type == TechniqueParserShaderType::VERTEX)
|
||||||
|
state->m_current_pass->m_vertex_shader = std::move(*state->m_current_shader);
|
||||||
|
else
|
||||||
|
state->m_current_pass->m_pixel_shader = std::move(*state->m_current_shader);
|
||||||
|
|
||||||
|
state->m_current_shader = std::nullopt;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -203,7 +210,7 @@ namespace techset
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(TechniqueParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
assert(state->m_in_shader == true);
|
assert(state->m_current_shader);
|
||||||
|
|
||||||
const auto& shaderArgumentNameToken = result.NextCapture(CAPTURE_SHADER_ARGUMENT);
|
const auto& shaderArgumentNameToken = result.NextCapture(CAPTURE_SHADER_ARGUMENT);
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,23 @@
|
|||||||
#include "Sequence/TechniquePassScopeSequences.h"
|
#include "Sequence/TechniquePassScopeSequences.h"
|
||||||
#include "Sequence/TechniqueShaderScopeSequences.h"
|
#include "Sequence/TechniqueShaderScopeSequences.h"
|
||||||
|
|
||||||
using namespace techset;
|
namespace techset
|
||||||
|
|
||||||
TechniqueParser::TechniqueParser(SimpleLexer* lexer, ITechniqueDefinitionAcceptor* acceptor)
|
|
||||||
: AbstractParser(lexer, std::make_unique<TechniqueParserState>(acceptor))
|
|
||||||
{
|
{
|
||||||
}
|
TechniqueParser::TechniqueParser(SimpleLexer& lexer,
|
||||||
|
std::string techniqueName,
|
||||||
|
const CommonCodeSourceInfos& codeSourceInfos,
|
||||||
|
const CommonStreamRoutingInfos& routingInfos)
|
||||||
|
: AbstractParser(&lexer, std::make_unique<TechniqueParserState>(std::move(techniqueName), codeSourceInfos, routingInfos))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<TechniqueParser::sequence_t*>& TechniqueParser::GetTestsForState()
|
std::unique_ptr<CommonTechnique> TechniqueParser::GetParsingResult() const
|
||||||
{
|
{
|
||||||
|
return std::move(m_state->m_technique);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<TechniqueParser::sequence_t*>& TechniqueParser::GetTestsForState()
|
||||||
|
{
|
||||||
if (m_state->m_in_shader)
|
if (m_state->m_in_shader)
|
||||||
return TechniqueShaderScopeSequences::GetSequences();
|
return TechniqueShaderScopeSequences::GetSequences();
|
||||||
|
|
||||||
@@ -20,4 +28,5 @@ const std::vector<TechniqueParser::sequence_t*>& TechniqueParser::GetTestsForSta
|
|||||||
return TechniquePassScopeSequences::GetSequences();
|
return TechniquePassScopeSequences::GetSequences();
|
||||||
|
|
||||||
return TechniqueNoScopeSequences::GetSequences();
|
return TechniqueNoScopeSequences::GetSequences();
|
||||||
}
|
}
|
||||||
|
} // namespace techset
|
||||||
|
|||||||
@@ -4,15 +4,20 @@
|
|||||||
#include "Parsing/Simple/SimpleLexer.h"
|
#include "Parsing/Simple/SimpleLexer.h"
|
||||||
#include "Parsing/Simple/SimpleParserValue.h"
|
#include "Parsing/Simple/SimpleParserValue.h"
|
||||||
#include "TechniqueFileParserState.h"
|
#include "TechniqueFileParserState.h"
|
||||||
|
#include "Techset/CommonTechnique.h"
|
||||||
|
|
||||||
namespace techset
|
namespace techset
|
||||||
{
|
{
|
||||||
class TechniqueParser final : public AbstractParser<SimpleParserValue, TechniqueParserState>
|
class TechniqueParser final : public AbstractParser<SimpleParserValue, TechniqueParserState>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
TechniqueParser(SimpleLexer& lexer,
|
||||||
|
std::string techniqueName,
|
||||||
|
const CommonCodeSourceInfos& codeSourceInfos,
|
||||||
|
const CommonStreamRoutingInfos& routingInfos);
|
||||||
|
[[nodiscard]] std::unique_ptr<CommonTechnique> GetParsingResult() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const std::vector<sequence_t*>& GetTestsForState() override;
|
const std::vector<sequence_t*>& GetTestsForState() override;
|
||||||
|
|
||||||
public:
|
|
||||||
TechniqueParser(SimpleLexer* lexer, ITechniqueDefinitionAcceptor* acceptor);
|
|
||||||
};
|
};
|
||||||
} // namespace techset
|
} // namespace techset
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
#include "TechniqueFileParserState.h"
|
#include "TechniqueFileParserState.h"
|
||||||
|
|
||||||
#include <cassert>
|
namespace techset
|
||||||
|
{
|
||||||
using namespace techset;
|
TechniqueParserState::TechniqueParserState(std::string techniqueName,
|
||||||
|
const CommonCodeSourceInfos& codeSourceInfos,
|
||||||
TechniqueParserState::TechniqueParserState(ITechniqueDefinitionAcceptor* acceptor)
|
const CommonStreamRoutingInfos& routingInfos)
|
||||||
: m_acceptor(acceptor),
|
: m_technique(std::make_unique<CommonTechnique>(std::move(techniqueName))),
|
||||||
|
m_code_source_infos(codeSourceInfos),
|
||||||
|
m_routing_infos(routingInfos),
|
||||||
m_in_pass(false),
|
m_in_pass(false),
|
||||||
m_in_shader(false),
|
m_in_shader(false),
|
||||||
m_current_shader(ShaderSelector::VERTEX_SHADER)
|
m_current_shader(ShaderSelector::VERTEX_SHADER)
|
||||||
{
|
{
|
||||||
assert(acceptor);
|
}
|
||||||
}
|
} // namespace techset
|
||||||
|
|||||||
@@ -1,18 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Techset/TechniqueDefinitionAcceptor.h"
|
#include "Techset/CommonTechnique.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace techset
|
namespace techset
|
||||||
{
|
{
|
||||||
|
enum class TechniqueParserShaderType : std::uint8_t
|
||||||
|
{
|
||||||
|
VERTEX,
|
||||||
|
PIXEL
|
||||||
|
};
|
||||||
|
|
||||||
class TechniqueParserState
|
class TechniqueParserState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TechniqueParserState(ITechniqueDefinitionAcceptor* acceptor);
|
TechniqueParserState(std::string techniqueName, const CommonCodeSourceInfos& codeSourceInfos, const CommonStreamRoutingInfos& routingInfos);
|
||||||
|
|
||||||
ITechniqueDefinitionAcceptor* const m_acceptor;
|
std::unique_ptr<CommonTechnique> m_technique;
|
||||||
|
|
||||||
bool m_in_pass;
|
const CommonCodeSourceInfos& m_code_source_infos;
|
||||||
bool m_in_shader;
|
const CommonStreamRoutingInfos& m_routing_infos;
|
||||||
ShaderSelector m_current_shader;
|
|
||||||
|
std::optional<CommonPass> m_current_pass;
|
||||||
|
std::optional<CommonTechniqueShader> m_current_shader;
|
||||||
|
TechniqueParserShaderType m_current_shader_type;
|
||||||
};
|
};
|
||||||
} // namespace techset
|
} // namespace techset
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Parsing/Simple/Expression/SimpleExpressionMatchers.h"
|
#include "Parsing/Simple/Expression/SimpleExpressionMatchers.h"
|
||||||
#include "StateMap/Parsing/StateMapParserState.h"
|
#include "Techset/StateMap/Parsing/StateMapParserState.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -4,8 +4,6 @@
|
|||||||
#include "Parsing/Simple/SimpleLexer.h"
|
#include "Parsing/Simple/SimpleLexer.h"
|
||||||
#include "Parsing/Simple/SimpleParserValue.h"
|
#include "Parsing/Simple/SimpleParserValue.h"
|
||||||
#include "StateMapParserState.h"
|
#include "StateMapParserState.h"
|
||||||
#include "Techset/TechsetDefinition.h"
|
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
|
|
||||||
namespace state_map
|
namespace state_map
|
||||||
{
|
{
|
||||||
@@ -16,7 +14,7 @@ namespace state_map
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
StateMapParser(SimpleLexer* lexer, std::string stateMapName, const StateMapLayout& layout);
|
StateMapParser(SimpleLexer* lexer, std::string stateMapName, const StateMapLayout& layout);
|
||||||
_NODISCARD std::unique_ptr<StateMapDefinition> GetStateMapDefinition() const;
|
[[nodiscard]] std::unique_ptr<StateMapDefinition> GetStateMapDefinition() const;
|
||||||
_NODISCARD StateMapParserState* GetState() const;
|
[[nodiscard]] StateMapParserState* GetState() const;
|
||||||
};
|
};
|
||||||
} // namespace state_map
|
} // namespace state_map
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "StateMap/StateMapDefinition.h"
|
#include "Techset/StateMap/StateMapDefinition.h"
|
||||||
#include "StateMap/StateMapLayout.h"
|
#include "Techset/StateMap/StateMapLayout.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "StateMap/StateMapDefinition.h"
|
#include "Techset/StateMap/StateMapDefinition.h"
|
||||||
#include "StateMap/StateMapLayout.h"
|
#include "Techset/StateMap/StateMapLayout.h"
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -13,7 +12,7 @@ namespace state_map
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void AddValue(std::string key, std::string value);
|
void AddValue(std::string key, std::string value);
|
||||||
_NODISCARD SimpleExpressionValue ValueByName(const std::string& name) const override;
|
[[nodiscard]] SimpleExpressionValue ValueByName(const std::string& name) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::string> m_vars;
|
std::unordered_map<std::string, std::string> m_vars;
|
||||||
@@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
#include "Parsing/IParserLineStream.h"
|
#include "Parsing/IParserLineStream.h"
|
||||||
#include "Parsing/StateMapParserState.h"
|
#include "Parsing/StateMapParserState.h"
|
||||||
#include "StateMap/StateMapLayout.h"
|
|
||||||
#include "StateMapDefinition.h"
|
#include "StateMapDefinition.h"
|
||||||
#include "Utils/ClassUtils.h"
|
#include "Techset/StateMap/StateMapLayout.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -22,7 +21,7 @@ namespace state_map
|
|||||||
public:
|
public:
|
||||||
StateMapReader(std::istream& stream, std::string fileName, std::string stateMapName, const StateMapLayout& layout);
|
StateMapReader(std::istream& stream, std::string fileName, std::string stateMapName, const StateMapLayout& layout);
|
||||||
|
|
||||||
_NODISCARD bool IsValidEndState(const StateMapParserState* state) const;
|
[[nodiscard]] bool IsValidEndState(const StateMapParserState* state) const;
|
||||||
_NODISCARD std::unique_ptr<StateMapDefinition> ReadStateMapDefinition() const;
|
[[nodiscard]] std::unique_ptr<StateMapDefinition> ReadStateMapDefinition() const;
|
||||||
};
|
};
|
||||||
} // namespace state_map
|
} // namespace state_map
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Asset/IZoneAssetCreationState.h"
|
#include "Asset/IZoneAssetCreationState.h"
|
||||||
#include "StateMap/StateMapDefinition.h"
|
#include "Techset/StateMap/StateMapDefinition.h"
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -13,10 +12,10 @@ namespace techset
|
|||||||
class TechniqueStateMapCache final : public IZoneAssetCreationState
|
class TechniqueStateMapCache final : public IZoneAssetCreationState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD const state_map::StateMapDefinition* GetCachedStateMap(const std::string& name) const;
|
[[nodiscard]] const state_map::StateMapDefinition* GetCachedStateMap(const std::string& name) const;
|
||||||
void AddStateMapToCache(std::unique_ptr<state_map::StateMapDefinition> stateMap);
|
void AddStateMapToCache(std::unique_ptr<state_map::StateMapDefinition> stateMap);
|
||||||
|
|
||||||
_NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const;
|
[[nodiscard]] const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const;
|
||||||
void SetTechniqueUsesStateMap(std::string techniqueName, const state_map::StateMapDefinition* stateMap);
|
void SetTechniqueUsesStateMap(std::string techniqueName, const state_map::StateMapDefinition* stateMap);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#include "CommonTechsetCache.h"
|
|
||||||
|
|
||||||
using namespace techset;
|
|
||||||
|
|
||||||
CommonTechset* CommonTechsetCache::GetCachedTechsetDefinition(const std::string& techsetName) const
|
|
||||||
{
|
|
||||||
const auto foundTechset = m_cache.find(techsetName);
|
|
||||||
|
|
||||||
if (foundTechset != m_cache.end())
|
|
||||||
return foundTechset->second.get();
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonTechsetCache::AddCommonTechsetToCache(std::string name, std::unique_ptr<CommonTechset> definition)
|
|
||||||
{
|
|
||||||
m_cache.emplace(std::make_pair(std::move(name), std::move(definition)));
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Asset/IZoneAssetCreationState.h"
|
|
||||||
#include "Techset/CommonTechset.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace techset
|
|
||||||
{
|
|
||||||
class CommonTechsetCache final : public IZoneAssetCreationState
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
[[nodiscard]] CommonTechset* GetCachedTechsetDefinition(const std::string& techsetName) const;
|
|
||||||
void AddCommonTechsetToCache(std::string name, std::unique_ptr<CommonTechset> definition);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unordered_map<std::string, std::unique_ptr<CommonTechset>> m_cache;
|
|
||||||
};
|
|
||||||
} // namespace techset
|
|
||||||
9
src/ObjLoading/Techset/TechniqueCache.cpp
Normal file
9
src/ObjLoading/Techset/TechniqueCache.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "TechniqueCache.h"
|
||||||
|
|
||||||
|
namespace techset
|
||||||
|
{
|
||||||
|
void TechniqueCache::AddTechniqueToCache(std::string name, void* technique)
|
||||||
|
{
|
||||||
|
m_cache.emplace(std::move(name), technique);
|
||||||
|
}
|
||||||
|
} // namespace techset
|
||||||
28
src/ObjLoading/Techset/TechniqueCache.h
Normal file
28
src/ObjLoading/Techset/TechniqueCache.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Asset/IZoneAssetCreationState.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace techset
|
||||||
|
{
|
||||||
|
class TechniqueCache final : public IZoneAssetCreationState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename TechniqueType> [[nodiscard]] TechniqueType* GetCachedTechnique(const std::string& techniqueName) const
|
||||||
|
{
|
||||||
|
const auto foundTechnique = m_cache.find(techniqueName);
|
||||||
|
|
||||||
|
if (foundTechnique != m_cache.end())
|
||||||
|
return static_cast<TechniqueType*>(foundTechnique->second);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddTechniqueToCache(std::string name, void* technique);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, void*> m_cache;
|
||||||
|
};
|
||||||
|
} // namespace techset
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#include "TechniqueFileReader.h"
|
|
||||||
|
|
||||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
|
||||||
#include "Parsing/Impl/ParserSingleInputStream.h"
|
|
||||||
#include "Parsing/Simple/SimpleLexer.h"
|
|
||||||
#include "Parsing/TechniqueFileParser.h"
|
|
||||||
#include "Utils/Logging/Log.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace techset;
|
|
||||||
|
|
||||||
TechniqueFileReader::TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor)
|
|
||||||
: m_file_name(std::move(fileName)),
|
|
||||||
m_acceptor(acceptor)
|
|
||||||
{
|
|
||||||
m_base_stream = std::make_unique<ParserSingleInputStream>(stream, m_file_name);
|
|
||||||
m_comment_proxy = std::make_unique<CommentRemovingStreamProxy>(m_base_stream.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TechniqueFileReader::ReadTechniqueDefinition() const
|
|
||||||
{
|
|
||||||
SimpleLexer::Config lexerConfig;
|
|
||||||
lexerConfig.m_emit_new_line_tokens = false;
|
|
||||||
lexerConfig.m_read_strings = true;
|
|
||||||
lexerConfig.m_string_escape_sequences = false;
|
|
||||||
lexerConfig.m_read_integer_numbers = true;
|
|
||||||
lexerConfig.m_read_floating_point_numbers = true;
|
|
||||||
const auto lexer = std::make_unique<SimpleLexer>(m_comment_proxy.get(), std::move(lexerConfig));
|
|
||||||
|
|
||||||
const auto parser = std::make_unique<TechniqueParser>(lexer.get(), m_acceptor);
|
|
||||||
|
|
||||||
const auto success = parser->Parse();
|
|
||||||
if (success)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
con::error("Parsing technique file \"{}\" failed!", m_file_name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Parsing/IParserLineStream.h"
|
|
||||||
#include "TechniqueDefinitionAcceptor.h"
|
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace techset
|
|
||||||
{
|
|
||||||
class TechniqueFileReader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor);
|
|
||||||
|
|
||||||
[[nodiscard]] bool ReadTechniqueDefinition() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_file_name;
|
|
||||||
ITechniqueDefinitionAcceptor* m_acceptor;
|
|
||||||
std::unique_ptr<IParserLineStream> m_base_stream;
|
|
||||||
std::unique_ptr<IParserLineStream> m_comment_proxy;
|
|
||||||
};
|
|
||||||
} // namespace techset
|
|
||||||
@@ -281,13 +281,6 @@ namespace
|
|||||||
|
|
||||||
void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset)
|
void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset)
|
||||||
{
|
{
|
||||||
static techset::CommonCodeSourceInfos codeSourceInfos(commonCodeConstSources,
|
|
||||||
std::extent_v<decltype(commonCodeConstSources)>,
|
|
||||||
commonCodeSamplerSources,
|
|
||||||
std::extent_v<decltype(commonCodeSamplerSources)>);
|
|
||||||
static techset::CommonStreamRoutingInfos routingInfos(
|
|
||||||
streamRoutingSources, std::extent_v<decltype(streamRoutingSources)>, streamRoutingDestinations, std::extent_v<decltype(streamRoutingDestinations)>);
|
|
||||||
|
|
||||||
auto* techniqueState = context.GetZoneAssetDumperState<techset::TechniqueDumpingZoneState>();
|
auto* techniqueState = context.GetZoneAssetDumperState<techset::TechniqueDumpingZoneState>();
|
||||||
const auto* materialConstantState = context.GetZoneAssetDumperState<MaterialConstantZoneState>();
|
const auto* materialConstantState = context.GetZoneAssetDumperState<MaterialConstantZoneState>();
|
||||||
for (const auto* technique : techset.techniques)
|
for (const auto* technique : techset.techniques)
|
||||||
@@ -296,7 +289,7 @@ namespace
|
|||||||
{
|
{
|
||||||
const auto commonTechnique = ConvertToCommonTechnique(*technique);
|
const auto commonTechnique = ConvertToCommonTechnique(*technique);
|
||||||
|
|
||||||
techset::DumpCommonTechnique(context, commonTechnique, codeSourceInfos, routingInfos, *materialConstantState);
|
techset::DumpCommonTechnique(context, commonTechnique, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user