From b42a9f60b48821a1b4b529a29355acff21b68ef0 Mon Sep 17 00:00:00 2001 From: Danilo Date: Fri, 6 Sep 2024 21:22:38 -0300 Subject: [PATCH] Implementa ContentCompiler --- framework/pipeline/compiler.cpp | 33 +++++++++++++++++++++++++++++++++ inc/xna/default.hpp | 3 +++ inc/xna/pipeline/compiler.hpp | 32 +++++++++++++++++++++++++++++++- inc/xna/pipeline/writer.hpp | 16 +++++++++++++++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/framework/pipeline/compiler.cpp b/framework/pipeline/compiler.cpp index 4838cd4..201c199 100644 --- a/framework/pipeline/compiler.cpp +++ b/framework/pipeline/compiler.cpp @@ -1,5 +1,38 @@ #include "xna/pipeline/compiler.hpp" +#include "xna/pipeline/writer.hpp" namespace xna { + ContentCompiler::ContentCompiler() { + const auto writers = typeWriterFactory->Initialize(); + for (auto& writer : writers) + AddTypeWriter(writer); + + for (auto& dic : writerInstances) { + auto& writer = dic.second; + AddTypeWriter(writer); + } + } + + void ContentCompiler::Compile( + P_Stream const& output, + Object& value, + TargetPlatform targetPlatform, + GraphicsProfile targetProfile, + bool compressContent, + String const& rootDirectory, + String const& referenceRelocationPath) { + if (compressContent) + compressContent = ShouldCompressContent(targetPlatform, value); + + auto _this = shared_from_this(); + + auto contentWriter = unew( + _this, output, targetPlatform, + targetProfile, compressContent, + rootDirectory, referenceRelocationPath); + + contentWriter->WriteObject(value); + contentWriter->FlushOutput(); + } } \ No newline at end of file diff --git a/inc/xna/default.hpp b/inc/xna/default.hpp index 99f82db..b9f2842 100644 --- a/inc/xna/default.hpp +++ b/inc/xna/default.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "enumerations.hpp" #include "exception.hpp" @@ -204,6 +205,7 @@ namespace xna { class ContentWriter; class ContentCompiler; class ContentTypeWriter; + class ContentTypeWriterFactory; // @@ -230,6 +232,7 @@ namespace xna { using P_ContentWriter = sptr; using P_ContentCompiler = sptr; using P_ContentTypeWriter = sptr; + using P_ContentTypeWriterFactory = sptr; } diff --git a/inc/xna/pipeline/compiler.hpp b/inc/xna/pipeline/compiler.hpp index 9ca352c..9133c68 100644 --- a/inc/xna/pipeline/compiler.hpp +++ b/inc/xna/pipeline/compiler.hpp @@ -2,11 +2,41 @@ #define XNA_PIPELINE_COMPILER_HPP #include "../default.hpp" +#include "../csharp/stream.hpp" +#include "pipeline-enums.hpp" namespace xna { - class ContentCompiler { + //Provides methods for writing compiled binary format. + class ContentCompiler : public std::enable_shared_from_this { public: + ContentCompiler(); + + //Retrieves the worker writer for the specified type P_ContentTypeWriter GetTypeWriter(Type const& type, std::vector dependencies); + + private: + void Compile( + P_Stream const& output, + Object& value, + TargetPlatform targetPlatform, + GraphicsProfile targetProfile, + bool compressContent, + String const& rootDirectory, + String const& referenceRelocationPath); + + void AddTypeWriter(P_ContentTypeWriter const& writer); + + bool ShouldCompressContent(TargetPlatform targetPlatform, Object& value) { + return false; + } + + private: + using TypeList = std::vector; + + std::map writerInstances; + std::map writerDependecies; + std::stack initializeContext; + P_ContentTypeWriterFactory typeWriterFactory; }; } diff --git a/inc/xna/pipeline/writer.hpp b/inc/xna/pipeline/writer.hpp index 5b2e07c..3735c26 100644 --- a/inc/xna/pipeline/writer.hpp +++ b/inc/xna/pipeline/writer.hpp @@ -151,8 +151,22 @@ namespace xna { inline static const String FilenameExt = ".xnb"; }; + template + class TypeHandlerFactory { + + }; + + class ContentTypeWriterFactory : public TypeHandlerFactory { + public: + std::vector Initialize() const { + std::vector writers; + + return writers; + } + }; + // - // Generics implementations + // ContentTypeWriter // template