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

Corrige Windows e GraphicsInfo

This commit is contained in:
Danilo 2024-05-24 12:31:24 -03:00
parent 01af08b711
commit d2a8b1d397
16 changed files with 214 additions and 288 deletions

View File

@ -13,26 +13,18 @@ add_executable (xna WIN32
"platform/texture-dx.cpp" "platform/texture-dx.cpp"
"platform/blendstate-dx.cpp" "platform/blendstate-dx.cpp"
"platform/game-dx.cpp" "platform/game-dx.cpp"
"csharp/stream.cpp" "csharp/stream.cpp"
"platform/gdevicemanager-dx.cpp" "platform/gdevicemanager-dx.cpp"
"platform/shader-dx.cpp" "platform/shader-dx.cpp"
"platform/rasterizerstate-dx.cpp" "platform/rasterizerstate-dx.cpp"
"platform/samplerstate-dx.cpp" "platform/samplerstate-dx.cpp"
"platform/sprite-dx.cpp" "platform/sprite-dx.cpp"
"platform/depthstencilstate-dx.cpp" "platform/depthstencilstate-dx.cpp"
"platform/keyboard-dx.cpp" "platform/keyboard-dx.cpp"
"platform/mouse-dx.cpp" "platform/mouse-dx.cpp"
"platform/gamepad-dx.cpp" "platform/gamepad-dx.cpp"
"platform/soundeffect-dx.cpp" "platform/soundeffect-dx.cpp"
"platform/displaymode-dx.cpp" "platform/displaymode-dx.cpp"
"game/component.cpp" "game/component.cpp"
"content/manager.cpp" "content/manager.cpp"
"content/reader.cpp" "content/reader.cpp"
@ -47,7 +39,9 @@ add_executable (xna WIN32
"common/color.cpp" "common/color.cpp"
"common/collision.cpp" "common/collision.cpp"
"common/gjk.cpp" "common/gjk.cpp"
"common/numerics.cpp" "common/packedvalue.cpp" "platform/buffer.cpp") "common/numerics.cpp"
"common/packedvalue.cpp"
"platform/buffer.cpp" )
if (CMAKE_VERSION VERSION_GREATER 3.12) if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET xna PROPERTY CXX_STANDARD 20) set_property(TARGET xna PROPERTY CXX_STANDARD 20)

View File

