2024-04-23 16:11:17 -03:00
|
|
|
|
#define NOMINMAX
|
2024-03-23 17:23:07 -03:00
|
|
|
|
#include "../game/time.hpp"
|
2024-04-23 16:11:17 -03:00
|
|
|
|
#include "audioengine-dx.hpp"
|
|
|
|
|
#include "device-dx.hpp"
|
|
|
|
|
#include "game-dx.hpp"
|
|
|
|
|
#include "gamepad-dx.hpp"
|
2024-03-30 14:25:08 -03:00
|
|
|
|
#include "gdevicemanager-dx.hpp"
|
2024-04-20 13:39:19 -03:00
|
|
|
|
#include "keyboard-dx.hpp"
|
|
|
|
|
#include "mouse-dx.hpp"
|
2024-04-23 16:11:17 -03:00
|
|
|
|
#include "window-dx.hpp"
|
|
|
|
|
#include "Windows.h"
|
2024-03-21 16:01:47 -03:00
|
|
|
|
|
|
|
|
|
namespace xna {
|
|
|
|
|
Game::Game() {
|
2024-04-23 16:11:17 -03:00
|
|
|
|
Keyboard::_dxKeyboard = uNew<DirectX::Keyboard>();
|
|
|
|
|
Mouse::_dxMouse = uNew<DirectX::Mouse>();
|
|
|
|
|
GamePad::_dxGamePad = uNew<DirectX::GamePad>();
|
|
|
|
|
|
2024-03-21 16:01:47 -03:00
|
|
|
|
_gameWindow = New<GameWindow>();
|
|
|
|
|
_gameWindow->Color(255, 155, 55);
|
2024-04-20 13:39:19 -03:00
|
|
|
|
_gameWindow->Title("XN65");
|
2024-03-30 14:25:08 -03:00
|
|
|
|
_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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-23 16:11:17 -03:00
|
|
|
|
_audioEngine = New<AudioEngine>();
|
|
|
|
|
}
|
2024-04-20 13:39:19 -03:00
|
|
|
|
|
2024-04-22 16:14:55 -03:00
|
|
|
|
void Game::Exit()
|
|
|
|
|
{
|
|
|
|
|
_gameWindow->Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Game::Run() {
|
2024-04-16 16:13:36 -03:00
|
|
|
|
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
|
|
|
|
|
2024-04-23 16:11:17 -03:00
|
|
|
|
void Game::Draw(GameTime const& gameTime) {
|
|
|
|
|
_graphicsDevice->Present();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-20 13:39:19 -03:00
|
|
|
|
void Game::Initialize() {
|
|
|
|
|
LoadContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::Update(GameTime const& gameTime) {
|
|
|
|
|
_audioEngine->Update();
|
|
|
|
|
}
|
2024-04-23 16:11:17 -03:00
|
|
|
|
|
2024-03-21 16:01:47 -03:00
|
|
|
|
int Game::startLoop() {
|
2024-04-23 16:11:17 -03:00
|
|
|
|
MSG msg{};
|
|
|
|
|
_stepTimer = DX::StepTimer();
|
2024-03-21 16:01:47 -03:00
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
2024-04-23 16:11:17 -03:00
|
|
|
|
{
|
2024-03-21 16:01:47 -03:00
|
|
|
|
TranslateMessage(&msg);
|
2024-04-23 16:11:17 -03:00
|
|
|
|
DispatchMessage(&msg);
|
2024-03-21 16:01:47 -03:00
|
|
|
|
}
|
|
|
|
|
else {
|
2024-04-23 16:11:17 -03:00
|
|
|
|
step();
|
2024-04-16 16:13:36 -03:00
|
|
|
|
}
|
2024-03-23 17:23:07 -03:00
|
|
|
|
|
2024-04-16 16:13:36 -03:00
|
|
|
|
} while (msg.message != WM_QUIT);
|
2024-03-23 17:23:07 -03:00
|
|
|
|
|
2024-04-16 16:13:36 -03:00
|
|
|
|
return static_cast<int>(msg.wParam);
|
|
|
|
|
}
|
2024-03-23 17:23:07 -03:00
|
|
|
|
|
2024-04-23 16:11:17 -03:00
|
|
|
|
void Game::step()
|
|
|
|
|
{
|
|
|
|
|
_stepTimer.Tick([&]()
|
|
|
|
|
{
|
|
|
|
|
const auto elapsed = _stepTimer.GetElapsedSeconds();
|
|
|
|
|
const auto total =_stepTimer.GetTotalSeconds();
|
|
|
|
|
const auto elapsedTimeSpan = TimeSpan::FromSeconds(elapsed);
|
|
|
|
|
const auto totalTimeSpan = TimeSpan::FromSeconds(total);
|
|
|
|
|
_currentGameTime.ElapsedGameTime = elapsedTimeSpan;
|
|
|
|
|
_currentGameTime.TotalGameTime = totalTimeSpan;
|
|
|
|
|
Update(_currentGameTime);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Draw(_currentGameTime);
|
2024-03-21 16:01:47 -03:00
|
|
|
|
}
|
|
|
|
|
}
|