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]
|
||||
: 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) {
|
||||
Exception::Throw(Exception::INVALID_OPERATION);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
m_device->impl->_context->OMSetBlendState(
|
||||
|
@ -63,7 +63,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
if (!impl->dxDepthStencil) {
|
||||
Exception::Throw(Exception::INVALID_OPERATION);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil.Get(), 0);
|
||||
|
@ -1,8 +1,167 @@
|
||||
#include "xna/xna-dx.hpp"
|
||||
#include "xna/game/gdevicemanager.hpp"
|
||||
|
||||
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) {
|
||||
impl._device->Release();
|
||||
@ -20,7 +179,7 @@ namespace xna {
|
||||
}
|
||||
}
|
||||
|
||||
static void createDevice(GraphicsDevice::PlatformImplementation& impl) {
|
||||
void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter) {
|
||||
//
|
||||
// See ref
|
||||
//
|
||||
@ -34,11 +193,10 @@ namespace xna {
|
||||
auto createDeviceFlags = 0;
|
||||
#if _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
|
||||
//
|
||||
@ -75,220 +233,19 @@ namespace xna {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
}
|
||||
|
||||
static void initAndApplyState(GraphicsDevice::PlatformImplementation& impl, PGraphicsDevice const& device) {
|
||||
impl._blendState->Bind(device);
|
||||
impl._blendState->Initialize();
|
||||
impl._blendState->Apply();
|
||||
static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState, P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device) {
|
||||
blendState->Bind(device);
|
||||
blendState->Initialize();
|
||||
blendState->Apply();
|
||||
|
||||
impl._rasterizerState->Bind(device);
|
||||
impl._rasterizerState->Initialize();
|
||||
impl._rasterizerState->Apply();
|
||||
rasterizerState->Bind(device);
|
||||
rasterizerState->Initialize();
|
||||
rasterizerState->Apply();
|
||||
|
||||
impl._depthStencilState->Bind(device);
|
||||
impl._depthStencilState->Initialize();
|
||||
impl._depthStencilState->Apply();
|
||||
depthStencilState->Bind(device);
|
||||
depthStencilState->Initialize();
|
||||
depthStencilState->Apply();
|
||||
|
||||
impl._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();
|
||||
samplerStates->Apply(*device);
|
||||
}
|
||||
}
|
@ -5,27 +5,30 @@ namespace xna {
|
||||
impl = unew<PlatformImplementation>();
|
||||
services = snew<GameServiceContainer>();
|
||||
auto iservice = reinterpret_pointer_cast<IServiceProvider>(services);
|
||||
_contentManager = snew<ContentManager>(services, "");
|
||||
_contentManager->mainGameService = iservice;
|
||||
contentManager = snew<ContentManager>(services, "");
|
||||
contentManager->mainGameService = iservice;
|
||||
|
||||
_gameWindow = snew<GameWindow>();
|
||||
_gameWindow->impl->Color(146, 150, 154);
|
||||
_gameWindow->Title("XN65");
|
||||
_gameWindow->impl->Size(
|
||||
gameWindow = snew<GameWindow>();
|
||||
gameWindow->impl->Color(146, 150, 154);
|
||||
gameWindow->Title("XN65");
|
||||
gameWindow->impl->Size(
|
||||
GraphicsDeviceManager::DefaultBackBufferWidth,
|
||||
GraphicsDeviceManager::DefaultBackBufferHeight, false);
|
||||
|
||||
_gameComponents = snew<GameComponentCollection>();
|
||||
gameComponents = snew<GameComponentCollection>();
|
||||
|
||||
IsFixedTimeStep(isFixedTimeStep);
|
||||
TargetElapsedTime(targetElapsedTime);
|
||||
}
|
||||
|
||||
void Game::Exit() {
|
||||
_gameWindow->impl->Close();
|
||||
gameWindow->impl->Close();
|
||||
}
|
||||
|
||||
int Game::StartGameLoop() {
|
||||
MSG msg{};
|
||||
|
||||
impl->_stepTimer = xna::StepTimer();
|
||||
impl->_stepTimer = xna::StepTimer();
|
||||
|
||||
do {
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
@ -34,15 +37,16 @@ namespace xna {
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
else {
|
||||
Step();
|
||||
Tick();
|
||||
}
|
||||
|
||||
} while (msg.message != WM_QUIT);
|
||||
|
||||
EndRun();
|
||||
return static_cast<int>(msg.wParam);
|
||||
}
|
||||
|
||||
void Game::Step()
|
||||
void Game::Tick()
|
||||
{
|
||||
impl->_stepTimer.Tick([&]()
|
||||
{
|
||||
@ -50,17 +54,22 @@ namespace xna {
|
||||
const auto total = impl->_stepTimer.GetTotalSeconds();
|
||||
const auto elapsedTimeSpan = TimeSpan::FromSeconds(elapsed);
|
||||
const auto totalTimeSpan = TimeSpan::FromSeconds(total);
|
||||
_currentGameTime.ElapsedGameTime = elapsedTimeSpan;
|
||||
_currentGameTime.TotalGameTime = totalTimeSpan;
|
||||
Update(_currentGameTime);
|
||||
currentGameTime.ElapsedGameTime = elapsedTimeSpan;
|
||||
currentGameTime.TotalGameTime = totalTimeSpan;
|
||||
Update(currentGameTime);
|
||||
});
|
||||
|
||||
Draw(_currentGameTime);
|
||||
BeginDraw();
|
||||
Draw(currentGameTime);
|
||||
EndDraw();
|
||||
}
|
||||
|
||||
int Game::Run() {
|
||||
if (isRunning)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
try {
|
||||
if (!_gameWindow->impl->Create()) {
|
||||
if (!gameWindow->impl->Create()) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
return false;
|
||||
}
|
||||
@ -72,6 +81,8 @@ namespace xna {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
isRunning = true;
|
||||
BeginRun();
|
||||
return StartGameLoop();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
@ -82,7 +93,7 @@ namespace xna {
|
||||
|
||||
void Game::Initialize() {
|
||||
Keyboard::Initialize();
|
||||
Mouse::Initialize(_gameWindow->Handle());
|
||||
Mouse::Initialize(gameWindow->Handle());
|
||||
GamePad::Initialize();
|
||||
AudioEngine::Initialize();
|
||||
|
||||
@ -90,16 +101,16 @@ namespace xna {
|
||||
}
|
||||
|
||||
void Game::Draw(GameTime const& gameTime) {
|
||||
if (_enabledGameComponents && !_drawableGameComponents.empty()) {
|
||||
const auto count = _drawableGameComponents.size();
|
||||
if (enabledGameComponents && !drawableGameComponents.empty()) {
|
||||
const auto count = drawableGameComponents.size();
|
||||
|
||||
if (count != _drawableGameComponentsCount && _gameComponents->AutoSort) {
|
||||
GameComponentCollection::DrawSort(_drawableGameComponents);
|
||||
_drawableGameComponentsCount = count;
|
||||
if (count != drawableGameComponentsCount && gameComponents->AutoSort) {
|
||||
GameComponentCollection::DrawSort(drawableGameComponents);
|
||||
drawableGameComponentsCount = count;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
auto& component = _drawableGameComponents[i];
|
||||
auto& component = drawableGameComponents[i];
|
||||
|
||||
if (!component) continue;
|
||||
|
||||
@ -109,24 +120,24 @@ namespace xna {
|
||||
drawable->Draw(gameTime);
|
||||
}
|
||||
|
||||
_drawableGameComponents.clear();
|
||||
drawableGameComponents.clear();
|
||||
}
|
||||
|
||||
graphicsDevice->Present();
|
||||
}
|
||||
|
||||
void Game::Update(GameTime const& gameTime) {
|
||||
_audioEngine->Update();
|
||||
audioEngine->Update();
|
||||
|
||||
if (_enabledGameComponents && _gameComponents->Count() > 0) {
|
||||
const auto count = _gameComponents->Count();
|
||||
if (enabledGameComponents && gameComponents->Count() > 0) {
|
||||
const auto count = gameComponents->Count();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
auto component = _gameComponents->At(i);
|
||||
auto component = gameComponents->At(i);
|
||||
|
||||
if (!component) continue;
|
||||
|
||||
if (component->Type() == GameComponentType::Drawable) {
|
||||
_drawableGameComponents.push_back(component);
|
||||
drawableGameComponents.push_back(component);
|
||||
}
|
||||
|
||||
auto updatable = reinterpret_pointer_cast<IUpdateable>(component);
|
||||
@ -137,25 +148,65 @@ namespace xna {
|
||||
}
|
||||
}
|
||||
|
||||
sptr<GameWindow> Game::Window() { return _gameWindow; }
|
||||
sptr<GraphicsDevice> Game::GetGraphicsDevice() { return graphicsDevice; }
|
||||
sptr<GameComponentCollection> Game::Components() { return _gameComponents; }
|
||||
sptr<GameWindow> Game::Window() { return gameWindow; }
|
||||
sptr<GraphicsDevice> Game::Device() const { return graphicsDevice; }
|
||||
sptr<GameComponentCollection> Game::Components() const { return gameComponents; }
|
||||
sptr<GameServiceContainer> Game::Services() { return services; }
|
||||
sptr<ContentManager> Game::Content() { return _contentManager; }
|
||||
void Game::EnableGameComponents(bool value) { _enabledGameComponents = value; }
|
||||
sptr<ContentManager> Game::Content() const { return contentManager; }
|
||||
void Game::EnableGameComponents(bool value) { enabledGameComponents = value; }
|
||||
|
||||
void Game::AttachGraphicsDevice(sptr<GraphicsDevice> const& device) {
|
||||
graphicsDevice = device;
|
||||
}
|
||||
|
||||
void Game::ResizeWindow(int width, int heigth) {
|
||||
const auto windowBounds = _gameWindow->ClientBounds();
|
||||
const auto windowBounds = gameWindow->ClientBounds();
|
||||
|
||||
if (windowBounds.Width != width || windowBounds.Height != heigth) {
|
||||
_gameWindow->impl->Size(
|
||||
gameWindow->impl->Size(
|
||||
width,
|
||||
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->BackBufferFormat = SurfaceFormat::Color;
|
||||
parameters->IsFullscreen = false;
|
||||
information.PresentParameters = parameters;
|
||||
information.Window = game->Window();
|
||||
information.PresentParameters = parameters;
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::ApplyChanges() {
|
||||
@ -75,19 +74,18 @@ namespace xna {
|
||||
}
|
||||
|
||||
if (flag2)
|
||||
CreateDevice(*bestDevice);
|
||||
|
||||
auto presentationParameters = device->PresentParameters();
|
||||
CreateDevice(*bestDevice);
|
||||
|
||||
screenDeviceName = device->Adapter()->DeviceName();
|
||||
const auto presentationParameters = device->PresentParameters();
|
||||
|
||||
isReallyFullScreen = presentationParameters.IsFullscreen;
|
||||
isReallyFullScreen = presentationParameters->IsFullscreen;
|
||||
|
||||
if (presentationParameters.BackBufferWidth != 0)
|
||||
clientWidth = presentationParameters.BackBufferWidth;
|
||||
if (presentationParameters->BackBufferWidth != 0)
|
||||
clientWidth = presentationParameters->BackBufferWidth;
|
||||
|
||||
if (presentationParameters.BackBufferHeight != 0)
|
||||
clientHeight = presentationParameters.BackBufferHeight;
|
||||
if (presentationParameters->BackBufferHeight != 0)
|
||||
clientHeight = presentationParameters->BackBufferHeight;
|
||||
|
||||
isDeviceDirty = false;
|
||||
|
||||
|
@ -37,8 +37,10 @@ namespace xna {
|
||||
Exception::Throw(Exception::FAILED_TO_APPLY);
|
||||
}
|
||||
|
||||
if(!render_impl->_renderTargetView)
|
||||
Exception::Throw(Exception::INVALID_OPERATION);
|
||||
if (!render_impl->_renderTargetView)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
auto& context = m_device->impl->_context;
|
||||
context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr);
|
||||
|
@ -48,7 +48,7 @@ namespace xna {
|
||||
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.Height = static_cast<UINT>(parameters->BackBufferHeight);
|
||||
@ -79,11 +79,13 @@ namespace xna {
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
bool SwapChain::Present(bool vsync) {
|
||||
bool SwapChain::Present(bool vsync) const {
|
||||
if (!impl || !impl->dxSwapChain)
|
||||
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);
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ namespace xna {
|
||||
return texture2d;
|
||||
}
|
||||
|
||||
bool Texture2D::Initialize()
|
||||
void Texture2D::Initialize()
|
||||
{
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||
@ -62,7 +62,8 @@ namespace xna {
|
||||
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) {
|
||||
@ -79,24 +80,24 @@ namespace xna {
|
||||
impl.dxShaderDescription.Texture2D.MostDetailedMip = 0;
|
||||
}
|
||||
|
||||
Texture2D::Texture2D() : GraphicsResource(nullptr) {
|
||||
Texture2D::Texture2D() : Texture(nullptr) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
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>();
|
||||
setDefaultDesc(*impl);
|
||||
impl->dxDescription.Width = static_cast<UINT>(width);
|
||||
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>();
|
||||
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>();
|
||||
setDefaultDesc(*impl);
|
||||
|
@ -194,6 +194,16 @@ namespace xna {
|
||||
struct GamePadState;
|
||||
struct KeyboardState;
|
||||
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,
|
||||
};
|
||||
|
||||
//Defines flags that describe the relationship between the adapter refresh rate and the rate at which Present operations are completed.
|
||||
enum class PresentInterval {
|
||||
//Equivalent to setting One.
|
||||
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,
|
||||
//The driver waits for the vertical retrace period. Present operations are not affected more frequently than every second screen refresh.
|
||||
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
|
||||
};
|
||||
|
||||
|
@ -5,44 +5,90 @@
|
||||
#include "time.hpp"
|
||||
|
||||
namespace xna {
|
||||
//Provides basic graphics device initialization, game logic, and rendering code.
|
||||
class Game : public std::enable_shared_from_this<Game> {
|
||||
public:
|
||||
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 ResizeWindow(int width, int heigth);
|
||||
|
||||
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);
|
||||
//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();
|
||||
//Called when graphics resources need to be loaded.
|
||||
virtual void LoadContent(){}
|
||||
virtual void Update(GameTime const& gameTime);
|
||||
int StartGameLoop();
|
||||
void Step();
|
||||
|
||||
public:
|
||||
sptr<GraphicsDevice> graphicsDevice = nullptr;
|
||||
|
||||
protected:
|
||||
sptr<GameServiceContainer> services = nullptr;
|
||||
//Called when the game has determined that game logic needs to be processed.
|
||||
virtual void Update(GameTime const& gameTime);
|
||||
|
||||
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{};
|
||||
int StartGameLoop();
|
||||
|
||||
private:
|
||||
friend class GraphicsDeviceManager;
|
||||
|
||||
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{};
|
||||
bool isFixedTimeStep{ true };
|
||||
TimeSpan targetElapsedTime{ TimeSpan::FromTicks(166667L) };
|
||||
bool isRunning{ false };
|
||||
sptr<GameServiceContainer> services = nullptr;
|
||||
sptr<GraphicsDevice> graphicsDevice = nullptr;
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
|
@ -4,15 +4,18 @@
|
||||
#include "../default.hpp"
|
||||
|
||||
namespace xna {
|
||||
//Holds the settings for creating a graphics device on Windows.
|
||||
struct GraphicsDeviceInformation {
|
||||
GraphicsDeviceInformation() {
|
||||
PresentParameters = snew<PresentationParameters>();
|
||||
}
|
||||
|
||||
//Specifies which graphics adapter to create the device on.
|
||||
sptr<GraphicsAdapter> Adapter = nullptr;
|
||||
//Gets the graphics profile, which determines the graphics feature set.
|
||||
xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach };
|
||||
//Specifies the presentation parameters to use when creating a graphics device.
|
||||
sptr<xna::PresentationParameters> PresentParameters = nullptr;
|
||||
sptr<GameWindow> Window = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,13 +6,18 @@
|
||||
#include <map>
|
||||
|
||||
namespace xna {
|
||||
//A collection of game services.
|
||||
class GameServiceContainer : public IServiceProvider {
|
||||
public:
|
||||
//Adds a service to the GameServiceContainer.
|
||||
void AddService(Type& type, std::any& provider);
|
||||
|
||||
// Inherited via IServiceProvider
|
||||
std::any GetService(Type& serviceType) override;
|
||||
|
||||
//Removes the object providing a specified service.
|
||||
void RemoveService(Type& type);
|
||||
|
||||
private:
|
||||
std::map<size_t, std::any> services;
|
||||
};
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "../csharp/timespan.hpp"
|
||||
|
||||
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 {
|
||||
public:
|
||||
constexpr GameTime() = default;
|
||||
@ -14,8 +15,11 @@ namespace xna {
|
||||
IsRunningSlowly(isRunningSlowly),
|
||||
TotalGameTime(totalGameTime) { }
|
||||
|
||||
//The amount of elapsed game time since the last update.
|
||||
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 };
|
||||
//The amount of game time since the start of the game.
|
||||
TimeSpan TotalGameTime{ 0 };
|
||||
};
|
||||
}
|
||||
|
@ -3,59 +3,60 @@
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "presentparams.hpp"
|
||||
#include "viewport.hpp"
|
||||
|
||||
namespace xna {
|
||||
//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> {
|
||||
public:
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
void DepthStencilState(sptr<xna::DepthStencilState> const& value);
|
||||
void DepthStencilState(P_DepthStencilState const& value);
|
||||
//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.
|
||||
void RasterizerState(sptr<xna::RasterizerState> const& value);
|
||||
void RasterizerState(P_RasterizerState const& value);
|
||||
//Retrieves a collection of SamplerState objects for the current GraphicsDevice.
|
||||
sptr<SamplerStateCollection> SamplerStates() const;
|
||||
|
||||
//Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff).
|
||||
Int MultiSampleMask() const;
|
||||
//Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff).
|
||||
void MultiSampleMask(Int value);
|
||||
|
||||
constexpr GraphicsProfile Profile() const {
|
||||
return GraphicsProfile::HiDef;
|
||||
}
|
||||
|
||||
constexpr PresentationParameters PresentParameters() const {
|
||||
return PresentationParameters();
|
||||
}
|
||||
|
||||
void Clear(Color const& color);
|
||||
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;
|
||||
inline P_SamplerStateCollection SamplerStates() const { return samplerStateCollection; }
|
||||
//Gets the graphics profile.
|
||||
constexpr GraphicsProfile Profile() const { return graphicsProfile; }
|
||||
//Gets the presentation parameters associated with this graphics device.
|
||||
P_PresentationParameters PresentParameters() const { return presentationParameters; }
|
||||
//Clears resource buffers.
|
||||
void Clear(Color const& color) const;
|
||||
//Clears resource buffers.
|
||||
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;
|
||||
//Resets the presentation parameters for the current GraphicsDevice.
|
||||
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; }
|
||||
//Gets or sets a viewport identifying the portion of the render target to receive draw calls.
|
||||
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:
|
||||
struct PlatformImplementation;
|
||||
|
@ -11,7 +11,7 @@ namespace xna {
|
||||
SwapChain(sptr<GraphicsDevice> const& device);
|
||||
~SwapChain() override;
|
||||
bool Initialize();
|
||||
bool Present(bool vsync);
|
||||
bool Present(bool vsync) const;
|
||||
bool GetBackBuffer(Texture2D& texture2D);
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
|
@ -5,28 +5,41 @@
|
||||
#include "gresource.hpp"
|
||||
|
||||
namespace xna {
|
||||
class Texture {
|
||||
//Represents a texture resource.
|
||||
class Texture : public GraphicsResource {
|
||||
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:
|
||||
Texture2D();
|
||||
Texture2D(sptr<GraphicsDevice> const& device);
|
||||
Texture2D(sptr<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);
|
||||
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height);
|
||||
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
||||
~Texture2D() override;
|
||||
Int Width() const;
|
||||
Int Height() 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<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(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 sptr<Texture2D> FromMemory(GraphicsDevice& device, std::vector<Byte> const& data);
|
||||
static P_Texture2D FromStream(GraphicsDevice& device, String const& fileName);
|
||||
static P_Texture2D FromMemory(GraphicsDevice& device, std::vector<Byte> const& data);
|
||||
|
||||
void Initialize();
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
@ -34,7 +47,7 @@ namespace xna {
|
||||
};
|
||||
|
||||
|
||||
using PTexture2D = sptr<Texture2D>;
|
||||
using PTexture2D = P_Texture2D;
|
||||
}
|
||||
|
||||
#endif
|
@ -831,31 +831,14 @@ namespace xna {
|
||||
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
|
||||
};
|
||||
|
||||
struct GraphicsDevice::PlatformImplementation {
|
||||
PlatformImplementation() {
|
||||
_blendState = xna::BlendState::Opaque();
|
||||
_depthStencilState = xna::DepthStencilState::Default();
|
||||
_rasterizerState = xna::RasterizerState::CullCounterClockwise();
|
||||
_samplerStates = snew<SamplerStateCollection>();
|
||||
}
|
||||
|
||||
public:
|
||||
struct GraphicsDevice::PlatformImplementation {
|
||||
comptr<ID3D11Device> _device = nullptr;
|
||||
comptr<ID3D11DeviceContext> _context = nullptr;
|
||||
comptr<IDXGIFactory1> _factory = nullptr;
|
||||
|
||||
PBlendState _blendState = nullptr;
|
||||
PRasterizerState _rasterizerState = nullptr;
|
||||
PDepthStencilState _depthStencilState = nullptr;
|
||||
PSamplerStateCollection _samplerStates = nullptr;
|
||||
Int _multiSampleMask = 0xffffffff;
|
||||
|
||||
comptr<IDXGIFactory1> _factory = nullptr;
|
||||
|
||||
sptr<SwapChain> _swapChain = nullptr;
|
||||
sptr<GraphicsAdapter> _adapter = nullptr;
|
||||
sptr<RenderTarget2D> _renderTarget2D = nullptr;
|
||||
intptr_t windowHandle{ 0 };
|
||||
xna::Viewport _viewport{};
|
||||
sptr<xna::PresentationParameters> _presentationParameters;
|
||||
intptr_t windowHandle{ 0 };
|
||||
|
||||
D3D_FEATURE_LEVEL featureLevels[7] =
|
||||
{
|
||||
@ -873,7 +856,7 @@ namespace xna {
|
||||
private:
|
||||
friend class GraphicsDevice;
|
||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||
bool _usevsync{ true };
|
||||
UINT vSyncValue = 1;
|
||||
};
|
||||
|
||||
struct Game::PlatformImplementation {
|
||||
|
@ -20,14 +20,14 @@ namespace xna {
|
||||
//graphics->Initialize();
|
||||
graphics->ApplyChanges();
|
||||
|
||||
std::any device = graphicsDevice;
|
||||
services->AddService(*typeof<GraphicsDevice>(), device);
|
||||
std::any device = Device();
|
||||
Services()->AddService(*typeof<GraphicsDevice>(), device);
|
||||
|
||||
Game::Initialize();
|
||||
}
|
||||
|
||||
void LoadContent() override {
|
||||
spriteBatch = snew<SpriteBatch>(graphicsDevice);
|
||||
spriteBatch = snew<SpriteBatch>(Device());
|
||||
Game::LoadContent();
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
void Draw(GameTime const& gameTime) override {
|
||||
graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||
Device()->Clear(Colors::CornflowerBlue);
|
||||
Game::Draw(gameTime);
|
||||
}
|
||||
|
||||
|
@ -24,14 +24,14 @@ namespace PlatformerStarterKit {
|
||||
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
||||
graphics->ApplyChanges();
|
||||
|
||||
std::any device = graphicsDevice;
|
||||
services->AddService(*typeof<GraphicsDevice>(), device);
|
||||
std::any device = Device();
|
||||
Services()->AddService(*typeof<GraphicsDevice>(), device);
|
||||
|
||||
Game::Initialize();
|
||||
}
|
||||
|
||||
void LoadContent() override {
|
||||
spriteBatch = snew<SpriteBatch>(graphicsDevice);
|
||||
spriteBatch = snew<SpriteBatch>(Device());
|
||||
|
||||
// Load fonts
|
||||
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");
|
||||
@ -55,7 +55,7 @@ namespace PlatformerStarterKit {
|
||||
}
|
||||
|
||||
void Draw(GameTime const& gameTime) override {
|
||||
graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||
Device()->Clear(Colors::CornflowerBlue);
|
||||
|
||||
spriteBatch->Begin();
|
||||
|
||||
@ -73,7 +73,7 @@ namespace PlatformerStarterKit {
|
||||
auto keyboardState = Keyboard::GetState();
|
||||
auto gamepadState = GamePad::GetState(PlayerIndex::One);
|
||||
|
||||
if (gamepadState.Buttons.Back == ButtonState::Pressed)
|
||||
if (gamepadState.Buttons().Back() == ButtonState::Pressed)
|
||||
Exit();
|
||||
|
||||
bool continuePressed =
|
||||
@ -111,7 +111,7 @@ namespace PlatformerStarterKit {
|
||||
levelIndex = -1;
|
||||
}
|
||||
|
||||
level = snew<Level>(services, levelPath);
|
||||
level = snew<Level>(Services(), levelPath);
|
||||
level->Initialize();
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ namespace PlatformerStarterKit {
|
||||
|
||||
void DrawHud()
|
||||
{
|
||||
auto titleSafeArea = graphicsDevice->Viewport().Bounds();
|
||||
auto titleSafeArea = Device()->Viewport().Bounds();
|
||||
auto hudLocation = Vector2(titleSafeArea.X, titleSafeArea.Y);
|
||||
auto center = Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
|
||||
titleSafeArea.Y + titleSafeArea.Height / 2.0f);
|
||||
|
@ -92,7 +92,7 @@ namespace PlatformerStarterKit {
|
||||
auto gamePadState = xna::GamePad::GetState(xna::PlayerIndex::One);
|
||||
auto keyboardState = xna::Keyboard::GetState();
|
||||
|
||||
movement = gamePadState.ThumbSticks.Left().X * MoveStickScale;
|
||||
movement = gamePadState.ThumbSticks().Left().X * MoveStickScale;
|
||||
|
||||
if (std::abs(movement) < 0.5f)
|
||||
movement = 0.0f;
|
||||
|
Loading…
x
Reference in New Issue
Block a user