mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2026-04-22 08:16:54 +00:00
Tidy up some C++ a little
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
+9
-19
@@ -3,19 +3,20 @@
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <Device.h>
|
||||
|
||||
#include "GameController.h"
|
||||
#include "SDLWrapper.h"
|
||||
|
||||
class Configuration;
|
||||
|
||||
namespace Gaming {
|
||||
|
||||
class GameController;
|
||||
|
||||
class Game : public EightBit::Device {
|
||||
public:
|
||||
Game();
|
||||
@@ -28,10 +29,10 @@ namespace Gaming {
|
||||
virtual float fps() const = 0;
|
||||
virtual bool useVsync() 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 windowWidth() const noexcept;
|
||||
virtual int windowHeight() const noexcept;
|
||||
virtual int displayWidth() const noexcept;
|
||||
virtual int displayHeight() const noexcept;
|
||||
virtual int displayScale() const noexcept = 0;
|
||||
virtual int rasterWidth() const noexcept = 0;
|
||||
virtual int rasterHeight() const noexcept = 0;
|
||||
@@ -67,19 +68,8 @@ namespace Gaming {
|
||||
|
||||
void toggleFullscreen();
|
||||
|
||||
std::shared_ptr<GameController> 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;
|
||||
}
|
||||
std::shared_ptr<GameController> gameController(int which) const;
|
||||
int mappedController(const SDL_JoystickID which) const;
|
||||
|
||||
int chooseControllerIndex(int who) const;
|
||||
std::shared_ptr<GameController> chooseController(int who) const;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Gaming {
|
||||
class SDLWrapper final {
|
||||
public:
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
#include "stdafx.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include "GameController.h"
|
||||
|
||||
namespace Gaming {
|
||||
|
||||
Game::Game() {}
|
||||
|
||||
Game::~Game() {}
|
||||
|
||||
int Game::windowWidth() const noexcept {
|
||||
return displayWidth() * displayScale();
|
||||
}
|
||||
|
||||
int Game::windowHeight() const noexcept {
|
||||
return displayHeight() * displayScale();
|
||||
}
|
||||
|
||||
int Game::displayWidth() const noexcept {
|
||||
return rasterWidth();
|
||||
}
|
||||
|
||||
int Game::displayHeight() const noexcept {
|
||||
return rasterHeight();
|
||||
}
|
||||
|
||||
void Game::raisePOWER() {
|
||||
|
||||
Device::raisePOWER();
|
||||
@@ -168,6 +186,20 @@ void Game::addJoystick(SDL_Event& e) {
|
||||
SDL_Log("Joystick device %d added (%zd controllers)", which, m_gameControllers.size());
|
||||
}
|
||||
|
||||
std::shared_ptr<GameController> Game::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 Game::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;
|
||||
}
|
||||
|
||||
// -1 if no controllers, otherwise index
|
||||
int Game::chooseControllerIndex(const int who) const {
|
||||
const auto count = m_gameControllers.size();
|
||||
|
||||
Reference in New Issue
Block a user