2019-09-28 13:29:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#include <Device.h>
|
|
|
|
|
2019-10-01 22:54:48 +00:00
|
|
|
#include "SDLWrapper.h"
|
2019-09-28 13:29:44 +00:00
|
|
|
|
|
|
|
class Configuration;
|
|
|
|
|
|
|
|
namespace Gaming {
|
2021-04-07 20:36:09 +00:00
|
|
|
|
|
|
|
class GameController;
|
|
|
|
|
2019-09-28 13:29:44 +00:00
|
|
|
class Game : public EightBit::Device {
|
|
|
|
public:
|
|
|
|
Game();
|
|
|
|
virtual ~Game();
|
|
|
|
|
|
|
|
virtual void runLoop();
|
2021-08-23 08:44:48 +00:00
|
|
|
void raisePOWER() override;
|
2019-09-28 13:29:44 +00:00
|
|
|
|
|
|
|
protected:
|
2021-07-18 13:28:40 +00:00
|
|
|
virtual float fps() const noexcept = 0;
|
|
|
|
virtual bool useVsync() const noexcept = 0;
|
2019-09-28 13:29:44 +00:00
|
|
|
|
2021-04-07 20:36:09 +00:00
|
|
|
virtual int windowWidth() const noexcept;
|
|
|
|
virtual int windowHeight() const noexcept;
|
|
|
|
virtual int displayWidth() const noexcept;
|
|
|
|
virtual int displayHeight() const noexcept;
|
2019-09-28 23:27:45 +00:00
|
|
|
virtual int displayScale() const noexcept = 0;
|
|
|
|
virtual int rasterWidth() const noexcept = 0;
|
|
|
|
virtual int rasterHeight() const noexcept = 0;
|
2019-09-28 13:29:44 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
virtual std::string title() const noexcept = 0;
|
2019-09-28 13:29:44 +00:00
|
|
|
|
2020-05-03 19:55:58 +00:00
|
|
|
virtual void handleEvents();
|
|
|
|
virtual void update();
|
|
|
|
virtual void draw();
|
|
|
|
virtual bool maybeSynchronise(); // true, if manual synchronisation required
|
|
|
|
virtual void synchronise();
|
|
|
|
|
2019-09-29 00:46:56 +00:00
|
|
|
virtual void runRasterLines() {};
|
|
|
|
virtual void runVerticalBlank() {}
|
2019-09-28 13:29:44 +00:00
|
|
|
|
|
|
|
void addJoystick(SDL_Event& e);
|
|
|
|
void removeJoystick(SDL_Event& e);
|
|
|
|
|
|
|
|
virtual void updateTexture();
|
|
|
|
virtual void copyTexture();
|
|
|
|
virtual void displayTexture();
|
|
|
|
|
|
|
|
virtual const uint32_t* pixels() const = 0;
|
|
|
|
|
2019-10-01 22:54:48 +00:00
|
|
|
virtual bool handleKeyDown(SDL_Keycode key);
|
|
|
|
virtual bool handleKeyUp(SDL_Keycode key);
|
|
|
|
|
|
|
|
virtual bool handleJoyButtonDown(SDL_JoyButtonEvent event);
|
|
|
|
virtual bool handleJoyButtonUp(SDL_JoyButtonEvent event);
|
|
|
|
|
|
|
|
virtual bool handleControllerButtonDown(SDL_ControllerButtonEvent event);
|
|
|
|
virtual bool handleControllerButtonUp(SDL_ControllerButtonEvent event);
|
|
|
|
|
|
|
|
void toggleFullscreen();
|
|
|
|
|
2021-04-07 20:36:09 +00:00
|
|
|
std::shared_ptr<GameController> gameController(int which) const;
|
|
|
|
int mappedController(const SDL_JoystickID which) const;
|
2019-09-28 23:27:45 +00:00
|
|
|
|
|
|
|
int chooseControllerIndex(int who) const;
|
|
|
|
std::shared_ptr<GameController> chooseController(int who) const;
|
|
|
|
|
|
|
|
std::shared_ptr<SDL_Renderer> renderer() const noexcept { return m_renderer; }
|
|
|
|
std::shared_ptr<SDL_Texture> bitmapTexture() const noexcept { return m_bitmapTexture; }
|
|
|
|
std::shared_ptr<SDL_PixelFormat> pixelFormat() const noexcept { return m_pixelFormat; }
|
2019-09-28 13:29:44 +00:00
|
|
|
|
|
|
|
private:
|
2019-10-01 22:54:48 +00:00
|
|
|
SDLWrapper m_wrapper;
|
|
|
|
|
2019-09-28 13:29:44 +00:00
|
|
|
std::shared_ptr<SDL_Window> m_window;
|
|
|
|
std::shared_ptr<SDL_Renderer> m_renderer;
|
|
|
|
std::shared_ptr<SDL_Texture> m_bitmapTexture;
|
2019-09-28 23:27:45 +00:00
|
|
|
std::shared_ptr<SDL_PixelFormat> m_pixelFormat;
|
|
|
|
|
2019-09-28 13:29:44 +00:00
|
|
|
Uint32 m_pixelType = SDL_PIXELFORMAT_ARGB8888;
|
|
|
|
|
|
|
|
bool m_vsync = false;
|
|
|
|
Uint32 m_startTicks = 0;
|
|
|
|
Uint32 m_frames = 0;
|
|
|
|
|
|
|
|
std::map<int, std::shared_ptr<GameController>> m_gameControllers;
|
|
|
|
std::map<SDL_JoystickID, int> m_mappedControllers;
|
|
|
|
|
|
|
|
void configureBackground() const;
|
|
|
|
void createBitmapTexture();
|
|
|
|
};
|
|
|
|
}
|