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

63 lines
1.4 KiB
C++
Raw Normal View History

2024-03-21 16:01:47 -03:00
#include "game-dx.hpp"
#include "window-dx.hpp"
#include "device-dx.hpp"
#include "Windows.h"
2024-03-23 17:23:07 -03:00
#include "../game/time.hpp"
#include "gdevicemanager-dx.hpp"
2024-03-21 16:01:47 -03:00
namespace xna {
Game::Game() {
_gameWindow = New<GameWindow>();
_gameWindow->Color(255, 155, 55);
_gameWindow->Title("Teste de t<>tulo");
_gameWindow->Size(
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight, false);
2024-03-21 16:01:47 -03:00
}
int Game::Run() {
2024-04-01 14:37:07 -03:00
if (GraphicsDevice == nullptr) {
MessageBox(nullptr, "O dispositivo gr<67>fico n<>o foi inicializar corretamente", "Xna Game Engine", MB_OK);
2024-03-21 16:01:47 -03:00
return EXIT_FAILURE;
}
return startLoop();
}
int Game::startLoop() {
2024-03-23 17:23:07 -03:00
MSG msg{};
_clock.Start();
2024-03-21 16:01:47 -03:00
GameTime gameTime{};
TimeSpan endElapsedTime{};
2024-03-21 16:01:47 -03:00
do {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
auto elapsed = _clock.ElapsedTime();
gameTime.ElapsedGameTime = elapsed - endElapsedTime;
gameTime.TotalGameTime = _clock.TotalTime();
2024-03-23 17:23:07 -03:00
2024-04-01 14:37:07 -03:00
this->Update(gameTime);
2024-03-23 17:23:07 -03:00
elapsed = _clock.ElapsedTime();
gameTime.ElapsedGameTime = elapsed - endElapsedTime;
gameTime.TotalGameTime = _clock.TotalTime();
2024-03-23 17:23:07 -03:00
this->Draw(gameTime);
2024-03-23 17:23:07 -03:00
2024-04-01 14:37:07 -03:00
GraphicsDevice->Present();
endElapsedTime = _clock.ElapsedTime();
2024-03-21 16:01:47 -03:00
}
} while (msg.message != WM_QUIT);
2024-03-23 17:23:07 -03:00
return static_cast<int>(msg.wParam);
2024-03-21 16:01:47 -03:00
}
}