Restore const for Event class by using 'mutable' mutex.

This commit is contained in:
Stephen Anthony 2018-09-20 21:51:10 -02:30
parent c475072455
commit 1bb19a05ba
35 changed files with 46 additions and 45 deletions

View File

@ -54,7 +54,7 @@ KeyboardWidget::KeyboardWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KeyboardWidget::loadConfig()
{
Event& event = instance().eventHandler().event();
const Event& event = instance().eventHandler().event();
for(int i = 0; i < 12; ++i)
myBox[i]->setState(event.get(myEvent[i]));
}

View File

@ -30,7 +30,7 @@ class AmigaMouse : public PointingDevice
@param event The event object to use for events
@param system The system using this controller
*/
AmigaMouse(Jack jack, Event& event, const System& system)
AmigaMouse(Jack jack, const Event& event, const System& system)
: PointingDevice(jack, event, system, Controller::AmigaMouse,
trackballSensitivity) { }
virtual ~AmigaMouse() = default;

View File

@ -30,7 +30,7 @@ class AtariMouse : public PointingDevice
@param event The event object to use for events
@param system The system using this controller
*/
AtariMouse(Jack jack, Event& event, const System& system)
AtariMouse(Jack jack, const Event& event, const System& system)
: PointingDevice(jack, event, system, Controller::AtariMouse,
trackballSensitivity) { }
virtual ~AtariMouse() = default;

View File

@ -20,7 +20,7 @@
#include "AtariVox.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AtariVox::AtariVox(Jack jack, Event& event, const System& system,
AtariVox::AtariVox(Jack jack, const Event& event, const System& system,
const SerialPort& port, const string& portname,
const string& eepromfile)
: SaveKey(jack, event, system, eepromfile, Controller::AtariVox),

View File

