1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/inc/xna/game/game.hpp

87 lines
3.2 KiB
C++
Raw Normal View History

2024-03-21 16:01:47 -03:00
#ifndef XNA_GAME_GAME_HPP
#define XNA_GAME_GAME_HPP
2024-05-06 10:32:17 -03:00
#include "../default.hpp"
2024-06-03 21:55:09 -03:00
#include "time.hpp"
2024-03-21 16:01:47 -03:00
namespace xna {
2024-08-01 16:10:05 -03:00
//Provides basic graphics device initialization, game logic, and rendering code.
2024-05-24 22:57:41 -03:00
class Game : public std::enable_shared_from_this<Game> {
2024-03-21 16:01:47 -03:00
public:
2024-05-24 22:57:41 -03:00
Game();
2024-08-01 16:10:05 -03:00
//Gets the collection of GameComponents owned by the game.
sptr<GameComponentCollection> Components() const;
//Gets or sets the current ContentManager.
sptr<ContentManager> Content() const;
//Gets or sets the current ContentManager.
void Content(sptr<ContentManager> const& value);
//Gets the current GraphicsDevice.
sptr<GraphicsDevice> Device() const;
//Gets or sets a value indicating whether to use fixed time steps.
//The default value for IsFixedTimeStep is true.
constexpr bool IsFixedTimeStep() const { return isFixedTimeStep; }
//Gets or sets a value indicating whether to use fixed time steps.
//The default value for IsFixedTimeStep is true.
void IsFixedTimeStep(bool value);
//Gets or sets a value indicating whether the mouse cursor should be visible.
bool IsMouseVisible() const;
//Gets or sets a value indicating whether the mouse cursor should be visible.
void IsMouseVisible(bool value);
//Gets the GameServiceContainer holding all the service providers attached to the Game.
sptr<GameServiceContainer> Services();
//Gets or sets the target time between calls to Update when IsFixedTimeStep is true.
constexpr TimeSpan TargetElapsedTime() const { return targetElapsedTime; }
//Gets or sets the target time between calls to Update when IsFixedTimeStep is true.
void TargetElapsedTime(TimeSpan const& value);
//Gets the underlying operating system window.
sptr<GameWindow> Window();
//Exits the game.
2024-05-24 22:57:41 -03:00
void Exit();
2024-08-01 16:10:05 -03:00
//Resets the elapsed time counter.
void ResetElapsedTime() const;
//Call this method to initialize the game, begin running the game loop, and start processing events for the game.
2024-05-24 22:57:41 -03:00
int Run();
2024-08-01 16:10:05 -03:00
//Run the game through what would happen in a single tick of the game clock; this method is designed for debugging only.
void RunOneFrame();
//Updates the game's clock and calls Update and Draw.
void Tick();
2024-03-21 16:01:47 -03:00
2024-08-01 16:10:05 -03:00
void EnableGameComponents(bool value);
void AttachGraphicsDevice(sptr<GraphicsDevice> const& graphicsDevice);
void ResizeWindow(int width, int heigth);
2024-03-21 16:01:47 -03:00
protected:
2024-05-24 22:57:41 -03:00
virtual void Draw(GameTime const& gameTime);
virtual void Initialize();
virtual void LoadContent(){}
virtual void Update(GameTime const& gameTime);
2024-08-01 16:10:05 -03:00
int StartGameLoop();
2024-05-24 22:57:41 -03:00
public:
sptr<GraphicsDevice> graphicsDevice = nullptr;
protected:
sptr<GameServiceContainer> services = nullptr;
private:
sptr<GameComponentCollection> _gameComponents = nullptr;
sptr<GameWindow> _gameWindow{ nullptr };
sptr<AudioEngine> _audioEngine = nullptr;
2024-08-01 16:10:05 -03:00
sptr<ContentManager> contentManager;
2024-05-24 22:57:41 -03:00
std::vector<sptr<IGameComponent>> _drawableGameComponents;
size_t _drawableGameComponentsCount{ 0 };
bool _enabledGameComponents{ false };
GameTime _currentGameTime{};
2024-08-01 16:10:05 -03:00
bool isFixedTimeStep{ true };
TimeSpan targetElapsedTime{ TimeSpan::FromTicks(166667L) };
bool isRunning{ false };
2024-05-24 22:57:41 -03:00
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
2024-03-21 16:01:47 -03:00
};
}
#endif