mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em ContentManager
This commit is contained in:
parent
9327fc0ba5
commit
686693023f
@ -1 +1,13 @@
|
|||||||
#include "content/manager.hpp"
|
#include "content/manager.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
sptr<Stream> ContentManager::OpenStream(String const& assetName) const {
|
||||||
|
const String filePath = _rootDirectory + "\\" + assetName + contentExtension;
|
||||||
|
const auto stream = New<FileStream>(filePath, FileMode::Open);
|
||||||
|
|
||||||
|
if (stream->IsClosed())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return reinterpret_pointer_cast<Stream>(stream);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,8 @@ namespace xna {
|
|||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
services = New<GameServiceContainer>();
|
services = New<GameServiceContainer>();
|
||||||
auto iservice = reinterpret_pointer_cast<IServiceProvider>(services);
|
auto iservice = reinterpret_pointer_cast<IServiceProvider>(services);
|
||||||
_contentManager = New<ContentManager>("", services);
|
_contentManager = New<ContentManager>(services, "");
|
||||||
|
_contentManager->_gameServices = iservice;
|
||||||
|
|
||||||
_gameWindow = New<GameWindow>();
|
_gameWindow = New<GameWindow>();
|
||||||
_gameWindow->impl->Color(146, 150, 154);
|
_gameWindow->impl->Color(146, 150, 154);
|
||||||
|
@ -1,53 +1,63 @@
|
|||||||
#ifndef XNA_CONTENT_MANAGER_HPP
|
#ifndef XNA_CONTENT_MANAGER_HPP
|
||||||
#define XNA_CONTENT_MANAGER_HPP
|
#define XNA_CONTENT_MANAGER_HPP
|
||||||
|
|
||||||
#include "../csharp/stream.hpp"
|
#include "csharp/stream.hpp"
|
||||||
#include "../default.hpp"
|
#include "default.hpp"
|
||||||
#include "../game/servicecontainer.hpp"
|
#include "csharp/service.hpp"
|
||||||
#include "reader.hpp"
|
#include "reader.hpp"
|
||||||
#include <algorithm>
|
|
||||||
#include <filesystem>
|
|
||||||
#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.
|
||||||
class ContentManager {
|
class ContentManager {
|
||||||
public:
|
public:
|
||||||
friend class ContentReader;
|
ContentManager(sptr<IServiceProvider> const& services) :
|
||||||
|
_rootDirectory("") {
|
||||||
|
_services = services;
|
||||||
|
};
|
||||||
|
|
||||||
ContentManager(String const& rootDirectory, sptr<IServiceProvider> const& services) :
|
ContentManager(sptr<IServiceProvider> const& services, String const& rootDirectory) :
|
||||||
_rootDirectory(rootDirectory){
|
_rootDirectory(rootDirectory){
|
||||||
_services = services;
|
_services = services;
|
||||||
};
|
};
|
||||||
|
|
||||||
static sptr<IServiceProvider> Services() {
|
//Gets the service provider associated with the ContentManager.
|
||||||
|
sptr<IServiceProvider> ServiceProvider() const {
|
||||||
return _services;
|
return _services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets or sets the root directory associated with this ContentManager.
|
||||||
constexpr String RootDirectory() const {
|
constexpr String RootDirectory() const {
|
||||||
return _rootDirectory;
|
return _rootDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets or sets the root directory associated with this ContentManager.
|
||||||
void RootDirectory(String const& value) {
|
void RootDirectory(String const& value) {
|
||||||
_rootDirectory = value;
|
_rootDirectory = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Loads an asset that has been processed by the Content Pipeline.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto Load(String const& assetName) {
|
auto Load(String const& assetName) {
|
||||||
if (assetName.empty()) {
|
if (assetName.empty()) {
|
||||||
return XnaHelper::ReturnDefaultOrNull<T>();
|
return XnaHelper::ReturnDefaultOrNull<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto obj2 = ReadAsset<T>(assetName);
|
const auto obj2 = ReadAsset<T>(assetName);
|
||||||
|
|
||||||
return obj2;
|
return obj2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets the service provider associated with the main Game.
|
||||||
|
static sptr<IServiceProvider> GameServiceProvider() {
|
||||||
|
return _gameServices;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto ReadAsset(String const& assetName) {
|
auto ReadAsset(String const& assetName) {
|
||||||
auto input = OpenStream(assetName);
|
auto input = OpenStream(assetName);
|
||||||
|
|
||||||
if (input->IsClosed())
|
if (!input)
|
||||||
return XnaHelper::ReturnDefaultOrNull<T>();
|
return XnaHelper::ReturnDefaultOrNull<T>();
|
||||||
|
|
||||||
auto contentReader = ContentReader::Create(this, input, assetName);
|
auto contentReader = ContentReader::Create(this, input, assetName);
|
||||||
@ -56,19 +66,18 @@ namespace xna {
|
|||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
sptr<Stream> OpenStream(String const& assetName) {
|
sptr<Stream> OpenStream(String const& assetName) const;
|
||||||
String filePath = _rootDirectory + "\\" + assetName + contentExtension;
|
|
||||||
const auto stream = New<FileStream>(filePath, FileMode::Open);
|
|
||||||
//const auto stream = New<FileStream>(filePath);
|
|
||||||
return reinterpret_pointer_cast<Stream>(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class ContentReader;
|
||||||
|
friend class Game;
|
||||||
|
|
||||||
String _rootDirectory;
|
String _rootDirectory;
|
||||||
std::vector<Byte> byteBuffer;
|
std::vector<Byte> byteBuffer;
|
||||||
|
sptr<IServiceProvider> _services = nullptr;
|
||||||
|
|
||||||
|
inline static sptr<IServiceProvider> _gameServices = nullptr;
|
||||||
inline const static String contentExtension = ".xnb";
|
inline const static String contentExtension = ".xnb";
|
||||||
inline static sptr<IServiceProvider> _services = nullptr;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#ifndef XNA_CONTENT_READER_HPP
|
#ifndef XNA_CONTENT_READER_HPP
|
||||||
#define XNA_CONTENT_READER_HPP
|
#define XNA_CONTENT_READER_HPP
|
||||||
|
|
||||||
#include "../common/color.hpp"
|
#include "common/color.hpp"
|
||||||
#include "../common/numerics.hpp"
|
#include "common/numerics.hpp"
|
||||||
#include "../csharp/binary.hpp"
|
#include "csharp/binary.hpp"
|
||||||
#include "../csharp/type.hpp"
|
#include "csharp/type.hpp"
|
||||||
#include "../default.hpp"
|
#include "default.hpp"
|
||||||
#include "typereadermanager.hpp"
|
#include "typereadermanager.hpp"
|
||||||
#include <any>
|
#include <any>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace xna {
|
|||||||
const auto height = input.ReadInt32();
|
const auto height = input.ReadInt32();
|
||||||
const auto mipMaps = input.ReadInt32();
|
const auto mipMaps = input.ReadInt32();
|
||||||
|
|
||||||
auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>());
|
auto a_device = ContentManager::GameServiceProvider()->GetService(*typeof<GraphicsDevice>());
|
||||||
sptr<GraphicsDevice> device = nullptr;
|
sptr<GraphicsDevice> device = nullptr;
|
||||||
|
|
||||||
if (a_device.has_value())
|
if (a_device.has_value())
|
||||||
|
@ -43,6 +43,10 @@ namespace xna {
|
|||||||
constexpr double DoubleMaxValue = (std::numeric_limits<double>::max)();
|
constexpr double DoubleMaxValue = (std::numeric_limits<double>::max)();
|
||||||
constexpr double DoubleMinValue = (std::numeric_limits<double>::min)();
|
constexpr double DoubleMinValue = (std::numeric_limits<double>::min)();
|
||||||
|
|
||||||
|
//
|
||||||
|
// About strings: https://stackoverflow.com/questions/402283/stdwstring-vs-stdstring
|
||||||
|
//
|
||||||
|
|
||||||
using String = std::string;
|
using String = std::string;
|
||||||
using WString = std::wstring;
|
using WString = std::wstring;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
namespace PlatformerStarterKit {
|
namespace PlatformerStarterKit {
|
||||||
Level::Level(xna::sptr<xna::IServiceProvider> const& serviceProvider, xna::String const& path) : path(path)
|
Level::Level(xna::sptr<xna::IServiceProvider> const& serviceProvider, xna::String const& path) : path(path)
|
||||||
{
|
{
|
||||||
content = xna::snew<xna::ContentManager>("Content", serviceProvider);
|
content = xna::snew<xna::ContentManager>(serviceProvider, "Content");
|
||||||
timeRemaining = xna::TimeSpan::FromMinutes(2.0);
|
timeRemaining = xna::TimeSpan::FromMinutes(2.0);
|
||||||
|
|
||||||
layers = std::vector<xna::PTexture2D>(3);
|
layers = std::vector<xna::PTexture2D>(3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user