diff --git a/framework/forward.hpp b/framework/forward.hpp index 05b8592..c3b09c1 100644 --- a/framework/forward.hpp +++ b/framework/forward.hpp @@ -6,85 +6,84 @@ namespace xna { //Framework class BoundingBox; + using PBoundingBox = std::shared_ptr; class BoundingFrustum; + using PBoundingFrustum = std::shared_ptr; class BoundinSphere; + using PBoundinSphere = std::shared_ptr; struct Color; + using PColor = std::shared_ptr; class Curve; + using PCurve = std::shared_ptr; class CurveContinuity; + using PCurveContinuity = std::shared_ptr; class CurveKey; + using PCurveKey = std::shared_ptr; class CurveKeyCollection; + using PCurveKeyCollection = std::shared_ptr; struct Matrix; + using PMatrix = std::shared_ptr; class Plane; + using PPlane = std::shared_ptr; struct Point; + using PPoint = std::shared_ptr; class Quaternion; + using PQuaternion = std::shared_ptr; class Ray; + using PRay = std::shared_ptr; struct Rectangle; + using PRectangle = std::shared_ptr; struct Vector2; + using PVector2 = std::shared_ptr; struct Vector3; + using PVector3 = std::shared_ptr; struct Vector4; + using PVector4 = std::shared_ptr; + //Game class DrawableGameComponent; + using PDrawableGameComponent = std::shared_ptr; class Game; + using PGame = std::shared_ptr; class GameComponent; + using PGameComponent = std::shared_ptr; class GameComponentCollection; + using PGameComponentCollection = std::shared_ptr; class GameClock; + using PGameClock = std::shared_ptr; class GameTime; + using PGameTime = std::shared_ptr; class GameWindow; + using PGameWindow = std::shared_ptr; class IDrawable; + using PIDrawable = std::shared_ptr; class IGameComponent; + using PIGameComponent = std::shared_ptr; class IUpdatable; + using PIUpdatable = std::shared_ptr; //Graphics class BlendState; + using PBlendState = std::shared_ptr; class DisplayMode; + using PDisplayMode = std::shared_ptr; class DisplayModeCollection; + using PDisplayModeCollection = std::shared_ptr; class GraphicsAdapter; + using PGraphicsAdapter = std::shared_ptr; class GraphicsDevice; + using PGraphicsDevice = std::shared_ptr; class RenderTarget2D; + using PRenderTarget2D = std::shared_ptr; class SwapChain; + using PSwapChain = std::shared_ptr; class Texture; + using PTexture = std::shared_ptr; class Texture2D; + using PTexture2D = std::shared_ptr; struct Viewport; - - using PBoundingBox = std::shared_ptr; - using PBoundingFrustum = std::shared_ptr; - using PBoundinSphere = std::shared_ptr; - using PColor = std::shared_ptr; - using PCurve = std::shared_ptr; - using PCurveContinuity = std::shared_ptr; - using PCurveKey = std::shared_ptr; - using PCurveKeyCollection = std::shared_ptr; - using PMatrix = std::shared_ptr; - using PPlane = std::shared_ptr; - using PPoint = std::shared_ptr; - using PQuaternion = std::shared_ptr; - using PRay = std::shared_ptr; - using PRectangle = std::shared_ptr; - using PVector2 = std::shared_ptr; - using PVector3 = std::shared_ptr; - using PVector4 = std::shared_ptr; - - using PDrawableGameComponent = std::shared_ptr; - using PGame = std::shared_ptr; - using PGameComponent = std::shared_ptr; - using PGameComponentCollection = std::shared_ptr; - using PGameTime = std::shared_ptr; - using PGameWindow = std::shared_ptr; - using PIDrawable = std::shared_ptr; - using PIGameComponent = std::shared_ptr; - using PIUpdatable = std::shared_ptr; - - using PBlendState = std::shared_ptr; - using PDisplayMode = std::shared_ptr; - using PDisplayModeCollection = std::shared_ptr; - using PGraphicsAdapter = std::shared_ptr; - using PGraphicsDevice = std::shared_ptr; - using PRenderTarget2D = std::shared_ptr; - using PSwapChain = std::shared_ptr; - using PTexture = std::shared_ptr; - using PTexture2D = std::shared_ptr; - using PViewport = std::shared_ptr; + using PViewport = std::shared_ptr; } #endif \ No newline at end of file diff --git a/framework/platform/blendstate-dx.cpp b/framework/platform/blendstate-dx.cpp index 3dd79ba..e7fa87c 100644 --- a/framework/platform/blendstate-dx.cpp +++ b/framework/platform/blendstate-dx.cpp @@ -10,15 +10,21 @@ namespace xna { D3D11_BLEND_DESC blendDesc{}; blendDesc.AlphaToCoverageEnable = AlphaToCoverage; - blendDesc.IndependentBlendEnable = IndependentBlendEnable; - blendDesc.RenderTarget[0].BlendEnable = RenderTargets[0]->Enabled; - blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Source); - blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Destination); - blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(RenderTargets[0]->Operation); - blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->SourceAlpha); - blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->DestinationAlpha); - blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(RenderTargets[0]->OperationAlpha); - blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(RenderTargets[0]->WriteMask); + blendDesc.IndependentBlendEnable = IndependentBlendEnable; + + for (size_t i = 0; i < 8; ++i) { + if (RenderTargets[i] == nullptr) + break; + + blendDesc.RenderTarget[0].BlendEnable = RenderTargets[0]->Enabled; + blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Source); + blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Destination); + blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(RenderTargets[0]->Operation); + blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->SourceAlpha); + blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->DestinationAlpha); + blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(RenderTargets[0]->OperationAlpha); + blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(RenderTargets[0]->WriteMask); + } if (_device == nullptr || _device != device) _device = device; diff --git a/framework/platform/game-dx.cpp b/framework/platform/game-dx.cpp index 963990d..65ce6c3 100644 --- a/framework/platform/game-dx.cpp +++ b/framework/platform/game-dx.cpp @@ -31,6 +31,9 @@ namespace xna { MSG msg{}; _clock.Start(); + GameTime gameTime{}; + TimeSpan endElapsedTime{}; + do { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { @@ -38,23 +41,23 @@ namespace xna { DispatchMessage(&msg); } else { - GameTime gt; + auto elapsed = _clock.ElapsedTime(); + gameTime.ElapsedGameTime = elapsed - endElapsedTime; + gameTime.TotalGameTime = _clock.TotalTime(); - gt.ElapsedGameTime = _clock.ElapsedTime(); - gt.TotalGameTime = _clock.TotalTime(); - auto ml = gt.ElapsedGameTime.Milliseconds(); + this->Update(gameTime); - this->Update(gt); + //_graphicsDevice->Clear(); - _graphicsDevice->Clear(); + elapsed = _clock.ElapsedTime(); + gameTime.ElapsedGameTime = elapsed - endElapsedTime; + gameTime.TotalGameTime = _clock.TotalTime(); - gt.ElapsedGameTime = _clock.ElapsedTime(); - gt.TotalGameTime = _clock.TotalTime(); - ml = gt.ElapsedGameTime.Milliseconds(); - - this->Draw(gt); + this->Draw(gameTime); _graphicsDevice->Present(); + + endElapsedTime = _clock.ElapsedTime(); } } while (msg.message != WM_QUIT); diff --git a/framework/platform/game-dx.hpp b/framework/platform/game-dx.hpp index 45eada4..c5e7b05 100644 --- a/framework/platform/game-dx.hpp +++ b/framework/platform/game-dx.hpp @@ -22,9 +22,9 @@ namespace xna { virtual void Initialize() override{} virtual void Update(GameTime const& gameTime) override{} - private: + protected: + PGraphicsDevice _graphicsDevice{ nullptr }; PGameWindow _gameWindow{ nullptr }; - PGraphicsDevice _graphicsDevice{ nullptr }; GameClock _clock{}; GameTime _currentGameTime{}; diff --git a/framework/xna.cpp b/framework/xna.cpp index 5420f38..5a8a552 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -12,8 +12,23 @@ using namespace xna; // return 0; //} +class Game1 : public Game { + virtual void Update(GameTime const& gameTime) { + + Game::Update(gameTime); + } + + virtual void Draw(GameTime const& gameTime) { + _graphicsDevice->Clear(); + + Game::Draw(gameTime); + } +}; + int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) { - Game game; + /*Game game; + game.Run();*/ + Game1 game; game.Run(); return 0; }