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"
2024-04-24 10:11:53 -03:00
# include <Windows.h>
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 " ) ;
2024-03-30 14:25:08 -03:00
_gameWindow - > Size (
GraphicsDeviceManager : : DefaultBackBufferWidth ,
GraphicsDeviceManager : : DefaultBackBufferHeight , false ) ;
2024-04-24 10:11:53 -03:00
}
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 ( ) {
2024-04-24 10:11:53 -03:00
Keyboard : : Initialize ( ) ;
Mouse : : Initialize ( ) ;
//initialize <20> requisito para GamePad
Microsoft : : WRL : : Wrappers : : RoInitializeWrapper initialize ( RO_INIT_MULTITHREADED ) ;
if ( FAILED ( initialize ) )
MessageBox ( nullptr , " Ocorreu um erro ao executar Microsoft::WRL::Wrappers::RoInitializeWrapper. O GamePad n<> o foi inicializado corretamente. " , " XN65 " , MB_OK ) ;
GamePad . Initialize ( ) ;
//CoInitializeEx <20> requisito para AudioEngine
const auto hr = CoInitializeEx ( nullptr , COINIT_MULTITHREADED ) ;
if ( FAILED ( hr ) )
MessageBox ( nullptr , " Ocorreu um erro ao executar CoInitializeEx. O AudioEngine n<> o foi inicializado corretamente. " , " XN65 " , MB_OK ) ;
_audioEngine = New < AudioEngine > ( ) ;
2024-04-20 13:39:19 -03:00
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-04-24 10:11:53 -03:00
}
2024-03-23 17:23:07 -03:00
2024-04-23 16:11:17 -03:00
void Game : : step ( )
{
2024-04-24 10:11:53 -03:00
_stepTimer . Tick ( [ & ] ( )
2024-04-23 16:11:17 -03:00
{
const auto elapsed = _stepTimer . GetElapsedSeconds ( ) ;
2024-04-24 10:11:53 -03:00
const auto total = _stepTimer . GetTotalSeconds ( ) ;
2024-04-23 16:11:17 -03:00
const auto elapsedTimeSpan = TimeSpan : : FromSeconds ( elapsed ) ;
const auto totalTimeSpan = TimeSpan : : FromSeconds ( total ) ;
_currentGameTime . ElapsedGameTime = elapsedTimeSpan ;
_currentGameTime . TotalGameTime = totalTimeSpan ;
2024-04-24 10:11:53 -03:00
Update ( _currentGameTime ) ;
2024-04-23 16:11:17 -03:00
} ) ;
Draw ( _currentGameTime ) ;
2024-03-21 16:01:47 -03:00
}
}