mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Limpeza em Game
This commit is contained in:
parent
d3ceb91ca1
commit
da53a0a272
@ -15,8 +15,7 @@ namespace xna {
|
||||
friend class ContentReader;
|
||||
|
||||
ContentManager(String const& rootDirectory, sptr<GameServiceContainer> const& services) :
|
||||
_rootDirectory(rootDirectory),
|
||||
_path(rootDirectory){
|
||||
_rootDirectory(rootDirectory){
|
||||
_services = services;
|
||||
};
|
||||
|
||||
@ -34,7 +33,6 @@ namespace xna {
|
||||
|
||||
void RootDirectory(String const& value) {
|
||||
_rootDirectory = value;
|
||||
_path = value;
|
||||
}
|
||||
|
||||
virtual void Unload() {
|
||||
@ -56,7 +54,9 @@ namespace xna {
|
||||
}
|
||||
|
||||
auto obj2 = ReadAsset<T>(assetName);
|
||||
//auto obj3 = reinterpret_pointer_cast<T>(obj2);
|
||||
//auto voidAsset = reinterpret_pointer_cast<void>(obj2);
|
||||
_loadedAssets.insert({ assetName , obj2 });
|
||||
|
||||
return obj2;
|
||||
}
|
||||
|
||||
@ -77,7 +77,6 @@ namespace xna {
|
||||
|
||||
private:
|
||||
String _rootDirectory;
|
||||
std::filesystem::path _path;
|
||||
std::map<String, sptr<void>> _loadedAssets;
|
||||
inline const static String contentExtension = ".xnb";
|
||||
std::vector<Byte> byteBuffer;
|
||||
|
@ -3,21 +3,19 @@
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "time.hpp"
|
||||
#include "window.hpp"
|
||||
#include "component.hpp"
|
||||
#include "servicecontainer.hpp"
|
||||
|
||||
namespace xna {
|
||||
class IGame {
|
||||
public:
|
||||
virtual ~IGame(){}
|
||||
|
||||
virtual void Exit() = 0;
|
||||
virtual int Run() = 0;
|
||||
virtual sptr<GameWindow> Window() = 0;
|
||||
virtual sptr<GraphicsDevice> GetGraphicsDevice() = 0;
|
||||
virtual sptr<GameComponentCollection> Components() = 0;
|
||||
virtual sptr<GameServiceContainer> Services() = 0;
|
||||
virtual sptr<ContentManager> Content() = 0;
|
||||
|
||||
protected:
|
||||
virtual void Draw(GameTime const& gameTime) = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#define NOMINMAX
|
||||
#include "../csharp/type.hpp"
|
||||
#include "../game/time.hpp"
|
||||
#include "audioengine-dx.hpp"
|
||||
#include "device-dx.hpp"
|
||||
@ -8,15 +8,14 @@
|
||||
#include "keyboard-dx.hpp"
|
||||
#include "mouse-dx.hpp"
|
||||
#include "window-dx.hpp"
|
||||
#include <Windows.h>
|
||||
#include "../csharp/type.hpp"
|
||||
|
||||
namespace xna {
|
||||
Game::Game() {
|
||||
_services = New<GameServiceContainer>();
|
||||
services = New<GameServiceContainer>();
|
||||
_contentManager = New<ContentManager>("", services);
|
||||
|
||||
_gameWindow = New<GameWindow>();
|
||||
_gameWindow->Color(255, 155, 55);
|
||||
_gameWindow->Color(146, 150, 154);
|
||||
_gameWindow->Title("XN65");
|
||||
_gameWindow->Size(
|
||||
GraphicsDeviceManager::DefaultBackBufferWidth,
|
||||
@ -25,15 +24,14 @@ namespace xna {
|
||||
_gameComponents = New<GameComponentCollection>();
|
||||
}
|
||||
|
||||
void Game::Exit()
|
||||
{
|
||||
void Game::Exit() {
|
||||
_gameWindow->Close();
|
||||
}
|
||||
|
||||
int Game::Run() {
|
||||
Initialize();
|
||||
|
||||
if (_graphicsDevice == nullptr) {
|
||||
if (graphicsDevice == nullptr) {
|
||||
MessageBox(nullptr, "O dispositivo gráfico não foi inicializado corretamente", "XN65", MB_OK);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -43,33 +41,19 @@ namespace xna {
|
||||
|
||||
void Game::Initialize() {
|
||||
Keyboard::Initialize();
|
||||
Mouse::Initialize();
|
||||
|
||||
////initialize é requisito para GamePad
|
||||
//Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
||||
|
||||
//if (FAILED(initialize))
|
||||
// MessageBox(nullptr, "Ocorreu um erro ao executar Microsoft::WRL::Wrappers::RoInitializeWrapper. O GamePad não foi inicializado corretamente.", "XN65", MB_OK);
|
||||
|
||||
//GamePad.Initialize();
|
||||
|
||||
////CoInitializeEx é requisito para biblioteca DirectXTK
|
||||
//const auto hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
|
||||
//if (FAILED(hr))
|
||||
// MessageBox(nullptr, "Ocorreu um erro ao executar CoInitializeEx. O AudioEngine não foi inicializado corretamente.", "XN65", MB_OK);
|
||||
Mouse::Initialize();
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
||||
if (FAILED(initialize))
|
||||
{
|
||||
|
||||
MessageBox(nullptr, "Ocorreu um erro ao chamar Microsoft::WRL::Wrappers::RoInitializeWrapper.", "XN65", MB_OK);
|
||||
}
|
||||
#else
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
||||
MessageBox(nullptr, "Ocorreu um erro ao chamar CoInitializeEx.", "XN65", MB_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -101,7 +85,7 @@ namespace xna {
|
||||
_drawableGameComponents.clear();
|
||||
}
|
||||
|
||||
_graphicsDevice->Present();
|
||||
graphicsDevice->Present();
|
||||
}
|
||||
|
||||
void Game::Update(GameTime const& gameTime) {
|
||||
|
@ -1,76 +1,52 @@
|
||||
#ifndef XNA_PLATFORM_GAME_DX_HPP
|
||||
#define XNA_PLATFORM_GAME_DX_HPP
|
||||
|
||||
#include "../content/manager.hpp"
|
||||
#include "../default.hpp"
|
||||
#include "../game/game.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "dx/StepTimer.hpp"
|
||||
#include "../content/manager.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
|
||||
namespace xna {
|
||||
class Game : public IGame {
|
||||
public:
|
||||
Game();
|
||||
Game();
|
||||
|
||||
virtual ~Game() override {
|
||||
}
|
||||
|
||||
virtual void Exit() override;
|
||||
|
||||
virtual int Run() override;
|
||||
void Exit() override;
|
||||
int Run() override;
|
||||
|
||||
virtual sptr<GameWindow> Window() override {
|
||||
return _gameWindow;
|
||||
}
|
||||
|
||||
virtual sptr<GraphicsDevice> GetGraphicsDevice() override {
|
||||
return _graphicsDevice;
|
||||
}
|
||||
|
||||
sptr<GameComponentCollection> Components() override {
|
||||
return _gameComponents;
|
||||
}
|
||||
|
||||
sptr<GameServiceContainer> Services() override {
|
||||
return _services;
|
||||
}
|
||||
|
||||
sptr<ContentManager> Content() {
|
||||
return contentManager;
|
||||
}
|
||||
|
||||
constexpr void EnableGameComponents(bool value) {
|
||||
_enabledGameComponents = value;
|
||||
}
|
||||
inline sptr<GameWindow> Window() override { return _gameWindow; }
|
||||
inline sptr<GraphicsDevice> GetGraphicsDevice() override { return graphicsDevice; }
|
||||
inline sptr<GameComponentCollection> Components() override { return _gameComponents; }
|
||||
inline sptr<GameServiceContainer> Services() override { return services; }
|
||||
inline sptr<ContentManager> Content() override { return _contentManager; }
|
||||
constexpr void EnableGameComponents(bool value) { _enabledGameComponents = value; }
|
||||
|
||||
protected:
|
||||
virtual void Draw(GameTime const& gameTime) override;
|
||||
|
||||
virtual void Draw(GameTime const& gameTime) override;
|
||||
virtual void Initialize() override;
|
||||
|
||||
virtual void LoadContent() override{}
|
||||
|
||||
virtual void LoadContent() override{}
|
||||
virtual void Update(GameTime const& gameTime) override;
|
||||
|
||||
public:
|
||||
sptr<GraphicsDevice> _graphicsDevice{ nullptr };
|
||||
sptr<GraphicsDevice> graphicsDevice = nullptr;
|
||||
|
||||
protected:
|
||||
sptr<GameWindow> _gameWindow{ nullptr };
|
||||
sptr<AudioEngine> _audioEngine = nullptr;
|
||||
|
||||
GameTime _currentGameTime{};
|
||||
DX::StepTimer _stepTimer;
|
||||
sptr<ContentManager> contentManager;
|
||||
sptr<GameServiceContainer> _services = nullptr;
|
||||
protected:
|
||||
sptr<GameServiceContainer> services = nullptr;
|
||||
|
||||
private:
|
||||
int startLoop();
|
||||
void step();
|
||||
private:
|
||||
sptr<GameComponentCollection> _gameComponents = nullptr;
|
||||
sptr<GameWindow> _gameWindow{ nullptr };
|
||||
sptr<AudioEngine> _audioEngine = nullptr;
|
||||
sptr<ContentManager> _contentManager;
|
||||
std::vector<sptr<IGameComponent>> _drawableGameComponents;
|
||||
size_t _drawableGameComponentsCount{ 0 };
|
||||
bool _enabledGameComponents{ false };
|
||||
GameTime _currentGameTime{};
|
||||
DX::StepTimer _stepTimer{};
|
||||
|
||||
int startLoop();
|
||||
void step();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,10 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool GraphicsDeviceManager::ToggleFullScreen() {
|
||||
if (!_game || !_game->_graphicsDevice || !_game->_graphicsDevice->_swapChain)
|
||||
if (!_game || !_game->graphicsDevice || !_game->graphicsDevice->_swapChain)
|
||||
return false;
|
||||
|
||||
auto& swap = _game->_graphicsDevice->_swapChain;
|
||||
auto& swap = _game->graphicsDevice->_swapChain;
|
||||
|
||||
BOOL state = false;
|
||||
auto hr = swap->dxSwapChain->GetFullscreenState(&state, nullptr);
|
||||
@ -110,7 +110,7 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
_game->_graphicsDevice = _device;
|
||||
_game->graphicsDevice = _device;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -12,25 +12,22 @@ namespace xna {
|
||||
Game1() : Game() {
|
||||
auto _game = reinterpret_cast<Game*>(this);
|
||||
graphics = New<GraphicsDeviceManager>(_game);
|
||||
graphics->PreferredBackBufferWidth(1280);
|
||||
graphics->PreferredBackBufferHeight(720);
|
||||
contentManager = New<ContentManager>("Content", _services);
|
||||
|
||||
Content()->RootDirectory("Content");
|
||||
}
|
||||
|
||||
void Initialize() override {
|
||||
graphics->Initialize();
|
||||
|
||||
std::any device = _graphicsDevice;
|
||||
_services->AddService(*typeof<GraphicsDevice>(), device);
|
||||
std::any device = graphicsDevice;
|
||||
services->AddService(*typeof<GraphicsDevice>(), device);
|
||||
|
||||
Game::Initialize();
|
||||
}
|
||||
|
||||
void LoadContent() override {
|
||||
spriteBatch = New<SpriteBatch>(*_graphicsDevice);
|
||||
spriteBatch = New<SpriteBatch>(*graphicsDevice);
|
||||
|
||||
XnaErrorCode err{0};
|
||||
texture = contentManager->Load<Texture2D>("Idle");
|
||||
Game::LoadContent();
|
||||
}
|
||||
|
||||
@ -42,11 +39,9 @@ namespace xna {
|
||||
}
|
||||
|
||||
void Draw(GameTime const& gameTime) override {
|
||||
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||
graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||
|
||||
spriteBatch->Begin();
|
||||
spriteBatch->Draw(*texture, position, Colors::White);
|
||||
spriteBatch->End();
|
||||
|
||||
|
||||
Game::Draw(gameTime);
|
||||
}
|
||||
@ -54,14 +49,6 @@ namespace xna {
|
||||
private:
|
||||
sptr<GraphicsDeviceManager> graphics = nullptr;
|
||||
sptr<SpriteBatch> spriteBatch = nullptr;
|
||||
sptr<Texture2D> texture = nullptr; //200x200
|
||||
Vector2 position{};
|
||||
std::vector<Vector2> points;
|
||||
MouseState currentState{};
|
||||
MouseState oldState{};
|
||||
float vel = 1;
|
||||
int var = 0;
|
||||
//Texture2D tx;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user