mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
commit
fbd9043c38
@ -15,4 +15,12 @@ namespace xna {
|
|||||||
? services[hashCode]
|
? services[hashCode]
|
||||||
: std::any();
|
: std::any();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameServiceContainer::RemoveService(Type& type) {
|
||||||
|
auto hashCode = type.GetHashCode();
|
||||||
|
|
||||||
|
if (services.contains(hashCode))
|
||||||
|
services.erase(hashCode);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -122,7 +122,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!impl->dxBlendState) {
|
if (!impl->dxBlendState) {
|
||||||
Exception::Throw(Exception::INVALID_OPERATION);
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_device->impl->_context->OMSetBlendState(
|
m_device->impl->_context->OMSetBlendState(
|
||||||
|
@ -63,7 +63,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!impl->dxDepthStencil) {
|
if (!impl->dxDepthStencil) {
|
||||||
Exception::Throw(Exception::INVALID_OPERATION);
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil.Get(), 0);
|
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil.Get(), 0);
|
||||||
|
@ -1,8 +1,167 @@
|
|||||||
#include "xna/xna-dx.hpp"
|
#include "xna/xna-dx.hpp"
|
||||||
#include "xna/game/gdevicemanager.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
static void reset(GraphicsDevice::PlatformImplementation& impl)
|
static void reset(GraphicsDevice::PlatformImplementation& impl);
|
||||||
|
static void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter);
|
||||||
|
static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState,
|
||||||
|
P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device);
|
||||||
|
|
||||||
|
GraphicsDevice::GraphicsDevice() {
|
||||||
|
impl = unew<PlatformImplementation>();
|
||||||
|
adapter = GraphicsAdapter::DefaultAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsDevice::GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters)
|
||||||
|
: adapter(adapter), graphicsProfile(graphicsProfile), presentationParameters(presentationParameters) {
|
||||||
|
impl = unew<PlatformImplementation>();
|
||||||
|
|
||||||
|
blendState = xna::BlendState::Opaque();
|
||||||
|
depthStencilState = xna::DepthStencilState::Default();
|
||||||
|
rasterizerState = xna::RasterizerState::CullCounterClockwise();
|
||||||
|
samplerStateCollection = snew<SamplerStateCollection>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::Initialize() {
|
||||||
|
auto _this = shared_from_this();
|
||||||
|
|
||||||
|
reset(*impl);
|
||||||
|
createDevice(*impl, *adapter);
|
||||||
|
|
||||||
|
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory);
|
||||||
|
|
||||||
|
if FAILED(hr)
|
||||||
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
|
|
||||||
|
viewport = xna::Viewport(0.0F, 0.0F,
|
||||||
|
presentationParameters->BackBufferWidth,
|
||||||
|
presentationParameters->BackBufferHeight,
|
||||||
|
0.0F, 1.F);
|
||||||
|
|
||||||
|
const auto backColor = Colors::CornflowerBlue;
|
||||||
|
const auto backColorV3 = backColor.ToVector3();
|
||||||
|
|
||||||
|
impl->_backgroundColor[0] = backColorV3.X;
|
||||||
|
impl->_backgroundColor[1] = backColorV3.Y;
|
||||||
|
impl->_backgroundColor[2] = backColorV3.Z;
|
||||||
|
impl->_backgroundColor[3] = 1.0f;
|
||||||
|
|
||||||
|
impl->_swapChain = snew<xna::SwapChain>(_this);
|
||||||
|
impl->_swapChain->Initialize();
|
||||||
|
|
||||||
|
auto hwnd = reinterpret_cast<HWND>(presentationParameters->DeviceWindowHandle);
|
||||||
|
hr = impl->_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION);
|
||||||
|
|
||||||
|
impl->_renderTarget2D = snew<RenderTarget2D>(_this);
|
||||||
|
impl->_renderTarget2D->Initialize();
|
||||||
|
impl->_renderTarget2D->Apply();
|
||||||
|
|
||||||
|
D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport);
|
||||||
|
impl->_context->RSSetViewports(1, &view);
|
||||||
|
|
||||||
|
initAndApplyState(blendState, rasterizerState, depthStencilState, samplerStateCollection, _this);
|
||||||
|
|
||||||
|
const auto currentPresenInterval = presentationParameters->PresentationInterval;
|
||||||
|
|
||||||
|
switch (currentPresenInterval)
|
||||||
|
{
|
||||||
|
case PresentInterval::Default:
|
||||||
|
case PresentInterval::One:
|
||||||
|
case PresentInterval::Two:
|
||||||
|
impl->vSyncValue = 1;
|
||||||
|
break;
|
||||||
|
case PresentInterval::Immediate:
|
||||||
|
impl->vSyncValue = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
impl->vSyncValue = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GraphicsDevice::Present() const {
|
||||||
|
const auto currentPresenInterval = presentationParameters->PresentationInterval;
|
||||||
|
bool result = impl->_swapChain->Present(impl->vSyncValue != 0);
|
||||||
|
|
||||||
|
impl->_context->OMSetRenderTargets(
|
||||||
|
1,
|
||||||
|
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(),
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::Clear(Color const& color) const {
|
||||||
|
if (!impl) return;
|
||||||
|
|
||||||
|
const auto v4 = color.ToVector4();
|
||||||
|
|
||||||
|
impl->_backgroundColor[0] = v4.X;
|
||||||
|
impl->_backgroundColor[1] = v4.Y;
|
||||||
|
impl->_backgroundColor[2] = v4.Z;
|
||||||
|
impl->_backgroundColor[3] = v4.W;
|
||||||
|
|
||||||
|
impl->_context->ClearRenderTargetView(
|
||||||
|
impl->_renderTarget2D->render_impl->_renderTargetView.Get(),
|
||||||
|
impl->_backgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::Clear(ClearOptions options, Color const& color, float depth, Int stencil) const {
|
||||||
|
if (!impl) return;
|
||||||
|
|
||||||
|
switch (options)
|
||||||
|
{
|
||||||
|
case xna::ClearOptions::DepthBuffer:
|
||||||
|
Exception::Throw(Exception::NOT_IMPLEMENTED);
|
||||||
|
break;
|
||||||
|
case xna::ClearOptions::Stencil:
|
||||||
|
Exception::Throw(Exception::NOT_IMPLEMENTED);
|
||||||
|
break;
|
||||||
|
case xna::ClearOptions::Target:
|
||||||
|
Clear(color);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::Viewport(xna::Viewport const& value) {
|
||||||
|
viewport = value;
|
||||||
|
const auto view = DxHelpers::ViewportToDx(viewport);
|
||||||
|
|
||||||
|
impl->_context->RSSetViewports(1, &view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::BlendState(sptr<xna::BlendState> const& value) {
|
||||||
|
blendState = value;
|
||||||
|
blendState->Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::DepthStencilState(sptr<xna::DepthStencilState> const& value) {
|
||||||
|
depthStencilState = value;
|
||||||
|
depthStencilState->Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::RasterizerState(sptr<xna::RasterizerState> const& value) {
|
||||||
|
rasterizerState = value;
|
||||||
|
rasterizerState->Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::Reset(sptr<PresentationParameters> const& parameters, sptr<GraphicsAdapter> const& graphicsAdapter){
|
||||||
|
impl = unew<PlatformImplementation>();
|
||||||
|
adapter = graphicsAdapter;
|
||||||
|
presentationParameters = parameters;
|
||||||
|
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// INTERNAL
|
||||||
|
//
|
||||||
|
|
||||||
|
void reset(GraphicsDevice::PlatformImplementation& impl)
|
||||||
{
|
{
|
||||||
if (impl._device) {
|
if (impl._device) {
|
||||||
impl._device->Release();
|
impl._device->Release();
|
||||||
@ -20,7 +179,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createDevice(GraphicsDevice::PlatformImplementation& impl) {
|
void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter) {
|
||||||
//
|
//
|
||||||
// See ref
|
// See ref
|
||||||
//
|
//
|
||||||
@ -34,11 +193,10 @@ namespace xna {
|
|||||||
auto createDeviceFlags = 0;
|
auto createDeviceFlags = 0;
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
|
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const auto& pAdapter = GraphicsAdapter::UseNullDevice() ? NULL : currentAdapter.impl->dxAdapter.Get();
|
||||||
|
|
||||||
const auto& currentAdapter = impl._adapter;
|
|
||||||
const auto& pAdapter = GraphicsAdapter::UseNullDevice() ? NULL : currentAdapter->impl->dxAdapter.Get();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// if pAdapter is not NULL driverType must be D3D_DRIVER_TYPE_UNKNOWN
|
// if pAdapter is not NULL driverType must be D3D_DRIVER_TYPE_UNKNOWN
|
||||||
//
|
//
|
||||||
@ -75,220 +233,19 @@ namespace xna {
|
|||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initAndApplyState(GraphicsDevice::PlatformImplementation& impl, PGraphicsDevice const& device) {
|
static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState, P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device) {
|
||||||
impl._blendState->Bind(device);
|
blendState->Bind(device);
|
||||||
impl._blendState->Initialize();
|
blendState->Initialize();
|
||||||
impl._blendState->Apply();
|
blendState->Apply();
|
||||||
|
|
||||||
impl._rasterizerState->Bind(device);
|
rasterizerState->Bind(device);
|
||||||
impl._rasterizerState->Initialize();
|
rasterizerState->Initialize();
|
||||||
impl._rasterizerState->Apply();
|
rasterizerState->Apply();
|
||||||
|
|
||||||
impl._depthStencilState->Bind(device);
|
depthStencilState->Bind(device);
|
||||||
impl._depthStencilState->Initialize();
|
depthStencilState->Initialize();
|
||||||
impl._depthStencilState->Apply();
|
depthStencilState->Apply();
|
||||||
|
|
||||||
impl._samplerStates->Apply(*device);
|
samplerStates->Apply(*device);
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsDevice::GraphicsDevice() {
|
|
||||||
impl = unew<PlatformImplementation>();
|
|
||||||
impl->_adapter = GraphicsAdapter::DefaultAdapter();
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) {
|
|
||||||
impl = unew<PlatformImplementation>();
|
|
||||||
|
|
||||||
impl->_adapter = info.Adapter;
|
|
||||||
impl->_presentationParameters = info.PresentParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsDevice::GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters) {
|
|
||||||
impl = unew<PlatformImplementation>();
|
|
||||||
impl->_adapter = adapter;
|
|
||||||
impl->_presentationParameters = presentationParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GraphicsDevice::Initialize() {
|
|
||||||
auto _this = shared_from_this();
|
|
||||||
|
|
||||||
if (!impl)
|
|
||||||
impl = uptr<PlatformImplementation>();
|
|
||||||
|
|
||||||
reset(*impl);
|
|
||||||
|
|
||||||
createDevice(*impl);
|
|
||||||
|
|
||||||
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory);
|
|
||||||
|
|
||||||
if FAILED(hr)
|
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
|
||||||
|
|
||||||
//const auto bounds = impl->_gameWindow->ClientBounds();
|
|
||||||
|
|
||||||
impl->_viewport = xna::Viewport(0.0F, 0.0F,
|
|
||||||
impl->_presentationParameters->BackBufferWidth,
|
|
||||||
impl->_presentationParameters->BackBufferHeight,
|
|
||||||
0.0F, 1.F);
|
|
||||||
|
|
||||||
//COLORREF color = impl->_gameWindow->impl->Color();
|
|
||||||
const auto backColor = Colors::CornflowerBlue;
|
|
||||||
const auto backColorV3 = backColor.ToVector3();
|
|
||||||
|
|
||||||
impl->_backgroundColor[0] = backColorV3.X;
|
|
||||||
impl->_backgroundColor[1] = backColorV3.Y;
|
|
||||||
impl->_backgroundColor[2] = backColorV3.Z;
|
|
||||||
impl->_backgroundColor[3] = 1.0f;
|
|
||||||
|
|
||||||
impl->_swapChain = snew<xna::SwapChain>(_this);
|
|
||||||
impl->_swapChain->Initialize();
|
|
||||||
|
|
||||||
auto hwnd = reinterpret_cast<HWND>(impl->_presentationParameters->DeviceWindowHandle);
|
|
||||||
hr = impl->_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
|
||||||
|
|
||||||
if (FAILED(hr))
|
|
||||||
Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION);
|
|
||||||
|
|
||||||
impl->_renderTarget2D = snew<RenderTarget2D>(_this);
|
|
||||||
|
|
||||||
if (!impl->_renderTarget2D->Initialize())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
impl->_renderTarget2D->Apply();
|
|
||||||
|
|
||||||
D3D11_VIEWPORT view{};
|
|
||||||
view.TopLeftX = impl->_viewport.X;
|
|
||||||
view.TopLeftY = impl->_viewport.Y;
|
|
||||||
view.Width = impl->_viewport.Width;
|
|
||||||
view.Height = impl->_viewport.Height;
|
|
||||||
view.MinDepth = impl->_viewport.MinDetph;
|
|
||||||
view.MaxDepth = impl->_viewport.MaxDepth;
|
|
||||||
|
|
||||||
impl->_context->RSSetViewports(1, &view);
|
|
||||||
|
|
||||||
initAndApplyState(*impl, _this);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GraphicsDevice::Present() {
|
|
||||||
if (!impl) return false;
|
|
||||||
|
|
||||||
const auto result = impl->_swapChain->Present(impl->_usevsync);
|
|
||||||
impl->_context->OMSetRenderTargets(
|
|
||||||
1,
|
|
||||||
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(),
|
|
||||||
nullptr);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::Clear(Color const& color) {
|
|
||||||
if (!impl) return;
|
|
||||||
|
|
||||||
const auto v4 = color.ToVector4();
|
|
||||||
|
|
||||||
impl->_backgroundColor[0] = v4.X;
|
|
||||||
impl->_backgroundColor[1] = v4.Y;
|
|
||||||
impl->_backgroundColor[2] = v4.Z;
|
|
||||||
impl->_backgroundColor[3] = v4.W;
|
|
||||||
|
|
||||||
impl->_context->ClearRenderTargetView(
|
|
||||||
impl->_renderTarget2D->render_impl->_renderTargetView.Get(),
|
|
||||||
impl->_backgroundColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::Clear(ClearOptions options, Color const& color, float depth, Int stencil) {
|
|
||||||
if (!impl) return;
|
|
||||||
|
|
||||||
switch (options)
|
|
||||||
{
|
|
||||||
case xna::ClearOptions::DepthBuffer:
|
|
||||||
Exception::Throw(Exception::NOT_IMPLEMENTED);
|
|
||||||
break;
|
|
||||||
case xna::ClearOptions::Stencil:
|
|
||||||
Exception::Throw(Exception::NOT_IMPLEMENTED);
|
|
||||||
break;
|
|
||||||
case xna::ClearOptions::Target:
|
|
||||||
Clear(color);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil) {
|
|
||||||
if (!impl) return;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<GraphicsAdapter> GraphicsDevice::Adapter() const {
|
|
||||||
if (!impl) return nullptr;
|
|
||||||
|
|
||||||
return impl->_adapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
xna::Viewport GraphicsDevice::Viewport() const {
|
|
||||||
if (!impl) return {};
|
|
||||||
|
|
||||||
return impl->_viewport;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::Viewport(xna::Viewport const& viewport) {
|
|
||||||
if (!impl) return;
|
|
||||||
|
|
||||||
impl->_viewport = viewport;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::UseVSync(bool use) {
|
|
||||||
if (!impl) return;
|
|
||||||
|
|
||||||
impl->_usevsync = use;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sptr<xna::BlendState> GraphicsDevice::BlendState() const {
|
|
||||||
return impl->_blendState;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::BlendState(sptr<xna::BlendState> const& value) {
|
|
||||||
impl->_blendState = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<xna::DepthStencilState> GraphicsDevice::DepthStencilState() const {
|
|
||||||
return impl->_depthStencilState;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::DepthStencilState(sptr<xna::DepthStencilState> const& value) {
|
|
||||||
impl->_depthStencilState = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<xna::RasterizerState> GraphicsDevice::RasterizerState() const {
|
|
||||||
return impl->_rasterizerState;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::RasterizerState(sptr<xna::RasterizerState> const& value) {
|
|
||||||
impl->_rasterizerState = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
sptr<SamplerStateCollection> GraphicsDevice::SamplerStates() const {
|
|
||||||
return impl->_samplerStates;
|
|
||||||
}
|
|
||||||
|
|
||||||
Int GraphicsDevice::MultiSampleMask() const {
|
|
||||||
return impl->_multiSampleMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::MultiSampleMask(Int value) {
|
|
||||||
impl->_multiSampleMask = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDevice::Reset(sptr<PresentationParameters> const& presentationParameters, sptr<GraphicsAdapter> const& graphicsAdapter){
|
|
||||||
impl = unew<PlatformImplementation>();
|
|
||||||
impl->_adapter = graphicsAdapter;
|
|
||||||
impl->_presentationParameters = presentationParameters;
|
|
||||||
|
|
||||||
Initialize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,27 +5,30 @@ namespace xna {
|
|||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
services = snew<GameServiceContainer>();
|
services = snew<GameServiceContainer>();
|
||||||
auto iservice = reinterpret_pointer_cast<IServiceProvider>(services);
|
auto iservice = reinterpret_pointer_cast<IServiceProvider>(services);
|
||||||
_contentManager = snew<ContentManager>(services, "");
|
contentManager = snew<ContentManager>(services, "");
|
||||||
_contentManager->mainGameService = iservice;
|
contentManager->mainGameService = iservice;
|
||||||
|
|
||||||
_gameWindow = snew<GameWindow>();
|
gameWindow = snew<GameWindow>();
|
||||||
_gameWindow->impl->Color(146, 150, 154);
|
gameWindow->impl->Color(146, 150, 154);
|
||||||
_gameWindow->Title("XN65");
|
gameWindow->Title("XN65");
|
||||||
_gameWindow->impl->Size(
|
gameWindow->impl->Size(
|
||||||
GraphicsDeviceManager::DefaultBackBufferWidth,
|
GraphicsDeviceManager::DefaultBackBufferWidth,
|
||||||
GraphicsDeviceManager::DefaultBackBufferHeight, false);
|
GraphicsDeviceManager::DefaultBackBufferHeight, false);
|
||||||
|
|
||||||
_gameComponents = snew<GameComponentCollection>();
|
gameComponents = snew<GameComponentCollection>();
|
||||||
|
|
||||||
|
IsFixedTimeStep(isFixedTimeStep);
|
||||||
|
TargetElapsedTime(targetElapsedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Exit() {
|
void Game::Exit() {
|
||||||
_gameWindow->impl->Close();
|
gameWindow->impl->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Game::StartGameLoop() {
|
int Game::StartGameLoop() {
|
||||||
MSG msg{};
|
MSG msg{};
|
||||||
|
|
||||||
impl->_stepTimer = xna::StepTimer();
|
impl->_stepTimer = xna::StepTimer();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
@ -34,15 +37,16 @@ namespace xna {
|
|||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Step();
|
Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (msg.message != WM_QUIT);
|
} while (msg.message != WM_QUIT);
|
||||||
|
|
||||||
|
EndRun();
|
||||||
return static_cast<int>(msg.wParam);
|
return static_cast<int>(msg.wParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Step()
|
void Game::Tick()
|
||||||
{
|
{
|
||||||
impl->_stepTimer.Tick([&]()
|
impl->_stepTimer.Tick([&]()
|
||||||
{
|
{
|
||||||
@ -50,17 +54,22 @@ namespace xna {
|
|||||||
const auto total = impl->_stepTimer.GetTotalSeconds();
|
const auto total = impl->_stepTimer.GetTotalSeconds();
|
||||||
const auto elapsedTimeSpan = TimeSpan::FromSeconds(elapsed);
|
const auto elapsedTimeSpan = TimeSpan::FromSeconds(elapsed);
|
||||||
const auto totalTimeSpan = TimeSpan::FromSeconds(total);
|
const auto totalTimeSpan = TimeSpan::FromSeconds(total);
|
||||||
_currentGameTime.ElapsedGameTime = elapsedTimeSpan;
|
currentGameTime.ElapsedGameTime = elapsedTimeSpan;
|
||||||
_currentGameTime.TotalGameTime = totalTimeSpan;
|
currentGameTime.TotalGameTime = totalTimeSpan;
|
||||||
Update(_currentGameTime);
|
Update(currentGameTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
Draw(_currentGameTime);
|
BeginDraw();
|
||||||
|
Draw(currentGameTime);
|
||||||
|
EndDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Game::Run() {
|
int Game::Run() {
|
||||||
|
if (isRunning)
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!_gameWindow->impl->Create()) {
|
if (!gameWindow->impl->Create()) {
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -72,6 +81,8 @@ namespace xna {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
BeginRun();
|
||||||
return StartGameLoop();
|
return StartGameLoop();
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
@ -82,7 +93,7 @@ namespace xna {
|
|||||||
|
|
||||||
void Game::Initialize() {
|
void Game::Initialize() {
|
||||||
Keyboard::Initialize();
|
Keyboard::Initialize();
|
||||||
Mouse::Initialize(_gameWindow->Handle());
|
Mouse::Initialize(gameWindow->Handle());
|
||||||
GamePad::Initialize();
|
GamePad::Initialize();
|
||||||
AudioEngine::Initialize();
|
AudioEngine::Initialize();
|
||||||
|
|
||||||
@ -90,16 +101,16 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Draw(GameTime const& gameTime) {
|
void Game::Draw(GameTime const& gameTime) {
|
||||||
if (_enabledGameComponents && !_drawableGameComponents.empty()) {
|
if (enabledGameComponents && !drawableGameComponents.empty()) {
|
||||||
const auto count = _drawableGameComponents.size();
|
const auto count = drawableGameComponents.size();
|
||||||
|
|
||||||
if (count != _drawableGameComponentsCount && _gameComponents->AutoSort) {
|
if (count != drawableGameComponentsCount && gameComponents->AutoSort) {
|
||||||
GameComponentCollection::DrawSort(_drawableGameComponents);
|
GameComponentCollection::DrawSort(drawableGameComponents);
|
||||||
_drawableGameComponentsCount = count;
|
drawableGameComponentsCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
auto& component = _drawableGameComponents[i];
|
auto& component = drawableGameComponents[i];
|
||||||
|
|
||||||
if (!component) continue;
|
if (!component) continue;
|
||||||
|
|
||||||
@ -109,24 +120,24 @@ namespace xna {
|
|||||||
drawable->Draw(gameTime);
|
drawable->Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
_drawableGameComponents.clear();
|
drawableGameComponents.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
graphicsDevice->Present();
|
graphicsDevice->Present();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Update(GameTime const& gameTime) {
|
void Game::Update(GameTime const& gameTime) {
|
||||||
_audioEngine->Update();
|
audioEngine->Update();
|
||||||
|
|
||||||
if (_enabledGameComponents && _gameComponents->Count() > 0) {
|
if (enabledGameComponents && gameComponents->Count() > 0) {
|
||||||
const auto count = _gameComponents->Count();
|
const auto count = gameComponents->Count();
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
auto component = _gameComponents->At(i);
|
auto component = gameComponents->At(i);
|
||||||
|
|
||||||
if (!component) continue;
|
if (!component) continue;
|
||||||
|
|
||||||
if (component->Type() == GameComponentType::Drawable) {
|
if (component->Type() == GameComponentType::Drawable) {
|
||||||
_drawableGameComponents.push_back(component);
|
drawableGameComponents.push_back(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto updatable = reinterpret_pointer_cast<IUpdateable>(component);
|
auto updatable = reinterpret_pointer_cast<IUpdateable>(component);
|
||||||
@ -137,25 +148,65 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sptr<GameWindow> Game::Window() { return _gameWindow; }
|
sptr<GameWindow> Game::Window() { return gameWindow; }
|
||||||
sptr<GraphicsDevice> Game::GetGraphicsDevice() { return graphicsDevice; }
|
sptr<GraphicsDevice> Game::Device() const { return graphicsDevice; }
|
||||||
sptr<GameComponentCollection> Game::Components() { return _gameComponents; }
|
sptr<GameComponentCollection> Game::Components() const { return gameComponents; }
|
||||||
sptr<GameServiceContainer> Game::Services() { return services; }
|
sptr<GameServiceContainer> Game::Services() { return services; }
|
||||||
sptr<ContentManager> Game::Content() { return _contentManager; }
|
sptr<ContentManager> Game::Content() const { return contentManager; }
|
||||||
void Game::EnableGameComponents(bool value) { _enabledGameComponents = value; }
|
void Game::EnableGameComponents(bool value) { enabledGameComponents = value; }
|
||||||
|
|
||||||
void Game::AttachGraphicsDevice(sptr<GraphicsDevice> const& device) {
|
void Game::AttachGraphicsDevice(sptr<GraphicsDevice> const& device) {
|
||||||
graphicsDevice = device;
|
graphicsDevice = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ResizeWindow(int width, int heigth) {
|
void Game::ResizeWindow(int width, int heigth) {
|
||||||
const auto windowBounds = _gameWindow->ClientBounds();
|
const auto windowBounds = gameWindow->ClientBounds();
|
||||||
|
|
||||||
if (windowBounds.Width != width || windowBounds.Height != heigth) {
|
if (windowBounds.Width != width || windowBounds.Height != heigth) {
|
||||||
_gameWindow->impl->Size(
|
gameWindow->impl->Size(
|
||||||
width,
|
width,
|
||||||
heigth);
|
heigth);
|
||||||
_gameWindow->impl->Update();
|
gameWindow->impl->Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::Content(sptr<ContentManager> const& value) {
|
||||||
|
contentManager = value;
|
||||||
|
auto iservice = reinterpret_pointer_cast<IServiceProvider>(services);
|
||||||
|
contentManager->mainGameService = iservice;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::IsFixedTimeStep(bool value) {
|
||||||
|
isFixedTimeStep = value;
|
||||||
|
impl->_stepTimer.SetFixedTimeStep(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Game::IsMouseVisible() const {
|
||||||
|
if (!Mouse::impl)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Mouse::impl->_dxMouse->IsVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::IsMouseVisible(bool value) {
|
||||||
|
if (!Mouse::impl)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Mouse::impl->_dxMouse->SetVisible(value);
|
||||||
|
}
|
||||||
|
void Game::TargetElapsedTime(TimeSpan const& value) {
|
||||||
|
if (!isFixedTimeStep)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto ticks = targetElapsedTime.Ticks();
|
||||||
|
impl->_stepTimer.SetTargetElapsedTicks(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::ResetElapsedTime() const {
|
||||||
|
impl->_stepTimer.ResetElapsedTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::RunOneFrame() {
|
||||||
|
Tick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,7 @@ namespace xna {
|
|||||||
parameters->BackBufferHeight = backBufferHeight;
|
parameters->BackBufferHeight = backBufferHeight;
|
||||||
parameters->BackBufferFormat = SurfaceFormat::Color;
|
parameters->BackBufferFormat = SurfaceFormat::Color;
|
||||||
parameters->IsFullscreen = false;
|
parameters->IsFullscreen = false;
|
||||||
information.PresentParameters = parameters;
|
information.PresentParameters = parameters;
|
||||||
information.Window = game->Window();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDeviceManager::ApplyChanges() {
|
void GraphicsDeviceManager::ApplyChanges() {
|
||||||
@ -75,19 +74,18 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flag2)
|
if (flag2)
|
||||||
CreateDevice(*bestDevice);
|
CreateDevice(*bestDevice);
|
||||||
|
|
||||||
auto presentationParameters = device->PresentParameters();
|
|
||||||
|
|
||||||
screenDeviceName = device->Adapter()->DeviceName();
|
screenDeviceName = device->Adapter()->DeviceName();
|
||||||
|
const auto presentationParameters = device->PresentParameters();
|
||||||
|
|
||||||
isReallyFullScreen = presentationParameters.IsFullscreen;
|
isReallyFullScreen = presentationParameters->IsFullscreen;
|
||||||
|
|
||||||
if (presentationParameters.BackBufferWidth != 0)
|
if (presentationParameters->BackBufferWidth != 0)
|
||||||
clientWidth = presentationParameters.BackBufferWidth;
|
clientWidth = presentationParameters->BackBufferWidth;
|
||||||
|
|
||||||
if (presentationParameters.BackBufferHeight != 0)
|
if (presentationParameters->BackBufferHeight != 0)
|
||||||
clientHeight = presentationParameters.BackBufferHeight;
|
clientHeight = presentationParameters->BackBufferHeight;
|
||||||
|
|
||||||
isDeviceDirty = false;
|
isDeviceDirty = false;
|
||||||
|
|
||||||
|
@ -37,8 +37,10 @@ namespace xna {
|
|||||||
Exception::Throw(Exception::FAILED_TO_APPLY);
|
Exception::Throw(Exception::FAILED_TO_APPLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!render_impl->_renderTargetView)
|
if (!render_impl->_renderTargetView)
|
||||||
Exception::Throw(Exception::INVALID_OPERATION);
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
auto& context = m_device->impl->_context;
|
auto& context = m_device->impl->_context;
|
||||||
context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr);
|
context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr);
|
||||||
|
@ -48,7 +48,7 @@ namespace xna {
|
|||||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto parameters = m_device->impl->_presentationParameters;
|
const auto parameters = m_device->PresentParameters();
|
||||||
|
|
||||||
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);
|
||||||
@ -79,11 +79,13 @@ namespace xna {
|
|||||||
return !FAILED(hr);
|
return !FAILED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwapChain::Present(bool vsync) {
|
bool SwapChain::Present(bool vsync) const {
|
||||||
if (!impl || !impl->dxSwapChain)
|
if (!impl || !impl->dxSwapChain)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto hr = impl->dxSwapChain->Present(vsync, NULL);
|
const auto presentValue = static_cast<UINT>(vsync);
|
||||||
|
|
||||||
|
const auto hr = impl->dxSwapChain->Present(presentValue, NULL);
|
||||||
return !FAILED(hr);
|
return !FAILED(hr);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ namespace xna {
|
|||||||
return texture2d;
|
return texture2d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture2D::Initialize()
|
void Texture2D::Initialize()
|
||||||
{
|
{
|
||||||
if (!m_device || !m_device->impl->_device) {
|
if (!m_device || !m_device->impl->_device) {
|
||||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||||
@ -62,7 +62,8 @@ namespace xna {
|
|||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);
|
||||||
|
levelCount = static_cast<Int>(impl->dxShaderDescription.Texture2D.MipLevels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultDesc(Texture2D::PlatformImplementation& impl) {
|
void setDefaultDesc(Texture2D::PlatformImplementation& impl) {
|
||||||
@ -79,24 +80,24 @@ namespace xna {
|
|||||||
impl.dxShaderDescription.Texture2D.MostDetailedMip = 0;
|
impl.dxShaderDescription.Texture2D.MostDetailedMip = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D() : GraphicsResource(nullptr) {
|
Texture2D::Texture2D() : Texture(nullptr) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultDesc(*impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : GraphicsResource(device) {
|
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultDesc(*impl);
|
||||||
impl->dxDescription.Width = static_cast<UINT>(width);
|
impl->dxDescription.Width = static_cast<UINT>(width);
|
||||||
impl->dxDescription.Height = static_cast<UINT>(height);
|
impl->dxDescription.Height = static_cast<UINT>(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultDesc(*impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : GraphicsResource(device)
|
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : Texture(device)
|
||||||
{
|
{
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultDesc(*impl);
|
||||||
|
@ -194,6 +194,16 @@ namespace xna {
|
|||||||
struct GamePadState;
|
struct GamePadState;
|
||||||
struct KeyboardState;
|
struct KeyboardState;
|
||||||
struct MouseState;
|
struct MouseState;
|
||||||
|
|
||||||
|
using P_BlendState = sptr<BlendState>;
|
||||||
|
using P_DepthStencilState = sptr<DepthStencilState>;
|
||||||
|
using P_GraphicsAdapter = sptr<GraphicsAdapter>;
|
||||||
|
using P_GraphicsDevice = sptr<GraphicsDevice>;
|
||||||
|
using P_RasterizerState = sptr<RasterizerState>;
|
||||||
|
using P_PresentationParameters = sptr<PresentationParameters>;
|
||||||
|
using P_SamplerStateCollection = sptr<SamplerStateCollection>;
|
||||||
|
using P_Texture = sptr<Texture>;
|
||||||
|
using P_Texture2D = sptr<Texture2D>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,10 +223,15 @@ namespace xna {
|
|||||||
Four,
|
Four,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Defines flags that describe the relationship between the adapter refresh rate and the rate at which Present operations are completed.
|
||||||
enum class PresentInterval {
|
enum class PresentInterval {
|
||||||
|
//Equivalent to setting One.
|
||||||
Default,
|
Default,
|
||||||
|
//The driver waits for the vertical retrace period (the runtime will beam trace to prevent tearing). Present operations are not affected more frequently than the screen refresh rate; the runtime completes one Present operation per adapter refresh period, at most. This option is always available for both windowed and full-screen swap chains.
|
||||||
One,
|
One,
|
||||||
|
//The driver waits for the vertical retrace period. Present operations are not affected more frequently than every second screen refresh.
|
||||||
Two,
|
Two,
|
||||||
|
//The runtime updates the window client area immediately, and might do so more than once during the adapter refresh period. Present operations might be affected immediately. This option is always available for both windowed and full-screen swap chains.
|
||||||
Immediate
|
Immediate
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,44 +5,90 @@
|
|||||||
#include "time.hpp"
|
#include "time.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
//Provides basic graphics device initialization, game logic, and rendering code.
|
||||||
class Game : public std::enable_shared_from_this<Game> {
|
class Game : public std::enable_shared_from_this<Game> {
|
||||||
public:
|
public:
|
||||||
Game();
|
Game();
|
||||||
void Exit();
|
|
||||||
int Run();
|
|
||||||
sptr<GameWindow> Window();
|
|
||||||
sptr<GraphicsDevice> GetGraphicsDevice();
|
|
||||||
sptr<GameComponentCollection> Components();
|
|
||||||
sptr<GameServiceContainer> Services();
|
|
||||||
sptr<ContentManager> Content();
|
|
||||||
void EnableGameComponents(bool value);
|
|
||||||
|
|
||||||
|
//Gets the collection of GameComponents owned by the game.
|
||||||
|
sptr<GameComponentCollection> Components() const;
|
||||||
|
//Gets or sets the current ContentManager.
|
||||||
|
sptr<ContentManager> Content() const;
|
||||||
|
//Gets or sets the current ContentManager.
|
||||||
|
void Content(sptr<ContentManager> const& value);
|
||||||
|
//Gets the current GraphicsDevice.
|
||||||
|
sptr<GraphicsDevice> Device() const;
|
||||||
|
//Gets or sets a value indicating whether to use fixed time steps.
|
||||||
|
//The default value for IsFixedTimeStep is true.
|
||||||
|
constexpr bool IsFixedTimeStep() const { return isFixedTimeStep; }
|
||||||
|
//Gets or sets a value indicating whether to use fixed time steps.
|
||||||
|
//The default value for IsFixedTimeStep is true.
|
||||||
|
void IsFixedTimeStep(bool value);
|
||||||
|
//Gets or sets a value indicating whether the mouse cursor should be visible.
|
||||||
|
bool IsMouseVisible() const;
|
||||||
|
//Gets or sets a value indicating whether the mouse cursor should be visible.
|
||||||
|
void IsMouseVisible(bool value);
|
||||||
|
//Gets the GameServiceContainer holding all the service providers attached to the Game.
|
||||||
|
sptr<GameServiceContainer> Services();
|
||||||
|
//Gets or sets the target time between calls to Update when IsFixedTimeStep is true.
|
||||||
|
constexpr TimeSpan TargetElapsedTime() const { return targetElapsedTime; }
|
||||||
|
//Gets or sets the target time between calls to Update when IsFixedTimeStep is true.
|
||||||
|
void TargetElapsedTime(TimeSpan const& value);
|
||||||
|
//Gets the underlying operating system window.
|
||||||
|
sptr<GameWindow> Window();
|
||||||
|
|
||||||
|
//Exits the game.
|
||||||
|
void Exit();
|
||||||
|
//Resets the elapsed time counter.
|
||||||
|
void ResetElapsedTime() const;
|
||||||
|
//Call this method to initialize the game, begin running the game loop, and start processing events for the game.
|
||||||
|
int Run();
|
||||||
|
//Run the game through what would happen in a single tick of the game clock; this method is designed for debugging only.
|
||||||
|
void RunOneFrame();
|
||||||
|
//Updates the game's clock and calls Update and Draw.
|
||||||
|
void Tick();
|
||||||
|
|
||||||
|
void EnableGameComponents(bool value);
|
||||||
void AttachGraphicsDevice(sptr<GraphicsDevice> const& graphicsDevice);
|
void AttachGraphicsDevice(sptr<GraphicsDevice> const& graphicsDevice);
|
||||||
void ResizeWindow(int width, int heigth);
|
void ResizeWindow(int width, int heigth);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//Starts the drawing of a frame. This method is followed by calls to Draw and EndDraw.
|
||||||
|
virtual void BeginDraw(){}
|
||||||
|
//Called after all components are initialized but before the first update in the game loop.
|
||||||
|
virtual void BeginRun() {};
|
||||||
|
//Called when the game determines it is time to draw a frame.
|
||||||
virtual void Draw(GameTime const& gameTime);
|
virtual void Draw(GameTime const& gameTime);
|
||||||
|
//Ends the drawing of a frame. This method is preceeded by calls to Draw and BeginDraw.
|
||||||
|
virtual void EndDraw() {}
|
||||||
|
//Called after the game loop has stopped running before exiting.
|
||||||
|
virtual void EndRun() {};
|
||||||
|
//Called after the Game and GraphicsDevice are created, but before LoadContent.
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
|
//Called when graphics resources need to be loaded.
|
||||||
virtual void LoadContent(){}
|
virtual void LoadContent(){}
|
||||||
virtual void Update(GameTime const& gameTime);
|
//Called when the game has determined that game logic needs to be processed.
|
||||||
int StartGameLoop();
|
virtual void Update(GameTime const& gameTime);
|
||||||
void Step();
|
|
||||||
|
|
||||||
public:
|
|
||||||
sptr<GraphicsDevice> graphicsDevice = nullptr;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
sptr<GameServiceContainer> services = nullptr;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sptr<GameComponentCollection> _gameComponents = nullptr;
|
int StartGameLoop();
|
||||||
sptr<GameWindow> _gameWindow{ nullptr };
|
|
||||||
sptr<AudioEngine> _audioEngine = nullptr;
|
private:
|
||||||
sptr<ContentManager> _contentManager;
|
friend class GraphicsDeviceManager;
|
||||||
std::vector<sptr<IGameComponent>> _drawableGameComponents;
|
|
||||||
size_t _drawableGameComponentsCount{ 0 };
|
sptr<GameComponentCollection> gameComponents = nullptr;
|
||||||
bool _enabledGameComponents{ false };
|
sptr<GameWindow> gameWindow{ nullptr };
|
||||||
GameTime _currentGameTime{};
|
sptr<AudioEngine> audioEngine = nullptr;
|
||||||
|
sptr<ContentManager> contentManager;
|
||||||
|
std::vector<sptr<IGameComponent>> drawableGameComponents;
|
||||||
|
size_t drawableGameComponentsCount{ 0 };
|
||||||
|
bool enabledGameComponents{ false };
|
||||||
|
GameTime currentGameTime{};
|
||||||
|
bool isFixedTimeStep{ true };
|
||||||
|
TimeSpan targetElapsedTime{ TimeSpan::FromTicks(166667L) };
|
||||||
|
bool isRunning{ false };
|
||||||
|
sptr<GameServiceContainer> services = nullptr;
|
||||||
|
sptr<GraphicsDevice> graphicsDevice = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
@ -4,15 +4,18 @@
|
|||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
//Holds the settings for creating a graphics device on Windows.
|
||||||
struct GraphicsDeviceInformation {
|
struct GraphicsDeviceInformation {
|
||||||
GraphicsDeviceInformation() {
|
GraphicsDeviceInformation() {
|
||||||
PresentParameters = snew<PresentationParameters>();
|
PresentParameters = snew<PresentationParameters>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Specifies which graphics adapter to create the device on.
|
||||||
sptr<GraphicsAdapter> Adapter = nullptr;
|
sptr<GraphicsAdapter> Adapter = nullptr;
|
||||||
|
//Gets the graphics profile, which determines the graphics feature set.
|
||||||
xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach };
|
xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach };
|
||||||
|
//Specifies the presentation parameters to use when creating a graphics device.
|
||||||
sptr<xna::PresentationParameters> PresentParameters = nullptr;
|
sptr<xna::PresentationParameters> PresentParameters = nullptr;
|
||||||
sptr<GameWindow> Window = nullptr;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,13 +6,18 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
//A collection of game services.
|
||||||
class GameServiceContainer : public IServiceProvider {
|
class GameServiceContainer : public IServiceProvider {
|
||||||
public:
|
public:
|
||||||
|
//Adds a service to the GameServiceContainer.
|
||||||
void AddService(Type& type, std::any& provider);
|
void AddService(Type& type, std::any& provider);
|
||||||
|
|
||||||
// Inherited via IServiceProvider
|
// Inherited via IServiceProvider
|
||||||
std::any GetService(Type& serviceType) override;
|
std::any GetService(Type& serviceType) override;
|
||||||
|
|
||||||
|
//Removes the object providing a specified service.
|
||||||
|
void RemoveService(Type& type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<size_t, std::any> services;
|
std::map<size_t, std::any> services;
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "../csharp/timespan.hpp"
|
#include "../csharp/timespan.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
//Snapshot of the game timing state expressed in values that can be used by variable-step (real time) or fixed-step (game time) games.
|
||||||
class GameTime {
|
class GameTime {
|
||||||
public:
|
public:
|
||||||
constexpr GameTime() = default;
|
constexpr GameTime() = default;
|
||||||
@ -14,8 +15,11 @@ namespace xna {
|
|||||||
IsRunningSlowly(isRunningSlowly),
|
IsRunningSlowly(isRunningSlowly),
|
||||||
TotalGameTime(totalGameTime) { }
|
TotalGameTime(totalGameTime) { }
|
||||||
|
|
||||||
|
//The amount of elapsed game time since the last update.
|
||||||
TimeSpan ElapsedGameTime{ 0 };
|
TimeSpan ElapsedGameTime{ 0 };
|
||||||
|
//Gets a value indicating that the game loop is taking longer than its TargetElapsedTime. In this case, the game loop can be considered to be running too slowly and should do something to "catch up."
|
||||||
bool IsRunningSlowly{ false };
|
bool IsRunningSlowly{ false };
|
||||||
|
//The amount of game time since the start of the game.
|
||||||
TimeSpan TotalGameTime{ 0 };
|
TimeSpan TotalGameTime{ 0 };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3,59 +3,60 @@
|
|||||||
|
|
||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
#include "presentparams.hpp"
|
#include "presentparams.hpp"
|
||||||
|
#include "viewport.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
//Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders.
|
//Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders.
|
||||||
class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice> {
|
class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice> {
|
||||||
public:
|
public:
|
||||||
GraphicsDevice();
|
GraphicsDevice();
|
||||||
GraphicsDevice(GraphicsDeviceInformation const& info);
|
|
||||||
GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters);
|
GraphicsDevice(P_GraphicsAdapter const& adapter, GraphicsProfile const& graphicsProfile, P_PresentationParameters const& presentationParameters);
|
||||||
|
|
||||||
//Gets the graphics adapter.
|
//Gets the graphics adapter.
|
||||||
sptr<GraphicsAdapter> Adapter() const;
|
inline P_GraphicsAdapter Adapter() const { return adapter; }
|
||||||
|
|
||||||
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
|
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
|
||||||
sptr<xna::BlendState> BlendState() const;
|
inline P_BlendState BlendState() const { return blendState; }
|
||||||
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
|
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
|
||||||
void BlendState(sptr<xna::BlendState> const& value);
|
void BlendState(P_BlendState const& value);
|
||||||
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
|
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
|
||||||
sptr<xna::DepthStencilState> DepthStencilState() const;
|
inline P_DepthStencilState DepthStencilState() const { return depthStencilState; }
|
||||||
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
|
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
|
||||||
void DepthStencilState(sptr<xna::DepthStencilState> const& value);
|
void DepthStencilState(P_DepthStencilState const& value);
|
||||||
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
|
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
|
||||||
sptr<xna::RasterizerState> RasterizerState() const;
|
inline P_RasterizerState RasterizerState() const { return rasterizerState; }
|
||||||
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
|
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
|
||||||
void RasterizerState(sptr<xna::RasterizerState> const& value);
|
void RasterizerState(P_RasterizerState const& value);
|
||||||
//Retrieves a collection of SamplerState objects for the current GraphicsDevice.
|
//Retrieves a collection of SamplerState objects for the current GraphicsDevice.
|
||||||
sptr<SamplerStateCollection> SamplerStates() const;
|
inline P_SamplerStateCollection SamplerStates() const { return samplerStateCollection; }
|
||||||
|
//Gets the graphics profile.
|
||||||
//Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff).
|
constexpr GraphicsProfile Profile() const { return graphicsProfile; }
|
||||||
Int MultiSampleMask() const;
|
//Gets the presentation parameters associated with this graphics device.
|
||||||
//Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff).
|
P_PresentationParameters PresentParameters() const { return presentationParameters; }
|
||||||
void MultiSampleMask(Int value);
|
//Clears resource buffers.
|
||||||
|
void Clear(Color const& color) const;
|
||||||
constexpr GraphicsProfile Profile() const {
|
//Clears resource buffers.
|
||||||
return GraphicsProfile::HiDef;
|
void Clear(ClearOptions options, Color const& color, float depth, Int stencil) const;
|
||||||
}
|
//Presents the display with the contents of the next buffer in the sequence of back buffers owned by the GraphicsDevice.
|
||||||
|
bool Present() const;
|
||||||
constexpr PresentationParameters PresentParameters() const {
|
//Resets the presentation parameters for the current GraphicsDevice.
|
||||||
return PresentationParameters();
|
void Reset(P_PresentationParameters const& presentationParameters, P_GraphicsAdapter const& graphicsAdapter);
|
||||||
}
|
//Gets or sets a viewport identifying the portion of the render target to receive draw calls.
|
||||||
|
constexpr xna::Viewport Viewport() const { return viewport; }
|
||||||
void Clear(Color const& color);
|
//Gets or sets a viewport identifying the portion of the render target to receive draw calls.
|
||||||
void Clear(ClearOptions options, Color const& color, float depth, Int stencil);
|
|
||||||
void Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil);
|
|
||||||
bool Initialize();
|
|
||||||
bool Present();
|
|
||||||
|
|
||||||
void Reset(sptr<PresentationParameters> const& presentationParameters, sptr<GraphicsAdapter> const& graphicsAdapter);
|
|
||||||
|
|
||||||
xna::Viewport Viewport() const;
|
|
||||||
void Viewport(xna::Viewport const& viewport);
|
void Viewport(xna::Viewport const& viewport);
|
||||||
void UseVSync(bool use);
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
//void DrawPrimitives(PrimitiveType primitiveType, Int startVertex, Int primitiveCount);
|
private:
|
||||||
|
P_GraphicsAdapter adapter{ nullptr };
|
||||||
|
P_BlendState blendState{ nullptr };
|
||||||
|
P_DepthStencilState depthStencilState{ nullptr };
|
||||||
|
P_RasterizerState rasterizerState{ nullptr };
|
||||||
|
P_SamplerStateCollection samplerStateCollection{ nullptr };
|
||||||
|
P_PresentationParameters presentationParameters{ nullptr };
|
||||||
|
GraphicsProfile graphicsProfile{ GraphicsProfile::HiDef };
|
||||||
|
xna::Viewport viewport{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
@ -11,7 +11,7 @@ namespace xna {
|
|||||||
SwapChain(sptr<GraphicsDevice> const& device);
|
SwapChain(sptr<GraphicsDevice> const& device);
|
||||||
~SwapChain() override;
|
~SwapChain() override;
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
bool Present(bool vsync);
|
bool Present(bool vsync) const;
|
||||||
bool GetBackBuffer(Texture2D& texture2D);
|
bool GetBackBuffer(Texture2D& texture2D);
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
@ -5,28 +5,41 @@
|
|||||||
#include "gresource.hpp"
|
#include "gresource.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class Texture {
|
//Represents a texture resource.
|
||||||
|
class Texture : public GraphicsResource {
|
||||||
public:
|
public:
|
||||||
~Texture() {}
|
Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {}
|
||||||
|
|
||||||
|
virtual ~Texture() {}
|
||||||
|
|
||||||
|
//Gets the format of the texture data.
|
||||||
|
constexpr SurfaceFormat Format() const { return surfaceFormat; }
|
||||||
|
//Gets the number of texture levels in a multilevel texture.
|
||||||
|
constexpr Int LevelCount() const { return levelCount; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SurfaceFormat surfaceFormat{SurfaceFormat::Color};
|
||||||
|
Int levelCount{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class Texture2D : public Texture, public GraphicsResource {
|
class Texture2D : public Texture {
|
||||||
public:
|
public:
|
||||||
Texture2D();
|
Texture2D();
|
||||||
Texture2D(sptr<GraphicsDevice> const& device);
|
Texture2D(P_GraphicsDevice const& device);
|
||||||
Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height);
|
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height);
|
||||||
Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
||||||
~Texture2D() override;
|
~Texture2D() override;
|
||||||
Int Width() const;
|
Int Width() const;
|
||||||
Int Height() const;
|
Int Height() const;
|
||||||
Rectangle Bounds() const;
|
Rectangle Bounds() const;
|
||||||
bool Initialize();
|
|
||||||
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
||||||
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
||||||
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
||||||
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount);
|
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount);
|
||||||
static sptr<Texture2D> FromStream(GraphicsDevice& device, String const& fileName);
|
static P_Texture2D FromStream(GraphicsDevice& device, String const& fileName);
|
||||||
static sptr<Texture2D> FromMemory(GraphicsDevice& device, std::vector<Byte> const& data);
|
static P_Texture2D FromMemory(GraphicsDevice& device, std::vector<Byte> const& data);
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
@ -34,7 +47,7 @@ namespace xna {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using PTexture2D = sptr<Texture2D>;
|
using PTexture2D = P_Texture2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -831,31 +831,14 @@ namespace xna {
|
|||||||
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
|
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GraphicsDevice::PlatformImplementation {
|
struct GraphicsDevice::PlatformImplementation {
|
||||||
PlatformImplementation() {
|
|
||||||
_blendState = xna::BlendState::Opaque();
|
|
||||||
_depthStencilState = xna::DepthStencilState::Default();
|
|
||||||
_rasterizerState = xna::RasterizerState::CullCounterClockwise();
|
|
||||||
_samplerStates = snew<SamplerStateCollection>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
comptr<ID3D11Device> _device = nullptr;
|
comptr<ID3D11Device> _device = nullptr;
|
||||||
comptr<ID3D11DeviceContext> _context = nullptr;
|
comptr<ID3D11DeviceContext> _context = nullptr;
|
||||||
comptr<IDXGIFactory1> _factory = nullptr;
|
comptr<IDXGIFactory1> _factory = nullptr;
|
||||||
|
|
||||||
PBlendState _blendState = nullptr;
|
|
||||||
PRasterizerState _rasterizerState = nullptr;
|
|
||||||
PDepthStencilState _depthStencilState = nullptr;
|
|
||||||
PSamplerStateCollection _samplerStates = nullptr;
|
|
||||||
Int _multiSampleMask = 0xffffffff;
|
|
||||||
|
|
||||||
sptr<SwapChain> _swapChain = nullptr;
|
sptr<SwapChain> _swapChain = nullptr;
|
||||||
sptr<GraphicsAdapter> _adapter = nullptr;
|
|
||||||
sptr<RenderTarget2D> _renderTarget2D = nullptr;
|
sptr<RenderTarget2D> _renderTarget2D = nullptr;
|
||||||
intptr_t windowHandle{ 0 };
|
intptr_t windowHandle{ 0 };
|
||||||
xna::Viewport _viewport{};
|
|
||||||
sptr<xna::PresentationParameters> _presentationParameters;
|
|
||||||
|
|
||||||
D3D_FEATURE_LEVEL featureLevels[7] =
|
D3D_FEATURE_LEVEL featureLevels[7] =
|
||||||
{
|
{
|
||||||
@ -873,7 +856,7 @@ namespace xna {
|
|||||||
private:
|
private:
|
||||||
friend class GraphicsDevice;
|
friend class GraphicsDevice;
|
||||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||||
bool _usevsync{ true };
|
UINT vSyncValue = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Game::PlatformImplementation {
|
struct Game::PlatformImplementation {
|
||||||
|
@ -20,14 +20,14 @@ namespace xna {
|
|||||||
//graphics->Initialize();
|
//graphics->Initialize();
|
||||||
graphics->ApplyChanges();
|
graphics->ApplyChanges();
|
||||||
|
|
||||||
std::any device = graphicsDevice;
|
std::any device = Device();
|
||||||
services->AddService(*typeof<GraphicsDevice>(), device);
|
Services()->AddService(*typeof<GraphicsDevice>(), device);
|
||||||
|
|
||||||
Game::Initialize();
|
Game::Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadContent() override {
|
void LoadContent() override {
|
||||||
spriteBatch = snew<SpriteBatch>(graphicsDevice);
|
spriteBatch = snew<SpriteBatch>(Device());
|
||||||
Game::LoadContent();
|
Game::LoadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Draw(GameTime const& gameTime) override {
|
void Draw(GameTime const& gameTime) override {
|
||||||
graphicsDevice->Clear(Colors::CornflowerBlue);
|
Device()->Clear(Colors::CornflowerBlue);
|
||||||
Game::Draw(gameTime);
|
Game::Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ namespace PlatformerStarterKit {
|
|||||||
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
||||||
graphics->ApplyChanges();
|
graphics->ApplyChanges();
|
||||||
|
|
||||||
std::any device = graphicsDevice;
|
std::any device = Device();
|
||||||
services->AddService(*typeof<GraphicsDevice>(), device);
|
Services()->AddService(*typeof<GraphicsDevice>(), device);
|
||||||
|
|
||||||
Game::Initialize();
|
Game::Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadContent() override {
|
void LoadContent() override {
|
||||||
spriteBatch = snew<SpriteBatch>(graphicsDevice);
|
spriteBatch = snew<SpriteBatch>(Device());
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");
|
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");
|
||||||
@ -55,7 +55,7 @@ namespace PlatformerStarterKit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Draw(GameTime const& gameTime) override {
|
void Draw(GameTime const& gameTime) override {
|
||||||
graphicsDevice->Clear(Colors::CornflowerBlue);
|
Device()->Clear(Colors::CornflowerBlue);
|
||||||
|
|
||||||
spriteBatch->Begin();
|
spriteBatch->Begin();
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ namespace PlatformerStarterKit {
|
|||||||
auto keyboardState = Keyboard::GetState();
|
auto keyboardState = Keyboard::GetState();
|
||||||
auto gamepadState = GamePad::GetState(PlayerIndex::One);
|
auto gamepadState = GamePad::GetState(PlayerIndex::One);
|
||||||
|
|
||||||
if (gamepadState.Buttons.Back == ButtonState::Pressed)
|
if (gamepadState.Buttons().Back() == ButtonState::Pressed)
|
||||||
Exit();
|
Exit();
|
||||||
|
|
||||||
bool continuePressed =
|
bool continuePressed =
|
||||||
@ -111,7 +111,7 @@ namespace PlatformerStarterKit {
|
|||||||
levelIndex = -1;
|
levelIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
level = snew<Level>(services, levelPath);
|
level = snew<Level>(Services(), levelPath);
|
||||||
level->Initialize();
|
level->Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ namespace PlatformerStarterKit {
|
|||||||
|
|
||||||
void DrawHud()
|
void DrawHud()
|
||||||
{
|
{
|
||||||
auto titleSafeArea = graphicsDevice->Viewport().Bounds();
|
auto titleSafeArea = Device()->Viewport().Bounds();
|
||||||
auto hudLocation = Vector2(titleSafeArea.X, titleSafeArea.Y);
|
auto hudLocation = Vector2(titleSafeArea.X, titleSafeArea.Y);
|
||||||
auto center = Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
|
auto center = Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
|
||||||
titleSafeArea.Y + titleSafeArea.Height / 2.0f);
|
titleSafeArea.Y + titleSafeArea.Height / 2.0f);
|
||||||
|
@ -92,7 +92,7 @@ namespace PlatformerStarterKit {
|
|||||||
auto gamePadState = xna::GamePad::GetState(xna::PlayerIndex::One);
|
auto gamePadState = xna::GamePad::GetState(xna::PlayerIndex::One);
|
||||||
auto keyboardState = xna::Keyboard::GetState();
|
auto keyboardState = xna::Keyboard::GetState();
|
||||||
|
|
||||||
movement = gamePadState.ThumbSticks.Left().X * MoveStickScale;
|
movement = gamePadState.ThumbSticks().Left().X * MoveStickScale;
|
||||||
|
|
||||||
if (std::abs(movement) < 0.5f)
|
if (std::abs(movement) < 0.5f)
|
||||||
movement = 0.0f;
|
movement = 0.0f;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user