diff --git a/Gaming/inc/Game.h b/Gaming/inc/Game.h index d69c113..858f9cc 100644 --- a/Gaming/inc/Game.h +++ b/Gaming/inc/Game.h @@ -37,12 +37,13 @@ namespace Gaming { virtual int fps() const = 0; virtual bool useVsync() const = 0; - virtual int displayWidth() const { return rasterWidth(); } - virtual int displayHeight() const { return rasterHeight(); } - virtual int displayScale() const = 0; - - virtual int rasterWidth() const = 0; - virtual int rasterHeight() const = 0; + virtual int windowWidth() const noexcept { return displayWidth() * displayScale(); } + virtual int windowHeight() const noexcept { return displayHeight() * displayScale(); } + virtual int displayWidth() const noexcept { return rasterWidth(); } + virtual int displayHeight() const noexcept { return rasterHeight(); } + virtual int displayScale() const noexcept = 0; + virtual int rasterWidth() const noexcept = 0; + virtual int rasterHeight() const noexcept = 0; virtual std::string title() const = 0; @@ -57,12 +58,33 @@ namespace Gaming { virtual const uint32_t* pixels() const = 0; - std::shared_ptr m_pixelFormat; + std::shared_ptr gameController(const int which) const { + const auto i = m_gameControllers.find(which); + if (i == m_gameControllers.cend()) + throw std::runtime_error("Unknown controller"); + return i->second; + } + + int mappedController(const SDL_JoystickID which) const { + const auto i = m_mappedControllers.find(which); + if (i == m_mappedControllers.cend()) + throw std::runtime_error("Unknown joystick"); + return i->second; + } + + int chooseControllerIndex(int who) const; + std::shared_ptr chooseController(int who) const; + + std::shared_ptr renderer() const noexcept { return m_renderer; } + std::shared_ptr bitmapTexture() const noexcept { return m_bitmapTexture; } + std::shared_ptr pixelFormat() const noexcept { return m_pixelFormat; } private: std::shared_ptr m_window; std::shared_ptr m_renderer; std::shared_ptr m_bitmapTexture; + std::shared_ptr m_pixelFormat; + Uint32 m_pixelType = SDL_PIXELFORMAT_ARGB8888; bool m_vsync = false; @@ -80,8 +102,5 @@ namespace Gaming { virtual void handleJoyButtonDown(SDL_JoyButtonEvent event) {} virtual void handleJoyButtonUp(SDL_JoyButtonEvent event) {} - - int chooseControllerIndex(int who) const; - std::shared_ptr chooseController(int who) const; }; } diff --git a/Gaming/src/Game.cpp b/Gaming/src/Game.cpp index 56489fd..a1f9d7b 100644 --- a/Gaming/src/Game.cpp +++ b/Gaming/src/Game.cpp @@ -18,7 +18,7 @@ void Game::raisePOWER() { m_window.reset(::SDL_CreateWindow( title().c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - displayWidth() * displayScale(), displayHeight() * displayScale(), + windowWidth(), windowHeight(), SDL_WINDOW_SHOWN), ::SDL_DestroyWindow); if (m_window == nullptr) throwSDLException("Unable to create window: ");