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() void KeyboardWidget::loadConfig()
{ {
Event& event = instance().eventHandler().event(); const Event& event = instance().eventHandler().event();
for(int i = 0; i < 12; ++i) for(int i = 0; i < 12; ++i)
myBox[i]->setState(event.get(myEvent[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 event The event object to use for events
@param system The system using this controller @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, : PointingDevice(jack, event, system, Controller::AmigaMouse,
trackballSensitivity) { } trackballSensitivity) { }
virtual ~AmigaMouse() = default; virtual ~AmigaMouse() = default;

View File

@ -30,7 +30,7 @@ class AtariMouse : public PointingDevice
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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, : PointingDevice(jack, event, system, Controller::AtariMouse,
trackballSensitivity) { } trackballSensitivity) { }
virtual ~AtariMouse() = default; virtual ~AtariMouse() = default;

View File

@ -20,7 +20,7 @@
#include "AtariVox.hxx" #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 SerialPort& port, const string& portname,
const string& eepromfile) const string& eepromfile)
: SaveKey(jack, event, system, eepromfile, Controller::AtariVox), : 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 portname Name of the port used for reading and writing
@param eepromfile The file containing the EEPROM data @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 SerialPort& port, const string& portname,
const string& eepromfile); const string& eepromfile);
virtual ~AtariVox() = default; virtual ~AtariVox() = default;

View File

@ -19,7 +19,7 @@
#include "Booster.hxx" #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), : Controller(jack, event, system, Controller::BoosterGrip),
myControlID(-1) myControlID(-1)
{ {

View File

@ -38,7 +38,7 @@ class BoosterGrip : public Controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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; virtual ~BoosterGrip() = default;
public: public:

View File

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

View File

@ -50,7 +50,7 @@ class CompuMate
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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 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 event The event object to use for events
@param system The system using this controller @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) const System& system)
: Controller(jack, event, system, Controller::CompuMate), : Controller(jack, event, system, Controller::CompuMate),
myHandler(handler) { } myHandler(handler) { }

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@
#include "Driving.hxx" #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), : Controller(jack, event, system, Controller::Driving),
myCounter(0), myCounter(0),
myGrayIndex(0), myGrayIndex(0),

View File

@ -37,7 +37,7 @@ class Driving : public Controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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; virtual ~Driving() = default;
public: public:

View File

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

View File

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

View File

@ -19,7 +19,7 @@
#include "Genesis.hxx" #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), : Controller(jack, event, system, Controller::Genesis),
myControlID(-1) myControlID(-1)
{ {

View File

@ -40,7 +40,7 @@ class Genesis : public Controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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; virtual ~Genesis() = default;
public: public:

View File

@ -19,7 +19,7 @@
#include "Joystick.hxx" #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), : Controller(jack, event, system, Controller::Joystick),
myControlID(-1) myControlID(-1)
{ {

View File

@ -37,7 +37,7 @@ class Joystick : public Controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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; virtual ~Joystick() = default;
public: public:

View File

@ -19,7 +19,7 @@
#include "Keyboard.hxx" #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) : Controller(jack, event, system, Controller::Keyboard)
{ {
if(myJack == Left) if(myJack == Left)

View File

@ -37,7 +37,7 @@ class Keyboard : public Controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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; virtual ~Keyboard() = default;
public: public:

View File

@ -21,7 +21,7 @@
#include "KidVid.hxx" #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) const string& rommd5)
: Controller(jack, event, system, Controller::KidVid), : Controller(jack, event, system, Controller::KidVid),
myEnabled(myJack == Right), myEnabled(myJack == Right),

View File

@ -47,7 +47,7 @@ class KidVid : public Controller
@param system The system using this controller @param system The system using this controller
@param md5sum The md5 of the ROM 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); const string& md5sum);
virtual ~KidVid(); virtual ~KidVid();

View File

@ -19,7 +19,7 @@
#include "MindLink.hxx" #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), : Controller(jack, event, system, Controller::MindLink),
myMindlinkPos(0x2800), myMindlinkPos(0x2800),
myMindlinkShift(1), myMindlinkShift(1),

View File

@ -47,7 +47,7 @@ class MindLink : public Controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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; virtual ~MindLink() = default;
public: public:

View File

@ -19,7 +19,7 @@
#include "Paddles.hxx" #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) bool swappaddle, bool swapaxis, bool swapdir)
: Controller(jack, event, system, Controller::Paddles), : Controller(jack, event, system, Controller::Paddles),
myMPaddleID(-1), myMPaddleID(-1),

View File

@ -43,7 +43,7 @@ class Paddles : public Controller
causes movement (lesser axis values cause paddle causes movement (lesser axis values cause paddle
resistance to decrease instead of increase) 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); bool swappaddle, bool swapaxis, bool swapdir);
virtual ~Paddles() = default; virtual ~Paddles() = default;

View File

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

View File

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

View File

@ -20,7 +20,7 @@
#include "SaveKey.hxx" #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) const string& eepromfile, Type type)
: Controller(jack, event, system, 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) const string& eepromfile)
: SaveKey(jack, event, system, eepromfile, Controller::SaveKey) : 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 system The system using this controller
@param eepromfile The file containing the EEPROM data @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); const string& eepromfile);
virtual ~SaveKey(); virtual ~SaveKey();
@ -51,7 +51,7 @@ class SaveKey : public Controller
Delegating constructor currently used by both this class and classes Delegating constructor currently used by both this class and classes
that inherit from SaveKey (currently, AtariVox) 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); const string& eepromfile, Type type);
public: public:

View File

@ -21,7 +21,7 @@
#include "Switches.hxx" #include "Switches.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Switches::Switches(Event& event, const Properties& properties, Switches::Switches(const Event& event, const Properties& properties,
const Settings& settings) const Settings& settings)
: myEvent(event), : myEvent(event),
mySwitches(0xFF), 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 props The ROM properties to use for the currently enabled ROM
@param settings The settings used by the system @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; virtual ~Switches() = default;
public: public:
@ -124,7 +124,7 @@ class Switches : public Serializable
private: private:
// Reference to the event object to use // Reference to the event object to use
Event& myEvent; const Event& myEvent;
// State of the console switches // State of the console switches
uInt8 mySwitches; uInt8 mySwitches;

View File

@ -30,7 +30,7 @@ class TrakBall : public PointingDevice
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @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, : PointingDevice(jack, event, system, Controller::TrakBall,
trackballSensitivity) { } trackballSensitivity) { }
virtual ~TrakBall() = default; virtual ~TrakBall() = default;