2024-11-16 17:05:24 -03:00
|
|
|
#ifndef XNA_PIPELINE_IMPORTER_HPP
|
|
|
|
#define XNA_PIPELINE_IMPORTER_HPP
|
|
|
|
|
2024-11-20 12:02:35 -03:00
|
|
|
#include "pipeline.hpp"
|
2024-11-16 17:05:24 -03:00
|
|
|
#include <any>
|
2024-11-17 17:16:51 -03:00
|
|
|
#include <map>
|
2024-11-16 17:05:24 -03:00
|
|
|
#include <memory>
|
2024-11-17 17:16:51 -03:00
|
|
|
#include <string>
|
2024-11-16 17:05:24 -03:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace xna {
|
|
|
|
//Provides properties that define logging behavior for the importer.
|
|
|
|
struct ContentImporterContext {
|
|
|
|
//Gets the logger for an importer.
|
|
|
|
virtual std::shared_ptr<ContentBuilderLogger> Logger() = 0;
|
|
|
|
//Name of an asset file.
|
|
|
|
virtual void AddDependency(std::string filename) = 0;
|
|
|
|
//The absolute path to the root of the build output (binaries) directory.
|
|
|
|
virtual std::string OutputDirectory() = 0;
|
|
|
|
//The absolute path to the root of the build intermediate (object) directory.
|
|
|
|
virtual std::string IntermediateDirectory() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//Accesses a statically typed ContentImporter instance from generic code using dynamic typing.
|
|
|
|
struct IContentImporter {
|
|
|
|
//Imports an asset from the specified file.
|
2024-11-16 19:07:04 -03:00
|
|
|
virtual std::any ImportObject(std::string const& filename, ContentImporterContext& context) = 0;
|
2024-11-16 17:05:24 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
//Implements a file format importer for use with game assets.
|
|
|
|
template <typename T>
|
2024-11-20 12:02:35 -03:00
|
|
|
struct ContentImporter : public IContentImporter {
|
2024-11-16 17:05:24 -03:00
|
|
|
//Imports an asset from the specified file.
|
|
|
|
virtual T Import(std::string const& filename, ContentImporterContext& context) = 0;
|
|
|
|
|
|
|
|
//Imports an asset from the specified file.
|
2024-11-16 19:07:04 -03:00
|
|
|
std::any ImportObject(std::string const& filename, ContentImporterContext& context) override {
|
|
|
|
std::any obj = Import(filename, context);
|
2024-11-16 17:05:24 -03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//rovides properties that identify and provide metadata about the importer, such as supported file extensions and caching information.
|
|
|
|
struct ContentImporterAttribute {
|
2024-11-16 19:07:04 -03:00
|
|
|
bool CacheImportedData{ false };
|
2024-11-16 17:05:24 -03:00
|
|
|
std::string DisplayName;
|
|
|
|
std::string DefaultProcessor;
|
|
|
|
|
|
|
|
ContentImporterAttribute(std::string const& fileExtension) {
|
|
|
|
fileExtensions.push_back(fileExtension);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentImporterAttribute(std::vector<std::string> const& fileExtensions) {
|
|
|
|
this->fileExtensions = fileExtensions;
|
|
|
|
//TODO: check extensions
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::string>& FileExtensions() const {
|
|
|
|
return fileExtensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<std::string> fileExtensions;
|
|
|
|
};
|
2024-11-16 19:07:04 -03:00
|
|
|
|
|
|
|
struct ImporterRegistration {
|
|
|
|
inline static auto Importers = std::vector<IContentImporter>();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ImporterManager {
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-11-20 12:02:35 -03:00
|
|
|
struct XmlImporter : ContentImporter<std::any> {
|
2024-11-16 19:07:04 -03:00
|
|
|
std::any Import(std::string const& filename, ContentImporterContext& context) override {
|
|
|
|
//TODO: XmlReader
|
|
|
|
return { };
|
|
|
|
}
|
|
|
|
};
|
2024-11-16 17:05:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|