#ifndef XNA_CONTENT_MANAGER_HPP #define XNA_CONTENT_MANAGER_HPP #include "../csharp/stream.hpp" #include "../default.hpp" #include "../game/servicecontainer.hpp" #include "reader.hpp" #include #include #include namespace xna { class ContentManager { public: friend class ContentReader; ContentManager(String const& rootDirectory, sptr const& services) : _rootDirectory(rootDirectory){ _services = services; }; static sptr Services() { return _services; } constexpr String RootDirectory() const { return _rootDirectory; } void RootDirectory(String const& value) { _rootDirectory = value; } template T Load(String const& assetName) { if (assetName.empty()) return T(); auto obj2 = ReadAsset(assetName); return obj2; } protected: template T ReadAsset(String const& assetName) { auto input = OpenStream(assetName); if (input->IsClosed()) return T(); auto contentReader = ContentReader::Create(this, input, assetName); return contentReader->ReadAsset(); } sptr OpenStream(String const& assetName) { String filePath = _rootDirectory + "\\" + assetName + contentExtension; const auto stream = New(filePath, FileMode::Open); //const auto stream = New(filePath); return reinterpret_pointer_cast(stream); } private: String _rootDirectory; std::vector byteBuffer; inline const static String contentExtension = ".xnb"; inline static sptr _services = nullptr; }; } #endif