@ -3,11 +3,9 @@
#include "graphics/blendstate.hpp" #include "graphics/blendstate.hpp"
#include "graphics/rendertarget.hpp" #include "graphics/rendertarget.hpp"
#include "platform-dx/device-dx.hpp" #include "platform-dx/device-dx.hpp"
#include "platform-dx/gdeviceinfo-dx.hpp"
#include "platform-dx/gdevicemanager-dx.hpp" #include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/implementations.hpp" #include "platform-dx/implementations.hpp"
#include "platform-dx/window-dx.hpp" #include "game/gdeviceinfo.hpp"
#include "platform-dx/implementations.hpp"
namespace xna { namespace xna {
GraphicsDevice::GraphicsDevice() { GraphicsDevice::GraphicsDevice() {
@ -16,12 +14,12 @@ namespace xna {
} }
GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) { GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) {
_adapter = info.Adapter(); _adapter = info.Adapter;
_presentationParameters = info.PresentationParameters(); _presentationParameters = info.Parameters;
_adapter->CurrentDisplayMode( _adapter->CurrentDisplayMode(
_presentationParameters.BackBufferFormat, _presentationParameters->BackBufferFormat,
_presentationParameters.BackBufferWidth, _presentationParameters->BackBufferWidth,
_presentationParameters.BackBufferHeight); _presentationParameters->BackBufferHeight);
} }
bool GraphicsDevice::Initialize(GameWindow& gameWindow) { bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
@ -41,7 +39,7 @@ namespace xna {
static_cast<float>(bounds.Height), static_cast<float>(bounds.Height),
0.0F, 1.F); 0.0F, 1.F);
COLORREF color = gameWindow.Color(); COLORREF color = gameWindow.impl->Color();
_backgroundColor[0] = GetRValue(color) / 255.0f; _backgroundColor[0] = GetRValue(color) / 255.0f;
_backgroundColor[1] = GetGValue(color) / 255.0f; _backgroundColor[1] = GetGValue(color) / 255.0f;
_backgroundColor[2] = GetBValue(color) / 255.0f; _backgroundColor[2] = GetBValue(color) / 255.0f;
@ -50,7 +48,7 @@ namespace xna {
_swapChain = New<xna::SwapChain>(_this); _swapChain = New<xna::SwapChain>(_this);
_swapChain->Initialize(); _swapChain->Initialize();
hr = _factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER); hr = _factory->MakeWindowAssociation(gameWindow.impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER);
if (FAILED(hr)) return false; if (FAILED(hr)) return false;
_renderTarget2D = New<RenderTarget2D>(_this); _renderTarget2D = New<RenderTarget2D>(_this);

View File

@ -1,11 +1,9 @@
#include "csharp/type.hpp" #include "csharp/type.hpp"
#include "game/time.hpp" #include "game/time.hpp"
#include "platform-dx/audioengine-dx.hpp" #include "platform-dx/audioengine-dx.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/game-dx.hpp" #include "platform-dx/game-dx.hpp"
#include "platform-dx/gdevicemanager-dx.hpp" #include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/implementations.hpp" #include "platform-dx/implementations.hpp"
#include "platform-dx/window-dx.hpp"
namespace xna { namespace xna {
Game::Game() { Game::Game() {
@ -13,9 +11,9 @@ namespace xna {
_contentManager = New<ContentManager>("", services); _contentManager = New<ContentManager>("", services);
_gameWindow = New<GameWindow>(); _gameWindow = New<GameWindow>();
_gameWindow->Color(146, 150, 154); _gameWindow->impl->Color(146, 150, 154);
_gameWindow->Title("XN65"); _gameWindow->Title("XN65");
_gameWindow->Size( _gameWindow->impl->Size(
GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight, false); GraphicsDeviceManager::DefaultBackBufferHeight, false);
@ -23,7 +21,7 @@ namespace xna {
} }
void Game::Exit() { void Game::Exit() {
_gameWindow->Close(); _gameWindow->impl->Close();
} }
int Game::Run() { int Game::Run() {

View File

@ -1,8 +1,6 @@
#include "platform-dx/gdevicemanager-dx.hpp" #include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/device-dx.hpp" #include "platform-dx/device-dx.hpp"
#include "platform-dx/game-dx.hpp" #include "platform-dx/game-dx.hpp"
#include "platform-dx/window-dx.hpp"
#include "platform-dx/gdeviceinfo-dx.hpp"
#include "graphics/presentparams.hpp" #include "graphics/presentparams.hpp"
#include "graphics/swapchain.hpp" #include "graphics/swapchain.hpp"
#include "platform-dx/implementations.hpp" #include "platform-dx/implementations.hpp"
@ -10,17 +8,18 @@
namespace xna { namespace xna {
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) { GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter(); sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
_information.Adapter(adp); _information.Adapter = adp;
_information.GraphicsProfile(xna::GraphicsProfile::HiDef); _information.Profile = xna::GraphicsProfile::HiDef;
PresentationParameters parameters; auto parameters = snew<PresentationParameters>();
parameters.BackBufferWidth = _backBufferWidth; parameters->BackBufferWidth = _backBufferWidth;
parameters.BackBufferHeight = _backBufferHeight; parameters->BackBufferHeight = _backBufferHeight;
parameters.BackBufferFormat = SurfaceFormat::Color; parameters->BackBufferFormat = SurfaceFormat::Color;
parameters.Fullscreen = false; parameters->Fullscreen = false;
_information.PresentationParameters(parameters); _information.Parameters = parameters;
if(_game) _information.Window(_game->Window()); if(_game)
_information.Window =_game->Window();
} }
bool GraphicsDeviceManager::Initialize() { bool GraphicsDeviceManager::Initialize() {
@ -65,8 +64,8 @@ namespace xna {
bool GraphicsDeviceManager::CreateDevice() { bool GraphicsDeviceManager::CreateDevice() {
if (_isDeviceDirty) { if (_isDeviceDirty) {
_information._parameters.BackBufferWidth = _backBufferWidth; _information.Parameters->BackBufferWidth = _backBufferWidth;
_information._parameters.BackBufferHeight = _backBufferHeight; _information.Parameters->BackBufferHeight = _backBufferHeight;
} }
auto result = initWindow(); auto result = initWindow();
@ -81,32 +80,32 @@ namespace xna {
bool GraphicsDeviceManager::initWindow() bool GraphicsDeviceManager::initWindow()
{ {
auto window = _information.Window(); auto window = _information.Window;
if (!window) { if (!window) {
window = _game->Window(); window = _game->Window();
_information.Window(window); _information.Window = window;
} }
window->Size(_backBufferWidth, _backBufferHeight); window->impl->Size(_backBufferWidth, _backBufferHeight);
if (!window->Create()) { if (!window->impl->Create()) {
MessageBox(nullptr, "Falha na criação da janela", "XN65", MB_OK); MessageBox(nullptr, "Falha na criação da janela", "XN65", MB_OK);
return false; return false;
} }
_information._parameters.DeviceWindowHandle = reinterpret_cast<intptr_t>(window->WindowHandle()); _information.Parameters->DeviceWindowHandle = reinterpret_cast<intptr_t>(window->impl->WindowHandle());
return true; return true;
} }
bool GraphicsDeviceManager::initDevice() bool GraphicsDeviceManager::initDevice()
{ {
auto window = _information.Window(); auto window = _information.Window;
_device = New<GraphicsDevice>(_information); _device = New<GraphicsDevice>(_information);
if (!_device->Initialize(*window)) { if (!_device->Initialize(*window)) {
MessageBox(window->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK); MessageBox(window->impl->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK);
_device = nullptr; _device = nullptr;
return false; return false;
} }

View File

@ -59,23 +59,23 @@ namespace xna {
const auto parameters = m_device->_presentationParameters; const auto parameters = m_device->_presentationParameters;
impl->dxDescription.Width = static_cast<UINT>(parameters.BackBufferWidth); impl->dxDescription.Width = static_cast<UINT>(parameters->BackBufferWidth);
impl->dxDescription.Height = static_cast<UINT>(parameters.BackBufferHeight); impl->dxDescription.Height = static_cast<UINT>(parameters->BackBufferHeight);
impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(parameters.BackBufferFormat); impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(parameters->BackBufferFormat);
impl->dxDescription.SampleDesc.Count = 1; impl->dxDescription.SampleDesc.Count = 1;
impl->dxDescription.SampleDesc.Quality = 0; impl->dxDescription.SampleDesc.Quality = 0;
impl->dxDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; impl->dxDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
impl->dxDescription.BufferCount = 2; impl->dxDescription.BufferCount = 2;
impl->dxDescription.SwapEffect = static_cast<DXGI_SWAP_EFFECT>(parameters.PresentationSwapEffect); impl->dxDescription.SwapEffect = static_cast<DXGI_SWAP_EFFECT>(parameters->PresentationSwapEffect);
impl->dxDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; impl->dxDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
impl->dxDescription.AlphaMode = DXGI_ALPHA_MODE::DXGI_ALPHA_MODE_UNSPECIFIED; impl->dxDescription.AlphaMode = DXGI_ALPHA_MODE::DXGI_ALPHA_MODE_UNSPECIFIED;
impl->dxFullScreenDescription.RefreshRate.Numerator = 60; impl->dxFullScreenDescription.RefreshRate.Numerator = 60;
impl->dxFullScreenDescription.RefreshRate.Denominator = 1; impl->dxFullScreenDescription.RefreshRate.Denominator = 1;
impl->dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; impl->dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
impl->dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; impl->dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
impl->dxFullScreenDescription.Windowed = !parameters.Fullscreen; impl->dxFullScreenDescription.Windowed = !parameters->Fullscreen;
HWND hwnd = reinterpret_cast<HWND>(parameters.DeviceWindowHandle); HWND hwnd = reinterpret_cast<HWND>(parameters->DeviceWindowHandle);
return internalInit(*m_device, hwnd, impl->dxSwapChain, impl->dxDescription, impl->dxFullScreenDescription); return internalInit(*m_device, hwnd, impl->dxSwapChain, impl->dxDescription, impl->dxFullScreenDescription);
} }

View File

@ -1,19 +1,23 @@
#include "platform-dx/window-dx.hpp"
#include "input/gamepad.hpp"
#include "platform-dx/implementations.hpp" #include "platform-dx/implementations.hpp"
namespace xna { namespace xna {
GameWindow::GameWindow() { GameWindow::GameWindow() {
_hInstance = GetModuleHandle(NULL); impl = unew<PlatformImplementation>();
_windowIcon = LoadIcon(NULL, IDI_APPLICATION);
_windowCursor = LoadCursor(NULL, IDC_ARROW); impl->_hInstance = GetModuleHandle(NULL);
_windowStyle = static_cast<int>(GameWindowMode::Windowed); impl->_windowIcon = LoadIcon(NULL, IDI_APPLICATION);
_windowCenterX = _windowWidth / 2.0F; impl->_windowCursor = LoadCursor(NULL, IDC_ARROW);
_windowCenterY = _windowHeight / 2.0F; impl->_windowStyle = static_cast<int>(GameWindowMode::Windowed);
impl->_windowCenterX = impl->_windowWidth / 2.0F;
impl->_windowCenterY = impl->_windowHeight / 2.0F;
} }
void GameWindow::Position(int width, int height, bool update) { GameWindow::~GameWindow() {
impl = nullptr;
}
void GameWindow::PlatformImplementation::Position(int width, int height, bool update) {
_windowPosX = width; _windowPosX = width;
_windowPosY = height; _windowPosY = height;
setCenter(); setCenter();
@ -21,7 +25,7 @@ namespace xna {
if(update) Update(); if(update) Update();
} }
void GameWindow::Size(int width, int height, bool update) { void GameWindow::PlatformImplementation::Size(int width, int height, bool update) {
_windowWidth = width; _windowWidth = width;
_windowHeight = height; _windowHeight = height;
setPosition(); setPosition();
@ -31,10 +35,12 @@ namespace xna {
} }
void GameWindow::Title(String const& title) { void GameWindow::Title(String const& title) {
_windowTitle = title; if (!impl) return;
impl->_windowTitle = title;
} }
bool GameWindow::Create() { bool GameWindow::PlatformImplementation::Create() {
WNDCLASSEX wndClass{}; WNDCLASSEX wndClass{};
wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wndClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
@ -89,7 +95,7 @@ namespace xna {
return true; return true;
} }
bool GameWindow::Update() { bool GameWindow::PlatformImplementation::Update() {
if (_windowStyle == static_cast<int>(GameWindowMode::Windowed)) { if (_windowStyle == static_cast<int>(GameWindowMode::Windowed)) {
RECT winRect = { 0, 0, _windowWidth, _windowHeight }; RECT winRect = { 0, 0, _windowWidth, _windowHeight };
@ -116,23 +122,29 @@ namespace xna {
} }
String GameWindow::Title() const { String GameWindow::Title() const {
return _windowTitle; if (!impl) return String();
return impl->_windowTitle;
} }
Rectangle GameWindow::ClientBounds() const { Rectangle GameWindow::ClientBounds() const {
if (!impl) return {};
return Rectangle( return Rectangle(
_windowPosX, impl->_windowPosX,
_windowPosY, impl->_windowPosY,
_windowWidth, impl->_windowWidth,
_windowHeight impl->_windowHeight
); );
} }
intptr_t GameWindow::Handle() const { intptr_t GameWindow::Handle() const {
return reinterpret_cast<intptr_t>(_windowHandle); if (!impl) return 0;
return reinterpret_cast<intptr_t>(impl->_windowHandle);
} }
LRESULT GameWindow::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT GameWindow::PlatformImplementation::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
switch (msg) { switch (msg) {
case WM_DESTROY: case WM_DESTROY:
@ -140,18 +152,18 @@ namespace xna {
return 0; return 0;
case WM_ACTIVATE: case WM_ACTIVATE:
case WM_ACTIVATEAPP: case WM_ACTIVATEAPP:
Keyboard::impl->ProcessMessage(msg, wParam, lParam); if(Keyboard::impl) Keyboard::impl->ProcessMessage(msg, wParam, lParam);
Mouse::impl->ProcessMessage(msg, wParam, lParam); if(Mouse::impl) Mouse::impl->ProcessMessage(msg, wParam, lParam);
break; break;
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) { if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) {
Keyboard::impl->ProcessMessage(msg, wParam, lParam); if (Keyboard::impl) Keyboard::impl->ProcessMessage(msg, wParam, lParam);
} }
break; break;
case WM_KEYDOWN: case WM_KEYDOWN:
case WM_KEYUP: case WM_KEYUP:
case WM_SYSKEYUP: case WM_SYSKEYUP:
Keyboard::impl->ProcessMessage(msg, wParam, lParam); if (Keyboard::impl) Keyboard::impl->ProcessMessage(msg, wParam, lParam);
break; break;
case WM_INPUT: case WM_INPUT:
@ -166,13 +178,13 @@ namespace xna {
case WM_XBUTTONDOWN: case WM_XBUTTONDOWN:
case WM_XBUTTONUP: case WM_XBUTTONUP:
case WM_MOUSEHOVER: case WM_MOUSEHOVER:
Mouse::impl->ProcessMessage(msg, wParam, lParam); if (Mouse::impl) Mouse::impl->ProcessMessage(msg, wParam, lParam);
break; break;
case WM_KILLFOCUS: case WM_KILLFOCUS:
GamePad::impl->Suspend(); if (GamePad::impl) GamePad::impl->Suspend();
break; break;
case WM_SETFOCUS: case WM_SETFOCUS:
GamePad::impl->Resume(); if (GamePad::impl) GamePad::impl->Resume();
break; break;
} }
return DefWindowProc(hWnd, msg, wParam, lParam); return DefWindowProc(hWnd, msg, wParam, lParam);

View File

@ -1,21 +1,15 @@
#ifndef XNA_GAME_GDEVICEINFO_HPP #ifndef XNA_GAME_GDEVICEINFO_HPP
#define XNA_GAME_GDEVICEINFO_HPP #define XNA_GAME_GDEVICEINFO_HPP
#include "../forward.hpp" #include "../default.hpp"
#include "../enums.hpp"
namespace xna { namespace xna {
class IGraphicsDeviceInformation { class GraphicsDeviceInformation {
public: public:
virtual ~IGraphicsDeviceInformation(){} sptr<GraphicsAdapter> Adapter = nullptr;
virtual sptr<GraphicsAdapter> Adapter() const = 0; xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach };
virtual void Adapter(sptr<GraphicsAdapter> const& value) = 0; sptr<xna::PresentationParameters> Parameters = nullptr;
virtual xna::PresentationParameters PresentationParameters() const = 0; sptr<GameWindow> Window = nullptr;
virtual void PresentationParameters(xna::PresentationParameters const& value) = 0;
virtual xna::GraphicsProfile GraphicsProfile() const = 0;
virtual void GraphicsProfile(xna::GraphicsProfile value) = 0;
virtual sptr<GameWindow> Window() const = 0;
virtual void Window(sptr<GameWindow> const& window) = 0;
}; };
} }

View File

@ -1,18 +1,22 @@
#ifndef XNA_GAME_WINDOW_HPP #ifndef XNA_GAME_WINDOW_HPP
#define XNA_GAME_WINDOW_HPP #define XNA_GAME_WINDOW_HPP
#include "../enums.hpp" #include "../default.hpp"
#include "../common/numerics.hpp" #include "../common/numerics.hpp"
namespace xna { namespace xna {
class IGameWindow { class GameWindow {
public: public:
virtual ~IGameWindow(){} GameWindow();
~GameWindow();
String Title() const;
void Title(String const& title);
Rectangle ClientBounds() const;
intptr_t Handle() const;
virtual String Title() const = 0; public:
virtual void Title(String const& title) = 0; struct PlatformImplementation;
virtual Rectangle ClientBounds() const = 0; uptr<PlatformImplementation> impl = nullptr;
virtual intptr_t Handle() const = 0;
}; };
} }

View File

@ -153,7 +153,7 @@ namespace xna {
bool Connected{ false }; bool Connected{ false };
Ushort Vid{ 0 }; Ushort Vid{ 0 };
Ushort Pid{ 0 }; Ushort Pid{ 0 };
GamePadId Id; GamePadId Id{};
}; };
struct GamePadState { struct GamePadState {

View File

@ -6,9 +6,7 @@
#include "../graphics/presentparams.hpp" #include "../graphics/presentparams.hpp"
#include "../graphics/viewport.hpp" #include "../graphics/viewport.hpp"
#include "dxheaders.hpp" #include "dxheaders.hpp"
#include "gdeviceinfo-dx.hpp" #include "game/gdeviceinfo.hpp"
#include "window-dx.hpp"
#include "graphics/presentparams.hpp"
namespace xna { namespace xna {
class GraphicsDevice : public IGraphicsDevice, public std::enable_shared_from_this<GraphicsDevice> { class GraphicsDevice : public IGraphicsDevice, public std::enable_shared_from_this<GraphicsDevice> {
@ -77,7 +75,7 @@ namespace xna {
sptr<RenderTarget2D> _renderTarget2D{ nullptr }; sptr<RenderTarget2D> _renderTarget2D{ nullptr };
sptr<BlendState> _blendState{ nullptr }; sptr<BlendState> _blendState{ nullptr };
xna::Viewport _viewport{}; xna::Viewport _viewport{};
xna::PresentationParameters _presentationParameters; sptr<xna::PresentationParameters> _presentationParameters;
private: private:
unsigned int _createDeviceFlags{ 0 }; unsigned int _createDeviceFlags{ 0 };

View File

@ -30,6 +30,7 @@
//Windows //Windows
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
#include <windowsx.h>
#include <Windows.Foundation.h> #include <Windows.Foundation.h>
#include <wrl\wrappers\corewrappers.h> #include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h> #include <wrl\client.h>

View File

@ -1,53 +0,0 @@
#ifndef XNA_PLATFORM_GDEVICEINFOR_DX_HPP
#define XNA_PLATFORM_GDEVICEINFOR_DX_HPP
#include "../game/gdeviceinfo.hpp"
#include "window-dx.hpp"
#include "graphics/presentparams.hpp"
namespace xna {
class GraphicsDeviceInformation : public IGraphicsDeviceInformation {
public:
virtual ~GraphicsDeviceInformation() override {}
inline virtual sptr<GraphicsAdapter> Adapter() const override {
return _adapter;
};
inline virtual void Adapter(sptr<GraphicsAdapter> const& value) override {
_adapter = value;
}
virtual xna::PresentationParameters PresentationParameters() const override{
return _parameters;
};
virtual void PresentationParameters(xna::PresentationParameters const& value) override{
_parameters = value;
};
virtual xna::GraphicsProfile GraphicsProfile() const override {
return _profile;
};
virtual void GraphicsProfile(xna::GraphicsProfile value) override {
_profile = value;
};
inline virtual sptr<GameWindow> Window() const override {
return _window;
}
inline virtual void Window(sptr<GameWindow> const& window) override {
_window = window;
}
public:
sptr<GraphicsAdapter> _adapter{ nullptr };
xna::GraphicsProfile _profile{xna::GraphicsProfile::Reach};
xna::PresentationParameters _parameters{};
sptr<GameWindow> _window{ nullptr };
};
}
#endif

View File

@ -2,7 +2,7 @@
#define XNA_PLATFORM_GDEVICEMANAGER_DX_HPP #define XNA_PLATFORM_GDEVICEMANAGER_DX_HPP
#include "../game/gdevicemanager.hpp" #include "../game/gdevicemanager.hpp"
#include "gdeviceinfo-dx.hpp" #include "game/gdeviceinfo.hpp"
namespace xna { namespace xna {
class GraphicsDeviceManager : public IGraphicsDeviceManager { class GraphicsDeviceManager : public IGraphicsDeviceManager {

View File

@ -2,11 +2,11 @@
#define XNA_PLATFORM_DX_IMPLEMENTATIONS_HPP #define XNA_PLATFORM_DX_IMPLEMENTATIONS_HPP
#include "dxheaders.hpp" #include "dxheaders.hpp"
#include "platform-dx/device-dx.hpp"
#include "graphics/adapter.hpp" #include "graphics/adapter.hpp"
#include "graphics/blendstate.hpp" #include "graphics/blendstate.hpp"
#include "graphics/buffer.hpp" #include "graphics/buffer.hpp"
#include "graphics/depthstencilstate.hpp" #include "graphics/depthstencilstate.hpp"
#include "graphics/device.hpp"
#include "graphics/displaymode.hpp" #include "graphics/displaymode.hpp"
#include "graphics/sprite.hpp" #include "graphics/sprite.hpp"
#include "graphics/samplerstate.hpp" #include "graphics/samplerstate.hpp"
@ -19,7 +19,7 @@
#include "graphics/swapchain.hpp" #include "graphics/swapchain.hpp"
#include "graphics/texture.hpp" #include "graphics/texture.hpp"
#include "graphics/rendertarget.hpp" #include "graphics/rendertarget.hpp"
#include "device-dx.hpp" #include "game/window.hpp"
namespace xna { namespace xna {
struct SpriteFont::PlatformImplementation { struct SpriteFont::PlatformImplementation {
@ -345,6 +345,118 @@ namespace xna {
ID3D11InputLayout* _inputLayout{ nullptr }; ID3D11InputLayout* _inputLayout{ nullptr };
std::vector<D3D11_INPUT_ELEMENT_DESC> _description{}; std::vector<D3D11_INPUT_ELEMENT_DESC> _description{};
}; };
enum class GameWindowMode : UINT {
Fullscreen = WS_POPUP | WS_VISIBLE,
Windowed = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE,
Borderless = WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE,
};
struct GameWindow::PlatformImplementation {
public:
constexpr void Mode(GameWindowMode mode) {
_windowStyle = static_cast<int>(mode);
}
constexpr GameWindowMode Mode() const {
return static_cast<GameWindowMode>(_windowStyle);
}
void Position(int width, int height, bool update = true);
void Size(int width, int height, bool update = true);
inline HINSTANCE HInstance() const {
return _hInstance;
}
inline HWND WindowHandle() const {
return _windowHandle;
}
constexpr int Width() const {
return _windowWidth;
}
constexpr int Height() const {
return _windowHeight;
}
inline void Icon(unsigned int icon) {
_windowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon));
}
inline void Icon(HICON icon) {
_windowIcon = icon;
}
inline void Cursor(unsigned int cursor) {
_windowCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(cursor));
}
inline void Cursor(HCURSOR cursor) {
_windowCursor = cursor;
}
constexpr float CenterX() const {
return _windowCenterX;
}
constexpr float CenterY() const {
return _windowCenterY;
}
inline void CursorVisibility(bool visible) const {
ShowCursor(visible);
}
inline void Close() {
PostMessage(_windowHandle, WM_DESTROY, 0, 0);
}
constexpr COLORREF Color() const {
return _windowColor;
}
constexpr void Color(COLORREF color) {
_windowColor = color;
}
constexpr void Color(BYTE r, BYTE g, BYTE b) {
_windowColor = RGB(r, g, b);
}
bool Create();
bool Update();
static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
private:
friend class GameWindow;
HINSTANCE _hInstance{ nullptr };
HWND _windowHandle{ nullptr };
int _windowWidth{ 800 };
int _windowHeight{ 600 };
HICON _windowIcon{ nullptr };
HCURSOR _windowCursor{ nullptr };
COLORREF _windowColor{ RGB(0,0,0) };
String _windowTitle{ "Xna++ Game Development" };
DWORD _windowStyle{ 0 };
int _windowPosX{ 0 };
int _windowPosY{ 0 };
float _windowCenterX{ 0 };
float _windowCenterY{ 0 };
inline void setPosition() {
_windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - _windowWidth / 2;
_windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - _windowHeight / 2;
}
inline void setCenter() {
_windowCenterX = _windowWidth / 2.0f;
_windowCenterY = _windowHeight / 2.0f;
}
};
} }
#endif #endif

View File

@ -1,129 +0,0 @@
#ifndef XNA_PLATFORM_WINDOW_DX_HPP
#define XNA_PLATFORM_WINDOW_DX_HPP
#include "../game/window.hpp"
#include <Windows.h>
#include <windowsx.h>
namespace xna {
enum class GameWindowMode : UINT {
Fullscreen = WS_POPUP | WS_VISIBLE,
Windowed = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE,
Borderless = WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE,
};
class GameWindow : public IGameWindow {
public:
GameWindow();
constexpr void Mode(GameWindowMode mode) {
_windowStyle = static_cast<int>(mode);
}
constexpr GameWindowMode Mode() const {
return static_cast<GameWindowMode>(_windowStyle);
}
void Position(int width, int height, bool update = true);
void Size(int width, int height, bool update = true);
inline HINSTANCE HInstance() const {
return _hInstance;
}
inline HWND WindowHandle() const {
return _windowHandle;
}
inline int Width() const {
return _windowWidth;
}
inline int Height() const {
return _windowHeight;
}
inline void Icon(unsigned int icon) {
_windowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon));
}
inline void Icon(HICON icon) {
_windowIcon = icon;
}
inline void Cursor(unsigned int cursor) {
_windowCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(cursor));
}
inline void Cursor(HCURSOR cursor) {
_windowCursor = cursor;
}
inline float CenterX() const {
return _windowCenterX;
}
inline float CenterY() const {
return _windowCenterY;
}
inline void CursorVisibility(bool visible) const {
ShowCursor(visible);
}
inline void Close() {
PostMessage(_windowHandle, WM_DESTROY, 0, 0);
}
inline COLORREF Color() const {
return _windowColor;
}
inline void Color(COLORREF color) {
_windowColor = color;
}
inline void Color(BYTE r, BYTE g, BYTE b) {
_windowColor = RGB(r, g, b);
}
bool Create();
bool Update();
static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
virtual String Title() const override;
virtual void Title(String const& title) override;
virtual Rectangle ClientBounds() const override;
virtual intptr_t Handle() const override;
private:
HINSTANCE _hInstance{ nullptr };
HWND _windowHandle{ nullptr };
int _windowWidth{ 800 };
int _windowHeight{ 600 };
HICON _windowIcon{ nullptr };
HCURSOR _windowCursor{ nullptr };
COLORREF _windowColor{ RGB(0,0,0) };
String _windowTitle{ "Xna++ Game Development" };
DWORD _windowStyle{ 0 };
int _windowPosX{ 0 };
int _windowPosY{ 0 };
float _windowCenterX{ 0 };
float _windowCenterY{ 0 };
private:
inline void setPosition() {
_windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - _windowWidth / 2;
_windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - _windowHeight / 2;
}
inline void setCenter() {
_windowCenterX = _windowWidth / 2.0f;
_windowCenterY = _windowHeight / 2.0f;
}
};
}
#endif

View File

@ -4,9 +4,7 @@
#include "dx/StepTimer.hpp" #include "dx/StepTimer.hpp"
#include "dxheaders.hpp" #include "dxheaders.hpp"
#include "game-dx.hpp" #include "game-dx.hpp"
#include "gdeviceinfo-dx.hpp"
#include "gdevicemanager-dx.hpp" #include "gdevicemanager-dx.hpp"
#include "init-dx.hpp" #include "init-dx.hpp"
#include "soundeffect-dx.hpp" #include "soundeffect-dx.hpp"
#include "window-dx.hpp"
#include "implementations.hpp" #include "implementations.hpp"