[Scummvm-git-logs] scummvm master -> e1a5c1778ba05bc9a819993450d33c58a4ab0d64

dreammaster dreammaster at scummvm.org
Sun Apr 11 20:15:57 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e1a5c1778b AGS: Cleanup of key state handling


Commit: e1a5c1778ba05bc9a819993450d33c58a4ab0d64
    https://github.com/scummvm/scummvm/commit/e1a5c1778ba05bc9a819993450d33c58a4ab0d64
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-04-11T13:15:47-07:00

Commit Message:
AGS: Cleanup of key state handling

Changed paths:
    engines/ags/engine/main/game_run.cpp
    engines/ags/events.cpp
    engines/ags/events.h
    engines/ags/globals.h


diff --git a/engines/ags/engine/main/game_run.cpp b/engines/ags/engine/main/game_run.cpp
index 5402d0d8b2..d6961c8a88 100644
--- a/engines/ags/engine/main/game_run.cpp
+++ b/engines/ags/engine/main/game_run.cpp
@@ -251,37 +251,35 @@ static int get_active_shifts() {
 // and no more processing required, otherwise returns true and provides current keycode and key shifts.
 bool run_service_key_controls(int &kgn) {
 	// check keypresses
-	static int old_key_shifts = 0; // for saving shift modes
-
 	bool handled = false;
 	int kbhit_res = ags_kbhit();
 	// First, check shifts
 	const int act_shifts = get_active_shifts();
 	// If shifts combination have already triggered an action, then do nothing
 	// until new shifts are empty, in which case reset saved shifts
-	if (old_key_shifts & KEY_SHIFTS_FIRED) {
+	if (_G(old_key_shifts) & KEY_SHIFTS_FIRED) {
 		if (act_shifts == 0)
-			old_key_shifts = 0;
+			_G(old_key_shifts) = 0;
 	} else {
 		// If any non-shift key is pressed, add fired flag to indicate that
 		// this is no longer a pure shifts key combination
 		if (kbhit_res) {
-			old_key_shifts = act_shifts | KEY_SHIFTS_FIRED;
+			_G(old_key_shifts) = act_shifts | KEY_SHIFTS_FIRED;
 		}
 		// If all the previously registered shifts are still pressed,
 		// then simply resave new shift state.
-		else if ((old_key_shifts & act_shifts) == old_key_shifts) {
-			old_key_shifts = act_shifts;
+		else if ((_G(old_key_shifts) & act_shifts) == _G(old_key_shifts)) {
+			_G(old_key_shifts) = act_shifts;
 		}
 		// Otherwise some of the shifts were released, then run key combo action
 		// and set KEY_COMBO_FIRED flag to prevent multiple execution
-		else if (old_key_shifts) {
+		else if (_G(old_key_shifts)) {
 			// Toggle mouse lock on Ctrl + Alt
-			if (old_key_shifts == (KB_ALT_FLAG | KB_CTRL_FLAG)) {
+			if (_G(old_key_shifts) == (KB_ALT_FLAG | KB_CTRL_FLAG)) {
 				toggle_mouse_lock();
 				handled = true;
 			}
-			old_key_shifts |= KEY_SHIFTS_FIRED;
+			_G(old_key_shifts) |= KEY_SHIFTS_FIRED;
 		}
 	}
 
diff --git a/engines/ags/events.cpp b/engines/ags/events.cpp
index 51df1dbcf9..704065d230 100644
--- a/engines/ags/events.cpp
+++ b/engines/ags/events.cpp
@@ -28,7 +28,7 @@ namespace AGS {
 
 EventsManager *g_events;
 
-EventsManager::EventsManager() : _keyFlags(0) {
+EventsManager::EventsManager() {
 	g_events = this;
 	_keys.resize(AGS3::__allegro_KEY_MAX);
 }
@@ -47,14 +47,14 @@ void EventsManager::pollEvents() {
 			_G(check_dynamic_sprites_at_exit) = false;
 
 		} else if (e.type == Common::EVENT_KEYDOWN) {
-			updateKeys(e.kbd.keycode, true);
+			updateKeys(e.kbd, true);
 
 			if (!isModifierKey(e.kbd.keycode)) {
 				// Add keypresses to the pending key list
 				_pendingKeys.push(e.kbd);
 			}
 		} else if (e.type == Common::EVENT_KEYUP) {
-			updateKeys(e.kbd.keycode, false);
+			updateKeys(e.kbd, false);
 
 		} else {
 			// Add other event types to the pending events queue. If the event is a
@@ -170,23 +170,30 @@ void EventsManager::updateKeys(const Common::KeyState &keyState, bool isDown) {
 	int scancode = getScancode(keyState.keycode);
 	if (scancode != 0)
 		_keys[scancode] = isDown;
+}
+
+uint EventsManager::getModifierFlags() const {
+	if (_pendingKeys.empty())
+		return 0;
 
-	// Update shift flags
-	_keyFlags = 0;
-	if (keyState.flags & Common::KBD_SHIFT)
-		_keyFlags |= AGS3::__allegro_KB_SHIFT_FLAG;
-	if (keyState.flags & Common::KBD_CTRL)
-		_keyFlags |= AGS3::__allegro_KB_CTRL_FLAG;
-	if (keyState.flags & Common::KBD_ALT)
-		_keyFlags |= AGS3::__allegro_KB_ALT_FLAG;
-	if (keyState.flags & Common::KBD_META)
-		_keyFlags |= AGS3::__allegro_KB_COMMAND_FLAG;
-	if (keyState.flags & Common::KBD_SCRL)
-		_keyFlags |= AGS3::__allegro_KB_SCROLOCK_FLAG;
-	if (keyState.flags & Common::KBD_NUM)
-		_keyFlags |= AGS3::__allegro_KB_NUMLOCK_FLAG;
-	if (keyState.flags & Common::KBD_CAPS)
-		_keyFlags |= AGS3::__allegro_KB_CAPSLOCK_FLAG;
+	byte flags = _pendingKeys.front().flags;
+	uint keyFlags = 0;
+	if (flags & Common::KBD_SHIFT)
+		keyFlags |= AGS3::__allegro_KB_SHIFT_FLAG;
+	if (flags & Common::KBD_CTRL)
+		keyFlags |= AGS3::__allegro_KB_CTRL_FLAG;
+	if (flags & Common::KBD_ALT)
+		keyFlags |= AGS3::__allegro_KB_ALT_FLAG;
+	if (flags & Common::KBD_META)
+		keyFlags |= AGS3::__allegro_KB_COMMAND_FLAG;
+	if (flags & Common::KBD_SCRL)
+		keyFlags |= AGS3::__allegro_KB_SCROLOCK_FLAG;
+	if (flags & Common::KBD_NUM)
+		keyFlags |= AGS3::__allegro_KB_NUMLOCK_FLAG;
+	if (flags & Common::KBD_CAPS)
+		keyFlags |= AGS3::__allegro_KB_CAPSLOCK_FLAG;
+
+	return keyFlags;
 }
 
 bool EventsManager::isKeyPressed(AGS3::AllegroKbdKeycode keycode) const {
diff --git a/engines/ags/events.h b/engines/ags/events.h
index f291136c07..4f361c0093 100644
--- a/engines/ags/events.h
+++ b/engines/ags/events.h
@@ -35,7 +35,6 @@ private:
 	Common::Queue<Common::Event> _pendingEvents;
 	Common::Queue<Common::KeyState> _pendingKeys;
 	Common::Array<bool> _keys;
-	uint _keyFlags;
 
 	bool isModifierKey(const Common::KeyCode &keycode) const;
 
@@ -79,9 +78,7 @@ public:
 	/**
 	 * Returns the bitset of currently pressed modifier keys
 	 */
-	uint getModifierFlags() const {
-		return _keyFlags;
-	}
+	uint getModifierFlags() const;
 };
 
 extern EventsManager *g_events;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index ee743f3e0b..926d29288b 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -728,6 +728,7 @@ public:
 	unsigned int _lastcounter = 0;
 	int _numEventsAtStartOfFunction = 0;
 	uint32 _t1 = 0; // timer for FPS
+	int _old_key_shifts = 0; // for saving shift modes
 
 	 /**@}*/
 




More information about the Scummvm-git-logs mailing list