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:
parent
686693023f
commit
b35f48a78a
@ -5,6 +5,7 @@
|
|||||||
#include "default.hpp"
|
#include "default.hpp"
|
||||||
#include "csharp/service.hpp"
|
#include "csharp/service.hpp"
|
||||||
#include "reader.hpp"
|
#include "reader.hpp"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
//The run-time component which loads managed objects from the binary files produced by the design time content pipeline.
|
//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()) {
|
if (assetName.empty()) {
|
||||||
return XnaHelper::ReturnDefaultOrNull<T>();
|
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);
|
const auto obj2 = ReadAsset<T>(assetName);
|
||||||
|
|
||||||
|
if constexpr (XnaHelper::is_shared_ptr<T>::value) {
|
||||||
|
|
||||||
|
if(obj2)
|
||||||
|
_loadedAssets.emplace( assetName, obj2 );
|
||||||
|
}
|
||||||
|
|
||||||
return 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.
|
//Gets the service provider associated with the main Game.
|
||||||
static sptr<IServiceProvider> GameServiceProvider() {
|
static sptr<IServiceProvider> GameServiceProvider() {
|
||||||
return _gameServices;
|
return _gameServices;
|
||||||
@ -75,6 +97,7 @@ namespace xna {
|
|||||||
String _rootDirectory;
|
String _rootDirectory;
|
||||||
std::vector<Byte> byteBuffer;
|
std::vector<Byte> byteBuffer;
|
||||||
sptr<IServiceProvider> _services = nullptr;
|
sptr<IServiceProvider> _services = nullptr;
|
||||||
|
std::map<String, sptr<void>> _loadedAssets;
|
||||||
|
|
||||||
inline static sptr<IServiceProvider> _gameServices = nullptr;
|
inline static sptr<IServiceProvider> _gameServices = nullptr;
|
||||||
inline const static String contentExtension = ".xnb";
|
inline const static String contentExtension = ".xnb";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user