1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Implementa ContentCompiler

This commit is contained in:
Danilo 2024-09-06 21:22:38 -03:00
parent 0e89ee381b
commit b42a9f60b4
4 changed files with 82 additions and 2 deletions

View File

@ -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<ContentWriter>(
_this, output, targetPlatform,
targetProfile, compressContent,
rootDirectory, referenceRelocationPath);
contentWriter->WriteObject(value);
contentWriter->FlushOutput();
}
}

View File

@ -14,6 +14,7 @@
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#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<ContentWriter>;
using P_ContentCompiler = sptr<ContentCompiler>;
using P_ContentTypeWriter = sptr<ContentTypeWriter>;
using P_ContentTypeWriterFactory = sptr<ContentTypeWriterFactory>;
}

View File

@ -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<ContentCompiler> {
public:
ContentCompiler();
//Retrieves the worker writer for the specified type
P_ContentTypeWriter GetTypeWriter(Type const& type, std::vector<P_Type> 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<P_Type>;
std::map<HashValue, P_ContentTypeWriter> writerInstances;
std::map<HashValue, TypeList> writerDependecies;
std::stack<P_ContentTypeWriter> initializeContext;
P_ContentTypeWriterFactory typeWriterFactory;
};
}

View File

@ -151,8 +151,22 @@ namespace xna {
inline static const String FilenameExt = ".xnb";
};
template <class T>
class TypeHandlerFactory {
};
class ContentTypeWriterFactory : public TypeHandlerFactory<ContentTypeWriter> {
public:
std::vector<P_ContentTypeWriter> Initialize() const {
std::vector<P_ContentTypeWriter> writers;
return writers;
}
};
//
// Generics implementations
// ContentTypeWriter
//
template <class T>