@ -45,7 +45,7 @@ class AtariVox : public SaveKey
@param portname Name of the port used for reading and writing
@param eepromfile The file containing the EEPROM data
*/
AtariVox(Jack jack, Event& event, const System& system,
AtariVox(Jack jack, const Event& event, const System& system,
const SerialPort& port, const string& portname,
const string& eepromfile);
virtual ~AtariVox() = default;

View File

@ -19,7 +19,7 @@
#include "Booster.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BoosterGrip::BoosterGrip(Jack jack, Event& event, const System& system)
BoosterGrip::BoosterGrip(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::BoosterGrip),
myControlID(-1)
{

View File

@ -38,7 +38,7 @@ class BoosterGrip : public Controller
@param event The event object to use for events
@param system The system using this controller
*/
BoosterGrip(Jack jack, Event& event, const System& system);
BoosterGrip(Jack jack, const Event& event, const System& system);
virtual ~BoosterGrip() = default;
public:

View File

@ -20,7 +20,7 @@
#include "CompuMate.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CompuMate::CompuMate(const Console& console, Event& event,
CompuMate::CompuMate(const Console& console, const Event& event,
const System& system)
: myConsole(console),
myColumn(0),

View File

@ -50,7 +50,7 @@ class CompuMate
@param event The event object to use for events
@param system The system using this controller
*/
CompuMate(const Console& console, Event& event, const System& system);
CompuMate(const Console& console, const Event& event, const System& system);
virtual ~CompuMate() = default; // Controllers are deleted outside this class
/**
@ -98,7 +98,7 @@ class CompuMate
@param event The event object to use for events
@param system The system using this controller
*/
CMControl(class CompuMate& handler, Controller::Jack jack, Event& event,
CMControl(class CompuMate& handler, Controller::Jack jack, const Event& event,
const System& system)
: Controller(jack, event, system, Controller::CompuMate),
myHandler(handler) { }

View File

@ -372,7 +372,7 @@ class Console : public Serializable
OSystem& myOSystem;
// Reference to the event object to use
Event& myEvent;
const Event& myEvent;
// Properties for the game
Properties myProperties;

View File

@ -21,7 +21,7 @@
#include "Control.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Controller::Controller(Jack jack, Event& event, const System& system,
Controller::Controller(Jack jack, const Event& event, const System& system,
Type type)
: myJack(jack),
myEvent(event),

View File

@ -108,7 +108,7 @@ class Controller : public Serializable
@param system The system using this controller
@param type The type for this controller
*/
Controller(Jack jack, Event& event, const System& system,
Controller(Jack jack, const Event& event, const System& system,
Type type);
virtual ~Controller() = default;
@ -275,7 +275,7 @@ class Controller : public Serializable
const Jack myJack;
/// Reference to the event object this controller uses
Event& myEvent;
const Event& myEvent;
/// Pointer to the System object (used for timing purposes)
const System& mySystem;

View File

@ -21,7 +21,7 @@
#include "Driving.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Driving::Driving(Jack jack, Event& event, const System& system)
Driving::Driving(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::Driving),
myCounter(0),
myGrayIndex(0),

View File

@ -37,7 +37,7 @@ class Driving : public Controller
@param event The event object to use for events
@param system The system using this controller
*/
Driving(Jack jack, Event& event, const System& system);
Driving(Jack jack, const Event& event, const System& system);
virtual ~Driving() = default;
public:

View File

@ -24,7 +24,7 @@
#include "StellaKeys.hxx"
/**
@author Bradford W. Mott, Stephen Anthony
@author Stephen Anthony, Christian Speckner
*/
class Event
{
@ -89,9 +89,10 @@ class Event
: myKeyTable(keyTable),
myMutex(mutex),
myIsEnabled(true)
{}
{
}
bool operator[](int type) {
bool operator[](int type) const {
if (!myIsEnabled) return false;
std::lock_guard<std::mutex> lock(myMutex);
@ -122,7 +123,7 @@ class Event
/**
Get the value associated with the event of the specified type.
*/
Int32 get(Type type) {
Int32 get(Type type) const {
std::lock_guard<std::mutex> lock(myMutex);
return myValues[type];
@ -154,7 +155,7 @@ class Event
/**
Get the keytable associated with this event.
*/
KeyTable getKeys() { return KeyTable(myKeyTable, myMutex); }
KeyTable getKeys() const { return KeyTable(myKeyTable, myMutex); }
/**
Set the value associated with the event of the specified type.
@ -189,7 +190,7 @@ class Event
// Array of keyboard key states
bool myKeyTable[KBDK_LAST];
std::mutex myMutex;
mutable std::mutex myMutex;
private:
// Following constructors and assignment operators not supported

View File

@ -63,7 +63,7 @@ class EventHandler
@return The event object
*/
Event& event() { return myEvent; }
const Event& event() const { return myEvent; }
/**
Initialize state of this eventhandler.

View File

@ -19,7 +19,7 @@
#include "Genesis.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Genesis::Genesis(Jack jack, Event& event, const System& system)
Genesis::Genesis(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::Genesis),
myControlID(-1)
{

View File

@ -40,7 +40,7 @@ class Genesis : public Controller
@param event The event object to use for events
@param system The system using this controller
*/
Genesis(Jack jack, Event& event, const System& system);
Genesis(Jack jack, const Event& event, const System& system);
virtual ~Genesis() = default;
public:

View File

@ -19,7 +19,7 @@
#include "Joystick.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Joystick::Joystick(Jack jack, Event& event, const System& system)
Joystick::Joystick(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::Joystick),
myControlID(-1)
{

View File

@ -37,7 +37,7 @@ class Joystick : public Controller
@param event The event object to use for events
@param system The system using this controller
*/
Joystick(Jack jack, Event& event, const System& system);
Joystick(Jack jack, const Event& event, const System& system);
virtual ~Joystick() = default;
public:

View File

@ -19,7 +19,7 @@
#include "Keyboard.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Keyboard::Keyboard(Jack jack, Event& event, const System& system)
Keyboard::Keyboard(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::Keyboard)
{
if(myJack == Left)

View File

@ -37,7 +37,7 @@ class Keyboard : public Controller
@param event The event object to use for events
@param system The system using this controller
*/
Keyboard(Jack jack, Event& event, const System& system);
Keyboard(Jack jack, const Event& event, const System& system);
virtual ~Keyboard() = default;
public:

View File

@ -21,7 +21,7 @@
#include "KidVid.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KidVid::KidVid(Jack jack, Event& event, const System& system,
KidVid::KidVid(Jack jack, const Event& event, const System& system,
const string& rommd5)
: Controller(jack, event, system, Controller::KidVid),
myEnabled(myJack == Right),

View File

@ -47,7 +47,7 @@ class KidVid : public Controller
@param system The system using this controller
@param md5sum The md5 of the ROM using this controller
*/
KidVid(Jack jack, Event& event, const System& system,
KidVid(Jack jack, const Event& event, const System& system,
const string& md5sum);
virtual ~KidVid();

View File

@ -19,7 +19,7 @@
#include "MindLink.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MindLink::MindLink(Jack jack, Event& event, const System& system)
MindLink::MindLink(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::MindLink),
myMindlinkPos(0x2800),
myMindlinkShift(1),

View File

@ -47,7 +47,7 @@ class MindLink : public Controller
@param event The event object to use for events
@param system The system using this controller
*/
MindLink(Jack jack, Event& event, const System& system);
MindLink(Jack jack, const Event& event, const System& system);
virtual ~MindLink() = default;
public:

View File

@ -19,7 +19,7 @@
#include "Paddles.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paddles::Paddles(Jack jack, Event& event, const System& system,
Paddles::Paddles(Jack jack, const Event& event, const System& system,
bool swappaddle, bool swapaxis, bool swapdir)
: Controller(jack, event, system, Controller::Paddles),
myMPaddleID(-1),

View File

@ -43,7 +43,7 @@ class Paddles : public Controller
causes movement (lesser axis values cause paddle
resistance to decrease instead of increase)
*/
Paddles(Jack jack, Event& event, const System& system,
Paddles(Jack jack, const Event& event, const System& system,
bool swappaddle, bool swapaxis, bool swapdir);
virtual ~Paddles() = default;

View File

@ -23,7 +23,7 @@
#include "PointingDevice.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PointingDevice::PointingDevice(Jack jack, Event& event,
PointingDevice::PointingDevice(Jack jack, const Event& event,
const System& system, Controller::Type type,
float sensitivity)
: Controller(jack, event, system, type),

View File

@ -35,7 +35,7 @@ class PointingDevice : public Controller
friend class PointingDeviceWidget;
public:
PointingDevice(Jack jack, Event& event,
PointingDevice(Jack jack, const Event& event,
const System& system, Controller::Type type,
float sensitivity);
virtual ~PointingDevice() = default;

View File

@ -20,7 +20,7 @@
#include "SaveKey.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey::SaveKey(Jack jack, Event& event, const System& system,
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, Type type)
: Controller(jack, event, system, type)
{
@ -30,7 +30,7 @@ SaveKey::SaveKey(Jack jack, Event& event, const System& system,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey::SaveKey(Jack jack, Event& event, const System& system,
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile)
: SaveKey(jack, event, system, eepromfile, Controller::SaveKey)
{

View File

@ -42,7 +42,7 @@ class SaveKey : public Controller
@param system The system using this controller
@param eepromfile The file containing the EEPROM data
*/
SaveKey(Jack jack, Event& event, const System& system,
SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile);
virtual ~SaveKey();
@ -51,7 +51,7 @@ class SaveKey : public Controller
Delegating constructor currently used by both this class and classes
that inherit from SaveKey (currently, AtariVox)
*/
SaveKey(Jack jack, Event& event, const System& system,
SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, Type type);
public:

View File

@ -21,7 +21,7 @@
#include "Switches.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Switches::Switches(Event& event, const Properties& properties,
Switches::Switches(const Event& event, const Properties& properties,
const Settings& settings)
: myEvent(event),
mySwitches(0xFF),

View File

@ -46,7 +46,7 @@ class Switches : public Serializable
@param props The ROM properties to use for the currently enabled ROM
@param settings The settings used by the system
*/
Switches(Event& event, const Properties& props, const Settings& settings);
Switches(const Event& event, const Properties& props, const Settings& settings);
virtual ~Switches() = default;
public:
@ -124,7 +124,7 @@ class Switches : public Serializable
private:
// Reference to the event object to use
Event& myEvent;
const Event& myEvent;
// State of the console switches
uInt8 mySwitches;

View File

@ -30,7 +30,7 @@ class TrakBall : public PointingDevice
@param event The event object to use for events
@param system The system using this controller
*/
TrakBall(Jack jack, Event& event, const System& system)
TrakBall(Jack jack, const Event& event, const System& system)
: PointingDevice(jack, event, system, Controller::TrakBall,
trackballSensitivity) { }
virtual ~TrakBall() = default;