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

Implementa LoadedAssets em ContentManager

This commit is contained in:
Danilo 2024-06-02 21:11:19 -03:00
parent 686693023f
commit b35f48a78a

View File

@ -5,6 +5,7 @@
#include "default.hpp"
#include "csharp/service.hpp"
#include "reader.hpp"
#include <map>
namespace xna {
//The run-time component which loads managed objects from the binary files produced by the design time content pipeline.
@ -41,12 +42,33 @@ namespace xna {
if (assetName.empty()) {
return XnaHelper::ReturnDefaultOrNull<T>();
}
if constexpr (XnaHelper::is_shared_ptr<T>::value) {
if (_loadedAssets.contains(assetName)) {
auto& voidAsset = _loadedAssets[assetName];
using TYPE = T::element_type;
auto asset = reinterpret_pointer_cast<TYPE>(voidAsset);
return asset;
}
}
const auto obj2 = ReadAsset<T>(assetName);
if constexpr (XnaHelper::is_shared_ptr<T>::value) {
if(obj2)
_loadedAssets.emplace( assetName, obj2 );
}
return obj2;
}
//Disposes all data that was loaded by this ContentManager.
void Unload() {
_loadedAssets.clear();
}
//Gets the service provider associated with the main Game.
static sptr<IServiceProvider> GameServiceProvider() {
return _gameServices;
@ -75,6 +97,7 @@ namespace xna {
String _rootDirectory;
std::vector<Byte> byteBuffer;
sptr<IServiceProvider> _services = nullptr;
std::map<String, sptr<void>> _loadedAssets;
inline static sptr<IServiceProvider> _gameServices = nullptr;
inline const static String contentExtension = ".xnb";