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

dreammaster dreammaster at scummvm.org
Tue Mar 9 05:15:15 UTC 2021


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

Summary:
5d2d8b2a73 AGS: Move cc_serializer.cpp globals to Globals
bb488f2d58 AGS: Move dynamicsprite.cpp globals to Globals
462f408bbd AGS: Move some global strings to statics
804158fb75 AGS: Refactor Mouse namespace to be a struct
fd7116d342 AGS: Move mousew32.cpp globals to Globals


Commit: 5d2d8b2a73a2a1260a99aff392d876407c9cde03
    https://github.com/scummvm/scummvm/commit/5d2d8b2a73a2a1260a99aff392d876407c9cde03
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-08T21:11:59-08:00

Commit Message:
AGS: Move cc_serializer.cpp globals to Globals

Changed paths:
    engines/ags/engine/ac/dynobj/cc_serializer.cpp
    engines/ags/engine/ac/dynobj/cc_serializer.h
    engines/ags/engine/ac/game.cpp
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/dynobj/cc_serializer.cpp b/engines/ags/engine/ac/dynobj/cc_serializer.cpp
index dee0d9e55c..535fb9b33f 100644
--- a/engines/ags/engine/ac/dynobj/cc_serializer.cpp
+++ b/engines/ags/engine/ac/dynobj/cc_serializer.cpp
@@ -110,6 +110,4 @@ void AGSDeSerializer::Unserialize(int index, const char *objectType, const char
 	}
 }
 
-AGSDeSerializer ccUnserializer;
-
 } // namespace AGS3
diff --git a/engines/ags/engine/ac/dynobj/cc_serializer.h b/engines/ags/engine/ac/dynobj/cc_serializer.h
index 963c65d1d2..ae6109f656 100644
--- a/engines/ags/engine/ac/dynobj/cc_serializer.h
+++ b/engines/ags/engine/ac/dynobj/cc_serializer.h
@@ -32,8 +32,6 @@ struct AGSDeSerializer : ICCObjectReader {
 	void Unserialize(int index, const char *objectType, const char *serializedData, int dataSize) override;
 };
 
