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

90 lines
1.9 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-04-20 13:39:19 -03:00
#include "keyboard-dx.hpp"
#include "mouse-dx.hpp"
#include "audioengine-dx.hpp"
2024-03-21 16:01:47 -03:00
namespace xna {
Game::Game() {
_gameWindow = New<GameWindow>();
_gameWindow->Color(255, 155, 55);
2024-04-20 13:39:19 -03:00
_gameWindow->Title("XN65");
_gameWindow->Size(
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight, false);
2024-04-20 13:39:19 -03:00
//CoInitializeEx <20> requisito para inicializa<7A><61>o correta de AudioEngine
const auto hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr)) {
MessageBox(nullptr, "Ocorreu um erro ao executar a fun<75><6E>o CoInitializeEx", "XN65", MB_OK);
}
_audioEngine = New<AudioEngine>();
Keyboard::_dxKeyboard = uNew<DirectX::Keyboard>();
Mouse::_dxMouse = uNew<DirectX::Mouse>();
2024-03-21 16:01:47 -03:00
}
2024-04-20 13:39:19 -03:00
static void intializeAudioEngine() {
}
int Game::Run() {
Initialize();
2024-04-07 14:06:12 -03:00
if (_graphicsDevice == nullptr) {
2024-04-20 13:39:19 -03:00
MessageBox(nullptr, "O dispositivo gr<67>fico n<>o foi inicializado corretamente", "XN65", MB_OK);
2024-03-21 16:01:47 -03:00
return EXIT_FAILURE;
}
return startLoop();
}
2024-04-20 13:39:19 -03:00
void Game::Initialize() {
LoadContent();
}
void Game::Update(GameTime const& gameTime) {
_audioEngine->Update();
}
2024-03-21 16:01:47 -03:00
int Game::startLoop() {
MSG msg{};
2024-03-23 17:23:07 -03:00
_clock.Start();
2024-03-21 16:01:47 -03:00
do {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
2024-03-21 16:01:47 -03:00
TranslateMessage(&msg);
DispatchMessage(&msg);
2024-03-21 16:01:47 -03:00
}
else {
tick();
}
2024-03-23 17:23:07 -03:00
} while (msg.message != WM_QUIT);
2024-03-23 17:23:07 -03:00
return static_cast<int>(msg.wParam);
}
2024-03-23 17:23:07 -03:00
void Game::tick() {
_clock.Reset();
2024-03-23 17:23:07 -03:00
this->Update(_currentGameTime);
_currentGameTime.ElapsedGameTime = _clock.ElapsedTime();
_currentGameTime.TotalGameTime = _clock.TotalTime();
2024-03-21 16:01:47 -03:00
this->Draw(_currentGameTime);
2024-03-21 16:01:47 -03:00
_graphicsDevice->Present();
_currentGameTime.ElapsedGameTime = _clock.ElapsedTime();
_currentGameTime.TotalGameTime = _clock.TotalTime();
2024-03-21 16:01:47 -03:00
}
}