-extern AGSDeSerializer ccUnserializer;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 891c582667..3f4b071cfe 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -1439,7 +1439,7 @@ HSaveError restore_game_data(Stream *in, SavegameVersion svg_version, const Pres
 	// save the new room music vol for later use
 	r_data.RoomVolume = (RoomVolumeMod)in->ReadInt32();
 
-	if (ccUnserializeAllObjects(in, &ccUnserializer)) {
+	if (ccUnserializeAllObjects(in, &_GP(ccUnserializer))) {
 		return new SavegameError(kSvgErr_GameObjectInitFailed,
 		                         String::FromFormat("Managed pool deserialization failed: %s.", _G(ccErrorString).GetCStr()));
 	}
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 0e29991f64..10b055cfa8 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -978,7 +978,7 @@ HSaveError WriteManagedPool(PStream out) {
 }
 
 HSaveError ReadManagedPool(PStream in, int32_t cmp_ver, const PreservedParams &pp, RestoredData &r_data) {
-	if (ccUnserializeAllObjects(in.get(), &ccUnserializer)) {
+	if (ccUnserializeAllObjects(in.get(), &_GP(ccUnserializer))) {
 		return new SavegameError(kSvgErr_GameObjectInitFailed,
 		                         String::FromFormat("Managed pool deserialization failed: %s", _G(ccErrorString).GetCStr()));
 	}
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 3ace0d4c8d..00899f98bf 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -48,16 +48,17 @@
 #include "ags/engine/ac/route_finder_jps.h"
 #include "ags/engine/ac/screenoverlay.h"
 #include "ags/engine/ac/spritelistentry.h"
+#include "ags/engine/ac/dynobj/cc_audiochannel.h"
+#include "ags/engine/ac/dynobj/cc_audioclip.h"
+#include "ags/engine/ac/dynobj/cc_character.h"
 #include "ags/engine/ac/dynobj/cc_dialog.h"
+#include "ags/engine/ac/dynobj/cc_gui.h"
 #include "ags/engine/ac/dynobj/cc_guiobject.h"
-#include "ags/engine/ac/dynobj/cc_character.h"
 #include "ags/engine/ac/dynobj/cc_hotspot.h"
-#include "ags/engine/ac/dynobj/cc_region.h"
 #include "ags/engine/ac/dynobj/cc_inventory.h"
-#include "ags/engine/ac/dynobj/cc_gui.h"
 #include "ags/engine/ac/dynobj/cc_object.h"
-#include "ags/engine/ac/dynobj/cc_audiochannel.h"
-#include "ags/engine/ac/dynobj/cc_audioclip.h"
+#include "ags/engine/ac/dynobj/cc_region.h"
+#include "ags/engine/ac/dynobj/cc_serializer.h"
 #include "ags/engine/ac/dynobj/managedobjectpool.h"
 #include "ags/engine/ac/dynobj/scriptaudiochannel.h"
 #include "ags/engine/ac/dynobj/scriptdialogoptionsrendering.h"
@@ -104,6 +105,9 @@ Globals::Globals() {
 	// cc_options.cpp globals
 	_ccCompOptions = SCOPT_LEFTTORIGHT;
 
+	// cc_serializer.cpp globals
+	_ccUnserializer = new AGSDeSerializer();
+
 	// debug.cpp globals
 	_fps = std::numeric_limits<float>::quiet_undefined();
 	_display_fps = kFPS_Hide;
@@ -253,6 +257,9 @@ Globals::~Globals() {
 	// button.cpp globals
 	delete[] _animbuts;
 
+	// cc_serializer.cpp globals
+	delete _ccUnserializer;
+
 	// debug.cpp globals
 	delete[] _debug_line;
 	delete _DebugMsgBuff;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index d1d76897f0..90eb8f1eac 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -80,6 +80,7 @@ class TTFFontRenderer;
 class WFNFontRenderer;
 
 struct ActiveDisplaySetting;
+struct AGSDeSerializer;
 struct AGSPlatformDriver;
 struct AmbientSound;
 struct AnimatingGUIButton;
@@ -265,6 +266,15 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup cc_serializer globals
+	 * @{
+	 */
+
+	AGSDeSerializer *_ccUnserializer;
+
+	/**@}*/
+
 	/**
 	 * \defgroup character globals
 	 * @{


Commit: bb488f2d58a7c62a91d216a8b3a7ae53b7e1eb12
    https://github.com/scummvm/scummvm/commit/bb488f2d58a7c62a91d216a8b3a7ae53b7e1eb12
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-08T21:12:00-08:00

Commit Message:
AGS: Move dynamicsprite.cpp globals to Globals

Changed paths:
    engines/ags/engine/ac/dynamicsprite.cpp
    engines/ags/engine/ac/sys_events.cpp
    engines/ags/engine/debugging/debug.cpp
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/quit.cpp
    engines/ags/events.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/dynamicsprite.cpp b/engines/ags/engine/ac/dynamicsprite.cpp
index 76f48da8ce..72f18b08aa 100644
--- a/engines/ags/engine/ac/dynamicsprite.cpp
+++ b/engines/ags/engine/ac/dynamicsprite.cpp
@@ -52,8 +52,6 @@ using namespace Engine;
 extern color palette[256];
 extern AGS::Engine::IGraphicsDriver *gfxDriver;
 
-char check_dynamic_sprites_at_exit = 1;
-
 // ** SCRIPT DYNAMIC SPRITE
 
 void DynamicSprite_Delete(ScriptDynamicSprite *sds) {
diff --git a/engines/ags/engine/ac/sys_events.cpp b/engines/ags/engine/ac/sys_events.cpp
index 6bd8bded4a..55af823055 100644
--- a/engines/ags/engine/ac/sys_events.cpp
+++ b/engines/ags/engine/ac/sys_events.cpp
@@ -42,8 +42,6 @@ using namespace AGS::Engine;
 extern volatile unsigned long globalTimerCounter;
 int pluginSimulatedClick;
 
-extern char check_dynamic_sprites_at_exit;
-
 extern void domouse(int str);
 extern int mgetbutton();
 extern int misbuttondown(int buno);
@@ -183,7 +181,7 @@ int ags_getch() {
 
 	// Alt+X, abort (but only once game is loaded)
 	if ((gott == _GP(play).abort_key) && (_G(displayed_room) >= 0)) {
-		check_dynamic_sprites_at_exit = 0;
+		_G(check_dynamic_sprites_at_exit) = false;
 		quit("!|");
 	}
 
diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index b9d543f228..56c9d84125 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -57,8 +57,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern char check_dynamic_sprites_at_exit;
-
 extern char pexbuf[STD_BUFFER_SIZE];
 
 const char *OutputMsgBufID = "buffer";
@@ -438,9 +436,9 @@ int check_for_messages_from_editor() {
 			_G(game_paused_in_debugger) = 0;
 			_G(break_on_next_script_step) = 1;
 		} else if (strncmp(msgPtr, "EXIT", 4) == 0) {
-			_G(want_exit) = 1;
-			_G(abort_engine) = 1;
-			check_dynamic_sprites_at_exit = 0;
+			_G(want_exit) = true;
+			_G(abort_engine) = true;
+			_G(check_dynamic_sprites_at_exit) = false;
 		}
 
 		free(msg);
@@ -450,9 +448,6 @@ int check_for_messages_from_editor() {
 	return 0;
 }
 
-
-
-
 bool send_exception_to_editor(const char *qmsg) {
 #if AGS_PLATFORM_OS_WINDOWS
 	_G(want_exit) = 0;
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 5c4daff788..fb3d2538d7 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -83,9 +83,7 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern char check_dynamic_sprites_at_exit;
 extern char pexbuf[STD_BUFFER_SIZE];
-
 extern IGraphicsDriver *gfxDriver;
 extern Bitmap **actsps;
 extern color palette[256];
diff --git a/engines/ags/engine/main/quit.cpp b/engines/ags/engine/main/quit.cpp
index 8c5cd4136d..0fef30aebf 100644
--- a/engines/ags/engine/main/quit.cpp
+++ b/engines/ags/engine/main/quit.cpp
@@ -55,7 +55,6 @@ using namespace AGS::Shared;
 using namespace AGS::Engine;
 
 extern char pexbuf[STD_BUFFER_SIZE];
-extern char check_dynamic_sprites_at_exit;
 extern int need_to_stop_cd;
 extern int use_cdplayer;
 extern IGraphicsDriver *gfxDriver;
@@ -83,7 +82,7 @@ void quit_shutdown_scripts() {
 }
 
 void quit_check_dynamic_sprites(QuitReason qreason) {
-	if ((qreason & kQuitKind_NormalExit) && (check_dynamic_sprites_at_exit) &&
+	if ((qreason & kQuitKind_NormalExit) && (_G(check_dynamic_sprites_at_exit)) &&
 		(_GP(game).options[OPT_DEBUGMODE] != 0)) {
 		// game exiting normally -- make sure the dynamic sprites
 		// have been deleted
diff --git a/engines/ags/events.cpp b/engines/ags/events.cpp
index 723d1edfca..d47b594b08 100644
--- a/engines/ags/events.cpp
+++ b/engines/ags/events.cpp
@@ -24,10 +24,6 @@
 #include "common/system.h"
 #include "ags/globals.h"
 
-namespace AGS3 {
-extern char check_dynamic_sprites_at_exit;
-}
-
 namespace AGS {
 
 EventsManager *g_events;
@@ -48,7 +44,7 @@ void EventsManager::pollEvents() {
 		if (e.type == Common::EVENT_QUIT) {
 			_G(want_exit) = true;
 			_G(abort_engine) = true;
-			::AGS3::check_dynamic_sprites_at_exit = 0;
+			_G(check_dynamic_sprites_at_exit) = false;
 
 		} else if (e.type == Common::EVENT_KEYDOWN) {
 			updateKeys(e.kbd.keycode, true);
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 90eb8f1eac..e7c1ebe0ec 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -391,6 +391,15 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup engine globals
+	 * @{
+	 */
+
+	bool _check_dynamic_sprites_at_exit = true;
+
+	/**@}*/
+
 	/**
 	 * \defgroup engine globals
 	 * @{


Commit: 462f408bbd50743effe36ed733383d23c85cd4f1
    https://github.com/scummvm/scummvm/commit/462f408bbd50743effe36ed733383d23c85cd4f1
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-08T21:12:00-08:00

Commit Message:
AGS: Move some global strings to statics

Changed paths:
    engines/ags/engine/debugging/debug.cpp


diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index 56c9d84125..9fe7df41fe 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -59,11 +59,10 @@ using namespace AGS::Engine;
 
 extern char pexbuf[STD_BUFFER_SIZE];
 
-const char *OutputMsgBufID = "buffer";
-const char *OutputFileID = "file";
-const char *OutputSystemID = "stdout";
-const char *OutputGameConsoleID = "console";
-
+static const char *OutputMsgBufID = "buffer";
+static const char *OutputFileID = "file";
+static const char *OutputSystemID = "stdout";
+static const char *OutputGameConsoleID = "console";
 
 #if AGS_PLATFORM_OS_WINDOWS
 HWND editor_window_handle = 0;


Commit: 804158fb754aab5e4f5c79ecfd44df04a22d22ab
    https://github.com/scummvm/scummvm/commit/804158fb754aab5e4f5c79ecfd44df04a22d22ab
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-08T21:12:00-08:00

Commit Message:
AGS: Refactor Mouse namespace to be a struct

Changed paths:
    engines/ags/engine/ac/game.cpp
    engines/ags/engine/ac/gamestate.cpp
    engines/ags/engine/ac/gui.cpp
    engines/ags/engine/ac/mouse.cpp
    engines/ags/engine/device/mousew32.cpp
    engines/ags/engine/device/mousew32.h
    engines/ags/engine/game/savegame.cpp
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/engine_setup.cpp
    engines/ags/engine/main/game_run.cpp
    engines/ags/engine/main/game_start.cpp
    engines/ags/plugins/agsplugin.cpp


diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 3f4b071cfe..eabca0fa90 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -1701,7 +1701,7 @@ void display_switch_out() {
 	_G(switched_away) = true;
 	ags_clear_input_buffer();
 	// Always unlock mouse when switching out from the game
-	Mouse::UnlockFromWindow();
+	_mouse.UnlockFromWindow();
 	_G(platform)->DisplaySwitchOut();
 	_G(platform)->ExitFullscreenMode();
 }
@@ -1750,7 +1750,7 @@ void display_switch_in() {
 	ags_clear_input_buffer();
 	// If auto lock option is set, lock mouse to the game window
 	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed)
-		Mouse::TryLockToWindow();
+		_mouse.TryLockToWindow();
 }
 
 void display_switch_in_resume() {
diff --git a/engines/ags/engine/ac/gamestate.cpp b/engines/ags/engine/ac/gamestate.cpp
index 2e6011afe9..c81887f388 100644
--- a/engines/ags/engine/ac/gamestate.cpp
+++ b/engines/ags/engine/ac/gamestate.cpp
@@ -79,7 +79,7 @@ void GameState::SetAutoRoomViewport(bool on) {
 
 void GameState::SetMainViewport(const Rect &viewport) {
 	_mainViewport.SetRect(viewport);
-	Mouse::SetGraphicArea();
+	_mouse.SetGraphicArea();
 	_GP(scsystem).viewport_width = game_to_data_coord(_mainViewport.GetRect().GetWidth());
 	_GP(scsystem).viewport_height = game_to_data_coord(_mainViewport.GetRect().GetHeight());
 	_mainViewportHasChanged = true;
diff --git a/engines/ags/engine/ac/gui.cpp b/engines/ags/engine/ac/gui.cpp
index 3a6b5bbb40..56d961d949 100644
--- a/engines/ags/engine/ac/gui.cpp
+++ b/engines/ags/engine/ac/gui.cpp
@@ -306,7 +306,7 @@ void remove_popup_interface(int ifacenum) {
 	UnPauseGame();
 	_GP(guis)[ifacenum].SetConceal(true);
 	if (_G(mousey) <= _GP(guis)[ifacenum].PopupAtMouseY)
-		Mouse::SetPosition(Point(_G(mousex), _GP(guis)[ifacenum].PopupAtMouseY + 2));
+		_mouse.SetPosition(Point(_G(mousex), _GP(guis)[ifacenum].PopupAtMouseY + 2));
 	if ((!IsInterfaceEnabled()) && (cur_cursor == cur_mode))
 		// Only change the mouse cursor if it hasn't been specifically changed first
 		set_mouse_cursor(CURS_WAIT);
diff --git a/engines/ags/engine/ac/mouse.cpp b/engines/ags/engine/ac/mouse.cpp
index b9bb9b6f74..81680879fd 100644
--- a/engines/ags/engine/ac/mouse.cpp
+++ b/engines/ags/engine/ac/mouse.cpp
@@ -34,6 +34,7 @@
 #include "ags/engine/ac/system.h"
 #include "ags/engine/ac/viewframe.h"
 #include "ags/engine/debugging/debug_log.h"
+#include "ags/engine/device/mousew32.h"
 #include "ags/shared/gui/guibutton.h"
 #include "ags/shared/gui/guimain.h"
 #include "ags/engine/device/mousew32.h"
@@ -66,7 +67,7 @@ Bitmap *dotted_mouse_cursor = nullptr;
 IDriverDependantBitmap *mouseCursor = nullptr;
 Bitmap *blank_mouse_cursor = nullptr;
 
-// The Mouse:: functions are static so the script doesn't pass
+// The _mouse. functions are static so the script doesn't pass
 // in an object parameter
 void Mouse_SetVisible(int isOn) {
 	if (isOn)
@@ -105,7 +106,7 @@ void SetMouseBounds(int x1, int y1, int x2, int y2) {
 	_GP(play).mboundx2 = x2;
 	_GP(play).mboundy1 = y1;
 	_GP(play).mboundy2 = y2;
-	Mouse::SetMoveLimit(Rect(x1, y1, x2, y2));
+	_mouse.SetMoveLimit(Rect(x1, y1, x2, y2));
 }
 
 // mouse cursor functions:
@@ -298,7 +299,7 @@ void SetMousePosition(int newx, int newy) {
 		newy = viewport.GetHeight() - 1;
 
 	data_to_game_coords(&newx, &newy);
-	Mouse::SetPosition(Point(newx, newy));
+	_mouse.SetPosition(Point(newx, newy));
 	RefreshMouse();
 }
 
@@ -335,9 +336,9 @@ void Mouse_EnableControl(bool on) {
 	// The resulting choice is made based on two aforementioned factors.
 	on &= should_control_mouse && can_control_mouse;
 	if (on)
-		Mouse::EnableControl(!is_windowed);
+		_mouse.EnableControl(!is_windowed);
 	else
-		Mouse::DisableControl();
+		_mouse.DisableControl();
 }
 
 //=============================================================================
@@ -559,7 +560,7 @@ RuntimeScriptValue Sc_Mouse_Click(const RuntimeScriptValue *params, int32_t para
 }
 
 RuntimeScriptValue Sc_Mouse_GetControlEnabled(const RuntimeScriptValue *params, int32_t param_count) {
-	API_SCALL_BOOL(Mouse::IsControlEnabled);
+	API_SCALL_BOOL(_mouse.IsControlEnabled);
 }
 
 RuntimeScriptValue Sc_Mouse_SetControlEnabled(const RuntimeScriptValue *params, int32_t param_count) {
@@ -568,64 +569,64 @@ RuntimeScriptValue Sc_Mouse_SetControlEnabled(const RuntimeScriptValue *params,
 
 
 RuntimeScriptValue Sc_Mouse_GetSpeed(const RuntimeScriptValue *params, int32_t param_count) {
-	API_SCALL_FLOAT(Mouse::GetSpeed);
+	API_SCALL_FLOAT(_mouse.GetSpeed);
 }
 
 RuntimeScriptValue Sc_Mouse_SetSpeed(const RuntimeScriptValue *params, int32_t param_count) {
-	ASSERT_VARIABLE_VALUE("Mouse::Speed");
-	Mouse::SetSpeed(params[0].FValue);
+	ASSERT_VARIABLE_VALUE("_mouse.Speed");
+	_mouse.SetSpeed(params[0].FValue);
 	return RuntimeScriptValue();
 }
 
 void RegisterMouseAPI() {
-	ccAddExternalStaticFunction("Mouse::ChangeModeGraphic^2", Sc_ChangeCursorGraphic);
-	ccAddExternalStaticFunction("Mouse::ChangeModeHotspot^3", Sc_ChangeCursorHotspot);
-	ccAddExternalStaticFunction("Mouse::ChangeModeView^2", Sc_Mouse_ChangeModeView);
-	ccAddExternalStaticFunction("Mouse::Click^1", Sc_Mouse_Click);
-	ccAddExternalStaticFunction("Mouse::DisableMode^1", Sc_disable_cursor_mode);
-	ccAddExternalStaticFunction("Mouse::EnableMode^1", Sc_enable_cursor_mode);
-	ccAddExternalStaticFunction("Mouse::GetModeGraphic^1", Sc_Mouse_GetModeGraphic);
-	ccAddExternalStaticFunction("Mouse::IsButtonDown^1", Sc_IsButtonDown);
-	ccAddExternalStaticFunction("Mouse::IsModeEnabled^1", Sc_IsModeEnabled);
-	ccAddExternalStaticFunction("Mouse::SaveCursorUntilItLeaves^0", Sc_SaveCursorForLocationChange);
-	ccAddExternalStaticFunction("Mouse::SelectNextMode^0", Sc_SetNextCursor);
-	ccAddExternalStaticFunction("Mouse::SelectPreviousMode^0", Sc_SetPreviousCursor);
-	ccAddExternalStaticFunction("Mouse::SetBounds^4", Sc_SetMouseBounds);
-	ccAddExternalStaticFunction("Mouse::SetPosition^2", Sc_SetMousePosition);
-	ccAddExternalStaticFunction("Mouse::Update^0", Sc_RefreshMouse);
-	ccAddExternalStaticFunction("Mouse::UseDefaultGraphic^0", Sc_set_default_cursor);
-	ccAddExternalStaticFunction("Mouse::UseModeGraphic^1", Sc_set_mouse_cursor);
-	ccAddExternalStaticFunction("Mouse::get_ControlEnabled", Sc_Mouse_GetControlEnabled);
-	ccAddExternalStaticFunction("Mouse::set_ControlEnabled", Sc_Mouse_SetControlEnabled);
-	ccAddExternalStaticFunction("Mouse::get_Mode", Sc_GetCursorMode);
-	ccAddExternalStaticFunction("Mouse::set_Mode", Sc_set_cursor_mode);
-	ccAddExternalStaticFunction("Mouse::get_Speed", Sc_Mouse_GetSpeed);
-	ccAddExternalStaticFunction("Mouse::set_Speed", Sc_Mouse_SetSpeed);
-	ccAddExternalStaticFunction("Mouse::get_Visible", Sc_Mouse_GetVisible);
-	ccAddExternalStaticFunction("Mouse::set_Visible", Sc_Mouse_SetVisible);
+	ccAddExternalStaticFunction("_mouse.ChangeModeGraphic^2", Sc_ChangeCursorGraphic);
+	ccAddExternalStaticFunction("_mouse.ChangeModeHotspot^3", Sc_ChangeCursorHotspot);
+	ccAddExternalStaticFunction("_mouse.ChangeModeView^2", Sc_Mouse_ChangeModeView);
+	ccAddExternalStaticFunction("_mouse.Click^1", Sc_Mouse_Click);
+	ccAddExternalStaticFunction("_mouse.DisableMode^1", Sc_disable_cursor_mode);
+	ccAddExternalStaticFunction("_mouse.EnableMode^1", Sc_enable_cursor_mode);
+	ccAddExternalStaticFunction("_mouse.GetModeGraphic^1", Sc_Mouse_GetModeGraphic);
+	ccAddExternalStaticFunction("_mouse.IsButtonDown^1", Sc_IsButtonDown);
+	ccAddExternalStaticFunction("_mouse.IsModeEnabled^1", Sc_IsModeEnabled);
+	ccAddExternalStaticFunction("_mouse.SaveCursorUntilItLeaves^0", Sc_SaveCursorForLocationChange);
+	ccAddExternalStaticFunction("_mouse.SelectNextMode^0", Sc_SetNextCursor);
+	ccAddExternalStaticFunction("_mouse.SelectPreviousMode^0", Sc_SetPreviousCursor);
+	ccAddExternalStaticFunction("_mouse.SetBounds^4", Sc_SetMouseBounds);
+	ccAddExternalStaticFunction("_mouse.SetPosition^2", Sc_SetMousePosition);
+	ccAddExternalStaticFunction("_mouse.Update^0", Sc_RefreshMouse);
+	ccAddExternalStaticFunction("_mouse.UseDefaultGraphic^0", Sc_set_default_cursor);
+	ccAddExternalStaticFunction("_mouse.UseModeGraphic^1", Sc_set_mouse_cursor);
+	ccAddExternalStaticFunction("_mouse.get_ControlEnabled", Sc_Mouse_GetControlEnabled);
+	ccAddExternalStaticFunction("_mouse.set_ControlEnabled", Sc_Mouse_SetControlEnabled);
+	ccAddExternalStaticFunction("_mouse.get_Mode", Sc_GetCursorMode);
+	ccAddExternalStaticFunction("_mouse.set_Mode", Sc_set_cursor_mode);
+	ccAddExternalStaticFunction("_mouse.get_Speed", Sc_Mouse_GetSpeed);
+	ccAddExternalStaticFunction("_mouse.set_Speed", Sc_Mouse_SetSpeed);
+	ccAddExternalStaticFunction("_mouse.get_Visible", Sc_Mouse_GetVisible);
+	ccAddExternalStaticFunction("_mouse.set_Visible", Sc_Mouse_SetVisible);
 
 	/* ----------------------- Registering unsafe exports for plugins -----------------------*/
 
-	ccAddExternalFunctionForPlugin("Mouse::ChangeModeGraphic^2", (void *)ChangeCursorGraphic);
-	ccAddExternalFunctionForPlugin("Mouse::ChangeModeHotspot^3", (void *)ChangeCursorHotspot);
-	ccAddExternalFunctionForPlugin("Mouse::ChangeModeView^2", (void *)Mouse_ChangeModeView);
-	ccAddExternalFunctionForPlugin("Mouse::DisableMode^1", (void *)disable_cursor_mode);
-	ccAddExternalFunctionForPlugin("Mouse::EnableMode^1", (void *)enable_cursor_mode);
-	ccAddExternalFunctionForPlugin("Mouse::GetModeGraphic^1", (void *)Mouse_GetModeGraphic);
-	ccAddExternalFunctionForPlugin("Mouse::IsButtonDown^1", (void *)IsButtonDown);
-	ccAddExternalFunctionForPlugin("Mouse::IsModeEnabled^1", (void *)IsModeEnabled);
-	ccAddExternalFunctionForPlugin("Mouse::SaveCursorUntilItLeaves^0", (void *)SaveCursorForLocationChange);
-	ccAddExternalFunctionForPlugin("Mouse::SelectNextMode^0", (void *)SetNextCursor);
-	ccAddExternalFunctionForPlugin("Mouse::SelectPreviousMode^0", (void *)SetPreviousCursor);
-	ccAddExternalFunctionForPlugin("Mouse::SetBounds^4", (void *)SetMouseBounds);
-	ccAddExternalFunctionForPlugin("Mouse::SetPosition^2", (void *)SetMousePosition);
-	ccAddExternalFunctionForPlugin("Mouse::Update^0", (void *)RefreshMouse);
-	ccAddExternalFunctionForPlugin("Mouse::UseDefaultGraphic^0", (void *)set_default_cursor);
-	ccAddExternalFunctionForPlugin("Mouse::UseModeGraphic^1", (void *)set_mouse_cursor);
-	ccAddExternalFunctionForPlugin("Mouse::get_Mode", (void *)GetCursorMode);
-	ccAddExternalFunctionForPlugin("Mouse::set_Mode", (void *)set_cursor_mode);
-	ccAddExternalFunctionForPlugin("Mouse::get_Visible", (void *)Mouse_GetVisible);
-	ccAddExternalFunctionForPlugin("Mouse::set_Visible", (void *)Mouse_SetVisible);
+	ccAddExternalFunctionForPlugin("_mouse.ChangeModeGraphic^2", (void *)ChangeCursorGraphic);
+	ccAddExternalFunctionForPlugin("_mouse.ChangeModeHotspot^3", (void *)ChangeCursorHotspot);
+	ccAddExternalFunctionForPlugin("_mouse.ChangeModeView^2", (void *)Mouse_ChangeModeView);
+	ccAddExternalFunctionForPlugin("_mouse.DisableMode^1", (void *)disable_cursor_mode);
+	ccAddExternalFunctionForPlugin("_mouse.EnableMode^1", (void *)enable_cursor_mode);
+	ccAddExternalFunctionForPlugin("_mouse.GetModeGraphic^1", (void *)Mouse_GetModeGraphic);
+	ccAddExternalFunctionForPlugin("_mouse.IsButtonDown^1", (void *)IsButtonDown);
+	ccAddExternalFunctionForPlugin("_mouse.IsModeEnabled^1", (void *)IsModeEnabled);
+	ccAddExternalFunctionForPlugin("_mouse.SaveCursorUntilItLeaves^0", (void *)SaveCursorForLocationChange);
+	ccAddExternalFunctionForPlugin("_mouse.SelectNextMode^0", (void *)SetNextCursor);
+	ccAddExternalFunctionForPlugin("_mouse.SelectPreviousMode^0", (void *)SetPreviousCursor);
+	ccAddExternalFunctionForPlugin("_mouse.SetBounds^4", (void *)SetMouseBounds);
+	ccAddExternalFunctionForPlugin("_mouse.SetPosition^2", (void *)SetMousePosition);
+	ccAddExternalFunctionForPlugin("_mouse.Update^0", (void *)RefreshMouse);
+	ccAddExternalFunctionForPlugin("_mouse.UseDefaultGraphic^0", (void *)set_default_cursor);
+	ccAddExternalFunctionForPlugin("_mouse.UseModeGraphic^1", (void *)set_mouse_cursor);
+	ccAddExternalFunctionForPlugin("_mouse.get_Mode", (void *)GetCursorMode);
+	ccAddExternalFunctionForPlugin("_mouse.set_Mode", (void *)set_cursor_mode);
+	ccAddExternalFunctionForPlugin("_mouse.get_Visible", (void *)Mouse_GetVisible);
+	ccAddExternalFunctionForPlugin("_mouse.set_Visible", (void *)Mouse_SetVisible);
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/device/mousew32.cpp b/engines/ags/engine/device/mousew32.cpp
index ec2fa2d5c8..da7997f325 100644
--- a/engines/ags/engine/device/mousew32.cpp
+++ b/engines/ags/engine/device/mousew32.cpp
@@ -66,40 +66,23 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-const int NONE = -1, LEFT = 0, RIGHT = 1, MIDDLE = 2;
+enum {
+	NONE = -1, LEFT = 0, RIGHT = 1, MIDDLE = 2
+};
 
 extern char lib_file_name[13];
 extern char alpha_blend_cursor;
 extern color palette[256];
 
-namespace Mouse {
-
-// Tells whether mouse was locked to the game window
-bool LockedToWindow = false;
-
-// Screen rectangle, in which the mouse movement is controlled by engine
-Rect  ControlRect;
-// Mouse control enabled flag
-bool  ControlEnabled = false;
-// Flag that tells whether the mouse must be forced to stay inside control rect
-bool  ConfineInCtrlRect = false;
-// Mouse speed value provided by user
-float SpeedVal = 1.f;
-// Mouse speed unit
-float SpeedUnit = 1.f;
-// Actual speed factor (cached)
-float Speed = 1.f;
-
-
-void AdjustPosition(int &x, int &y);
-}
+int butwas = 0;
+Mouse _mouse;
 
 void mgraphconfine(int x1, int y1, int x2, int y2) {
-	Mouse::ControlRect = Rect(x1, y1, x2, y2);
-	set_mouse_range(Mouse::ControlRect.Left, Mouse::ControlRect.Top, Mouse::ControlRect.Right, Mouse::ControlRect.Bottom);
+	_mouse.ControlRect = Rect(x1, y1, x2, y2);
+	set_mouse_range(_mouse.ControlRect.Left, _mouse.ControlRect.Top, _mouse.ControlRect.Right, _mouse.ControlRect.Bottom);
 	Debug::Printf("Mouse confined: (%d,%d)-(%d,%d) (%dx%d)",
-		Mouse::ControlRect.Left, Mouse::ControlRect.Top, Mouse::ControlRect.Right, Mouse::ControlRect.Bottom,
-		Mouse::ControlRect.GetWidth(), Mouse::ControlRect.GetHeight());
+		_mouse.ControlRect.Left, _mouse.ControlRect.Top, _mouse.ControlRect.Right, _mouse.ControlRect.Bottom,
+		_mouse.ControlRect.GetWidth(), _mouse.ControlRect.GetHeight());
 }
 
 void mgetgraphpos() {
@@ -116,22 +99,22 @@ void mgetgraphpos() {
 		return;
 	}
 
-	if (!_G(switched_away) && Mouse::ControlEnabled) {
+	if (!_G(switched_away) && _mouse.ControlEnabled) {
 		// Control mouse movement by querying mouse mickeys (movement deltas)
 		// and applying them to saved mouse coordinates.
 		int mickey_x, mickey_y;
 		get_mouse_mickeys(&mickey_x, &mickey_y);
 
 		// Apply mouse speed
-		int dx = Mouse::Speed * mickey_x;
-		int dy = Mouse::Speed * mickey_y;
+		int dx = _mouse.Speed * mickey_x;
+		int dy = _mouse.Speed * mickey_y;
 
 		//
 		// Perform actual cursor update
 		//---------------------------------------------------------------------
 		// If the real cursor is inside the control rectangle (read - game window),
 		// then apply sensitivity factors and adjust real cursor position
-		if (Mouse::ControlRect.IsInside(_G(real_mouse_x) + dx, _G(real_mouse_y) + dy)) {
+		if (_mouse.ControlRect.IsInside(_G(real_mouse_x) + dx, _G(real_mouse_y) + dy)) {
 			_G(real_mouse_x) += dx;
 			_G(real_mouse_y) += dy;
 			position_mouse(_G(real_mouse_x), _G(real_mouse_y));
@@ -139,9 +122,9 @@ void mgetgraphpos() {
 		// Otherwise, if real cursor was moved outside the control rect, yet we
 		// are required to confine cursor inside one, then adjust cursor position
 		// to stay inside the rect's bounds.
-		else if (Mouse::ConfineInCtrlRect) {
-			_G(real_mouse_x) = Math::Clamp(_G(real_mouse_x) + dx, Mouse::ControlRect.Left, Mouse::ControlRect.Right);
-			_G(real_mouse_y) = Math::Clamp(_G(real_mouse_y) + dy, Mouse::ControlRect.Top, Mouse::ControlRect.Bottom);
+		else if (_mouse.ConfineInCtrlRect) {
+			_G(real_mouse_x) = Math::Clamp(_G(real_mouse_x) + dx, _mouse.ControlRect.Left, _mouse.ControlRect.Right);
+			_G(real_mouse_y) = Math::Clamp(_G(real_mouse_y) + dy, _mouse.ControlRect.Top, _mouse.ControlRect.Bottom);
 			position_mouse(_G(real_mouse_x), _G(real_mouse_y));
 		}
 		// Lastly, if the real cursor is out of the control rect, simply add
@@ -152,7 +135,7 @@ void mgetgraphpos() {
 		}
 
 		// Do not update the game cursor if the real cursor is beyond the control rect
-		if (!Mouse::ControlRect.IsInside(_G(real_mouse_x), _G(real_mouse_y)))
+		if (!_mouse.ControlRect.IsInside(_G(real_mouse_x), _G(real_mouse_y)))
 			return;
 	} else {
 		// Save real cursor coordinates provided by system
@@ -172,7 +155,7 @@ void mgetgraphpos() {
 	}
 
 	// Convert to virtual coordinates
-	Mouse::AdjustPosition(_G(mousex), _G(mousey));
+	_mouse.AdjustPosition(_G(mousex), _G(mousey));
 }
 
 void msetcursorlimit(int x1, int y1, int x2, int y2) {
@@ -222,9 +205,6 @@ void mfreemem() {
 	}
 }
 
-
-
-
 void mloadwcursor(char *namm) {
 	color dummypal[256];
 	if (wloadsprites(&dummypal[0], namm, _G(mousecurs), 0, MAXCURSORS)) {
@@ -232,7 +212,6 @@ void mloadwcursor(char *namm) {
 	}
 }
 
-int butwas = 0;
 int mgetbutton() {
 	int toret = NONE;
 	poll_mouse();
diff --git a/engines/ags/engine/device/mousew32.h b/engines/ags/engine/device/mousew32.h
index 4cee33c6fb..905453f21d 100644
--- a/engines/ags/engine/device/mousew32.h
+++ b/engines/ags/engine/device/mousew32.h
@@ -31,6 +31,9 @@
 //
 //=============================================================================
 
+#ifndef AGS_ENGINE_DEVICE_MOUSEW32_H
+#define AGS_ENGINE_DEVICE_MOUSEW32_H
+
 #include "ags/shared/util/geometry.h"
 #include "ags/shared/util/geometry.h"
 
@@ -57,42 +60,60 @@ void msetgraphpos(int xa, int ya);
 void msethotspot(int xx, int yy);
 int minstalled();
 
-namespace Mouse {
-
-// Get if mouse is locked to the game window
-bool IsLockedToWindow();
-// Try locking mouse to the game window
-bool TryLockToWindow();
-// Unlock mouse from the game window
-void UnlockFromWindow();
-
-// Enable mouse movement control
-void EnableControl(bool confine);
-// Disable mouse movement control
-void DisableControl();
-// Tell if the mouse movement control is enabled
-bool IsControlEnabled();
-// Set base speed factor, which would serve as a mouse speed unit
-void SetSpeedUnit(float f);
-// Get base speed factor
-float GetSpeedUnit();
-// Set speed factors
-void SetSpeed(float speed);
-// Get speed factor
-float GetSpeed();
-
-} // namespace Mouse
-
-namespace Mouse {
-
-// Updates limits of the area inside which the standard OS cursor is not shown;
-// uses game's main viewport (in native coordinates) to calculate real area on screen
-void SetGraphicArea();
-// Limits the area where the game cursor can move on virtual screen;
-// parameter must be in native game coordinates
-void SetMoveLimit(const Rect &r);
-// Set actual OS cursor position on screen; parameter must be in native game coordinates
-void SetPosition(const Point p);
-
-} // namespace Mouse
+struct Mouse {
+	// Tells whether mouse was locked to the game window
+	bool LockedToWindow = false;
+
+	// Screen rectangle, in which the mouse movement is controlled by engine
+	Rect  ControlRect;
+	// Mouse control enabled flag
+	bool  ControlEnabled = false;
+	// Flag that tells whether the mouse must be forced to stay inside control rect
+	bool  ConfineInCtrlRect = false;
+	// Mouse speed value provided by user
+	float SpeedVal = 1.f;
+	// Mouse speed unit
+	float SpeedUnit = 1.f;
+	// Actual speed factor (cached)
+	float Speed = 1.f;
+
+
+	void AdjustPosition(int &x, int &y);
+
+	// Get if mouse is locked to the game window
+	bool IsLockedToWindow();
+	// Try locking mouse to the game window
+	bool TryLockToWindow();
+	// Unlock mouse from the game window
+	void UnlockFromWindow();
+
+	// Enable mouse movement control
+	void EnableControl(bool confine);
+	// Disable mouse movement control
+	void DisableControl();
+	// Tell if the mouse movement control is enabled
+	bool IsControlEnabled();
+	// Set base speed factor, which would serve as a mouse speed unit
+	void SetSpeedUnit(float f);
+	// Get base speed factor
+	float GetSpeedUnit();
+	// Set speed factors
+	void SetSpeed(float speed);
+	// Get speed factor
+	float GetSpeed();
+
+	// Updates limits of the area inside which the standard OS cursor is not shown;
+	// uses game's main viewport (in native coordinates) to calculate real area on screen
+	void SetGraphicArea();
+	// Limits the area where the game cursor can move on virtual screen;
+	// parameter must be in native game coordinates
+	void SetMoveLimit(const Rect &r);
+	// Set actual OS cursor position on screen; parameter must be in native game coordinates
+	void SetPosition(const Point p);
+};
+
+extern Mouse _mouse;
+
 } // namespace AGS3
+
+#endif
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index 5786f0f3a2..106804590b 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -499,7 +499,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
 	// it with SetMusicVolume)
 	_GP(thisroom).Options.MusicVolume = r_data.RoomVolume;
 
-	Mouse::SetMoveLimit(Rect(oldx1, oldy1, oldx2, oldy2));
+	_mouse.SetMoveLimit(Rect(oldx1, oldy1, oldx2, oldy2));
 
 	set_cursor_mode(r_data.CursorMode);
 	set_mouse_cursor(r_data.CursorID);
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index fb3d2538d7..a2d0a4618b 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -289,7 +289,7 @@ void engine_init_mouse() {
 		Debug::Printf(kDbgMsg_Info, "Initializing mouse: failed");
 	else
 		Debug::Printf(kDbgMsg_Info, "Initializing mouse: number of buttons reported is %d", res);
-	Mouse::SetSpeed(_GP(usetup).mouse_speed);
+	_mouse.SetSpeed(_GP(usetup).mouse_speed);
 }
 
 void engine_locate_speech_pak() {
diff --git a/engines/ags/engine/main/engine_setup.cpp b/engines/ags/engine/main/engine_setup.cpp
index f93f95a5a6..1848188658 100644
--- a/engines/ags/engine/main/engine_setup.cpp
+++ b/engines/ags/engine/main/engine_setup.cpp
@@ -262,30 +262,30 @@ void engine_post_gfxmode_mouse_setup(const DisplayMode &dm, const Size &init_des
 	//
 	// NOTE that we setup speed and other related properties regardless of
 	// whether mouse control was requested because it may be enabled later.
-	Mouse::SetSpeedUnit(1.f);
+	_mouse.SetSpeedUnit(1.f);
 	if (_GP(usetup).mouse_speed_def == kMouseSpeed_CurrentDisplay) {
 		Size cur_desktop;
 		if (get_desktop_resolution(&cur_desktop.Width, &cur_desktop.Height) == 0)
-			Mouse::SetSpeedUnit(Math::Max((float)cur_desktop.Width / (float)init_desktop.Width,
+			_mouse.SetSpeedUnit(Math::Max((float)cur_desktop.Width / (float)init_desktop.Width,
 			(float)cur_desktop.Height / (float)init_desktop.Height));
 	}
 
 	Mouse_EnableControl(_GP(usetup).mouse_ctrl_enabled);
-	Debug::Printf(kDbgMsg_Info, "Mouse control: %s, base: %f, speed: %f", Mouse::IsControlEnabled() ? "on" : "off",
-		Mouse::GetSpeedUnit(), Mouse::GetSpeed());
+	Debug::Printf(kDbgMsg_Info, "Mouse control: %s, base: %f, speed: %f", _mouse.IsControlEnabled() ? "on" : "off",
+		_mouse.GetSpeedUnit(), _mouse.GetSpeed());
 
 	on_coordinates_scaling_changed();
 
 	// If auto lock option is set, lock mouse to the game window
 	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed != 0)
-		Mouse::TryLockToWindow();
+		_mouse.TryLockToWindow();
 }
 
 // Reset mouse controls before changing gfx mode
 void engine_pre_gfxmode_mouse_cleanup() {
 	// Always disable mouse control and unlock mouse when releasing down gfx mode
-	Mouse::DisableControl();
-	Mouse::UnlockFromWindow();
+	_mouse.DisableControl();
+	_mouse.UnlockFromWindow();
 }
 
 // Fill in scsystem struct with display mode parameters
@@ -332,12 +332,12 @@ void engine_pre_gfxsystem_shutdown() {
 
 void on_coordinates_scaling_changed() {
 	// Reset mouse graphic area and bounds
-	Mouse::SetGraphicArea();
+	_mouse.SetGraphicArea();
 	// If mouse bounds do not have valid values yet, then limit cursor to viewport
 	if (_GP(play).mboundx1 == 0 && _GP(play).mboundy1 == 0 && _GP(play).mboundx2 == 0 && _GP(play).mboundy2 == 0)
-		Mouse::SetMoveLimit(_GP(play).GetMainViewport());
+		_mouse.SetMoveLimit(_GP(play).GetMainViewport());
 	else
-		Mouse::SetMoveLimit(Rect(_GP(play).mboundx1, _GP(play).mboundy1, _GP(play).mboundx2, _GP(play).mboundy2));
+		_mouse.SetMoveLimit(Rect(_GP(play).mboundx1, _GP(play).mboundy1, _GP(play).mboundx2, _GP(play).mboundy2));
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/main/game_run.cpp b/engines/ags/engine/main/game_run.cpp
index 4c1bc746d1..7372a09fb6 100644
--- a/engines/ags/engine/main/game_run.cpp
+++ b/engines/ags/engine/main/game_run.cpp
@@ -189,15 +189,15 @@ static int game_loop_check_ground_level_interactions() {
 
 static void lock_mouse_on_click() {
 	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed)
-		Mouse::TryLockToWindow();
+		_mouse.TryLockToWindow();
 }
 
 static void toggle_mouse_lock() {
 	if (_GP(scsystem).windowed) {
-		if (Mouse::IsLockedToWindow())
-			Mouse::UnlockFromWindow();
+		if (_mouse.IsLockedToWindow())
+			_mouse.UnlockFromWindow();
 		else
-			Mouse::TryLockToWindow();
+			_mouse.TryLockToWindow();
 	}
 }
 
diff --git a/engines/ags/engine/main/game_start.cpp b/engines/ags/engine/main/game_start.cpp
index 2fcd1d199a..b70220d120 100644
--- a/engines/ags/engine/main/game_start.cpp
+++ b/engines/ags/engine/main/game_start.cpp
@@ -76,7 +76,7 @@ void start_game_load_savegame_on_startup() {
 
 void start_game() {
 	set_cursor_mode(MODE_WALK);
-	Mouse::SetPosition(Point(160, 100));
+	_mouse.SetPosition(Point(160, 100));
 	newmusic(0);
 
 	_G(our_eip) = -42;
diff --git a/engines/ags/plugins/agsplugin.cpp b/engines/ags/plugins/agsplugin.cpp
index 27d92f7ea1..ead91cff33 100644
--- a/engines/ags/plugins/agsplugin.cpp
+++ b/engines/ags/plugins/agsplugin.cpp
@@ -781,7 +781,7 @@ int IAGSEngine::DecrementManagedObjectRefCount(const char *address) {
 }
 
 void IAGSEngine::SetMousePosition(int32 x, int32 y) {
-	Mouse::SetPosition(Point(x, y));
+	_mouse.SetPosition(Point(x, y));
 	RefreshMouse();
 }
 


Commit: fd7116d3429dfb3269eed1e43d25cf7197e193ce
    https://github.com/scummvm/scummvm/commit/fd7116d3429dfb3269eed1e43d25cf7197e193ce
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-08T21:12:00-08:00

Commit Message:
AGS: Move mousew32.cpp globals to Globals

Changed paths:
    engines/ags/engine/ac/game.cpp
    engines/ags/engine/ac/gamestate.cpp
    engines/ags/engine/ac/gui.cpp
    engines/ags/engine/ac/mouse.cpp
    engines/ags/engine/device/mousew32.cpp
    engines/ags/engine/device/mousew32.h
    engines/ags/engine/game/savegame.cpp
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/engine_setup.cpp
    engines/ags/engine/main/game_run.cpp
    engines/ags/engine/main/game_start.cpp
    engines/ags/engine/platform/android/acpland.cpp
    engines/ags/engine/platform/ios/acplios.cpp
    engines/ags/engine/platform/linux/acpllnx.cpp
    engines/ags/engine/platform/osx/acplmac.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/plugins/agsplugin.cpp


diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index eabca0fa90..b55fa7c458 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -1701,7 +1701,7 @@ void display_switch_out() {
 	_G(switched_away) = true;
 	ags_clear_input_buffer();
 	// Always unlock mouse when switching out from the game
-	_mouse.UnlockFromWindow();
+	_GP(mouse).UnlockFromWindow();
 	_G(platform)->DisplaySwitchOut();
 	_G(platform)->ExitFullscreenMode();
 }
@@ -1750,7 +1750,7 @@ void display_switch_in() {
 	ags_clear_input_buffer();
 	// If auto lock option is set, lock mouse to the game window
 	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed)
-		_mouse.TryLockToWindow();
+		_GP(mouse).TryLockToWindow();
 }
 
 void display_switch_in_resume() {
diff --git a/engines/ags/engine/ac/gamestate.cpp b/engines/ags/engine/ac/gamestate.cpp
index c81887f388..2800bd2d3d 100644
--- a/engines/ags/engine/ac/gamestate.cpp
+++ b/engines/ags/engine/ac/gamestate.cpp
@@ -79,7 +79,7 @@ void GameState::SetAutoRoomViewport(bool on) {
 
 void GameState::SetMainViewport(const Rect &viewport) {
 	_mainViewport.SetRect(viewport);
-	_mouse.SetGraphicArea();
+	_GP(mouse).SetGraphicArea();
 	_GP(scsystem).viewport_width = game_to_data_coord(_mainViewport.GetRect().GetWidth());
 	_GP(scsystem).viewport_height = game_to_data_coord(_mainViewport.GetRect().GetHeight());
 	_mainViewportHasChanged = true;
diff --git a/engines/ags/engine/ac/gui.cpp b/engines/ags/engine/ac/gui.cpp
index 56d961d949..050d88311b 100644
--- a/engines/ags/engine/ac/gui.cpp
+++ b/engines/ags/engine/ac/gui.cpp
@@ -306,7 +306,7 @@ void remove_popup_interface(int ifacenum) {
 	UnPauseGame();
 	_GP(guis)[ifacenum].SetConceal(true);
 	if (_G(mousey) <= _GP(guis)[ifacenum].PopupAtMouseY)
-		_mouse.SetPosition(Point(_G(mousex), _GP(guis)[ifacenum].PopupAtMouseY + 2));
+		_GP(mouse).SetPosition(Point(_G(mousex), _GP(guis)[ifacenum].PopupAtMouseY + 2));
 	if ((!IsInterfaceEnabled()) && (cur_cursor == cur_mode))
 		// Only change the mouse cursor if it hasn't been specifically changed first
 		set_mouse_cursor(CURS_WAIT);
diff --git a/engines/ags/engine/ac/mouse.cpp b/engines/ags/engine/ac/mouse.cpp
index 81680879fd..56615061b1 100644
--- a/engines/ags/engine/ac/mouse.cpp
+++ b/engines/ags/engine/ac/mouse.cpp
@@ -67,7 +67,7 @@ Bitmap *dotted_mouse_cursor = nullptr;
 IDriverDependantBitmap *mouseCursor = nullptr;
 Bitmap *blank_mouse_cursor = nullptr;
 
-// The _mouse. functions are static so the script doesn't pass
+// The _GP(mouse). functions are static so the script doesn't pass
 // in an object parameter
 void Mouse_SetVisible(int isOn) {
 	if (isOn)
@@ -106,7 +106,7 @@ void SetMouseBounds(int x1, int y1, int x2, int y2) {
 	_GP(play).mboundx2 = x2;
 	_GP(play).mboundy1 = y1;
 	_GP(play).mboundy2 = y2;
-	_mouse.SetMoveLimit(Rect(x1, y1, x2, y2));
+	_GP(mouse).SetMoveLimit(Rect(x1, y1, x2, y2));
 }
 
 // mouse cursor functions:
@@ -299,7 +299,7 @@ void SetMousePosition(int newx, int newy) {
 		newy = viewport.GetHeight() - 1;
 
 	data_to_game_coords(&newx, &newy);
-	_mouse.SetPosition(Point(newx, newy));
+	_GP(mouse).SetPosition(Point(newx, newy));
 	RefreshMouse();
 }
 
@@ -336,9 +336,9 @@ void Mouse_EnableControl(bool on) {
 	// The resulting choice is made based on two aforementioned factors.
 	on &= should_control_mouse && can_control_mouse;
 	if (on)
-		_mouse.EnableControl(!is_windowed);
+		_GP(mouse).EnableControl(!is_windowed);
 	else
-		_mouse.DisableControl();
+		_GP(mouse).DisableControl();
 }
 
 //=============================================================================
@@ -560,7 +560,7 @@ RuntimeScriptValue Sc_Mouse_Click(const RuntimeScriptValue *params, int32_t para
 }
 
 RuntimeScriptValue Sc_Mouse_GetControlEnabled(const RuntimeScriptValue *params, int32_t param_count) {
-	API_SCALL_BOOL(_mouse.IsControlEnabled);
+	API_SCALL_BOOL(_GP(mouse).IsControlEnabled);
 }
 
 RuntimeScriptValue Sc_Mouse_SetControlEnabled(const RuntimeScriptValue *params, int32_t param_count) {
@@ -569,64 +569,64 @@ RuntimeScriptValue Sc_Mouse_SetControlEnabled(const RuntimeScriptValue *params,
 
 
 RuntimeScriptValue Sc_Mouse_GetSpeed(const RuntimeScriptValue *params, int32_t param_count) {
-	API_SCALL_FLOAT(_mouse.GetSpeed);
+	API_SCALL_FLOAT(_GP(mouse).GetSpeed);
 }
 
 RuntimeScriptValue Sc_Mouse_SetSpeed(const RuntimeScriptValue *params, int32_t param_count) {
-	ASSERT_VARIABLE_VALUE("_mouse.Speed");
-	_mouse.SetSpeed(params[0].FValue);
+	ASSERT_VARIABLE_VALUE("_GP(mouse).Speed");
+	_GP(mouse).SetSpeed(params[0].FValue);
 	return RuntimeScriptValue();
 }
 
 void RegisterMouseAPI() {
-	ccAddExternalStaticFunction("_mouse.ChangeModeGraphic^2", Sc_ChangeCursorGraphic);
-	ccAddExternalStaticFunction("_mouse.ChangeModeHotspot^3", Sc_ChangeCursorHotspot);
-	ccAddExternalStaticFunction("_mouse.ChangeModeView^2", Sc_Mouse_ChangeModeView);
-	ccAddExternalStaticFunction("_mouse.Click^1", Sc_Mouse_Click);
-	ccAddExternalStaticFunction("_mouse.DisableMode^1", Sc_disable_cursor_mode);
-	ccAddExternalStaticFunction("_mouse.EnableMode^1", Sc_enable_cursor_mode);
-	ccAddExternalStaticFunction("_mouse.GetModeGraphic^1", Sc_Mouse_GetModeGraphic);
-	ccAddExternalStaticFunction("_mouse.IsButtonDown^1", Sc_IsButtonDown);
-	ccAddExternalStaticFunction("_mouse.IsModeEnabled^1", Sc_IsModeEnabled);
-	ccAddExternalStaticFunction("_mouse.SaveCursorUntilItLeaves^0", Sc_SaveCursorForLocationChange);
-	ccAddExternalStaticFunction("_mouse.SelectNextMode^0", Sc_SetNextCursor);
-	ccAddExternalStaticFunction("_mouse.SelectPreviousMode^0", Sc_SetPreviousCursor);
-	ccAddExternalStaticFunction("_mouse.SetBounds^4", Sc_SetMouseBounds);
-	ccAddExternalStaticFunction("_mouse.SetPosition^2", Sc_SetMousePosition);
-	ccAddExternalStaticFunction("_mouse.Update^0", Sc_RefreshMouse);
-	ccAddExternalStaticFunction("_mouse.UseDefaultGraphic^0", Sc_set_default_cursor);
-	ccAddExternalStaticFunction("_mouse.UseModeGraphic^1", Sc_set_mouse_cursor);
-	ccAddExternalStaticFunction("_mouse.get_ControlEnabled", Sc_Mouse_GetControlEnabled);
-	ccAddExternalStaticFunction("_mouse.set_ControlEnabled", Sc_Mouse_SetControlEnabled);
-	ccAddExternalStaticFunction("_mouse.get_Mode", Sc_GetCursorMode);
-	ccAddExternalStaticFunction("_mouse.set_Mode", Sc_set_cursor_mode);
-	ccAddExternalStaticFunction("_mouse.get_Speed", Sc_Mouse_GetSpeed);
-	ccAddExternalStaticFunction("_mouse.set_Speed", Sc_Mouse_SetSpeed);
-	ccAddExternalStaticFunction("_mouse.get_Visible", Sc_Mouse_GetVisible);
-	ccAddExternalStaticFunction("_mouse.set_Visible", Sc_Mouse_SetVisible);
+	ccAddExternalStaticFunction("_GP(mouse).ChangeModeGraphic^2", Sc_ChangeCursorGraphic);
+	ccAddExternalStaticFunction("_GP(mouse).ChangeModeHotspot^3", Sc_ChangeCursorHotspot);
+	ccAddExternalStaticFunction("_GP(mouse).ChangeModeView^2", Sc_Mouse_ChangeModeView);
+	ccAddExternalStaticFunction("_GP(mouse).Click^1", Sc_Mouse_Click);
+	ccAddExternalStaticFunction("_GP(mouse).DisableMode^1", Sc_disable_cursor_mode);
+	ccAddExternalStaticFunction("_GP(mouse).EnableMode^1", Sc_enable_cursor_mode);
+	ccAddExternalStaticFunction("_GP(mouse).GetModeGraphic^1", Sc_Mouse_GetModeGraphic);
+	ccAddExternalStaticFunction("_GP(mouse).IsButtonDown^1", Sc_IsButtonDown);
+	ccAddExternalStaticFunction("_GP(mouse).IsModeEnabled^1", Sc_IsModeEnabled);
+	ccAddExternalStaticFunction("_GP(mouse).SaveCursorUntilItLeaves^0", Sc_SaveCursorForLocationChange);
+	ccAddExternalStaticFunction("_GP(mouse).SelectNextMode^0", Sc_SetNextCursor);
+	ccAddExternalStaticFunction("_GP(mouse).SelectPreviousMode^0", Sc_SetPreviousCursor);
+	ccAddExternalStaticFunction("_GP(mouse).SetBounds^4", Sc_SetMouseBounds);
+	ccAddExternalStaticFunction("_GP(mouse).SetPosition^2", Sc_SetMousePosition);
+	ccAddExternalStaticFunction("_GP(mouse).Update^0", Sc_RefreshMouse);
+	ccAddExternalStaticFunction("_GP(mouse).UseDefaultGraphic^0", Sc_set_default_cursor);
+	ccAddExternalStaticFunction("_GP(mouse).UseModeGraphic^1", Sc_set_mouse_cursor);
+	ccAddExternalStaticFunction("_GP(mouse).get_ControlEnabled", Sc_Mouse_GetControlEnabled);
+	ccAddExternalStaticFunction("_GP(mouse).set_ControlEnabled", Sc_Mouse_SetControlEnabled);
+	ccAddExternalStaticFunction("_GP(mouse).get_Mode", Sc_GetCursorMode);
+	ccAddExternalStaticFunction("_GP(mouse).set_Mode", Sc_set_cursor_mode);
+	ccAddExternalStaticFunction("_GP(mouse).get_Speed", Sc_Mouse_GetSpeed);
+	ccAddExternalStaticFunction("_GP(mouse).set_Speed", Sc_Mouse_SetSpeed);
+	ccAddExternalStaticFunction("_GP(mouse).get_Visible", Sc_Mouse_GetVisible);
+	ccAddExternalStaticFunction("_GP(mouse).set_Visible", Sc_Mouse_SetVisible);
 
 	/* ----------------------- Registering unsafe exports for plugins -----------------------*/
 
-	ccAddExternalFunctionForPlugin("_mouse.ChangeModeGraphic^2", (void *)ChangeCursorGraphic);
-	ccAddExternalFunctionForPlugin("_mouse.ChangeModeHotspot^3", (void *)ChangeCursorHotspot);
-	ccAddExternalFunctionForPlugin("_mouse.ChangeModeView^2", (void *)Mouse_ChangeModeView);
-	ccAddExternalFunctionForPlugin("_mouse.DisableMode^1", (void *)disable_cursor_mode);
-	ccAddExternalFunctionForPlugin("_mouse.EnableMode^1", (void *)enable_cursor_mode);
-	ccAddExternalFunctionForPlugin("_mouse.GetModeGraphic^1", (void *)Mouse_GetModeGraphic);
-	ccAddExternalFunctionForPlugin("_mouse.IsButtonDown^1", (void *)IsButtonDown);
-	ccAddExternalFunctionForPlugin("_mouse.IsModeEnabled^1", (void *)IsModeEnabled);
-	ccAddExternalFunctionForPlugin("_mouse.SaveCursorUntilItLeaves^0", (void *)SaveCursorForLocationChange);
-	ccAddExternalFunctionForPlugin("_mouse.SelectNextMode^0", (void *)SetNextCursor);
-	ccAddExternalFunctionForPlugin("_mouse.SelectPreviousMode^0", (void *)SetPreviousCursor);
-	ccAddExternalFunctionForPlugin("_mouse.SetBounds^4", (void *)SetMouseBounds);
-	ccAddExternalFunctionForPlugin("_mouse.SetPosition^2", (void *)SetMousePosition);
-	ccAddExternalFunctionForPlugin("_mouse.Update^0", (void *)RefreshMouse);
-	ccAddExternalFunctionForPlugin("_mouse.UseDefaultGraphic^0", (void *)set_default_cursor);
-	ccAddExternalFunctionForPlugin("_mouse.UseModeGraphic^1", (void *)set_mouse_cursor);
-	ccAddExternalFunctionForPlugin("_mouse.get_Mode", (void *)GetCursorMode);
-	ccAddExternalFunctionForPlugin("_mouse.set_Mode", (void *)set_cursor_mode);
-	ccAddExternalFunctionForPlugin("_mouse.get_Visible", (void *)Mouse_GetVisible);
-	ccAddExternalFunctionForPlugin("_mouse.set_Visible", (void *)Mouse_SetVisible);
+	ccAddExternalFunctionForPlugin("_GP(mouse).ChangeModeGraphic^2", (void *)ChangeCursorGraphic);
+	ccAddExternalFunctionForPlugin("_GP(mouse).ChangeModeHotspot^3", (void *)ChangeCursorHotspot);
+	ccAddExternalFunctionForPlugin("_GP(mouse).ChangeModeView^2", (void *)Mouse_ChangeModeView);
+	ccAddExternalFunctionForPlugin("_GP(mouse).DisableMode^1", (void *)disable_cursor_mode);
+	ccAddExternalFunctionForPlugin("_GP(mouse).EnableMode^1", (void *)enable_cursor_mode);
+	ccAddExternalFunctionForPlugin("_GP(mouse).GetModeGraphic^1", (void *)Mouse_GetModeGraphic);
+	ccAddExternalFunctionForPlugin("_GP(mouse).IsButtonDown^1", (void *)IsButtonDown);
+	ccAddExternalFunctionForPlugin("_GP(mouse).IsModeEnabled^1", (void *)IsModeEnabled);
+	ccAddExternalFunctionForPlugin("_GP(mouse).SaveCursorUntilItLeaves^0", (void *)SaveCursorForLocationChange);
+	ccAddExternalFunctionForPlugin("_GP(mouse).SelectNextMode^0", (void *)SetNextCursor);
+	ccAddExternalFunctionForPlugin("_GP(mouse).SelectPreviousMode^0", (void *)SetPreviousCursor);
+	ccAddExternalFunctionForPlugin("_GP(mouse).SetBounds^4", (void *)SetMouseBounds);
+	ccAddExternalFunctionForPlugin("_GP(mouse).SetPosition^2", (void *)SetMousePosition);
+	ccAddExternalFunctionForPlugin("_GP(mouse).Update^0", (void *)RefreshMouse);
+	ccAddExternalFunctionForPlugin("_GP(mouse).UseDefaultGraphic^0", (void *)set_default_cursor);
+	ccAddExternalFunctionForPlugin("_GP(mouse).UseModeGraphic^1", (void *)set_mouse_cursor);
+	ccAddExternalFunctionForPlugin("_GP(mouse).get_Mode", (void *)GetCursorMode);
+	ccAddExternalFunctionForPlugin("_GP(mouse).set_Mode", (void *)set_cursor_mode);
+	ccAddExternalFunctionForPlugin("_GP(mouse).get_Visible", (void *)Mouse_GetVisible);
+	ccAddExternalFunctionForPlugin("_GP(mouse).set_Visible", (void *)Mouse_SetVisible);
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/device/mousew32.cpp b/engines/ags/engine/device/mousew32.cpp
index da7997f325..77c70de3d4 100644
--- a/engines/ags/engine/device/mousew32.cpp
+++ b/engines/ags/engine/device/mousew32.cpp
@@ -74,15 +74,14 @@ extern char lib_file_name[13];
 extern char alpha_blend_cursor;
 extern color palette[256];
 
-int butwas = 0;
-Mouse _mouse;
+static const int MB_ARRAY[3] = { 1, 2, 4 };
 
 void mgraphconfine(int x1, int y1, int x2, int y2) {
-	_mouse.ControlRect = Rect(x1, y1, x2, y2);
-	set_mouse_range(_mouse.ControlRect.Left, _mouse.ControlRect.Top, _mouse.ControlRect.Right, _mouse.ControlRect.Bottom);
+	_GP(mouse).ControlRect = Rect(x1, y1, x2, y2);
+	set_mouse_range(_GP(mouse).ControlRect.Left, _GP(mouse).ControlRect.Top, _GP(mouse).ControlRect.Right, _GP(mouse).ControlRect.Bottom);
 	Debug::Printf("Mouse confined: (%d,%d)-(%d,%d) (%dx%d)",
-		_mouse.ControlRect.Left, _mouse.ControlRect.Top, _mouse.ControlRect.Right, _mouse.ControlRect.Bottom,
-		_mouse.ControlRect.GetWidth(), _mouse.ControlRect.GetHeight());
+		_GP(mouse).ControlRect.Left, _GP(mouse).ControlRect.Top, _GP(mouse).ControlRect.Right, _GP(mouse).ControlRect.Bottom,
+		_GP(mouse).ControlRect.GetWidth(), _GP(mouse).ControlRect.GetHeight());
 }
 
 void mgetgraphpos() {
@@ -99,22 +98,22 @@ void mgetgraphpos() {
 		return;
 	}
 
-	if (!_G(switched_away) && _mouse.ControlEnabled) {
+	if (!_G(switched_away) && _GP(mouse).ControlEnabled) {
 		// Control mouse movement by querying mouse mickeys (movement deltas)
 		// and applying them to saved mouse coordinates.
 		int mickey_x, mickey_y;
 		get_mouse_mickeys(&mickey_x, &mickey_y);
 
 		// Apply mouse speed
-		int dx = _mouse.Speed * mickey_x;
-		int dy = _mouse.Speed * mickey_y;
+		int dx = _GP(mouse).Speed * mickey_x;
+		int dy = _GP(mouse).Speed * mickey_y;
 
 		//
 		// Perform actual cursor update
 		//---------------------------------------------------------------------
 		// If the real cursor is inside the control rectangle (read - game window),
 		// then apply sensitivity factors and adjust real cursor position
-		if (_mouse.ControlRect.IsInside(_G(real_mouse_x) + dx, _G(real_mouse_y) + dy)) {
+		if (_GP(mouse).ControlRect.IsInside(_G(real_mouse_x) + dx, _G(real_mouse_y) + dy)) {
 			_G(real_mouse_x) += dx;
 			_G(real_mouse_y) += dy;
 			position_mouse(_G(real_mouse_x), _G(real_mouse_y));
@@ -122,9 +121,9 @@ void mgetgraphpos() {
 		// Otherwise, if real cursor was moved outside the control rect, yet we
 		// are required to confine cursor inside one, then adjust cursor position
 		// to stay inside the rect's bounds.
-		else if (_mouse.ConfineInCtrlRect) {
-			_G(real_mouse_x) = Math::Clamp(_G(real_mouse_x) + dx, _mouse.ControlRect.Left, _mouse.ControlRect.Right);
-			_G(real_mouse_y) = Math::Clamp(_G(real_mouse_y) + dy, _mouse.ControlRect.Top, _mouse.ControlRect.Bottom);
+		else if (_GP(mouse).ConfineInCtrlRect) {
+			_G(real_mouse_x) = Math::Clamp(_G(real_mouse_x) + dx, _GP(mouse).ControlRect.Left, _GP(mouse).ControlRect.Right);
+			_G(real_mouse_y) = Math::Clamp(_G(real_mouse_y) + dy, _GP(mouse).ControlRect.Top, _GP(mouse).ControlRect.Bottom);
 			position_mouse(_G(real_mouse_x), _G(real_mouse_y));
 		}
 		// Lastly, if the real cursor is out of the control rect, simply add
@@ -135,7 +134,7 @@ void mgetgraphpos() {
 		}
 
 		// Do not update the game cursor if the real cursor is beyond the control rect
-		if (!_mouse.ControlRect.IsInside(_G(real_mouse_x), _G(real_mouse_y)))
+		if (!_GP(mouse).ControlRect.IsInside(_G(real_mouse_x), _G(real_mouse_y)))
 			return;
 	} else {
 		// Save real cursor coordinates provided by system
@@ -155,7 +154,7 @@ void mgetgraphpos() {
 	}
 
 	// Convert to virtual coordinates
-	_mouse.AdjustPosition(_G(mousex), _G(mousey));
+	_GP(mouse).AdjustPosition(_G(mousex), _G(mousey));
 }
 
 void msetcursorlimit(int x1, int y1, int x2, int y2) {
@@ -165,7 +164,6 @@ void msetcursorlimit(int x1, int y1, int x2, int y2) {
 	_G(boundy2) = y2;
 }
 
-int hotxwas = 0, hotywas = 0;
 void domouse(int str) {
 	/*
 	   TO USE THIS ROUTINE YOU MUST LOAD A MOUSE CURSOR USING mloadcursor.
@@ -173,7 +171,7 @@ void domouse(int str) {
 	*/
 	int poow = _G(mousecurs)[(int)_G(currentcursor)]->GetWidth();
 	int pooh = _G(mousecurs)[(int)_G(currentcursor)]->GetHeight();
-	//int smx = _G(mousex) - hotxwas, smy = _G(mousey) - hotywas;
+	//int smx = _G(mousex) - _G(hotxwas), smy = _G(mousey) - _G(hotywas);
 	const Rect &viewport = _GP(play).GetMainViewport();
 
 	mgetgraphpos();
@@ -188,8 +186,8 @@ void domouse(int str) {
 
 	_G(mousex) += _G(hotx);
 	_G(mousey) += _G(hoty);
-	hotxwas = _G(hotx);
-	hotywas = _G(hoty);
+	_G(hotxwas) = _G(hotx);
+	_G(hotywas) = _G(hoty);
 }
 
 int ismouseinbox(int lf, int tp, int rt, int bt) {
@@ -217,7 +215,7 @@ int mgetbutton() {
 	poll_mouse();
 	int butis = _G(mouse_b);
 
-	if ((butis > 0) &(butwas > 0))
+	if ((butis > 0) &(_G(butwas) > 0))
 		return NONE;  // don't allow holding button down
 
 	if (butis & 1) {
@@ -233,11 +231,10 @@ int mgetbutton() {
 	else if (butis & 4)
 		toret = MIDDLE;
 
-	butwas = butis;
+	_G(butwas) = butis;
 	return toret;
 }
 
-const int MB_ARRAY[3] = { 1, 2, 4 };
 int misbuttondown(int buno) {
 	poll_mouse();
 	if (_G(mouse_b) & MB_ARRAY[buno])
diff --git a/engines/ags/engine/device/mousew32.h b/engines/ags/engine/device/mousew32.h
index 905453f21d..8c4059c6ba 100644
--- a/engines/ags/engine/device/mousew32.h
+++ b/engines/ags/engine/device/mousew32.h
@@ -112,8 +112,6 @@ struct Mouse {
 	void SetPosition(const Point p);
 };
 
-extern Mouse _mouse;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index 106804590b..c8ed36982e 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -499,7 +499,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
 	// it with SetMusicVolume)
 	_GP(thisroom).Options.MusicVolume = r_data.RoomVolume;
 
-	_mouse.SetMoveLimit(Rect(oldx1, oldy1, oldx2, oldy2));
+	_GP(mouse).SetMoveLimit(Rect(oldx1, oldy1, oldx2, oldy2));
 
 	set_cursor_mode(r_data.CursorMode);
 	set_mouse_cursor(r_data.CursorID);
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index a2d0a4618b..cabc5ba1bf 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -289,7 +289,7 @@ void engine_init_mouse() {
 		Debug::Printf(kDbgMsg_Info, "Initializing mouse: failed");
 	else
 		Debug::Printf(kDbgMsg_Info, "Initializing mouse: number of buttons reported is %d", res);
-	_mouse.SetSpeed(_GP(usetup).mouse_speed);
+	_GP(mouse).SetSpeed(_GP(usetup).mouse_speed);
 }
 
 void engine_locate_speech_pak() {
diff --git a/engines/ags/engine/main/engine_setup.cpp b/engines/ags/engine/main/engine_setup.cpp
index 1848188658..ebb3d0328f 100644
--- a/engines/ags/engine/main/engine_setup.cpp
+++ b/engines/ags/engine/main/engine_setup.cpp
@@ -262,30 +262,30 @@ void engine_post_gfxmode_mouse_setup(const DisplayMode &dm, const Size &init_des
 	//
 	// NOTE that we setup speed and other related properties regardless of
 	// whether mouse control was requested because it may be enabled later.
-	_mouse.SetSpeedUnit(1.f);
+	_GP(mouse).SetSpeedUnit(1.f);
 	if (_GP(usetup).mouse_speed_def == kMouseSpeed_CurrentDisplay) {
 		Size cur_desktop;
 		if (get_desktop_resolution(&cur_desktop.Width, &cur_desktop.Height) == 0)
-			_mouse.SetSpeedUnit(Math::Max((float)cur_desktop.Width / (float)init_desktop.Width,
+			_GP(mouse).SetSpeedUnit(Math::Max((float)cur_desktop.Width / (float)init_desktop.Width,
 			(float)cur_desktop.Height / (float)init_desktop.Height));
 	}
 
 	Mouse_EnableControl(_GP(usetup).mouse_ctrl_enabled);
-	Debug::Printf(kDbgMsg_Info, "Mouse control: %s, base: %f, speed: %f", _mouse.IsControlEnabled() ? "on" : "off",
-		_mouse.GetSpeedUnit(), _mouse.GetSpeed());
+	Debug::Printf(kDbgMsg_Info, "Mouse control: %s, base: %f, speed: %f", _GP(mouse).IsControlEnabled() ? "on" : "off",
+		_GP(mouse).GetSpeedUnit(), _GP(mouse).GetSpeed());
 
 	on_coordinates_scaling_changed();
 
 	// If auto lock option is set, lock mouse to the game window
 	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed != 0)
-		_mouse.TryLockToWindow();
+		_GP(mouse).TryLockToWindow();
 }
 
 // Reset mouse controls before changing gfx mode
 void engine_pre_gfxmode_mouse_cleanup() {
 	// Always disable mouse control and unlock mouse when releasing down gfx mode
-	_mouse.DisableControl();
-	_mouse.UnlockFromWindow();
+	_GP(mouse).DisableControl();
+	_GP(mouse).UnlockFromWindow();
 }
 
 // Fill in scsystem struct with display mode parameters
@@ -332,12 +332,12 @@ void engine_pre_gfxsystem_shutdown() {
 
 void on_coordinates_scaling_changed() {
 	// Reset mouse graphic area and bounds
-	_mouse.SetGraphicArea();
+	_GP(mouse).SetGraphicArea();
 	// If mouse bounds do not have valid values yet, then limit cursor to viewport
 	if (_GP(play).mboundx1 == 0 && _GP(play).mboundy1 == 0 && _GP(play).mboundx2 == 0 && _GP(play).mboundy2 == 0)
-		_mouse.SetMoveLimit(_GP(play).GetMainViewport());
+		_GP(mouse).SetMoveLimit(_GP(play).GetMainViewport());
 	else
-		_mouse.SetMoveLimit(Rect(_GP(play).mboundx1, _GP(play).mboundy1, _GP(play).mboundx2, _GP(play).mboundy2));
+		_GP(mouse).SetMoveLimit(Rect(_GP(play).mboundx1, _GP(play).mboundy1, _GP(play).mboundx2, _GP(play).mboundy2));
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/main/game_run.cpp b/engines/ags/engine/main/game_run.cpp
index 7372a09fb6..eac940f223 100644
--- a/engines/ags/engine/main/game_run.cpp
+++ b/engines/ags/engine/main/game_run.cpp
@@ -189,15 +189,15 @@ static int game_loop_check_ground_level_interactions() {
 
 static void lock_mouse_on_click() {
 	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed)
-		_mouse.TryLockToWindow();
+		_GP(mouse).TryLockToWindow();
 }
 
 static void toggle_mouse_lock() {
 	if (_GP(scsystem).windowed) {
-		if (_mouse.IsLockedToWindow())
-			_mouse.UnlockFromWindow();
+		if (_GP(mouse).IsLockedToWindow())
+			_GP(mouse).UnlockFromWindow();
 		else
-			_mouse.TryLockToWindow();
+			_GP(mouse).TryLockToWindow();
 	}
 }
 
diff --git a/engines/ags/engine/main/game_start.cpp b/engines/ags/engine/main/game_start.cpp
index b70220d120..4d762bf006 100644
--- a/engines/ags/engine/main/game_start.cpp
+++ b/engines/ags/engine/main/game_start.cpp
@@ -76,7 +76,7 @@ void start_game_load_savegame_on_startup() {
 
 void start_game() {
 	set_cursor_mode(MODE_WALK);
-	_mouse.SetPosition(Point(160, 100));
+	_GP(mouse).SetPosition(Point(160, 100));
 	newmusic(0);
 
 	_G(our_eip) = -42;
diff --git a/engines/ags/engine/platform/android/acpland.cpp b/engines/ags/engine/platform/android/acpland.cpp
index 5df561b3e7..dfcd8dbd08 100644
--- a/engines/ags/engine/platform/android/acpland.cpp
+++ b/engines/ags/engine/platform/android/acpland.cpp
@@ -671,7 +671,7 @@ unsigned long AGSAndroid::GetDiskFreeSpaceMB() {
 }
 
 const char *AGSAndroid::GetNoMouseErrorString() {
-	return "This game requires a mouse. You need to configure and setup your mouse to play this game.\n";
+	return "This game requires a _GP(mouse). You need to configure and setup your mouse to play this game.\n";
 }
 
 eScriptSystemOSID AGSAndroid::GetSystemOSID() {
diff --git a/engines/ags/engine/platform/ios/acplios.cpp b/engines/ags/engine/platform/ios/acplios.cpp
index 4081f8d9f1..d3415efd50 100644
--- a/engines/ags/engine/platform/ios/acplios.cpp
+++ b/engines/ags/engine/platform/ios/acplios.cpp
@@ -591,7 +591,7 @@ unsigned long AGSIOS::GetDiskFreeSpaceMB() {
 }
 
 const char *AGSIOS::GetNoMouseErrorString() {
-	return "This game requires a mouse. You need to configure and setup your mouse to play this game.\n";
+	return "This game requires a _GP(mouse). You need to configure and setup your mouse to play this game.\n";
 }
 
 eScriptSystemOSID AGSIOS::GetSystemOSID() {
diff --git a/engines/ags/engine/platform/linux/acpllnx.cpp b/engines/ags/engine/platform/linux/acpllnx.cpp
index aad731b52d..063e3a5796 100644
--- a/engines/ags/engine/platform/linux/acpllnx.cpp
+++ b/engines/ags/engine/platform/linux/acpllnx.cpp
@@ -105,7 +105,7 @@ unsigned long AGSLinux::GetDiskFreeSpaceMB() {
 }
 
 const char *AGSLinux::GetNoMouseErrorString() {
-	return "This game requires a mouse. You need to configure and setup your mouse to play this game.\n";
+	return "This game requires a _GP(mouse). You need to configure and setup your mouse to play this game.\n";
 }
 
 const char *AGSLinux::GetAllegroFailUserHint() {
diff --git a/engines/ags/engine/platform/osx/acplmac.cpp b/engines/ags/engine/platform/osx/acplmac.cpp
index ae49c9d74b..6de8628862 100644
--- a/engines/ags/engine/platform/osx/acplmac.cpp
+++ b/engines/ags/engine/platform/osx/acplmac.cpp
@@ -99,7 +99,7 @@ unsigned long AGSMac::GetDiskFreeSpaceMB() {
 }
 
 const char *AGSMac::GetNoMouseErrorString() {
-	return "This game requires a mouse. You need to configure and setup your mouse to play this game.\n";
+	return "This game requires a _GP(mouse). You need to configure and setup your mouse to play this game.\n";
 }
 
 eScriptSystemOSID AGSMac::GetSystemOSID() {
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 00899f98bf..6c92da4c78 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -73,6 +73,7 @@
 #include "ags/engine/debugging/debugger.h"
 #include "ags/engine/debugging/logfile.h"
 #include "ags/engine/debugging/messagebuffer.h"
+#include "ags/engine/device/mousew32.h"
 #include "ags/engine/gui/animatingguibutton.h"
 #include "ags/engine/main/graphics_mode.h"
 #include "ags/engine/media/audio/ambientsound.h"
@@ -213,6 +214,9 @@ Globals::Globals() {
 	// managedobjectpool.cpp globals
 	_pool = new ManagedObjectPool();
 
+	// mousew32.cpp globals
+	_mouse = new Mouse();
+
 	// overlay.cpp globals
 	_screenover = new std::vector<ScreenOverlay>();
 
@@ -360,6 +364,9 @@ Globals::~Globals() {
 	// managedobjectpool.cpp globals
 	delete _pool;
 
+	// mousew32.cpp globals
+	delete _mouse;
+
 	// overlay.cpp globals
 	delete _screenover;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index e7c1ebe0ec..5849caa2db 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -109,6 +109,7 @@ struct GameSetupStruct;
 struct GameState;
 struct IAGSEditorDebugger;
 struct ManagedObjectPool;
+struct Mouse;
 struct MoveList;
 struct NonBlockingScriptFunction;
 struct ObjectCache;
@@ -754,6 +755,17 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup mousew32 globals
+	 * @{
+	 */
+
+	int _butwas = 0;
+	int _hotxwas = 0, _hotywas = 0;
+	Mouse *_mouse;
+
+	/**@}*/
+
 	/**
 	 * \defgroup overlay globals
 	 * @{
diff --git a/engines/ags/plugins/agsplugin.cpp b/engines/ags/plugins/agsplugin.cpp
index ead91cff33..4e1dda63de 100644
--- a/engines/ags/plugins/agsplugin.cpp
+++ b/engines/ags/plugins/agsplugin.cpp
@@ -781,7 +781,7 @@ int IAGSEngine::DecrementManagedObjectRefCount(const char *address) {
 }
 
 void IAGSEngine::SetMousePosition(int32 x, int32 y) {
-	_mouse.SetPosition(Point(x, y));
+	_GP(mouse).SetPosition(Point(x, y));
 	RefreshMouse();
 }
 




More information about the Scummvm-git-logs mailing list