[Scummvm-git-logs] scummvm master -> 07c005ff9a94e10bce8a6a0e952dc18f571b12dd

dreammaster dreammaster at scummvm.org
Sat Mar 6 05:54:22 UTC 2021


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

Summary:
0b899ebaa4 AGS: Move draw_software.cpp globals to Globals
f1d34ab766 AGS: Move guiinv.cpp globals to Globals
8989092cb5 AGS: Move guilabel.cpp globals to Globals
fbf0c9247b AGS: Move guilistbox.cpp globals to Globals
d2ea2beb64 AGS: Move guislider.cpp globals to Globals
51f2cf25e9 AGS: Move guitextbox.cpp globals to Globals
003d890955 AGS: Move systemimports.cpp globals to Globals
cd83601dc3 AGS: Move route_finder_impl.cpp globals to Globals
94423abaa1 AGS: Move usetup to Globals
3887515bfc AGS: Further game.cpp globals to Globals
07c005ff9a AGS: Remove unused LastOldFormatVersion


Commit: 0b899ebaa4e6d0178712d578691e6b37d1d04873
    https://github.com/scummvm/scummvm/commit/0b899ebaa4e6d0178712d578691e6b37d1d04873
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/ac/draw_software.cpp
    engines/ags/engine/ac/draw_software.h
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/draw_software.cpp b/engines/ags/engine/ac/draw_software.cpp
index 67eb7450db..e8cc26ebc5 100644
--- a/engines/ags/engine/ac/draw_software.cpp
+++ b/engines/ags/engine/ac/draw_software.cpp
@@ -51,61 +51,13 @@
 #include "ags/engine/ac/draw_software.h"
 #include "ags/shared/gfx/bitmap.h"
 #include "ags/engine/util/scaling.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-// TODO: choose these values depending on game resolution?
-#define MAXDIRTYREGIONS 25
-#define WHOLESCREENDIRTY (MAXDIRTYREGIONS + 5)
-#define MAX_SPANS_PER_ROW 4
-
-// Dirty rects store coordinate values in the coordinate system of a camera surface,
-// where coords always span from 0,0 to surface width,height.
-// Converting from room to dirty rects would require subtracting room camera offsets.
-struct IRSpan {
-	int x1, x2;
-	int mergeSpan(int tx1, int tx2);
-
-	IRSpan();
-};
-
-struct IRRow {
-	IRSpan span[MAX_SPANS_PER_ROW];
-	int numSpans;
-
-	IRRow();
-};
-
-struct DirtyRects {
-	// Size of the surface managed by this dirty rects object
-	Size SurfaceSize;
-	// Where the surface is rendered on screen
-	Rect Viewport;
-	// Room -> screen coordinate transformation
-	PlaneScaling Room2Screen;
-	// Screen -> dirty surface rect
-	// The dirty rects are saved in coordinates limited to (0,0)->(camera size) rather than room or screen coords
-	PlaneScaling Screen2DirtySurf;
-
-	std::vector<IRRow> DirtyRows;
-	Rect DirtyRegions[MAXDIRTYREGIONS];
-	size_t NumDirtyRegions;
-
-	DirtyRects();
-	bool IsInit() const;
-	// Initialize dirty rects for the given surface size
-	void Init(const Size &surf_size, const Rect &viewport);
-	void SetSurfaceOffsets(int x, int y);
-	// Delete dirty rects
-	void Destroy();
-	// Mark all surface as tidy
-	void Reset();
-};
-
-
 IRSpan::IRSpan()
 	: x1(0), x2(0) {
 }
@@ -166,52 +118,42 @@ void DirtyRects::Reset() {
 		DirtyRows[i].numSpans = 0;
 }
 
-// Dirty rects for the main viewport background (black screen);
-// these are used when the room viewport does not cover whole screen,
-// so that we know when to paint black after mouse cursor and gui.
-DirtyRects BlackRects;
-// Dirty rects object for the single room camera
-std::vector<DirtyRects> RoomCamRects;
-// Saved room camera offsets to know if we must invalidate whole surface.
-// TODO: if we support rotation then we also need to compare full transform!
-std::vector<std::pair<int, int>> RoomCamPositions;
-
 
 void dispose_invalid_regions(bool /* room_only */) {
-	RoomCamRects.clear();
-	RoomCamPositions.clear();
+	_GP(RoomCamRects).clear();
+	_GP(RoomCamPositions).clear();
 }
 
 void init_invalid_regions(int view_index, const Size &surf_size, const Rect &viewport) {
 	if (view_index < 0) {
-		BlackRects.Init(surf_size, viewport);
+		_GP(BlackRects).Init(surf_size, viewport);
 	} else {
-		if (RoomCamRects.size() <= (size_t)view_index) {
-			RoomCamRects.resize(view_index + 1);
-			RoomCamPositions.resize(view_index + 1);
+		if (_GP(RoomCamRects).size() <= (size_t)view_index) {
+			_GP(RoomCamRects).resize(view_index + 1);
+			_GP(RoomCamPositions).resize(view_index + 1);
 		}
-		RoomCamRects[view_index].Init(surf_size, viewport);
-		RoomCamPositions[view_index] = std::make_pair(-1000, -1000);
+		_GP(RoomCamRects)[view_index].Init(surf_size, viewport);
+		_GP(RoomCamPositions)[view_index] = std::make_pair(-1000, -1000);
 	}
 }
 
 void delete_invalid_regions(int view_index) {
 	if (view_index >= 0) {
-		RoomCamRects.erase(RoomCamRects.begin() + view_index);
-		RoomCamPositions.erase(RoomCamPositions.begin() + view_index);
+		_GP(RoomCamRects).erase(_GP(RoomCamRects).begin() + view_index);
+		_GP(RoomCamPositions).erase(_GP(RoomCamPositions).begin() + view_index);
 	}
 }
 
 void set_invalidrects_cameraoffs(int view_index, int x, int y) {
 	if (view_index < 0) {
-		BlackRects.SetSurfaceOffsets(x, y);
+		_GP(BlackRects).SetSurfaceOffsets(x, y);
 		return;
 	} else {
-		RoomCamRects[view_index].SetSurfaceOffsets(x, y);
+		_GP(RoomCamRects)[view_index].SetSurfaceOffsets(x, y);
 	}
 
-	int &posxwas = RoomCamPositions[view_index].first;
-	int &posywas = RoomCamPositions[view_index].second;
+	int &posxwas = _GP(RoomCamPositions)[view_index].first;
+	int &posywas = _GP(RoomCamPositions)[view_index].second;
 	if ((x != posxwas) || (y != posywas)) {
 		invalidate_all_camera_rects(view_index);
 		posxwas = x;
@@ -220,9 +162,9 @@ void set_invalidrects_cameraoffs(int view_index, int x, int y) {
 }
 
 void invalidate_all_rects() {
-	for (auto &rects : RoomCamRects) {
-		if (!IsRectInsideRect(rects.Viewport, BlackRects.Viewport))
-			BlackRects.NumDirtyRegions = WHOLESCREENDIRTY;
+	for (auto &rects : _GP(RoomCamRects)) {
+		if (!IsRectInsideRect(rects.Viewport, _GP(BlackRects).Viewport))
+			_GP(BlackRects).NumDirtyRegions = WHOLESCREENDIRTY;
 		rects.NumDirtyRegions = WHOLESCREENDIRTY;
 	}
 }
@@ -230,7 +172,7 @@ void invalidate_all_rects() {
 void invalidate_all_camera_rects(int view_index) {
 	if (view_index < 0)
 		return;
-	RoomCamRects[view_index].NumDirtyRegions = WHOLESCREENDIRTY;
+	_GP(RoomCamRects)[view_index].NumDirtyRegions = WHOLESCREENDIRTY;
 }
 
 void invalidate_rect_on_surf(int x1, int y1, int x2, int y2, DirtyRects &rects) {
@@ -322,7 +264,7 @@ void invalidate_rect_ds(DirtyRects &rects, int x1, int y1, int x2, int y2, bool
 		Rect r(x1, y1, x2, y2);
 		// If overlay is NOT completely over the room, then invalidate black rect
 		if (!IsRectInsideRect(rects.Viewport, r))
-			invalidate_rect_on_surf(x1, y1, x2, y2, BlackRects);
+			invalidate_rect_on_surf(x1, y1, x2, y2, _GP(BlackRects));
 		// If overlay is NOT intersecting room viewport at all, then stop
 		if (!AreRectsIntersecting(rects.Viewport, r))
 			return;
@@ -343,7 +285,7 @@ void invalidate_rect_ds(DirtyRects &rects, int x1, int y1, int x2, int y2, bool
 }
 
 void invalidate_rect_ds(int x1, int y1, int x2, int y2, bool in_room) {
-	for (auto &rects : RoomCamRects)
+	for (auto &rects : _GP(RoomCamRects))
 		invalidate_rect_ds(rects, x1, y1, x2, y2, in_room);
 }
 
@@ -433,18 +375,18 @@ void update_invalid_region(Bitmap *ds, color_t fill_color, const DirtyRects &rec
 }
 
 void update_black_invreg_and_reset(Bitmap *ds) {
-	if (!BlackRects.IsInit())
+	if (!_GP(BlackRects).IsInit())
 		return;
-	update_invalid_region(ds, (color_t)0, BlackRects);
-	BlackRects.Reset();
+	update_invalid_region(ds, (color_t)0, _GP(BlackRects));
+	_GP(BlackRects).Reset();
 }
 
 void update_room_invreg_and_reset(int view_index, Bitmap *ds, Bitmap *src, bool no_transform) {
-	if (view_index < 0 || RoomCamRects.empty())
+	if (view_index < 0 || _GP(RoomCamRects).empty())
 		return;
 
-	update_invalid_region(ds, src, RoomCamRects[view_index], no_transform);
-	RoomCamRects[view_index].Reset();
+	update_invalid_region(ds, src, _GP(RoomCamRects)[view_index], no_transform);
+	_GP(RoomCamRects)[view_index].Reset();
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/ac/draw_software.h b/engines/ags/engine/ac/draw_software.h
index 7a28ca0d7c..f8d3cc6a75 100644
--- a/engines/ags/engine/ac/draw_software.h
+++ b/engines/ags/engine/ac/draw_software.h
@@ -33,9 +33,60 @@
 #include "ags/shared/gfx/bitmap.h"
 #include "ags/engine/gfx/ddb.h"
 #include "ags/shared/util/geometry.h"
+#include "ags/engine/util/scaling.h"
 
 namespace AGS3 {
 
+using AGS::Engine::PlaneScaling;
+
+// TODO: choose these values depending on game resolution?
+#define MAXDIRTYREGIONS 25
+#define WHOLESCREENDIRTY (MAXDIRTYREGIONS + 5)
+#define MAX_SPANS_PER_ROW 4
+
+// Dirty rects store coordinate values in the coordinate system of a camera surface,
+// where coords always span from 0,0 to surface width,height.
+// Converting from room to dirty rects would require subtracting room camera offsets.
+struct IRSpan {
+	int x1, x2;
+	int mergeSpan(int tx1, int tx2);
+
+	IRSpan();
+};
+
+struct IRRow {
+	IRSpan span[MAX_SPANS_PER_ROW];
+	int numSpans;
+
+	IRRow();
+};
+
+struct DirtyRects {
+	// Size of the surface managed by this dirty rects object
+	Size SurfaceSize;
+	// Where the surface is rendered on screen
+	Rect Viewport;
+	// Room -> screen coordinate transformation
+	PlaneScaling Room2Screen;
+	// Screen -> dirty surface rect
+	// The dirty rects are saved in coordinates limited to (0,0)->(camera size) rather than room or screen coords
+	PlaneScaling Screen2DirtySurf;
+
+	std::vector<IRRow> DirtyRows;
+	Rect DirtyRegions[MAXDIRTYREGIONS];
+	size_t NumDirtyRegions;
+
+	DirtyRects();
+	bool IsInit() const;
+	// Initialize dirty rects for the given surface size
+	void Init(const Size &surf_size, const Rect &viewport);
+	void SetSurfaceOffsets(int x, int y);
+	// Delete dirty rects
+	void Destroy();
+	// Mark all surface as tidy
+	void Reset();
+};
+
 // Inits dirty rects array for the given room camera/viewport pair
 // View_index indicates the room viewport (>= 0) or the main viewport (-1)
 void init_invalid_regions(int view_index, const Size &surf_size, const Rect &viewport);
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 3655e0ddea..52b93366c1 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -30,6 +30,7 @@
 #include "ags/shared/game/roomstruct.h"
 #include "ags/shared/gui/guibutton.h"
 #include "ags/engine/ac/draw.h"
+#include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
 #include "ags/engine/ac/objectcache.h"
 #include "ags/engine/ac/roomstatus.h"
@@ -81,6 +82,11 @@ Globals::Globals() {
 	_sprlist = new std::vector<SpriteListEntry>();
 	_thingsToDrawList = new std::vector<SpriteListEntry>();
 
+	// draw_software.cpp globals
+	_BlackRects = new DirtyRects();
+	_RoomCamRects = new std::vector<DirtyRects>();
+	_RoomCamPositions = new std::vector<std::pair<int, int> >();
+
 	// fonts.cpp globals
 	_fonts = new std::vector<AGS::Shared::Font>();
 	_ttfRenderer = new TTFFontRenderer();
@@ -161,6 +167,16 @@ Globals::~Globals() {
 	// debugmanager.cpp globals
 	delete _DbgMgr;
 
+	// draw.cpp globals
+	delete _CameraDrawData;
+	delete _sprlist;
+	delete _thingsToDrawList;
+
+	// draw_software.cpp globals
+	delete _BlackRects;
+	delete _RoomCamRects;
+	delete _RoomCamPositions;
+
 	// fonts.cpp globals
 	delete _fonts;
 	delete _ttfRenderer;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 726e255fcb..1a7bab73d1 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -66,6 +66,7 @@ struct CCInventory;
 struct CCObject;
 struct CCRegion;
 struct CharacterCache;
+struct DirtyRects;
 struct ExecutingScript;
 struct GameSetupStruct;
 struct GameState;
@@ -169,6 +170,23 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup draw_software globals
+	 * @{
+	 */
+
+	// Dirty rects for the main viewport background (black screen);
+	// these are used when the room viewport does not cover whole screen,
+	// so that we know when to paint black after mouse cursor and gui.
+	DirtyRects *_BlackRects;
+	// Dirty rects object for the single room camera
+	std::vector<DirtyRects> *_RoomCamRects;
+	// Saved room camera offsets to know if we must invalidate whole surface.
+	// TODO: if we support rotation then we also need to compare full transform!
+	std::vector<std::pair<int, int> > *_RoomCamPositions;
+
+	/**@}*/
+
 	/**
 	 * \defgroup fonts globals
 	 * @{


Commit: f1d34ab7663abb4b2ab8d438b8236e087e9a24c3
    https://github.com/scummvm/scummvm/commit/f1d34ab7663abb4b2ab8d438b8236e087e9a24c3
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/ac/global_invwindow.cpp
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/engine/main/engine_setup.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/gui/guiinv.cpp
    engines/ags/shared/gui/guiinv.h
    engines/ags/shared/gui/guimain.cpp


diff --git a/engines/ags/engine/ac/global_invwindow.cpp b/engines/ags/engine/ac/global_invwindow.cpp
index 30435ad45e..252f2226d3 100644
--- a/engines/ags/engine/ac/global_invwindow.cpp
+++ b/engines/ags/engine/ac/global_invwindow.cpp
@@ -39,10 +39,10 @@ void SetInvDimensions(int ww, int hh) {
 	_GP(play).inv_item_hit = hh;
 	_GP(play).inv_numdisp = 0;
 	// backwards compatibility
-	for (int i = 0; i < numguiinv; i++) {
-		guiinv[i].ItemWidth = ww;
-		guiinv[i].ItemHeight = hh;
-		guiinv[i].OnResized();
+	for (int i = 0; i < _G(numguiinv); i++) {
+		_GP(guiinv)[i].ItemWidth = ww;
+		_GP(guiinv)[i].ItemHeight = hh;
+		_GP(guiinv)[i].OnResized();
 	}
 	guis_need_update = 1;
 }
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 90768a2671..eb7fe66db6 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -547,9 +547,9 @@ HSaveError WriteGUI(PStream out) {
 		guilabels[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUIInvWindows");
-	out->WriteInt32(numguiinv);
-	for (int i = 0; i < numguiinv; ++i)
-		guiinv[i].WriteToSavegame(out.get());
+	out->WriteInt32(_G(numguiinv));
+	for (int i = 0; i < _G(numguiinv); ++i)
+		_GP(guiinv)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUISliders");
 	out->WriteInt32(numguislider);
@@ -601,10 +601,10 @@ HSaveError ReadGUI(PStream in, int32_t cmp_ver, const PreservedParams &pp, Resto
 
 	if (!AssertFormatTagStrict(err, in, "GUIInvWindows"))
 		return err;
-	if (!AssertGameContent(err, in->ReadInt32(), numguiinv, "GUI InvWindows"))
+	if (!AssertGameContent(err, in->ReadInt32(), _G(numguiinv), "GUI InvWindows"))
 		return err;
-	for (int i = 0; i < numguiinv; ++i)
-		guiinv[i].ReadFromSavegame(in.get(), svg_ver);
+	for (int i = 0; i < _G(numguiinv); ++i)
+		_GP(guiinv)[i].ReadFromSavegame(in.get(), svg_ver);
 
 	if (!AssertFormatTagStrict(err, in, "GUISliders"))
 		return err;
diff --git a/engines/ags/engine/main/engine_setup.cpp b/engines/ags/engine/main/engine_setup.cpp
index f583d928a5..46c03e0768 100644
--- a/engines/ags/engine/main/engine_setup.cpp
+++ b/engines/ags/engine/main/engine_setup.cpp
@@ -115,10 +115,10 @@ void convert_objects_to_data_resolution(GameDataVersion filever) {
 		_GP(game).chars[i].y /= mul;
 	}
 
-	for (int i = 0; i < numguiinv; ++i) {
-		guiinv[i].ItemWidth /= mul;
-		guiinv[i].ItemHeight /= mul;
-		guiinv[i].OnResized();
+	for (int i = 0; i < _G(numguiinv); ++i) {
+		_GP(guiinv)[i].ItemWidth /= mul;
+		_GP(guiinv)[i].ItemHeight /= mul;
+		_GP(guiinv)[i].OnResized();
 	}
 }
 
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 52b93366c1..b0aaf680a3 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -29,6 +29,7 @@
 #include "ags/shared/font/wfnfontrenderer.h"
 #include "ags/shared/game/roomstruct.h"
 #include "ags/shared/gui/guibutton.h"
+#include "ags/shared/gui/guiinv.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
@@ -129,6 +130,9 @@ Globals::Globals() {
 	// guibutton.cpp globals
 	_guibuts = new std::vector<AGS::Shared::GUIButton>();
 
+	// guiinv.cpp globals
+	_guiinv = new std::vector<AGS::Shared::GUIInvWindow>();
+
 	// managedobjectpool.cpp globals
 	_pool = new ManagedObjectPool();
 
@@ -218,6 +222,9 @@ Globals::~Globals() {
 	// guibutton.cpp globals
 	delete _guibuts;
 
+	// guiinv.cpp globals
+	delete _guiinv;
+
 	// managedobjectpool.cpp globals
 	delete _pool;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 1a7bab73d1..05d8a6d6d5 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -44,6 +44,7 @@ class Bitmap;
 class DebugManager;
 struct Font;
 class GUIButton;
+class GUIInvWindow;
 class RoomStruct;
 
 } // namespace Shared
@@ -266,6 +267,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup guiinv globals
+	 * @{
+	 */
+
+	std::vector<AGS::Shared::GUIInvWindow> *_guiinv;
+	int _numguiinv = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/gui/guiinv.cpp b/engines/ags/shared/gui/guiinv.cpp
index 59c413cba3..1fb2563f7f 100644
--- a/engines/ags/shared/gui/guiinv.cpp
+++ b/engines/ags/shared/gui/guiinv.cpp
@@ -20,7 +20,6 @@
  *
  */
 
-//include <math.h>
 #include "ags/shared/ac/game_version.h"
 #include "ags/shared/gui/guiinv.h"
 #include "ags/shared/gui/guimain.h"
@@ -28,9 +27,6 @@
 
 namespace AGS3 {
 
-std::vector<AGS::Shared::GUIInvWindow> guiinv;
-int numguiinv = 0;
-
 namespace AGS {
 namespace Shared {
 
diff --git a/engines/ags/shared/gui/guiinv.h b/engines/ags/shared/gui/guiinv.h
index 5e585ded79..9035062a02 100644
--- a/engines/ags/shared/gui/guiinv.h
+++ b/engines/ags/shared/gui/guiinv.h
@@ -69,10 +69,6 @@ private:
 
 } // namespace Shared
 } // namespace AGS
-
-extern std::vector<AGS::Shared::GUIInvWindow> guiinv;
-extern int numguiinv;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/shared/gui/guimain.cpp b/engines/ags/shared/gui/guimain.cpp
index b34db17004..4e202731d8 100644
--- a/engines/ags/shared/gui/guimain.cpp
+++ b/engines/ags/shared/gui/guimain.cpp
@@ -335,7 +335,7 @@ HError GUIMain::RebuildArray() {
 		else if (thistype == kGUILabel)
 			_controls[i] = &guilabels[thisnum];
 		else if (thistype == kGUIInvWindow)
-			_controls[i] = &guiinv[thisnum];
+			_controls[i] = &_GP(guiinv)[thisnum];
 		else if (thistype == kGUISlider)
 			_controls[i] = &guislider[thisnum];
 		else if (thistype == kGUITextBox)
@@ -735,10 +735,10 @@ HError ReadGUI(std::vector<GUIMain> &theGuis, Stream *in, bool is_savegame) {
 		guilabels[i].ReadFromFile(in, GameGuiVersion);
 	}
 	// inv controls
-	numguiinv = in->ReadInt32();
-	guiinv.resize(numguiinv);
-	for (int i = 0; i < numguiinv; ++i) {
-		guiinv[i].ReadFromFile(in, GameGuiVersion);
+	_G(numguiinv) = in->ReadInt32();
+	_GP(guiinv).resize(_G(numguiinv));
+	for (int i = 0; i < _G(numguiinv); ++i) {
+		_GP(guiinv)[i].ReadFromFile(in, GameGuiVersion);
 	}
 
 	if (GameGuiVersion >= kGuiVersion_214) {
@@ -784,9 +784,9 @@ void WriteGUI(const std::vector<GUIMain> &theGuis, Stream *out) {
 	for (int i = 0; i < numguilabels; ++i) {
 		guilabels[i].WriteToFile(out);
 	}
-	out->WriteInt32(numguiinv);
-	for (int i = 0; i < numguiinv; ++i) {
-		guiinv[i].WriteToFile(out);
+	out->WriteInt32(_G(numguiinv));
+	for (int i = 0; i < _G(numguiinv); ++i) {
+		_GP(guiinv)[i].WriteToFile(out);
 	}
 	out->WriteInt32(numguislider);
 	for (int i = 0; i < numguislider; ++i) {


Commit: 8989092cb515f8b902c503cdd6f15bcb4ca8cca6
    https://github.com/scummvm/scummvm/commit/8989092cb515f8b902c503cdd6f15bcb4ca8cca6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/game/game_init.cpp
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/gui/guilabel.cpp
    engines/ags/shared/gui/guilabel.h
    engines/ags/shared/gui/guimain.cpp


diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 7656916f33..b05600ce3d 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -366,9 +366,9 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
 	//
 	// 5. Initialize runtime state of certain game objects
 	//
-	for (int i = 0; i < numguilabels; ++i) {
+	for (int i = 0; i < _G(numguilabels); ++i) {
 		// labels are not clickable by default
-		guilabels[i].SetClickable(false);
+		_GP(guilabels)[i].SetClickable(false);
 	}
 	_GP(play).gui_draw_order = (int32_t *)calloc(_GP(game).numgui * sizeof(int32_t), 1);
 	update_gui_zorder();
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index eb7fe66db6..6917d97c60 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -542,9 +542,9 @@ HSaveError WriteGUI(PStream out) {
 		_GP(guibuts)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUILabels");
-	out->WriteInt32(numguilabels);
-	for (int i = 0; i < numguilabels; ++i)
-		guilabels[i].WriteToSavegame(out.get());
+	out->WriteInt32(_G(numguilabels));
+	for (int i = 0; i < _G(numguilabels); ++i)
+		_GP(guilabels)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUIInvWindows");
 	out->WriteInt32(_G(numguiinv));
@@ -594,10 +594,10 @@ HSaveError ReadGUI(PStream in, int32_t cmp_ver, const PreservedParams &pp, Resto
 
 	if (!AssertFormatTagStrict(err, in, "GUILabels"))
 		return err;
-	if (!AssertGameContent(err, in->ReadInt32(), numguilabels, "GUI Labels"))
+	if (!AssertGameContent(err, in->ReadInt32(), _G(numguilabels), "GUI Labels"))
 		return err;
-	for (int i = 0; i < numguilabels; ++i)
-		guilabels[i].ReadFromSavegame(in.get(), svg_ver);
+	for (int i = 0; i < _G(numguilabels); ++i)
+		_GP(guilabels)[i].ReadFromSavegame(in.get(), svg_ver);
 
 	if (!AssertFormatTagStrict(err, in, "GUIInvWindows"))
 		return err;
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index b0aaf680a3..fed8dfb404 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -30,6 +30,7 @@
 #include "ags/shared/game/roomstruct.h"
 #include "ags/shared/gui/guibutton.h"
 #include "ags/shared/gui/guiinv.h"
+#include "ags/shared/gui/guilabel.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
@@ -133,6 +134,9 @@ Globals::Globals() {
 	// guiinv.cpp globals
 	_guiinv = new std::vector<AGS::Shared::GUIInvWindow>();
 
+	// guilabel.cpp globals
+	_guilabels = new std::vector<AGS::Shared::GUILabel>();
+
 	// managedobjectpool.cpp globals
 	_pool = new ManagedObjectPool();
 
@@ -225,6 +229,9 @@ Globals::~Globals() {
 	// guiinv.cpp globals
 	delete _guiinv;
 
+	// guilabel.cpp globals
+	delete _guilabels;
+
 	// managedobjectpool.cpp globals
 	delete _pool;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 05d8a6d6d5..1967a2c829 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -45,6 +45,7 @@ class DebugManager;
 struct Font;
 class GUIButton;
 class GUIInvWindow;
+class GUILabel;
 class RoomStruct;
 
 } // namespace Shared
@@ -277,6 +278,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup guilabel globals
+	 * @{
+	 */
+
+	std::vector<AGS::Shared::GUILabel> *_guilabels;
+	int _numguilabels = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/gui/guilabel.cpp b/engines/ags/shared/gui/guilabel.cpp
index f17f80e7ae..a3a3c9f482 100644
--- a/engines/ags/shared/gui/guilabel.cpp
+++ b/engines/ags/shared/gui/guilabel.cpp
@@ -30,9 +30,6 @@
 
 namespace AGS3 {
 
-std::vector<AGS::Shared::GUILabel> guilabels;
-int numguilabels = 0;
-
 #define GUILABEL_TEXTLENGTH_PRE272 200
 
 namespace AGS {
diff --git a/engines/ags/shared/gui/guilabel.h b/engines/ags/shared/gui/guilabel.h
index 22a690b45f..02d7a78efe 100644
--- a/engines/ags/shared/gui/guilabel.h
+++ b/engines/ags/shared/gui/guilabel.h
@@ -68,9 +68,6 @@ private:
 } // namespace Shared
 } // namespace AGS
 
-extern std::vector<AGS::Shared::GUILabel> guilabels;
-extern int numguilabels;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/shared/gui/guimain.cpp b/engines/ags/shared/gui/guimain.cpp
index 4e202731d8..5e19bbeb70 100644
--- a/engines/ags/shared/gui/guimain.cpp
+++ b/engines/ags/shared/gui/guimain.cpp
@@ -333,7 +333,7 @@ HError GUIMain::RebuildArray() {
 		if (thistype == kGUIButton)
 			_controls[i] = &_GP(guibuts)[thisnum];
 		else if (thistype == kGUILabel)
-			_controls[i] = &guilabels[thisnum];
+			_controls[i] = &_GP(guilabels)[thisnum];
 		else if (thistype == kGUIInvWindow)
 			_controls[i] = &_GP(guiinv)[thisnum];
 		else if (thistype == kGUISlider)
@@ -729,10 +729,10 @@ HError ReadGUI(std::vector<GUIMain> &theGuis, Stream *in, bool is_savegame) {
 		_GP(guibuts)[i].ReadFromFile(in, GameGuiVersion);
 	}
 	// labels
-	numguilabels = in->ReadInt32();
-	guilabels.resize(numguilabels);
-	for (int i = 0; i < numguilabels; ++i) {
-		guilabels[i].ReadFromFile(in, GameGuiVersion);
+	_G(numguilabels) = in->ReadInt32();
+	_GP(guilabels).resize(_G(numguilabels));
+	for (int i = 0; i < _G(numguilabels); ++i) {
+		_GP(guilabels)[i].ReadFromFile(in, GameGuiVersion);
 	}
 	// inv controls
 	_G(numguiinv) = in->ReadInt32();
@@ -780,9 +780,9 @@ void WriteGUI(const std::vector<GUIMain> &theGuis, Stream *out) {
 	for (int i = 0; i < _G(numguibuts); ++i) {
 		_GP(guibuts)[i].WriteToFile(out);
 	}
-	out->WriteInt32(numguilabels);
-	for (int i = 0; i < numguilabels; ++i) {
-		guilabels[i].WriteToFile(out);
+	out->WriteInt32(_G(numguilabels));
+	for (int i = 0; i < _G(numguilabels); ++i) {
+		_GP(guilabels)[i].WriteToFile(out);
 	}
 	out->WriteInt32(_G(numguiinv));
 	for (int i = 0; i < _G(numguiinv); ++i) {


Commit: fbf0c9247b3f2bb86dbc18b43c422dbe5b1ce199
    https://github.com/scummvm/scummvm/commit/fbf0c9247b3f2bb86dbc18b43c422dbe5b1ce199
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/gui/guilistbox.cpp
    engines/ags/shared/gui/guilistbox.h
    engines/ags/shared/gui/guimain.cpp


diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 6917d97c60..48435939b0 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -562,9 +562,9 @@ HSaveError WriteGUI(PStream out) {
 		guitext[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUIListBoxes");
-	out->WriteInt32(numguilist);
-	for (int i = 0; i < numguilist; ++i)
-		guilist[i].WriteToSavegame(out.get());
+	out->WriteInt32(_G(numguilist));
+	for (int i = 0; i < _G(numguilist); ++i)
+		_GP(guilist)[i].WriteToSavegame(out.get());
 
 	// Animated buttons
 	WriteFormatTag(out, "AnimatedButtons");
@@ -622,10 +622,10 @@ HSaveError ReadGUI(PStream in, int32_t cmp_ver, const PreservedParams &pp, Resto
 
 	if (!AssertFormatTagStrict(err, in, "GUIListBoxes"))
 		return err;
-	if (!AssertGameContent(err, in->ReadInt32(), numguilist, "GUI ListBoxes"))
+	if (!AssertGameContent(err, in->ReadInt32(), _G(numguilist), "GUI ListBoxes"))
 		return err;
-	for (int i = 0; i < numguilist; ++i)
-		guilist[i].ReadFromSavegame(in.get(), svg_ver);
+	for (int i = 0; i < _G(numguilist); ++i)
+		_GP(guilist)[i].ReadFromSavegame(in.get(), svg_ver);
 
 	// Animated buttons
 	if (!AssertFormatTagStrict(err, in, "AnimatedButtons"))
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index fed8dfb404..3e747d0f23 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -31,6 +31,7 @@
 #include "ags/shared/gui/guibutton.h"
 #include "ags/shared/gui/guiinv.h"
 #include "ags/shared/gui/guilabel.h"
+#include "ags/shared/gui/guilistbox.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
@@ -137,6 +138,9 @@ Globals::Globals() {
 	// guilabel.cpp globals
 	_guilabels = new std::vector<AGS::Shared::GUILabel>();
 
+	// guilistbox.cpp globals
+	_guilist = new std::vector<AGS::Shared::GUIListBox>();
+
 	// managedobjectpool.cpp globals
 	_pool = new ManagedObjectPool();
 
@@ -232,6 +236,9 @@ Globals::~Globals() {
 	// guilabel.cpp globals
 	delete _guilabels;
 
+	// guilistbox.cpp globals
+	delete _guilist;
+
 	// managedobjectpool.cpp globals
 	delete _pool;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 1967a2c829..40fbaf026b 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -46,6 +46,7 @@ struct Font;
 class GUIButton;
 class GUIInvWindow;
 class GUILabel;
+class GUIListBox;
 class RoomStruct;
 
 } // namespace Shared
@@ -288,6 +289,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup guilistbox globals
+	 * @{
+	 */
+
+	std::vector<AGS::Shared::GUIListBox> *_guilist;
+	int _numguilist = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/gui/guilistbox.cpp b/engines/ags/shared/gui/guilistbox.cpp
index f908df0dac..ed8b965263 100644
--- a/engines/ags/shared/gui/guilistbox.cpp
+++ b/engines/ags/shared/gui/guilistbox.cpp
@@ -28,9 +28,6 @@
 
 namespace AGS3 {
 
-std::vector<AGS::Shared::GUIListBox> guilist;
-int numguilist = 0;
-
 namespace AGS {
 namespace Shared {
 
diff --git a/engines/ags/shared/gui/guilistbox.h b/engines/ags/shared/gui/guilistbox.h
index b754decaab..1d9147af28 100644
--- a/engines/ags/shared/gui/guilistbox.h
+++ b/engines/ags/shared/gui/guilistbox.h
@@ -98,9 +98,6 @@ private:
 } // namespace Shared
 } // namespace AGS
 
-extern std::vector<AGS::Shared::GUIListBox> guilist;
-extern int numguilist;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/shared/gui/guimain.cpp b/engines/ags/shared/gui/guimain.cpp
index 5e19bbeb70..53453006c4 100644
--- a/engines/ags/shared/gui/guimain.cpp
+++ b/engines/ags/shared/gui/guimain.cpp
@@ -341,7 +341,7 @@ HError GUIMain::RebuildArray() {
 		else if (thistype == kGUITextBox)
 			_controls[i] = &guitext[thisnum];
 		else if (thistype == kGUIListBox)
-			_controls[i] = &guilist[thisnum];
+			_controls[i] = &_GP(guilist)[thisnum];
 		else
 			return new Error(String::FromFormat("GUIMain (%d): unknown control type %d in ref #%d", ID, thistype, i));
 
@@ -759,10 +759,10 @@ HError ReadGUI(std::vector<GUIMain> &theGuis, Stream *in, bool is_savegame) {
 	}
 	if (GameGuiVersion >= kGuiVersion_230) {
 		// list boxes
-		numguilist = in->ReadInt32();
-		guilist.resize(numguilist);
-		for (int i = 0; i < numguilist; ++i) {
-			guilist[i].ReadFromFile(in, GameGuiVersion);
+		_G(numguilist) = in->ReadInt32();
+		_GP(guilist).resize(_G(numguilist));
+		for (int i = 0; i < _G(numguilist); ++i) {
+			_GP(guilist)[i].ReadFromFile(in, GameGuiVersion);
 		}
 	}
 	return ResortGUI(theGuis, GameGuiVersion < kGuiVersion_272e);
@@ -796,9 +796,9 @@ void WriteGUI(const std::vector<GUIMain> &theGuis, Stream *out) {
 	for (int i = 0; i < numguitext; ++i) {
 		guitext[i].WriteToFile(out);
 	}
-	out->WriteInt32(numguilist);
-	for (int i = 0; i < numguilist; ++i) {
-		guilist[i].WriteToFile(out);
+	out->WriteInt32(_G(numguilist));
+	for (int i = 0; i < _G(numguilist); ++i) {
+		_GP(guilist)[i].WriteToFile(out);
 	}
 }
 


Commit: d2ea2beb640f81ef61e13d7feb5d80e3b91878c0
    https://github.com/scummvm/scummvm/commit/d2ea2beb640f81ef61e13d7feb5d80e3b91878c0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/gui/guimain.cpp
    engines/ags/shared/gui/guislider.cpp
    engines/ags/shared/gui/guislider.h


diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 48435939b0..94460d5615 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -552,9 +552,9 @@ HSaveError WriteGUI(PStream out) {
 		_GP(guiinv)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUISliders");
-	out->WriteInt32(numguislider);
-	for (int i = 0; i < numguislider; ++i)
-		guislider[i].WriteToSavegame(out.get());
+	out->WriteInt32(_G(numguislider));
+	for (int i = 0; i < _G(numguislider); ++i)
+		_GP(guislider)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUITextBoxes");
 	out->WriteInt32(numguitext);
@@ -608,10 +608,10 @@ HSaveError ReadGUI(PStream in, int32_t cmp_ver, const PreservedParams &pp, Resto
 
 	if (!AssertFormatTagStrict(err, in, "GUISliders"))
 		return err;
-	if (!AssertGameContent(err, in->ReadInt32(), numguislider, "GUI Sliders"))
+	if (!AssertGameContent(err, in->ReadInt32(), _G(numguislider), "GUI Sliders"))
 		return err;
-	for (int i = 0; i < numguislider; ++i)
-		guislider[i].ReadFromSavegame(in.get(), svg_ver);
+	for (int i = 0; i < _G(numguislider); ++i)
+		_GP(guislider)[i].ReadFromSavegame(in.get(), svg_ver);
 
 	if (!AssertFormatTagStrict(err, in, "GUITextBoxes"))
 		return err;
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 3e747d0f23..41c19e3a16 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -32,6 +32,7 @@
 #include "ags/shared/gui/guiinv.h"
 #include "ags/shared/gui/guilabel.h"
 #include "ags/shared/gui/guilistbox.h"
+#include "ags/shared/gui/guislider.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
@@ -141,6 +142,9 @@ Globals::Globals() {
 	// guilistbox.cpp globals
 	_guilist = new std::vector<AGS::Shared::GUIListBox>();
 
+	// guislider.cpp globals
+	_guislider = new std::vector<AGS::Shared::GUISlider>();
+
 	// managedobjectpool.cpp globals
 	_pool = new ManagedObjectPool();
 
@@ -239,6 +243,9 @@ Globals::~Globals() {
 	// guilistbox.cpp globals
 	delete _guilist;
 
+	// guislider.cpp globals
+	delete _guislider;
+
 	// managedobjectpool.cpp globals
 	delete _pool;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 40fbaf026b..09ebe0d1a5 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -47,6 +47,7 @@ class GUIButton;
 class GUIInvWindow;
 class GUILabel;
 class GUIListBox;
+class GUISlider;
 class RoomStruct;
 
 } // namespace Shared
@@ -299,6 +300,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup guislider globals
+	 * @{
+	 */
+
+	std::vector<AGS::Shared::GUISlider> *_guislider;
+	int _numguislider = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/gui/guimain.cpp b/engines/ags/shared/gui/guimain.cpp
index 53453006c4..ce248d2f68 100644
--- a/engines/ags/shared/gui/guimain.cpp
+++ b/engines/ags/shared/gui/guimain.cpp
@@ -337,7 +337,7 @@ HError GUIMain::RebuildArray() {
 		else if (thistype == kGUIInvWindow)
 			_controls[i] = &_GP(guiinv)[thisnum];
 		else if (thistype == kGUISlider)
-			_controls[i] = &guislider[thisnum];
+			_controls[i] = &_GP(guislider)[thisnum];
 		else if (thistype == kGUITextBox)
 			_controls[i] = &guitext[thisnum];
 		else if (thistype == kGUIListBox)
@@ -743,10 +743,10 @@ HError ReadGUI(std::vector<GUIMain> &theGuis, Stream *in, bool is_savegame) {
 
 	if (GameGuiVersion >= kGuiVersion_214) {
 		// sliders
-		numguislider = in->ReadInt32();
-		guislider.resize(numguislider);
-		for (int i = 0; i < numguislider; ++i) {
-			guislider[i].ReadFromFile(in, GameGuiVersion);
+		_G(numguislider) = in->ReadInt32();
+		_GP(guislider).resize(_G(numguislider));
+		for (int i = 0; i < _G(numguislider); ++i) {
+			_GP(guislider)[i].ReadFromFile(in, GameGuiVersion);
 		}
 	}
 	if (GameGuiVersion >= kGuiVersion_222) {
@@ -788,9 +788,9 @@ void WriteGUI(const std::vector<GUIMain> &theGuis, Stream *out) {
 	for (int i = 0; i < _G(numguiinv); ++i) {
 		_GP(guiinv)[i].WriteToFile(out);
 	}
-	out->WriteInt32(numguislider);
-	for (int i = 0; i < numguislider; ++i) {
-		guislider[i].WriteToFile(out);
+	out->WriteInt32(_G(numguislider));
+	for (int i = 0; i < _G(numguislider); ++i) {
+		_GP(guislider)[i].WriteToFile(out);
 	}
 	out->WriteInt32(numguitext);
 	for (int i = 0; i < numguitext; ++i) {
diff --git a/engines/ags/shared/gui/guislider.cpp b/engines/ags/shared/gui/guislider.cpp
index 50f83b74a2..2e4419560d 100644
--- a/engines/ags/shared/gui/guislider.cpp
+++ b/engines/ags/shared/gui/guislider.cpp
@@ -28,9 +28,6 @@
 
 namespace AGS3 {
 
-std::vector<AGS::Shared::GUISlider> guislider;
-int numguislider = 0;
-
 namespace AGS {
 namespace Shared {
 
diff --git a/engines/ags/shared/gui/guislider.h b/engines/ags/shared/gui/guislider.h
index b2ac2663d7..b6281f7002 100644
--- a/engines/ags/shared/gui/guislider.h
+++ b/engines/ags/shared/gui/guislider.h
@@ -70,10 +70,6 @@ private:
 
 } // namespace Shared
 } // namespace AGS
-
-extern std::vector<AGS::Shared::GUISlider> guislider;
-extern int numguislider;
-
 } // namespace AGS3
 
 #endif


Commit: 51f2cf25e96dcbb75430a0d2d18cde04d8246061
    https://github.com/scummvm/scummvm/commit/51f2cf25e96dcbb75430a0d2d18cde04d8246061
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/gui/guimain.cpp
    engines/ags/shared/gui/guitextbox.cpp
    engines/ags/shared/gui/guitextbox.h


diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index 94460d5615..41120f7a96 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -557,9 +557,9 @@ HSaveError WriteGUI(PStream out) {
 		_GP(guislider)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUITextBoxes");
-	out->WriteInt32(numguitext);
-	for (int i = 0; i < numguitext; ++i)
-		guitext[i].WriteToSavegame(out.get());
+	out->WriteInt32(_G(numguitext));
+	for (int i = 0; i < _G(numguitext); ++i)
+		_GP(guitext)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUIListBoxes");
 	out->WriteInt32(_G(numguilist));
@@ -615,10 +615,10 @@ HSaveError ReadGUI(PStream in, int32_t cmp_ver, const PreservedParams &pp, Resto
 
 	if (!AssertFormatTagStrict(err, in, "GUITextBoxes"))
 		return err;
-	if (!AssertGameContent(err, in->ReadInt32(), numguitext, "GUI TextBoxes"))
+	if (!AssertGameContent(err, in->ReadInt32(), _G(numguitext), "GUI TextBoxes"))
 		return err;
-	for (int i = 0; i < numguitext; ++i)
-		guitext[i].ReadFromSavegame(in.get(), svg_ver);
+	for (int i = 0; i < _G(numguitext); ++i)
+		_GP(guitext)[i].ReadFromSavegame(in.get(), svg_ver);
 
 	if (!AssertFormatTagStrict(err, in, "GUIListBoxes"))
 		return err;
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 41c19e3a16..e0b2eba857 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -33,6 +33,7 @@
 #include "ags/shared/gui/guilabel.h"
 #include "ags/shared/gui/guilistbox.h"
 #include "ags/shared/gui/guislider.h"
+#include "ags/shared/gui/guitextbox.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
@@ -145,6 +146,9 @@ Globals::Globals() {
 	// guislider.cpp globals
 	_guislider = new std::vector<AGS::Shared::GUISlider>();
 
+	// guitextbox.cpp globals
+	_guitext = new std::vector<AGS::Shared::GUITextBox>();
+
 	// managedobjectpool.cpp globals
 	_pool = new ManagedObjectPool();
 
@@ -246,6 +250,9 @@ Globals::~Globals() {
 	// guislider.cpp globals
 	delete _guislider;
 
+	// guitextbox.cpp globals
+	delete _guitext;
+
 	// managedobjectpool.cpp globals
 	delete _pool;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 09ebe0d1a5..5bae3b84f4 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -48,6 +48,7 @@ class GUIInvWindow;
 class GUILabel;
 class GUIListBox;
 class GUISlider;
+class GUITextBox;
 class RoomStruct;
 
 } // namespace Shared
@@ -310,6 +311,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup guitextbox globals
+	 * @{
+	 */
+
+	std::vector<AGS::Shared::GUITextBox> *_guitext;
+	int _numguitext = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/gui/guimain.cpp b/engines/ags/shared/gui/guimain.cpp
index ce248d2f68..82632a3825 100644
--- a/engines/ags/shared/gui/guimain.cpp
+++ b/engines/ags/shared/gui/guimain.cpp
@@ -339,7 +339,7 @@ HError GUIMain::RebuildArray() {
 		else if (thistype == kGUISlider)
 			_controls[i] = &_GP(guislider)[thisnum];
 		else if (thistype == kGUITextBox)
-			_controls[i] = &guitext[thisnum];
+			_controls[i] = &_GP(guitext)[thisnum];
 		else if (thistype == kGUIListBox)
 			_controls[i] = &_GP(guilist)[thisnum];
 		else
@@ -751,10 +751,10 @@ HError ReadGUI(std::vector<GUIMain> &theGuis, Stream *in, bool is_savegame) {
 	}
 	if (GameGuiVersion >= kGuiVersion_222) {
 		// text boxes
-		numguitext = in->ReadInt32();
-		guitext.resize(numguitext);
-		for (int i = 0; i < numguitext; ++i) {
-			guitext[i].ReadFromFile(in, GameGuiVersion);
+		_G(numguitext) = in->ReadInt32();
+		_GP(guitext).resize(_G(numguitext));
+		for (int i = 0; i < _G(numguitext); ++i) {
+			_GP(guitext)[i].ReadFromFile(in, GameGuiVersion);
 		}
 	}
 	if (GameGuiVersion >= kGuiVersion_230) {
@@ -792,9 +792,9 @@ void WriteGUI(const std::vector<GUIMain> &theGuis, Stream *out) {
 	for (int i = 0; i < _G(numguislider); ++i) {
 		_GP(guislider)[i].WriteToFile(out);
 	}
-	out->WriteInt32(numguitext);
-	for (int i = 0; i < numguitext; ++i) {
-		guitext[i].WriteToFile(out);
+	out->WriteInt32(_G(numguitext));
+	for (int i = 0; i < _G(numguitext); ++i) {
+		_GP(guitext)[i].WriteToFile(out);
 	}
 	out->WriteInt32(_G(numguilist));
 	for (int i = 0; i < _G(numguilist); ++i) {
diff --git a/engines/ags/shared/gui/guitextbox.cpp b/engines/ags/shared/gui/guitextbox.cpp
index b9b24df44b..6c08cd2709 100644
--- a/engines/ags/shared/gui/guitextbox.cpp
+++ b/engines/ags/shared/gui/guitextbox.cpp
@@ -30,9 +30,6 @@ namespace AGS3 {
 
 #define GUITEXTBOX_LEGACY_TEXTLEN 200
 
-std::vector<AGS::Shared::GUITextBox> guitext;
-int numguitext = 0;
-
 namespace AGS {
 namespace Shared {
 
diff --git a/engines/ags/shared/gui/guitextbox.h b/engines/ags/shared/gui/guitextbox.h
index 840f3f6e27..b79354d4f1 100644
--- a/engines/ags/shared/gui/guitextbox.h
+++ b/engines/ags/shared/gui/guitextbox.h
@@ -64,10 +64,6 @@ private:
 
 } // namespace Shared
 } // namespace AGS
-
-extern std::vector<AGS::Shared::GUITextBox> guitext;
-extern int numguitext;
-
 } // namespace AGS3
 
 #endif


Commit: 003d890955bf4b7a2d61ced8777e72455bf85697
    https://github.com/scummvm/scummvm/commit/003d890955bf4b7a2d61ced8777e72455bf85697
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:51-08:00

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

Changed paths:
    engines/ags/engine/script/cc_instance.cpp
    engines/ags/engine/script/script_runtime.cpp
    engines/ags/engine/script/systemimports.cpp
    engines/ags/engine/script/systemimports.h
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index abcb1698ad..f1650f97f3 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -486,7 +486,7 @@ int ccInstance::Run(int32_t curpc) {
 					codeOp.Args[i].SetStringLiteral(&codeInst->strings[0] + codeInst->code[pc_at]);
 					break;
 				case FIXUP_IMPORT: {
-					const ScriptImport *import = simp.getByIndex((int32_t)codeInst->code[pc_at]);
+					const ScriptImport *import = _GP(simp).getByIndex((int32_t)codeInst->code[pc_at]);
 					if (import) {
 						codeOp.Args[i] = import->Value;
 					} else {
@@ -1415,7 +1415,7 @@ void ccInstance::Free() {
 	if (instanceof != nullptr) {
 		instanceof->instances--;
 		if (instanceof->instances == 0) {
-			simp.RemoveScriptExports(this);
+			_GP(simp).RemoveScriptExports(this);
 		}
 	}
 
@@ -1471,7 +1471,7 @@ bool ccInstance::ResolveScriptImports(PScript scri) {
 			continue;
 		}
 
-		resolved_imports[i] = simp.get_index_of(scri->imports[i]);
+		resolved_imports[i] = _GP(simp).get_index_of(scri->imports[i]);
 		if (resolved_imports[i] < 0) {
 			cc_error("unresolved import '%s'", scri->imports[i]);
 			return false;
@@ -1594,7 +1594,7 @@ bool ccInstance::CreateRuntimeCodeFixups(PScript scri) {
 			// must fixup the following instruction in certain case
 		{
 			int import_index = resolved_imports[code[fixup]];
-			const ScriptImport *import = simp.getByIndex(import_index);
+			const ScriptImport *import = _GP(simp).getByIndex(import_index);
 			if (!import) {
 				cc_error("cannot resolve import, key = %d", import_index);
 				return false;
@@ -1674,7 +1674,7 @@ bool ccInstance::FixupArgument(intptr_t code_value, char fixup_type, RuntimeScri
         break;
     case FIXUP_IMPORT:
         {
-            const ScriptImport *import = simp.getByIndex((int32_t)code_value);
+            const ScriptImport *import = _GP(simp).getByIndex((int32_t)code_value);
             if (import)
             {
                 argument = import->Value;
diff --git a/engines/ags/engine/script/script_runtime.cpp b/engines/ags/engine/script/script_runtime.cpp
index 9c0c2d1659..2433292907 100644
--- a/engines/ags/engine/script/script_runtime.cpp
+++ b/engines/ags/engine/script/script_runtime.cpp
@@ -43,45 +43,46 @@
 #include "ags/engine/ac/dynobj/cc_dynamicarray.h"
 #include "ags/engine/ac/statobj/staticobject.h"
 #include "ags/plugins/plugin_base.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
 extern ccInstance *current_instance; // in script/cc_instance
 
 bool ccAddExternalStaticFunction(const String &name, ScriptAPIFunction *pfn) {
-	return simp.add(name, RuntimeScriptValue().SetStaticFunction(pfn), nullptr) == 0;
+	return _GP(simp).add(name, RuntimeScriptValue().SetStaticFunction(pfn), nullptr) == 0;
 }
 
 bool ccAddExternalPluginFunction(const String &name, void *pfn) {
-	return simp.add(name, RuntimeScriptValue().SetPluginFunction(pfn), nullptr) == 0;
+	return _GP(simp).add(name, RuntimeScriptValue().SetPluginFunction(pfn), nullptr) == 0;
 }
 
 bool ccAddExternalStaticObject(const String &name, void *ptr, ICCStaticObject *manager) {
-	return simp.add(name, RuntimeScriptValue().SetStaticObject(ptr, manager), nullptr) == 0;
+	return _GP(simp).add(name, RuntimeScriptValue().SetStaticObject(ptr, manager), nullptr) == 0;
 }
 
 bool ccAddExternalStaticArray(const String &name, void *ptr, StaticArray *array_mgr) {
-	return simp.add(name, RuntimeScriptValue().SetStaticArray(ptr, array_mgr), nullptr) == 0;
+	return _GP(simp).add(name, RuntimeScriptValue().SetStaticArray(ptr, array_mgr), nullptr) == 0;
 }
 
 bool ccAddExternalDynamicObject(const String &name, void *ptr, ICCDynamicObject *manager) {
-	return simp.add(name, RuntimeScriptValue().SetDynamicObject(ptr, manager), nullptr) == 0;
+	return _GP(simp).add(name, RuntimeScriptValue().SetDynamicObject(ptr, manager), nullptr) == 0;
 }
 
 bool ccAddExternalObjectFunction(const String &name, ScriptAPIObjectFunction *pfn) {
-	return simp.add(name, RuntimeScriptValue().SetObjectFunction(pfn), nullptr) == 0;
+	return _GP(simp).add(name, RuntimeScriptValue().SetObjectFunction(pfn), nullptr) == 0;
 }
 
 bool ccAddExternalScriptSymbol(const String &name, const RuntimeScriptValue &prval, ccInstance *inst) {
-	return simp.add(name, prval, inst) == 0;
+	return _GP(simp).add(name, prval, inst) == 0;
 }
 
 void ccRemoveExternalSymbol(const String &name) {
-	simp.remove(name);
+	_GP(simp).remove(name);
 }
 
 void ccRemoveAllSymbols() {
-	simp.clear();
+	_GP(simp).clear();
 }
 
 ccInstance *loadedInstances[MAX_LOADED_INSTANCES] = { nullptr,
@@ -95,7 +96,7 @@ void nullfree(void *data) {
 }
 
 void *ccGetSymbolAddress(const String &name) {
-	const ScriptImport *import = simp.getByName(name);
+	const ScriptImport *import = _GP(simp).getByName(name);
 	if (import) {
 		return import->Value.Ptr;
 	}
@@ -103,16 +104,16 @@ void *ccGetSymbolAddress(const String &name) {
 }
 
 bool ccAddExternalFunctionForPlugin(const String &name, void *pfn) {
-	return simp_for_plugin.add(name, RuntimeScriptValue().SetPluginFunction(pfn), nullptr) == 0;
+	return _GP(simp_for_plugin).add(name, RuntimeScriptValue().SetPluginFunction(pfn), nullptr) == 0;
 }
 
 void *ccGetSymbolAddressForPlugin(const String &name) {
-	const ScriptImport *import = simp_for_plugin.getByName(name);
+	const ScriptImport *import = _GP(simp_for_plugin).getByName(name);
 	if (import) {
 		return import->Value.Ptr;
 	} else {
 		// Also search the internal symbol table for non-function symbols
-		import = simp.getByName(name);
+		import = _GP(simp).getByName(name);
 		if (import) {
 			return import->Value.Ptr;
 		}
diff --git a/engines/ags/engine/script/systemimports.cpp b/engines/ags/engine/script/systemimports.cpp
index 843e9f0119..165d138114 100644
--- a/engines/ags/engine/script/systemimports.cpp
+++ b/engines/ags/engine/script/systemimports.cpp
@@ -20,17 +20,12 @@
  *
  */
 
-//include <stdlib.h>
-//include <string.h>
 #include "ags/engine/script/systemimports.h"
 
 namespace AGS3 {
 
 extern void quit(const char *);
 
-SystemImports simp;
-SystemImports simp_for_plugin;
-
 int SystemImports::add(const String &name, const RuntimeScriptValue &value, ccInstance *anotherscr) {
 	int ixof;
 
diff --git a/engines/ags/engine/script/systemimports.h b/engines/ags/engine/script/systemimports.h
index 1332252b06..f79fd65bff 100644
--- a/engines/ags/engine/script/systemimports.h
+++ b/engines/ags/engine/script/systemimports.h
@@ -63,11 +63,6 @@ public:
 	void clear();
 };
 
-extern SystemImports simp;
-// This is to register symbols exclusively for plugins, to allow them
-// perform old style unsafe function calls
-extern SystemImports simp_for_plugin;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index e0b2eba857..7e5ed5d1df 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -64,6 +64,7 @@
 #include "ags/engine/script/executingscript.h"
 #include "ags/engine/script/nonblockingscriptfunction.h"
 #include "ags/engine/script/script.h"
+#include "ags/engine/script/systemimports.h"
 
 namespace AGS3 {
 
@@ -155,7 +156,7 @@ Globals::Globals() {
 	// overlay.cpp globals
 	_screenover = new std::vector<ScreenOverlay>();
 
-	// script.cpp
+	// script.cpp globals
 	_scripts = new ExecutingScript[MAX_SCRIPT_AT_ONCE];
 	_gamescript = new PScript();
 	_dialogScriptsScript = new PScript();
@@ -175,6 +176,10 @@ Globals::Globals() {
 	_characterScriptObjNames = new std::vector<String>();
 	_objectScriptObjNames = new String[MAX_ROOM_OBJECTS];
 	_guiScriptObjNames = new std::vector<String>();
+
+	// systemimports.cpp globals
+	_simp = new SystemImports();
+	_simp_for_plugin = new SystemImports();
 }
 
 Globals::~Globals() {
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 5bae3b84f4..d6b3aa4be5 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -95,6 +95,7 @@ struct ScriptSystem;
 struct SOUNDCLIP;
 struct SpriteListEntry;
 struct StaticArray;
+struct SystemImports;
 struct ViewStruct;
 
 class SpriteCache;
@@ -464,6 +465,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup script globals
+	 * @{
+	 */
+
+	SystemImports *_simp;
+	SystemImports *_simp_for_plugin;
+
+	/**@}*/
+
 public:
 	Globals();
 	~Globals();


Commit: cd83601dc37ec8c7f1d632329b76fe5324af390e
    https://github.com/scummvm/scummvm/commit/cd83601dc37ec8c7f1d632329b76fe5324af390e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T20:14:52-08:00

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

Changed paths:
    engines/ags/engine/ac/movelist.h
    engines/ags/engine/ac/route_finder_impl.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/movelist.h b/engines/ags/engine/ac/movelist.h
index e8cc8570b6..fd68e4a1a1 100644
--- a/engines/ags/engine/ac/movelist.h
+++ b/engines/ags/engine/ac/movelist.h
@@ -39,6 +39,7 @@ using namespace AGS; // FIXME later
 
 #define MAXNEEDSTAGES 256
 #define MAXNEEDSTAGES_LEGACY 40
+#define MAXNAVPOINTS MAXNEEDSTAGES
 
 struct MoveList {
 	int32_t pos[MAXNEEDSTAGES];
diff --git a/engines/ags/engine/ac/route_finder_impl.cpp b/engines/ags/engine/ac/route_finder_impl.cpp
index 275012e4e2..8c7e8f0aee 100644
--- a/engines/ags/engine/ac/route_finder_impl.cpp
+++ b/engines/ags/engine/ac/route_finder_impl.cpp
@@ -39,22 +39,12 @@ namespace AGS3 {
 
 using AGS::Shared::Bitmap;
 
-// #define DEBUG_PATHFINDER
-
 namespace AGS {
 namespace Engine {
 namespace RouteFinder {
 
 #define MAKE_INTCOORD(x,y) (((unsigned short)x << 16) | ((unsigned short)y))
 
-static const int MAXNAVPOINTS = MAXNEEDSTAGES;
-static int32_t navpoints[MAXNAVPOINTS];
-static int num_navpoints;
-static fixed move_speed_x, move_speed_y;
-static Navigation nav;
-static Bitmap *wallscreen;
-static int lastcx, lastcy;
-
 void init_pathfinder() {
 }
 
@@ -62,32 +52,32 @@ void shutdown_pathfinder() {
 }
 
 void set_wallscreen(Bitmap *wallscreen_) {
-	wallscreen = wallscreen_;
+	_G(wallscreen) = wallscreen_;
 }
 
 static void sync_nav_wallscreen() {
 	// FIXME: this is dumb, but...
-	nav.Resize(wallscreen->GetWidth(), wallscreen->GetHeight());
+	_GP(nav).Resize(_G(wallscreen)->GetWidth(), _G(wallscreen)->GetHeight());
 
-	for (int y = 0; y < wallscreen->GetHeight(); y++)
-		nav.SetMapRow(y, wallscreen->GetScanLine(y));
+	for (int y = 0; y < _G(wallscreen)->GetHeight(); y++)
+		_GP(nav).SetMapRow(y, _G(wallscreen)->GetScanLine(y));
 }
 
 int can_see_from(int x1, int y1, int x2, int y2) {
-	lastcx = x1;
-	lastcy = y1;
+	_G(lastcx) = x1;
+	_G(lastcy) = y1;
 
 	if ((x1 == x2) && (y1 == y2))
 		return 1;
 
 	sync_nav_wallscreen();
 
-	return !nav.TraceLine(x1, y1, x2, y2, lastcx, lastcy);
+	return !_GP(nav).TraceLine(x1, y1, x2, y2, _G(lastcx), _G(lastcy));
 }
 
 void get_lastcpos(int &lastcx_, int &lastcy_) {
-	lastcx_ = lastcx;
-	lastcy_ = lastcy;
+	lastcx_ = _G(lastcx);
+	lastcy_ = _G(lastcy);
 }
 
 // new routing using JPS
@@ -98,19 +88,19 @@ static int find_route_jps(int fromx, int fromy, int destx, int desty) {
 	path.clear();
 	cpath.clear();
 
-	if (nav.NavigateRefined(fromx, fromy, destx, desty, path, cpath) == Navigation::NAV_UNREACHABLE)
+	if (_GP(nav).NavigateRefined(fromx, fromy, destx, desty, path, cpath) == Navigation::NAV_UNREACHABLE)
 		return 0;
 
-	num_navpoints = 0;
+	_G(num_navpoints) = 0;
 
 	// new behavior: cut path if too complex rather than abort with error message
 	int count = std::min<int>((int)cpath.size(), MAXNAVPOINTS);
 
 	for (int i = 0; i < count; i++) {
 		int x, y;
-		nav.UnpackSquare(cpath[i], x, y);
+		_GP(nav).UnpackSquare(cpath[i], x, y);
 
-		navpoints[num_navpoints++] = MAKE_INTCOORD(x, y);
+		_G(navpoints)[_G(num_navpoints)++] = MAKE_INTCOORD(x, y);
 	}
 
 	return 1;
@@ -119,15 +109,15 @@ static int find_route_jps(int fromx, int fromy, int destx, int desty) {
 void set_route_move_speed(int speed_x, int speed_y) {
 	// negative move speeds like -2 get converted to 1/2
 	if (speed_x < 0) {
-		move_speed_x = itofix(1) / (-speed_x);
+		_G(move_speed_x) = itofix(1) / (-speed_x);
 	} else {
-		move_speed_x = itofix(speed_x);
+		_G(move_speed_x) = itofix(speed_x);
 	}
 
 	if (speed_y < 0) {
-		move_speed_y = itofix(1) / (-speed_y);
+		_G(move_speed_y) = itofix(1) / (-speed_y);
 	} else {
-		move_speed_y = itofix(speed_y);
+		_G(move_speed_y) = itofix(speed_y);
 	}
 }
 
@@ -149,7 +139,7 @@ void calculate_move_stage(MoveList *mlsp, int aaa) {
 	// Special case for vertical and horizontal movements
 	if (ourx == destx) {
 		mlsp->xpermove[aaa] = 0;
-		mlsp->ypermove[aaa] = move_speed_y;
+		mlsp->ypermove[aaa] = _G(move_speed_y);
 		if (desty < oury)
 			mlsp->ypermove[aaa] = -mlsp->ypermove[aaa];
 
@@ -157,7 +147,7 @@ void calculate_move_stage(MoveList *mlsp, int aaa) {
 	}
 
 	if (oury == desty) {
-		mlsp->xpermove[aaa] = move_speed_x;
+		mlsp->xpermove[aaa] = _G(move_speed_x);
 		mlsp->ypermove[aaa] = 0;
 		if (destx < ourx)
 			mlsp->xpermove[aaa] = -mlsp->xpermove[aaa];
@@ -170,19 +160,19 @@ void calculate_move_stage(MoveList *mlsp, int aaa) {
 
 	fixed useMoveSpeed;
 
-	if (move_speed_x == move_speed_y) {
-		useMoveSpeed = move_speed_x;
+	if (_G(move_speed_x) == _G(move_speed_y)) {
+		useMoveSpeed = _G(move_speed_x);
 	} else {
 		// different X and Y move speeds
 		// the X proportion of the movement is (x / (x + y))
 		fixed xproportion = fixdiv(xdist, (xdist + ydist));
 
-		if (move_speed_x > move_speed_y) {
+		if (_G(move_speed_x) > _G(move_speed_y)) {
 			// speed = y + ((1 - xproportion) * (x - y))
-			useMoveSpeed = move_speed_y + fixmul(xproportion, move_speed_x - move_speed_y);
+			useMoveSpeed = _G(move_speed_y) + fixmul(xproportion, _G(move_speed_x) - _G(move_speed_y));
 		} else {
 			// speed = x + (xproportion * (y - x))
-			useMoveSpeed = move_speed_x + fixmul(itofix(1) - xproportion, move_speed_y - move_speed_x);
+			useMoveSpeed = _G(move_speed_x) + fixmul(itofix(1) - xproportion, _G(move_speed_y) - _G(move_speed_x));
 		}
 	}
 
@@ -209,42 +199,42 @@ void calculate_move_stage(MoveList *mlsp, int aaa) {
 int find_route(short srcx, short srcy, short xx, short yy, Bitmap *onscreen, int movlst, int nocross, int ignore_walls) {
 	int i;
 
-	wallscreen = onscreen;
+	_G(wallscreen) = onscreen;
 
-	num_navpoints = 0;
+	_G(num_navpoints) = 0;
 
 	if (ignore_walls || can_see_from(srcx, srcy, xx, yy)) {
-		num_navpoints = 2;
-		navpoints[0] = MAKE_INTCOORD(srcx, srcy);
-		navpoints[1] = MAKE_INTCOORD(xx, yy);
+		_G(num_navpoints) = 2;
+		_G(navpoints)[0] = MAKE_INTCOORD(srcx, srcy);
+		_G(navpoints)[1] = MAKE_INTCOORD(xx, yy);
 	} else {
-		if ((nocross == 0) && (wallscreen->GetPixel(xx, yy) == 0))
+		if ((nocross == 0) && (_G(wallscreen)->GetPixel(xx, yy) == 0))
 			return 0; // clicked on a wall
 
 		find_route_jps(srcx, srcy, xx, yy);
 	}
 
-	if (!num_navpoints)
+	if (!_G(num_navpoints))
 		return 0;
 
 	// FIXME: really necessary?
-	if (num_navpoints == 1)
-		navpoints[num_navpoints++] = navpoints[0];
+	if (_G(num_navpoints) == 1)
+		_G(navpoints)[_G(num_navpoints)++] = _G(navpoints)[0];
 
-	assert(num_navpoints <= MAXNAVPOINTS);
+	assert(_G(num_navpoints) <= MAXNAVPOINTS);
 
 #ifdef DEBUG_PATHFINDER
-	AGS::Shared::Debug::Printf("Route from %d,%d to %d,%d - %d stages", srcx, srcy, xx, yy, num_navpoints);
+	AGS::Shared::Debug::Printf("Route from %d,%d to %d,%d - %d stages", srcx, srcy, xx, yy, _G(num_navpoints));
 #endif
 
 	int mlist = movlst;
-	_G(mls)[mlist].numstage = num_navpoints;
-	memcpy(&_G(mls)[mlist].pos[0], &navpoints[0], sizeof(int32_t) * num_navpoints);
+	_G(mls)[mlist].numstage = _G(num_navpoints);
+	memcpy(&_G(mls)[mlist].pos[0], &_G(navpoints)[0], sizeof(int32_t) * _G(num_navpoints));
 #ifdef DEBUG_PATHFINDER
-	AGS::Shared::Debug::Printf("stages: %d\n", num_navpoints);
+	AGS::Shared::Debug::Printf("stages: %d\n", _G(num_navpoints));
 #endif
 
-	for (i = 0; i < num_navpoints - 1; i++)
+	for (i = 0; i < _G(num_navpoints) - 1; i++)
 		calculate_move_stage(&_G(mls)[mlist], i);
 
 	_G(mls)[mlist].fromx = srcx;
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 7e5ed5d1df..feaf0e458b 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -37,8 +37,10 @@
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamestate.h"
+#include "ags/engine/ac/movelist.h"
 #include "ags/engine/ac/objectcache.h"
 #include "ags/engine/ac/roomstatus.h"
+#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_dialog.h"
@@ -156,6 +158,10 @@ Globals::Globals() {
 	// overlay.cpp globals
 	_screenover = new std::vector<ScreenOverlay>();
 
+	// route_finder_impl.cpp globals
+	_navpoints = new int32_t[MAXNEEDSTAGES];
+	_nav = new Navigation();
+
 	// script.cpp globals
 	_scripts = new ExecutingScript[MAX_SCRIPT_AT_ONCE];
 	_gamescript = new PScript();
@@ -264,6 +270,10 @@ Globals::~Globals() {
 	// overlay.cpp globals
 	delete _screenover;
 
+	// route_finder_impl.cpp globals
+	delete _navpoints;
+	delete _nav;
+
 	// script.cpp globals
 	delete[] _scripts;
 	delete _gamescript;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index d6b3aa4be5..ae543bd1ad 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -29,6 +29,7 @@
 #include "ags/shared/script/cc_script.h"
 #include "ags/lib/std/array.h"
 #include "ags/lib/std/set.h"
+#include "ags/lib/allegro/fixed.h"
 
 namespace AGS3 {
 
@@ -54,6 +55,7 @@ class RoomStruct;
 } // namespace Shared
 } // namespace AGS
 
+class Navigation;
 class SplitLines;
 class TTFFontRenderer;
 class WFNFontRenderer;
@@ -420,6 +422,20 @@ public:
 
 	 /**@}*/
 
+	/**
+	 * \defgroup route_finder_impl globals
+	 * @{
+	 */
+
+	int32_t *_navpoints;
+	Navigation *_nav;
+	int _num_navpoints = 0;
+	fixed _move_speed_x = 0, _move_speed_y = 0;
+	AGS::Shared::Bitmap *_wallscreen = nullptr;
+	int _lastcx = 0, _lastcy = 0;
+
+	 /**@}*/
+
 	/**
 	 * \defgroup script globals
 	 * @{


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

Commit Message:
AGS: Move usetup to Globals

Changed paths:
    engines/ags/ags.cpp
    engines/ags/engine/ac/draw.cpp
    engines/ags/engine/ac/draw.h
    engines/ags/engine/ac/file.cpp
    engines/ags/engine/ac/game.cpp
    engines/ags/engine/ac/gamesetup.h
    engines/ags/engine/ac/global_audio.cpp
    engines/ags/engine/ac/global_debug.cpp
    engines/ags/engine/ac/global_game.cpp
    engines/ags/engine/ac/global_screen.cpp
    engines/ags/engine/ac/global_video.cpp
    engines/ags/engine/ac/gui.cpp
    engines/ags/engine/ac/mouse.cpp
    engines/ags/engine/ac/room.cpp
    engines/ags/engine/ac/system.cpp
    engines/ags/engine/ac/translation.cpp
    engines/ags/engine/game/game_init.cpp
    engines/ags/engine/gui/cscidialog.cpp
    engines/ags/engine/gui/guidialog.cpp
    engines/ags/engine/gui/guidialoginternaldefs.h
    engines/ags/engine/gui/mylabel.cpp
    engines/ags/engine/gui/mylistbox.cpp
    engines/ags/engine/gui/mytextbox.cpp
    engines/ags/engine/main/config.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/quit.cpp
    engines/ags/engine/media/audio/audio.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/plugins/agsplugin.cpp


diff --git a/engines/ags/ags.cpp b/engines/ags/ags.cpp
index b37e83d41b..b366b7df65 100644
--- a/engines/ags/ags.cpp
+++ b/engines/ags/ags.cpp
@@ -69,7 +69,6 @@ using namespace Engine;
 
 extern HSaveError load_game(int slotNumber, bool &data_overwritten);
 
-extern GameSetup usetup;
 extern int our_eip;
 extern AGSPlatformDriver *platform;
 extern int convert_16bit_bgr;
@@ -147,7 +146,7 @@ static int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
 			strncpy(_G(return_to_roomedit), argv[ee + 1], 30);
 			strncpy(_G(return_to_room), argv[ee + 2], 150);
 			ee += 2;
-		} else if (scumm_stricmp(arg, "-noexceptionhandler") == 0) usetup.disable_exception_handling = true;
+		} else if (scumm_stricmp(arg, "-noexceptionhandler") == 0) _GP(usetup).disable_exception_handling = true;
 		else if (scumm_stricmp(arg, "--setup") == 0) {
 			_G(justRunSetup) = true;
 		} else if (scumm_stricmp(arg, "-registergame") == 0) {
@@ -163,9 +162,9 @@ static int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
 			_G(force_window) = 1;
 			ee++;
 		} else if (scumm_stricmp(arg, "--runfromide") == 0 && (argc > ee + 3)) {
-			usetup.install_dir = argv[ee + 1];
-			usetup.install_audio_dir = argv[ee + 2];
-			usetup.install_voice_dir = argv[ee + 3];
+			_GP(usetup).install_dir = argv[ee + 1];
+			_GP(usetup).install_audio_dir = argv[ee + 2];
+			_GP(usetup).install_voice_dir = argv[ee + 3];
 			ee += 3;
 		} else if (scumm_stricmp(arg, "--takeover") == 0) {
 			if (argc < ee + 2)
@@ -364,7 +363,7 @@ Common::Error AGSEngine::run() {
 	_G(loadSaveGameOnStartup) = ConfMan.getInt("save_slot");
 
 #ifdef USE_CUSTOM_EXCEPTION_HANDLER
-	if (usetup.disable_exception_handling)
+	if (_GP(usetup).disable_exception_handling)
 #endif
 	{
 		AGS3::initialize_engine(startup_opts);
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index c27fbca371..6cc9b3aa9a 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -88,13 +88,8 @@ extern "C" void android_render();
 extern "C" void ios_render();
 #endif
 
-extern GameSetup usetup;
-
-
 extern int convert_16bit_bgr;
-
 extern AGSPlatformDriver *platform;
-
 extern char noWalkBehindsAtAll;
 extern unsigned int loopcounter;
 extern char *walkBehindExists;  // whether a WB area is in this column
@@ -2143,7 +2138,7 @@ void construct_game_scene(bool full_redraw) {
 	_GP(play).UpdateViewports();
 
 	gfxDriver->UseSmoothScaling(IS_ANTIALIAS_SPRITES);
-	gfxDriver->RenderSpritesAtScreenResolution(usetup.RenderAtScreenRes, usetup.Supersampling);
+	gfxDriver->RenderSpritesAtScreenResolution(_GP(usetup).RenderAtScreenRes, _GP(usetup).Supersampling);
 
 	pl_run_plugin_hooks(AGSE_PRERENDER, 0);
 
diff --git a/engines/ags/engine/ac/draw.h b/engines/ags/engine/ac/draw.h
index 67d0f52875..5549737664 100644
--- a/engines/ags/engine/ac/draw.h
+++ b/engines/ags/engine/ac/draw.h
@@ -44,7 +44,7 @@ class IDriverDependantBitmap;
 
 using namespace AGS; // FIXME later
 
-#define IS_ANTIALIAS_SPRITES usetup.enable_antialiasing && (_GP(play).disable_antialiasing == 0)
+#define IS_ANTIALIAS_SPRITES _GP(usetup).enable_antialiasing && (_GP(play).disable_antialiasing == 0)
 
 // [IKM] WARNING: these definitions has to be made AFTER Allegro headers
 // were included, because they override few Allegro function names;
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index f2532ba5a1..9f4cdd3bda 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -55,10 +55,7 @@ namespace AGS3 {
 
 using namespace AGS::Shared;
 
-extern GameSetup usetup;
-
 extern AGSPlatformDriver *platform;
-
 extern int MAXSTRLEN;
 
 // TODO: the asset path configuration should certainly be revamped at some
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 27cf30baa8..859a51da9c 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -148,7 +148,6 @@ extern IGraphicsDriver *gfxDriver;
 
 //=============================================================================
 
-GameSetup usetup;
 RoomObject *objs;
 RoomStatus *croom = nullptr;
 
@@ -810,7 +809,7 @@ int Game_ChangeTranslation(const char *newFilename) {
 	if ((newFilename == nullptr) || (newFilename[0] == 0)) {
 		close_translation();
 		strcpy(transFileName, "");
-		usetup.translation = "";
+		_GP(usetup).translation = "";
 		return 1;
 	}
 
@@ -818,7 +817,7 @@ int Game_ChangeTranslation(const char *newFilename) {
 	oldTransFileName = transFileName;
 
 	if (init_translation(newFilename, oldTransFileName.LeftSection('.'), false)) {
-		usetup.translation = newFilename;
+		_GP(usetup).translation = newFilename;
 		return 1;
 	} else {
 		strcpy(transFileName, oldTransFileName);
@@ -1785,7 +1784,7 @@ void display_switch_in() {
 	platform->DisplaySwitchIn();
 	ags_clear_input_buffer();
 	// If auto lock option is set, lock mouse to the game window
-	if (usetup.mouse_auto_lock && _GP(scsystem).windowed)
+	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed)
 		Mouse::TryLockToWindow();
 }
 
diff --git a/engines/ags/engine/ac/gamesetup.h b/engines/ags/engine/ac/gamesetup.h
index 280df15d5c..3bce390839 100644
--- a/engines/ags/engine/ac/gamesetup.h
+++ b/engines/ags/engine/ac/gamesetup.h
@@ -83,11 +83,6 @@ struct GameSetup {
 	GameSetup();
 };
 
-// TODO: setup object is used for two purposes: temporarily storing config
-// options before engine is initialized, and storing certain runtime variables.
-// Perhaps it makes sense to separate those two group of vars at some point.
-extern GameSetup usetup;
-
 } // namespace AGS3
 
 #endif
diff --git a/engines/ags/engine/ac/global_audio.cpp b/engines/ags/engine/ac/global_audio.cpp
index 40cfe0a7b1..f1f3fb76f1 100644
--- a/engines/ags/engine/ac/global_audio.cpp
+++ b/engines/ags/engine/ac/global_audio.cpp
@@ -41,10 +41,6 @@ namespace AGS3 {
 
 using namespace AGS::Shared;
 
-extern GameSetup usetup;
-
-
-
 extern SpeechLipSyncLine *splipsync;
 extern int numLipLines, curLipLine, curLipLinePhoneme;
 
diff --git a/engines/ags/engine/ac/global_debug.cpp b/engines/ags/engine/ac/global_debug.cpp
index fbca3d3136..5290658b6d 100644
--- a/engines/ags/engine/ac/global_debug.cpp
+++ b/engines/ags/engine/ac/global_debug.cpp
@@ -53,18 +53,11 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-
-extern GameSetup usetup;
-
-
 extern CharacterInfo *playerchar;
-
 extern int convert_16bit_bgr;
 extern IGraphicsDriver *gfxDriver;
-
 extern TreeMap *transtree;
 extern int displayed_room, starting_room;
-
 extern char transFileName[MAX_PATH];
 
 String GetRuntimeInfo() {
diff --git a/engines/ags/engine/ac/global_game.cpp b/engines/ags/engine/ac/global_game.cpp
index d71b1c20e5..79df31351e 100644
--- a/engines/ags/engine/ac/global_game.cpp
+++ b/engines/ags/engine/ac/global_game.cpp
@@ -80,7 +80,6 @@ using namespace AGS::Shared;
 extern int displayed_room;
 extern int game_paused;
 extern char gamefilenamebuf[200];
-extern GameSetup usetup;
 extern unsigned int load_new_game;
 extern int load_new_game_restore;
 extern RoomStatus *croom;
@@ -270,7 +269,7 @@ int RunAGSGame(const char *newgame, unsigned int mode, int data) {
 	unload_game_file();
 
 	// Adjust config (NOTE: normally, RunAGSGame would need a redesign to allow separate config etc per each game)
-	usetup.translation = ""; // reset to default, prevent from trying translation file of game A in game B
+	_GP(usetup).translation = ""; // reset to default, prevent from trying translation file of game A in game B
 
 	if (Shared::AssetManager::SetDataFile(ResPaths.GamePak.Path) != Shared::kAssetNoError)
 		quitprintf("!RunAGSGame: unable to load new game file '%s'", ResPaths.GamePak.Path.GetCStr());
@@ -858,8 +857,8 @@ void SetMultitasking(int mode) {
 	if ((mode < 0) | (mode > 1))
 		quit("!SetMultitasking: invalid mode parameter");
 
-	if (usetup.override_multitasking >= 0) {
-		mode = usetup.override_multitasking;
+	if (_GP(usetup).override_multitasking >= 0) {
+		mode = _GP(usetup).override_multitasking;
 	}
 
 	// Don't allow background running if full screen
diff --git a/engines/ags/engine/ac/global_screen.cpp b/engines/ags/engine/ac/global_screen.cpp
index cc4f177401..aadce3e7e6 100644
--- a/engines/ags/engine/ac/global_screen.cpp
+++ b/engines/ags/engine/ac/global_screen.cpp
@@ -41,10 +41,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern GameSetup usetup;
-
-
-
 extern IGraphicsDriver *gfxDriver;
 extern AGSPlatformDriver *platform;
 extern color palette[256];
diff --git a/engines/ags/engine/ac/global_video.cpp b/engines/ags/engine/ac/global_video.cpp
index 2f5dc91f21..d2faf689df 100644
--- a/engines/ags/engine/ac/global_video.cpp
+++ b/engines/ags/engine/ac/global_video.cpp
@@ -45,7 +45,7 @@ void scrPlayVideo(const char *name, int skip, int flags) {
 	if (debug_flags & DBG_NOVIDEO)
 		return;
 
-	if ((flags < 10) && (usetup.audio_backend == 0)) {
+	if ((flags < 10) && (_GP(usetup).audio_backend == 0)) {
 		// if game audio is disabled in Setup, then don't
 		// play any sound on the video either
 		flags += 10;
diff --git a/engines/ags/engine/ac/gui.cpp b/engines/ags/engine/ac/gui.cpp
index fca9d3750e..5e8db0d8b7 100644
--- a/engines/ags/engine/ac/gui.cpp
+++ b/engines/ags/engine/ac/gui.cpp
@@ -64,7 +64,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern GameSetup usetup;
 extern int cur_mode, cur_cursor;
 extern Bitmap **guibg;
 extern IDriverDependantBitmap **guibgbmp;
diff --git a/engines/ags/engine/ac/mouse.cpp b/engines/ags/engine/ac/mouse.cpp
index b91c7299e6..9b360edac3 100644
--- a/engines/ags/engine/ac/mouse.cpp
+++ b/engines/ags/engine/ac/mouse.cpp
@@ -326,13 +326,13 @@ int IsModeEnabled(int which) {
 }
 
 void Mouse_EnableControl(bool on) {
-	usetup.mouse_ctrl_enabled = on; // remember setting in config
+	_GP(usetup).mouse_ctrl_enabled = on; // remember setting in config
 
 	bool is_windowed = _GP(scsystem).windowed != 0;
 	// Whether mouse movement should be controlled by the engine - this is
 	// determined based on related config option.
-	bool should_control_mouse = usetup.mouse_ctrl_when == kMouseCtrl_Always ||
-		(usetup.mouse_ctrl_when == kMouseCtrl_Fullscreen && !is_windowed);
+	bool should_control_mouse = _GP(usetup).mouse_ctrl_when == kMouseCtrl_Always ||
+		(_GP(usetup).mouse_ctrl_when == kMouseCtrl_Fullscreen && !is_windowed);
 	// Whether mouse movement control is supported by the engine - this is
 	// determined on per platform basis. Some builds may not have such
 	// capability, e.g. because of how backend library implements mouse utils.
diff --git a/engines/ags/engine/ac/room.cpp b/engines/ags/engine/ac/room.cpp
index 020c295977..4fc0562152 100644
--- a/engines/ags/engine/ac/room.cpp
+++ b/engines/ags/engine/ac/room.cpp
@@ -85,9 +85,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern GameSetup usetup;
-
-
 extern RoomStatus *croom;
 extern int displayed_room;
 extern RoomObject *objs;
diff --git a/engines/ags/engine/ac/system.cpp b/engines/ags/engine/ac/system.cpp
index 87ac0f1986..f7d2950b03 100644
--- a/engines/ags/engine/ac/system.cpp
+++ b/engines/ags/engine/ac/system.cpp
@@ -52,11 +52,8 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern GameSetup usetup;
 extern ScriptAudioChannel scrAudioChannel[MAX_SOUND_CHANNELS + 1];
-
 extern IGraphicsDriver *gfxDriver;
-
 extern volatile bool switched_away;
 
 bool System_HasInputFocus() {
@@ -204,11 +201,11 @@ const char *System_GetRuntimeInfo() {
 }
 
 int System_GetRenderAtScreenResolution() {
-	return usetup.RenderAtScreenRes;
+	return _GP(usetup).RenderAtScreenRes;
 }
 
 void System_SetRenderAtScreenResolution(int enable) {
-	usetup.RenderAtScreenRes = enable != 0;
+	_GP(usetup).RenderAtScreenRes = enable != 0;
 }
 
 //=============================================================================
diff --git a/engines/ags/engine/ac/translation.cpp b/engines/ags/engine/ac/translation.cpp
index 909a0b2ca8..b5a3bcbbd4 100644
--- a/engines/ags/engine/ac/translation.cpp
+++ b/engines/ags/engine/ac/translation.cpp
@@ -40,8 +40,6 @@ namespace AGS3 {
 
 using namespace AGS::Shared;
 
-extern GameSetup usetup;
-
 extern char transFileName[MAX_PATH];
 
 TreeMap *transtree = nullptr;
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index b05600ce3d..9178ead0e9 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -322,7 +322,7 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
 	// itself still supports it, technically.
 	// This overriding option re-enables "upscaling". It works ONLY for low-res
 	// resolutions, such as 320x200 and 320x240.
-	if (usetup.override_upscale) {
+	if (_GP(usetup).override_upscale) {
 		if (_GP(game).GetResolutionType() == kGameResolution_320x200)
 			_GP(game).SetGameResolution(kGameResolution_640x400);
 		else if (_GP(game).GetResolutionType() == kGameResolution_320x240)
diff --git a/engines/ags/engine/gui/cscidialog.cpp b/engines/ags/engine/gui/cscidialog.cpp
index ca8e720d1b..beb648fdb6 100644
--- a/engines/ags/engine/gui/cscidialog.cpp
+++ b/engines/ags/engine/gui/cscidialog.cpp
@@ -50,8 +50,6 @@ using AGS::Shared::Bitmap;
 namespace BitmapHelper = AGS::Shared::BitmapHelper;
 
 extern IGraphicsDriver *gfxDriver;
-extern GameSetup usetup;
-
 
 //-----------------------------------------------------------------------------
 // DIALOG SYSTEM STUFF below
diff --git a/engines/ags/engine/gui/guidialog.cpp b/engines/ags/engine/gui/guidialog.cpp
index e2ad58836e..3943ac26dd 100644
--- a/engines/ags/engine/gui/guidialog.cpp
+++ b/engines/ags/engine/gui/guidialog.cpp
@@ -40,8 +40,6 @@ using namespace AGS::Shared;
 using namespace AGS::Engine;
 
 extern IGraphicsDriver *gfxDriver;
-extern GameSetup usetup;
-
 
 namespace {
 
@@ -111,7 +109,7 @@ int loadgamedialog() {
 	const int wnd_height = 120;
 	const int boxleft = myscrnwid / 2 - wnd_width / 2;
 	const int boxtop = myscrnhit / 2 - wnd_height / 2;
-	const int buttonhit = usetup.textheight + 5;
+	const int buttonhit = _GP(usetup).textheight + 5;
 
 	int handl = CSCIDrawWindow(boxleft, boxtop, wnd_width, wnd_height);
 	int ctrlok =
@@ -165,7 +163,7 @@ int savegamedialog() {
 	const int wnd_height = 120;
 	const int boxleft = myscrnwid / 2 - wnd_width / 2;
 	const int boxtop = myscrnhit / 2 - wnd_height / 2;
-	const int buttonhit = usetup.textheight + 5;
+	const int buttonhit = _GP(usetup).textheight + 5;
 	int labeltop = 5;
 
 	int handl = CSCIDrawWindow(boxleft, boxtop, wnd_width, wnd_height);
diff --git a/engines/ags/engine/gui/guidialoginternaldefs.h b/engines/ags/engine/gui/guidialoginternaldefs.h
index ea363da5d8..54083d02cf 100644
--- a/engines/ags/engine/gui/guidialoginternaldefs.h
+++ b/engines/ags/engine/gui/guidialoginternaldefs.h
@@ -34,7 +34,7 @@ namespace AGS3 {
 #define WINAPI
 extern int ags_misbuttondown(int but);
 #define mbutrelease(X) (!ags_misbuttondown(X))
-#define TEXT_HT usetup.textheight
+#define TEXT_HT _GP(usetup).textheight
 
 } // namespace AGS3
 
diff --git a/engines/ags/engine/gui/mylabel.cpp b/engines/ags/engine/gui/mylabel.cpp
index f8f4db6f65..f69c6ad595 100644
--- a/engines/ags/engine/gui/mylabel.cpp
+++ b/engines/ags/engine/gui/mylabel.cpp
@@ -33,8 +33,6 @@ namespace AGS3 {
 
 using namespace Shared;
 
-extern GameSetup usetup;
-
 extern int acdialog_font;
 
 MyLabel::MyLabel(int xx, int yy, int wii, const char *tee) {
diff --git a/engines/ags/engine/gui/mylistbox.cpp b/engines/ags/engine/gui/mylistbox.cpp
index a4e5d08ec7..edf4f1f314 100644
--- a/engines/ags/engine/gui/mylistbox.cpp
+++ b/engines/ags/engine/gui/mylistbox.cpp
@@ -35,7 +35,6 @@ namespace AGS3 {
 
 using AGS::Shared::Bitmap;
 
-extern GameSetup usetup;
 extern int windowbackgroundcolor;
 extern int cbuttfont;
 extern int smcode;
diff --git a/engines/ags/engine/gui/mytextbox.cpp b/engines/ags/engine/gui/mytextbox.cpp
index 48507fb7de..9207b2c0f9 100644
--- a/engines/ags/engine/gui/mytextbox.cpp
+++ b/engines/ags/engine/gui/mytextbox.cpp
@@ -20,19 +20,17 @@
  *
  */
 
-//include <string.h>
 #include "ags/shared/util/wgt2allg.h"
 #include "ags/shared/font/fonts.h"
 #include "ags/engine/gui/mytextbox.h"
 #include "ags/engine/gui/guidialoginternaldefs.h"
 #include "ags/shared/gfx/bitmap.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
 using AGS::Shared::Bitmap;
 
-extern GameSetup usetup;
-
 extern int windowbackgroundcolor;
 extern int cbuttfont;
 
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index b218a26956..f40bd26e28 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -51,8 +51,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-extern GameSetup usetup;
-
 // Filename of the default config file, the one found in the game installation
 const String DefaultConfigFileName = "acsetup.cfg";
 
@@ -201,13 +199,13 @@ void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, Game
 		// For the windowed we define mode by the scaled game.
 		scsz_setup.SizeDef = kScreenDef_ByGameScaling;
 		scsz_setup.MatchDeviceRatio = false;
-		frame_setup = usetup.Screen.WinGameFrame;
+		frame_setup = _GP(usetup).Screen.WinGameFrame;
 	} else {
 		// For the fullscreen we set current desktop resolution, which
 		// corresponds to most comfortable fullscreen mode for the driver.
 		scsz_setup.SizeDef = kScreenDef_MaxDisplay;
 		scsz_setup.MatchDeviceRatio = true;
-		frame_setup = usetup.Screen.FsGameFrame;
+		frame_setup = _GP(usetup).Screen.FsGameFrame;
 	}
 }
 
@@ -237,47 +235,47 @@ String find_user_cfg_file() {
 
 void config_defaults() {
 #if AGS_PLATFORM_OS_WINDOWS
-	usetup.Screen.DriverID = "D3D9";
+	_GP(usetup).Screen.DriverID = "D3D9";
 #else
-	usetup.Screen.DriverID = "ScummVM";
+	_GP(usetup).Screen.DriverID = "ScummVM";
 #endif
-	usetup.audio_backend = 1;
-	usetup.translation = "";
+	_GP(usetup).audio_backend = 1;
+	_GP(usetup).translation = "";
 }
 
 void read_game_data_location(const ConfigTree &cfg) {
-	usetup.data_files_dir = INIreadstring(cfg, "misc", "datadir", usetup.data_files_dir);
-	if (!usetup.data_files_dir.IsEmpty()) {
+	_GP(usetup).data_files_dir = INIreadstring(cfg, "misc", "datadir", _GP(usetup).data_files_dir);
+	if (!_GP(usetup).data_files_dir.IsEmpty()) {
 		// strip any trailing slash
 		// TODO: move this to Path namespace later
-		AGS::Shared::Path::FixupPath(usetup.data_files_dir);
+		AGS::Shared::Path::FixupPath(_GP(usetup).data_files_dir);
 #if AGS_PLATFORM_OS_WINDOWS
 		// if the path is just x:\ don't strip the slash
-		if (!(usetup.data_files_dir.GetLength() == 3 && usetup.data_files_dir[1u] == ':')) {
-			usetup.data_files_dir.TrimRight('/');
+		if (!(_GP(usetup).data_files_dir.GetLength() == 3 && _GP(usetup).data_files_dir[1u] == ':')) {
+			_GP(usetup).data_files_dir.TrimRight('/');
 		}
 #else
-		usetup.data_files_dir.TrimRight('/');
+		_GP(usetup).data_files_dir.TrimRight('/');
 #endif
 	}
-	usetup.main_data_filename = INIreadstring(cfg, "misc", "datafile", usetup.main_data_filename);
+	_GP(usetup).main_data_filename = INIreadstring(cfg, "misc", "datafile", _GP(usetup).main_data_filename);
 }
 
 void read_legacy_graphics_config(const ConfigTree &cfg) {
-	usetup.Screen.DisplayMode.Windowed = INIreadint(cfg, "misc", "windowed") > 0;
-	usetup.Screen.DriverID = INIreadstring(cfg, "misc", "gfxdriver", usetup.Screen.DriverID);
+	_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "misc", "windowed") > 0;
+	_GP(usetup).Screen.DriverID = INIreadstring(cfg, "misc", "gfxdriver", _GP(usetup).Screen.DriverID);
 
 	{
 		String legacy_filter = INIreadstring(cfg, "misc", "gfxfilter");
 		if (!legacy_filter.IsEmpty()) {
 			// NOTE: legacy scaling config is applied only to windowed setting
-			if (usetup.Screen.DisplayMode.Windowed)
-				usetup.Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
-			parse_legacy_frame_config(legacy_filter, usetup.Screen.Filter.ID, usetup.Screen.WinGameFrame);
+			if (_GP(usetup).Screen.DisplayMode.Windowed)
+				_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
+			parse_legacy_frame_config(legacy_filter, _GP(usetup).Screen.Filter.ID, _GP(usetup).Screen.WinGameFrame);
 
 			// AGS 3.2.1 and 3.3.0 aspect ratio preferences
-			if (!usetup.Screen.DisplayMode.Windowed) {
-				usetup.Screen.DisplayMode.ScreenSize.MatchDeviceRatio =
+			if (!_GP(usetup).Screen.DisplayMode.Windowed) {
+				_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio =
 					(INIreadint(cfg, "misc", "sideborders") > 0 || INIreadint(cfg, "misc", "forceletterbox") > 0 ||
 						INIreadint(cfg, "misc", "prefer_sideborders") > 0 || INIreadint(cfg, "misc", "prefer_letterbox") > 0);
 			}
@@ -288,12 +286,12 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 		if (!uniform_frame_scale.IsEmpty()) {
 			GameFrameSetup frame_setup;
 			parse_scaling_option(uniform_frame_scale, frame_setup);
-			usetup.Screen.FsGameFrame = frame_setup;
-			usetup.Screen.WinGameFrame = frame_setup;
+			_GP(usetup).Screen.FsGameFrame = frame_setup;
+			_GP(usetup).Screen.WinGameFrame = frame_setup;
 		}
 	}
 
-	usetup.Screen.DisplayMode.RefreshRate = INIreadint(cfg, "misc", "refresh");
+	_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "misc", "refresh");
 }
 
 void override_config_ext(ConfigTree &cfg) {
@@ -339,97 +337,97 @@ void override_config_ext(ConfigTree &cfg) {
 
 void apply_config(const ConfigTree &cfg) {
 	{
-		usetup.audio_backend = INIreadint(cfg, "sound", "enabled", usetup.audio_backend);
+		_GP(usetup).audio_backend = INIreadint(cfg, "sound", "enabled", _GP(usetup).audio_backend);
 
 		// Legacy graphics settings has to be translated into new options;
 		// they must be read first, to let newer options override them, if ones are present
 		read_legacy_graphics_config(cfg);
 
 		// Graphics mode
-		usetup.Screen.DriverID = INIreadstring(cfg, "graphics", "driver", usetup.Screen.DriverID);
+		_GP(usetup).Screen.DriverID = INIreadstring(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
 
-		usetup.Screen.DisplayMode.Windowed = INIreadint(cfg, "graphics", "windowed") > 0;
+		_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "graphics", "windowed") > 0;
 		const char *screen_sz_def_options[kNumScreenDef] = { "explicit", "scaling", "max" };
-		usetup.Screen.DisplayMode.ScreenSize.SizeDef = usetup.Screen.DisplayMode.Windowed ? kScreenDef_ByGameScaling : kScreenDef_MaxDisplay;
+		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = _GP(usetup).Screen.DisplayMode.Windowed ? kScreenDef_ByGameScaling : kScreenDef_MaxDisplay;
 		String screen_sz_def_str = INIreadstring(cfg, "graphics", "screen_def");
 		for (int i = 0; i < kNumScreenDef; ++i) {
 			if (screen_sz_def_str.CompareNoCase(screen_sz_def_options[i]) == 0) {
-				usetup.Screen.DisplayMode.ScreenSize.SizeDef = (ScreenSizeDefinition)i;
+				_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = (ScreenSizeDefinition)i;
 				break;
 			}
 		}
 
-		usetup.Screen.DisplayMode.ScreenSize.Size = Size(INIreadint(cfg, "graphics", "screen_width"),
+		_GP(usetup).Screen.DisplayMode.ScreenSize.Size = Size(INIreadint(cfg, "graphics", "screen_width"),
 			INIreadint(cfg, "graphics", "screen_height"));
-		usetup.Screen.DisplayMode.ScreenSize.MatchDeviceRatio = INIreadint(cfg, "graphics", "match_device_ratio", 1) != 0;
+		_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio = INIreadint(cfg, "graphics", "match_device_ratio", 1) != 0;
 		// TODO: move to config overrides (replace values during config load)
 #if AGS_PLATFORM_OS_MACOS
-		usetup.Screen.Filter.ID = "none";
+		_GP(usetup).Screen.Filter.ID = "none";
 #else
-		usetup.Screen.Filter.ID = INIreadstring(cfg, "graphics", "filter", "StdScale");
-		parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs", "proportional"), usetup.Screen.FsGameFrame);
-		parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win", "max_round"), usetup.Screen.WinGameFrame);
+		_GP(usetup).Screen.Filter.ID = INIreadstring(cfg, "graphics", "filter", "StdScale");
+		parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs", "proportional"), _GP(usetup).Screen.FsGameFrame);
+		parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win", "max_round"), _GP(usetup).Screen.WinGameFrame);
 #endif
 
-		usetup.Screen.DisplayMode.RefreshRate = INIreadint(cfg, "graphics", "refresh");
-		usetup.Screen.DisplayMode.VSync = INIreadint(cfg, "graphics", "vsync") > 0;
-		usetup.RenderAtScreenRes = INIreadint(cfg, "graphics", "render_at_screenres") > 0;
-		usetup.Supersampling = INIreadint(cfg, "graphics", "supersampling", 1);
+		_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "graphics", "refresh");
+		_GP(usetup).Screen.DisplayMode.VSync = INIreadint(cfg, "graphics", "vsync") > 0;
+		_GP(usetup).RenderAtScreenRes = INIreadint(cfg, "graphics", "render_at_screenres") > 0;
+		_GP(usetup).Supersampling = INIreadint(cfg, "graphics", "supersampling", 1);
 
-		usetup.enable_antialiasing = INIreadint(cfg, "misc", "antialias") > 0;
+		_GP(usetup).enable_antialiasing = INIreadint(cfg, "misc", "antialias") > 0;
 
 		// This option is backwards (usevox is 0 if no_speech_pack)
-		usetup.no_speech_pack = INIreadint(cfg, "sound", "usespeech", 1) == 0;
+		_GP(usetup).no_speech_pack = INIreadint(cfg, "sound", "usespeech", 1) == 0;
 
-		usetup.user_data_dir = INIreadstring(cfg, "misc", "user_data_dir");
-		usetup.shared_data_dir = INIreadstring(cfg, "misc", "shared_data_dir");
+		_GP(usetup).user_data_dir = INIreadstring(cfg, "misc", "user_data_dir");
+		_GP(usetup).shared_data_dir = INIreadstring(cfg, "misc", "shared_data_dir");
 
 		Common::String translation;
 		if (ConfMan.getActiveDomain()->tryGetVal("translation", translation) && !translation.empty())
-			usetup.translation = translation;
+			_GP(usetup).translation = translation;
 		else
-			usetup.translation = INIreadstring(cfg, "language", "translation");
+			_GP(usetup).translation = INIreadstring(cfg, "language", "translation");
 
 		int cache_size_kb = INIreadint(cfg, "misc", "cachemax", DEFAULTCACHESIZE_KB);
 		if (cache_size_kb > 0)
 			_GP(spriteset).SetMaxCacheSize((size_t)cache_size_kb * 1024);
 
-		usetup.mouse_auto_lock = INIreadint(cfg, "mouse", "auto_lock") > 0;
+		_GP(usetup).mouse_auto_lock = INIreadint(cfg, "mouse", "auto_lock") > 0;
 
-		usetup.mouse_speed = INIreadfloat(cfg, "mouse", "speed", 1.f);
-		if (usetup.mouse_speed <= 0.f)
-			usetup.mouse_speed = 1.f;
+		_GP(usetup).mouse_speed = INIreadfloat(cfg, "mouse", "speed", 1.f);
+		if (_GP(usetup).mouse_speed <= 0.f)
+			_GP(usetup).mouse_speed = 1.f;
 		const char *mouse_ctrl_options[kNumMouseCtrlOptions] = { "never", "fullscreen", "always" };
 		String mouse_str = INIreadstring(cfg, "mouse", "control_when", "fullscreen");
 		for (int i = 0; i < kNumMouseCtrlOptions; ++i) {
 			if (mouse_str.CompareNoCase(mouse_ctrl_options[i]) == 0) {
-				usetup.mouse_ctrl_when = (MouseControlWhen)i;
+				_GP(usetup).mouse_ctrl_when = (MouseControlWhen)i;
 				break;
 			}
 		}
-		usetup.mouse_ctrl_enabled = INIreadint(cfg, "mouse", "control_enabled", 1) > 0;
+		_GP(usetup).mouse_ctrl_enabled = INIreadint(cfg, "mouse", "control_enabled", 1) > 0;
 		const char *mouse_speed_options[kNumMouseSpeedDefs] = { "absolute", "current_display" };
 		mouse_str = INIreadstring(cfg, "mouse", "speed_def", "current_display");
 		for (int i = 0; i < kNumMouseSpeedDefs; ++i) {
 			if (mouse_str.CompareNoCase(mouse_speed_options[i]) == 0) {
-				usetup.mouse_speed_def = (MouseSpeedDef)i;
+				_GP(usetup).mouse_speed_def = (MouseSpeedDef)i;
 				break;
 			}
 		}
 
-		usetup.override_multitasking = INIreadint(cfg, "override", "multitasking", -1);
+		_GP(usetup).override_multitasking = INIreadint(cfg, "override", "multitasking", -1);
 		String override_os = INIreadstring(cfg, "override", "os");
-		usetup.override_script_os = -1;
+		_GP(usetup).override_script_os = -1;
 		if (override_os.CompareNoCase("dos") == 0) {
-			usetup.override_script_os = eOS_DOS;
+			_GP(usetup).override_script_os = eOS_DOS;
 		} else if (override_os.CompareNoCase("win") == 0) {
-			usetup.override_script_os = eOS_Win;
+			_GP(usetup).override_script_os = eOS_Win;
 		} else if (override_os.CompareNoCase("linux") == 0) {
-			usetup.override_script_os = eOS_Linux;
+			_GP(usetup).override_script_os = eOS_Linux;
 		} else if (override_os.CompareNoCase("mac") == 0) {
-			usetup.override_script_os = eOS_Mac;
+			_GP(usetup).override_script_os = eOS_Mac;
 		}
-		usetup.override_upscale = INIreadint(cfg, "override", "upscale") > 0;
+		_GP(usetup).override_upscale = INIreadint(cfg, "override", "upscale") > 0;
 	}
 
 	// Apply logging configuration
@@ -437,26 +435,26 @@ void apply_config(const ConfigTree &cfg) {
 }
 
 void post_config() {
-	if (usetup.Screen.DriverID.IsEmpty() || usetup.Screen.DriverID.CompareNoCase("DX5") == 0)
-		usetup.Screen.DriverID = "Software";
+	if (_GP(usetup).Screen.DriverID.IsEmpty() || _GP(usetup).Screen.DriverID.CompareNoCase("DX5") == 0)
+		_GP(usetup).Screen.DriverID = "Software";
 
 	// FIXME: this correction is needed at the moment because graphics driver
 	// implementation requires some filter to be created anyway
-	usetup.Screen.Filter.UserRequest = usetup.Screen.Filter.ID;
-	if (usetup.Screen.Filter.ID.IsEmpty() || usetup.Screen.Filter.ID.CompareNoCase("none") == 0) {
-		usetup.Screen.Filter.ID = "StdScale";
+	_GP(usetup).Screen.Filter.UserRequest = _GP(usetup).Screen.Filter.ID;
+	if (_GP(usetup).Screen.Filter.ID.IsEmpty() || _GP(usetup).Screen.Filter.ID.CompareNoCase("none") == 0) {
+		_GP(usetup).Screen.Filter.ID = "StdScale";
 	}
 
-	if (!usetup.Screen.FsGameFrame.IsValid())
-		usetup.Screen.FsGameFrame = GameFrameSetup(kFrame_MaxProportional);
-	if (!usetup.Screen.WinGameFrame.IsValid())
-		usetup.Screen.WinGameFrame = GameFrameSetup(kFrame_MaxRound);
+	if (!_GP(usetup).Screen.FsGameFrame.IsValid())
+		_GP(usetup).Screen.FsGameFrame = GameFrameSetup(kFrame_MaxProportional);
+	if (!_GP(usetup).Screen.WinGameFrame.IsValid())
+		_GP(usetup).Screen.WinGameFrame = GameFrameSetup(kFrame_MaxRound);
 
 	// TODO: helper functions to remove slash in paths (or distinct path type)
-	if (usetup.user_data_dir.GetLast() == '/' || usetup.user_data_dir.GetLast() == '\\')
-		usetup.user_data_dir.ClipRight(1);
-	if (usetup.shared_data_dir.GetLast() == '/' || usetup.shared_data_dir.GetLast() == '\\')
-		usetup.shared_data_dir.ClipRight(1);
+	if (_GP(usetup).user_data_dir.GetLast() == '/' || _GP(usetup).user_data_dir.GetLast() == '\\')
+		_GP(usetup).user_data_dir.ClipRight(1);
+	if (_GP(usetup).shared_data_dir.GetLast() == '/' || _GP(usetup).shared_data_dir.GetLast() == '\\')
+		_GP(usetup).shared_data_dir.ClipRight(1);
 }
 
 void save_config_file() {
@@ -478,7 +476,7 @@ void save_config_file() {
 		// in each modes (by explicit width/height values or from game scaling).
 		// This specifically *must* be done if there will be script API for modifying fullscreen
 		// resolution, or size of the window could be changed any way at runtime.
-		if (is_windowed != usetup.Screen.DisplayMode.Windowed) {
+		if (is_windowed != _GP(usetup).Screen.DisplayMode.Windowed) {
 			if (is_windowed)
 				cfg["graphics"]["screen_def"] = "scaling";
 			else
@@ -488,16 +486,16 @@ void save_config_file() {
 
 	// Other game options that could be changed at runtime
 	if (_GP(game).options[OPT_RENDERATSCREENRES] == kRenderAtScreenRes_UserDefined)
-		cfg["graphics"]["render_at_screenres"] = String::FromFormat("%d", usetup.RenderAtScreenRes ? 1 : 0);
-	cfg["mouse"]["control_enabled"] = String::FromFormat("%d", usetup.mouse_ctrl_enabled ? 1 : 0);
+		cfg["graphics"]["render_at_screenres"] = String::FromFormat("%d", _GP(usetup).RenderAtScreenRes ? 1 : 0);
+	cfg["mouse"]["control_enabled"] = String::FromFormat("%d", _GP(usetup).mouse_ctrl_enabled ? 1 : 0);
 	cfg["mouse"]["speed"] = String::FromFormat("%f", Mouse::GetSpeed());
-	cfg["language"]["translation"] = usetup.translation;
+	cfg["language"]["translation"] = _GP(usetup).translation;
 
-	if (usetup.translation.empty()) {
+	if (_GP(usetup).translation.empty()) {
 		if (ConfMan.getActiveDomain()->contains("translation"))
 			ConfMan.getActiveDomain()->erase("translation");
 	} else
-		ConfMan.getActiveDomain()->setVal("translation", usetup.translation);
+		ConfMan.getActiveDomain()->setVal("translation", _GP(usetup).translation);
 	
 	ConfMan.flushToDisk();
 
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 69863c8a91..0d047e9290 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -85,12 +85,9 @@ using namespace AGS::Engine;
 
 extern char check_dynamic_sprites_at_exit;
 extern int our_eip;
-extern GameSetup usetup;
 extern int proper_exit;
 extern char pexbuf[STD_BUFFER_SIZE];
 
-
-
 extern int displayed_room;
 extern int eip_guinum;
 extern int eip_guiobj;
@@ -187,11 +184,11 @@ void engine_force_window() {
 	// Force to run in a window, override the config file
 	// TODO: actually overwrite config tree instead
 	if (_G(force_window) == 1) {
-		usetup.Screen.DisplayMode.Windowed = true;
-		usetup.Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
+		_GP(usetup).Screen.DisplayMode.Windowed = true;
+		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
 	} else if (_G(force_window) == 2) {
-		usetup.Screen.DisplayMode.Windowed = false;
-		usetup.Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_MaxDisplay;
+		_GP(usetup).Screen.DisplayMode.Windowed = false;
+		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_MaxDisplay;
 	}
 }
 
@@ -249,8 +246,8 @@ bool search_for_game_data_file(String &filename, String &search_path) {
 		}
 	}
 	// 2.2. Search in the provided data dir
-	else if (!usetup.data_files_dir.IsEmpty()) {
-		search_path = usetup.data_files_dir;
+	else if (!_GP(usetup).data_files_dir.IsEmpty()) {
+		search_path = _GP(usetup).data_files_dir;
 		filename = find_game_data_in_directory(search_path);
 	}
 	// 3. Look in known locations
@@ -308,13 +305,13 @@ 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(usetup.mouse_speed);
+	Mouse::SetSpeed(_GP(usetup).mouse_speed);
 }
 
 void engine_locate_speech_pak() {
 	_GP(play).want_speech = -2;
 
-	if (!usetup.no_speech_pack) {
+	if (!_GP(usetup).no_speech_pack) {
 		String speech_file = "speech.vox";
 		String speech_filepath = find_assetlib(speech_file);
 		if (!speech_filepath.IsEmpty()) {
@@ -395,14 +392,14 @@ void engine_init_timer() {
 
 void engine_init_audio() {
 #if !AGS_PLATFORM_SCUMMVM
-	if (usetup.audio_backend != 0) {
+	if (_GP(usetup).audio_backend != 0) {
 		Debug::Printf("Initializing audio");
 		audio_core_init(); // audio core system
 	}
 #endif
 	our_eip = -181;
 
-	if (usetup.audio_backend == 0) {
+	if (_GP(usetup).audio_backend == 0) {
 		// all audio is disabled
 		// and the voice mode should not go to Voice Only
 		_GP(play).want_speech = -2;
@@ -488,24 +485,24 @@ void engine_init_title() {
 }
 
 void engine_init_directories() {
-	Debug::Printf(kDbgMsg_Info, "Data directory: %s", usetup.data_files_dir.GetCStr());
-	if (!usetup.install_dir.IsEmpty())
-		Debug::Printf(kDbgMsg_Info, "Optional install directory: %s", usetup.install_dir.GetCStr());
-	if (!usetup.install_audio_dir.IsEmpty())
-		Debug::Printf(kDbgMsg_Info, "Optional audio directory: %s", usetup.install_audio_dir.GetCStr());
-	if (!usetup.install_voice_dir.IsEmpty())
-		Debug::Printf(kDbgMsg_Info, "Optional voice-over directory: %s", usetup.install_voice_dir.GetCStr());
-	if (!usetup.user_data_dir.IsEmpty())
-		Debug::Printf(kDbgMsg_Info, "User data directory: %s", usetup.user_data_dir.GetCStr());
-	if (!usetup.shared_data_dir.IsEmpty())
-		Debug::Printf(kDbgMsg_Info, "Shared data directory: %s", usetup.shared_data_dir.GetCStr());
-
-	ResPaths.DataDir = usetup.data_files_dir;
-	ResPaths.GamePak.Path = usetup.main_data_filepath;
-	ResPaths.GamePak.Name = Shared::Path::get_filename(usetup.main_data_filepath);
-
-	set_install_dir(usetup.install_dir, usetup.install_audio_dir, usetup.install_voice_dir);
-	if (!usetup.install_dir.IsEmpty()) {
+	Debug::Printf(kDbgMsg_Info, "Data directory: %s", _GP(usetup).data_files_dir.GetCStr());
+	if (!_GP(usetup).install_dir.IsEmpty())
+		Debug::Printf(kDbgMsg_Info, "Optional install directory: %s", _GP(usetup).install_dir.GetCStr());
+	if (!_GP(usetup).install_audio_dir.IsEmpty())
+		Debug::Printf(kDbgMsg_Info, "Optional audio directory: %s", _GP(usetup).install_audio_dir.GetCStr());
+	if (!_GP(usetup).install_voice_dir.IsEmpty())
+		Debug::Printf(kDbgMsg_Info, "Optional voice-over directory: %s", _GP(usetup).install_voice_dir.GetCStr());
+	if (!_GP(usetup).user_data_dir.IsEmpty())
+		Debug::Printf(kDbgMsg_Info, "User data directory: %s", _GP(usetup).user_data_dir.GetCStr());
+	if (!_GP(usetup).shared_data_dir.IsEmpty())
+		Debug::Printf(kDbgMsg_Info, "Shared data directory: %s", _GP(usetup).shared_data_dir.GetCStr());
+
+	ResPaths.DataDir = _GP(usetup).data_files_dir;
+	ResPaths.GamePak.Path = _GP(usetup).main_data_filepath;
+	ResPaths.GamePak.Name = Shared::Path::get_filename(_GP(usetup).main_data_filepath);
+
+	set_install_dir(_GP(usetup).install_dir, _GP(usetup).install_audio_dir, _GP(usetup).install_voice_dir);
+	if (!_GP(usetup).install_dir.IsEmpty()) {
 		// running in debugger: don't redirect to the game exe folder (_Debug)
 		// TODO: find out why we need to do this (and do we?)
 		ResPaths.DataDir = ".";
@@ -513,8 +510,8 @@ void engine_init_directories() {
 
 	// if end-user specified custom save path, use it
 	bool res = false;
-	if (!usetup.user_data_dir.IsEmpty()) {
-		res = SetCustomSaveParent(usetup.user_data_dir);
+	if (!_GP(usetup).user_data_dir.IsEmpty()) {
+		res = SetCustomSaveParent(_GP(usetup).user_data_dir);
 		if (!res) {
 			Debug::Printf(kDbgMsg_Warn, "WARNING: custom user save path failed, using default system paths");
 			res = false;
@@ -882,8 +879,8 @@ void engine_init_game_settings() {
 	for (ee = 0; ee < MAXGLOBALSTRINGS; ee++)
 		_GP(play).globalstrings[ee][0] = 0;
 
-	if (!usetup.translation.IsEmpty())
-		init_translation(usetup.translation, "", true);
+	if (!_GP(usetup).translation.IsEmpty())
+		init_translation(_GP(usetup).translation, "", true);
 
 	update_invorder();
 	displayed_room = -10;
@@ -894,16 +891,16 @@ void engine_init_game_settings() {
 
 	// We use same variable to read config and be used at runtime for now,
 	// so update it here with regards to game design option
-	usetup.RenderAtScreenRes =
-	    (_GP(game).options[OPT_RENDERATSCREENRES] == kRenderAtScreenRes_UserDefined && usetup.RenderAtScreenRes) ||
+	_GP(usetup).RenderAtScreenRes =
+	    (_GP(game).options[OPT_RENDERATSCREENRES] == kRenderAtScreenRes_UserDefined && _GP(usetup).RenderAtScreenRes) ||
 	    _GP(game).options[OPT_RENDERATSCREENRES] == kRenderAtScreenRes_Enabled;
 }
 
 void engine_setup_scsystem_auxiliary() {
 	// ScriptSystem::aci_version is only 10 chars long
 	strncpy(_GP(scsystem).aci_version, _G(EngineVersion).LongString, 10);
-	if (usetup.override_script_os >= 0) {
-		_GP(scsystem).os = usetup.override_script_os;
+	if (_GP(usetup).override_script_os >= 0) {
+		_GP(scsystem).os = _GP(usetup).override_script_os;
 	} else {
 		_GP(scsystem).os = platform->GetSystemOSID();
 	}
@@ -951,7 +948,7 @@ HError define_gamedata_location_checkall(const String &exe_path) {
 		Directory::SetCurrentDirectory(Path::GetDirectoryPath(_G(cmdGameDataPath)));
 		// If it's a file, then keep it and proceed
 		if (Path::IsFile(_G(cmdGameDataPath))) {
-			usetup.main_data_filepath = _G(cmdGameDataPath);
+			_GP(usetup).main_data_filepath = _G(cmdGameDataPath);
 			return HError::None();
 		}
 	}
@@ -961,14 +958,14 @@ HError define_gamedata_location_checkall(const String &exe_path) {
 	String def_cfg_file = find_default_cfg_file(exe_path);
 	IniUtil::Read(def_cfg_file, cfg);
 	read_game_data_location(cfg);
-	if (!usetup.main_data_filename.IsEmpty())
+	if (!_GP(usetup).main_data_filename.IsEmpty())
 		return HError::None();
 
 #if defined (AGS_SEARCH_FOR_GAME_ON_LAUNCH)
 	// No direct filepath provided, search in common locations.
 	String path, search_path;
 	if (search_for_game_data_file(path, search_path)) {
-		usetup.main_data_filepath = path;
+		_GP(usetup).main_data_filepath = path;
 		return HError::None();
 	}
 	return new Error("Engine was not able to find any compatible game data.",
@@ -989,16 +986,16 @@ bool define_gamedata_location(const String &exe_path) {
 
 	// On success: set all the necessary path and filename settings,
 	// derive missing ones from available.
-	if (usetup.main_data_filename.IsEmpty()) {
-		usetup.main_data_filename = Shared::Path::get_filename(usetup.main_data_filepath);
-	} else if (usetup.main_data_filepath.IsEmpty()) {
-		if (usetup.data_files_dir.IsEmpty() || !is_relative_filename(usetup.main_data_filename))
-			usetup.main_data_filepath = usetup.main_data_filename;
+	if (_GP(usetup).main_data_filename.IsEmpty()) {
+		_GP(usetup).main_data_filename = Shared::Path::get_filename(_GP(usetup).main_data_filepath);
+	} else if (_GP(usetup).main_data_filepath.IsEmpty()) {
+		if (_GP(usetup).data_files_dir.IsEmpty() || !is_relative_filename(_GP(usetup).main_data_filename))
+			_GP(usetup).main_data_filepath = _GP(usetup).main_data_filename;
 		else
-			usetup.main_data_filepath = Path::ConcatPaths(usetup.data_files_dir, usetup.main_data_filename);
+			_GP(usetup).main_data_filepath = Path::ConcatPaths(_GP(usetup).data_files_dir, _GP(usetup).main_data_filename);
 	}
-	if (usetup.data_files_dir.IsEmpty())
-		usetup.data_files_dir = Path::GetDirectoryPath(usetup.main_data_filepath);
+	if (_GP(usetup).data_files_dir.IsEmpty())
+		_GP(usetup).data_files_dir = Path::GetDirectoryPath(_GP(usetup).main_data_filepath);
 	return true;
 }
 
@@ -1007,7 +1004,7 @@ bool engine_init_gamedata(const String &exe_path) {
 	Debug::Printf(kDbgMsg_Info, "Initializing game data");
 	if (!define_gamedata_location(exe_path))
 		return false;
-	if (!engine_try_init_gamedata(usetup.main_data_filepath))
+	if (!engine_try_init_gamedata(_GP(usetup).main_data_filepath))
 		return false;
 
 	// Pre-load game name and savegame folder names from data file
@@ -1125,7 +1122,7 @@ static void engine_print_info(const std::set<String> &keys, const String &exe_pa
 		data["data"]["gamename"] = _GP(game).gamename;
 		data["data"]["version"] = String::FromFormat("%d", loaded_game_file_version);
 		data["data"]["compiledwith"] = _GP(game).compiled_with;
-		data["data"]["basepack"] = usetup.main_data_filepath;
+		data["data"]["basepack"] = _GP(usetup).main_data_filepath;
 	}
 	String full;
 	IniUtil::WriteToString(full, data);
@@ -1271,7 +1268,7 @@ int initialize_engine(const ConfigTree &startup_opts) {
 	engine_init_resolution_settings(_GP(game).GetGameRes());
 
 	// Attempt to initialize graphics mode
-	if (!engine_try_set_gfxmode_any(usetup.Screen))
+	if (!engine_try_set_gfxmode_any(_GP(usetup).Screen))
 		return EXIT_ERROR;
 
 	SetMultitasking(0);
@@ -1332,7 +1329,7 @@ bool engine_try_switch_windowed_gfxmode() {
 		res = graphics_mode_set_dm(last_opposite_mode);
 	} else {
 		// we need to clone from initial config, because not every parameter is set by graphics_mode_get_defaults()
-		DisplayModeSetup dm_setup = usetup.Screen.DisplayMode;
+		DisplayModeSetup dm_setup = _GP(usetup).Screen.DisplayMode;
 		dm_setup.Windowed = !old_dm.Windowed;
 		graphics_mode_get_defaults(dm_setup.Windowed, dm_setup.ScreenSize, use_frame_setup);
 		res = graphics_mode_set_dm_any(_GP(game).GetGameRes(), dm_setup, old_dm.ColorDepth, use_frame_setup);
diff --git a/engines/ags/engine/main/engine_setup.cpp b/engines/ags/engine/main/engine_setup.cpp
index 46c03e0768..a89ef86665 100644
--- a/engines/ags/engine/main/engine_setup.cpp
+++ b/engines/ags/engine/main/engine_setup.cpp
@@ -131,7 +131,7 @@ void engine_setup_system_gamesize() {
 
 void engine_init_resolution_settings(const Size game_size) {
 	Debug::Printf("Initializing resolution settings");
-	usetup.textheight = getfontheight_outlined(0) + 1;
+	_GP(usetup).textheight = getfontheight_outlined(0) + 1;
 
 	Debug::Printf(kDbgMsg_Info, "Game native resolution: %d x %d (%d bit)%s", game_size.Width, game_size.Height, _GP(game).color_depth * 8,
 		_GP(game).IsLegacyLetterbox() ? " letterbox-by-design" : "");
@@ -267,21 +267,21 @@ 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);
-	if (usetup.mouse_speed_def == kMouseSpeed_CurrentDisplay) {
+	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,
 			(float)cur_desktop.Height / (float)init_desktop.Height));
 	}
 
-	Mouse_EnableControl(usetup.mouse_ctrl_enabled);
+	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());
 
 	on_coordinates_scaling_changed();
 
 	// If auto lock option is set, lock mouse to the game window
-	if (usetup.mouse_auto_lock && _GP(scsystem).windowed != 0)
+	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed != 0)
 		Mouse::TryLockToWindow();
 }
 
diff --git a/engines/ags/engine/main/game_run.cpp b/engines/ags/engine/main/game_run.cpp
index 7cf0d0cc33..a664d60615 100644
--- a/engines/ags/engine/main/game_run.cpp
+++ b/engines/ags/engine/main/game_run.cpp
@@ -203,7 +203,7 @@ static int game_loop_check_ground_level_interactions() {
 }
 
 static void lock_mouse_on_click() {
-	if (usetup.mouse_auto_lock && _GP(scsystem).windowed)
+	if (_GP(usetup).mouse_auto_lock && _GP(scsystem).windowed)
 		Mouse::TryLockToWindow();
 }
 
diff --git a/engines/ags/engine/main/quit.cpp b/engines/ags/engine/main/quit.cpp
index f7972a68e6..2caa7a833c 100644
--- a/engines/ags/engine/main/quit.cpp
+++ b/engines/ags/engine/main/quit.cpp
@@ -54,12 +54,7 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-
-
-
-    // used for non-saveable rooms, eg. intro
 extern int our_eip;
-extern GameSetup usetup;
 extern char pexbuf[STD_BUFFER_SIZE];
 extern int proper_exit;
 extern char check_dynamic_sprites_at_exit;
diff --git a/engines/ags/engine/media/audio/audio.cpp b/engines/ags/engine/media/audio/audio.cpp
index 45fedaecc9..c915e16681 100644
--- a/engines/ags/engine/media/audio/audio.cpp
+++ b/engines/ags/engine/media/audio/audio.cpp
@@ -102,8 +102,6 @@ void set_clip_to_channel(int chanid, SOUNDCLIP *clip) {
 
 volatile bool _audio_doing_crossfade;
 
-extern GameSetup usetup;
-
 extern CharacterInfo *playerchar;
 
 extern volatile int switching_away_from_game;
@@ -209,7 +207,7 @@ static int find_free_audio_channel(ScriptAudioClip *clip, int priority, bool int
 }
 
 bool is_audiotype_allowed_to_play(AudioFileType type) {
-	return usetup.audio_backend != 0;
+	return _GP(usetup).audio_backend != 0;
 }
 
 SOUNDCLIP *load_sound_clip(ScriptAudioClip *audioClip, bool repeat) {
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index feaf0e458b..1d5ce97192 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -36,6 +36,7 @@
 #include "ags/shared/gui/guitextbox.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
+#include "ags/engine/ac/gamesetup.h"
 #include "ags/engine/ac/gamestate.h"
 #include "ags/engine/ac/movelist.h"
 #include "ags/engine/ac/objectcache.h"
@@ -119,6 +120,7 @@ Globals::Globals() {
 	_spriteset = new SpriteCache(_game->SpriteInfos);
 	_thisroom = new AGS::Shared::RoomStruct();
 	_troom = new RoomStatus();
+	_usetup = new GameSetup();
 	_scrObj = new ScriptObject[MAX_ROOM_OBJECTS];
 	_scrHotspot = new ScriptHotspot[MAX_ROOM_HOTSPOTS];
 	_scrRegion = new ScriptRegion[MAX_ROOM_REGIONS];
@@ -231,6 +233,7 @@ Globals::~Globals() {
 	delete _spriteset;
 	delete _thisroom;
 	delete _troom;
+	delete _usetup;
 	delete[] _scrObj;
 	delete[] _scrHotspot;
 	delete[] _scrRegion;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index ae543bd1ad..eaac6713f8 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -75,6 +75,7 @@ struct CCRegion;
 struct CharacterCache;
 struct DirtyRects;
 struct ExecutingScript;
+struct GameSetup;
 struct GameSetupStruct;
 struct GameState;
 struct IAGSEditorDebugger;
@@ -246,6 +247,7 @@ public:
 	CharacterCache *_charcache = nullptr;
 	ObjectCache *_objcache;
 	MoveList *_mls = nullptr;
+	GameSetup *_usetup;
 
 	 /**@}*/
 
diff --git a/engines/ags/plugins/agsplugin.cpp b/engines/ags/plugins/agsplugin.cpp
index 2becd2404a..004c8b8c49 100644
--- a/engines/ags/plugins/agsplugin.cpp
+++ b/engines/ags/plugins/agsplugin.cpp
@@ -89,7 +89,6 @@ extern int displayed_room;
 extern RoomStatus *croom;
 
 extern int game_paused;
-extern GameSetup usetup;
 extern color palette[256];
 extern PluginObjectReader pluginReaders[MAX_PLUGIN_OBJECT_READERS];
 extern int numPluginReaders;
@@ -657,7 +656,7 @@ int IAGSEngine::IsSpriteAlphaBlended(int32 slot) {
 // disable AGS's sound engine
 void IAGSEngine::DisableSound() {
 	shutdown_sound();
-	usetup.audio_backend = 0;
+	_GP(usetup).audio_backend = 0;
 }
 int IAGSEngine::CanRunScriptFunctionNow() {
 	if (_G(inside_script))


Commit: 3887515bfc86a8b1df64241f60bc2aba7e9d650d
    https://github.com/scummvm/scummvm/commit/3887515bfc86a8b1df64241f60bc2aba7e9d650d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T21:44:25-08:00

Commit Message:
AGS: Further game.cpp globals to Globals

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


diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 859a51da9c..ae1b8dbabe 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -166,12 +166,6 @@ int proper_exit = 0, our_eip = 0;
 
 //=============================================================================
 
-String saveGameDirectory = SAVE_FOLDER_PREFIX;
-// Custom save game parent directory
-String saveGameParent;
-
-String saveGameSuffix;
-
 int game_paused = 0;
 char pexbuf[STD_BUFFER_SIZE];
 
@@ -309,15 +303,15 @@ void restore_after_dialog() {
 
 
 String get_save_game_directory() {
-	return saveGameDirectory;
+	return _G(saveGameDirectory);
 }
 
 String get_save_game_suffix() {
-	return saveGameSuffix;
+	return _G(saveGameSuffix);
 }
 
 void set_save_game_suffix(const String &suffix) {
-	saveGameSuffix = suffix;
+	_G(saveGameSuffix) = suffix;
 }
 
 String get_save_game_path(int slotNum) {
@@ -327,9 +321,9 @@ String get_save_game_path(int slotNum) {
 #else
 	String filename;
 	filename.Format(sgnametemplate, slotNum);
-	String path = saveGameDirectory;
+	String path = _G(_G(saveGameDirectory));
 	path.Append(filename);
-	path.Append(saveGameSuffix);
+	path.Append(_G(saveGameSuffix));
 	return path;
 #endif
 }
@@ -345,7 +339,7 @@ bool MakeSaveGameDir(const String &newFolder, ResolvedPath &rp) {
 	String newSaveGameDir = FixSlashAfterToken(newFolder);
 
 	if (newSaveGameDir.CompareLeft(UserSavedgamesRootToken, strlen(UserSavedgamesRootToken)) == 0) {
-		if (saveGameParent.IsEmpty()) {
+		if (_G(saveGameParent).IsEmpty()) {
 			base_dir = PathOrCurDir(platform->GetUserSavedgamesDirectory());
 			newSaveGameDir.ReplaceMid(0, strlen(UserSavedgamesRootToken), base_dir);
 		} else {
@@ -354,18 +348,18 @@ bool MakeSaveGameDir(const String &newFolder, ResolvedPath &rp) {
 			newSaveGameDir.ClipSection('/', 0, 1);
 			if (!newSaveGameDir.IsEmpty())
 				newSaveGameDir.PrependChar('/');
-			newSaveGameDir.Prepend(saveGameParent);
-			base_dir = saveGameParent;
+			newSaveGameDir.Prepend(_G(saveGameParent));
+			base_dir = _G(saveGameParent);
 		}
 	} else {
 		// Convert the path relative to installation folder into path relative to the
 		// safe save path with default name
-		if (saveGameParent.IsEmpty()) {
+		if (_G(saveGameParent).IsEmpty()) {
 			base_dir = PathOrCurDir(platform->GetUserSavedgamesDirectory());
 			newSaveGameDir.Format("%s/%s/%s", base_dir.GetCStr(), _GP(game).saveGameFolderName, newFolder.GetCStr());
 		} else {
-			base_dir = saveGameParent;
-			newSaveGameDir.Format("%s/%s", saveGameParent.GetCStr(), newFolder.GetCStr());
+			base_dir = _G(saveGameParent);
+			newSaveGameDir.Format("%s/%s", _G(saveGameParent).GetCStr(), newFolder.GetCStr());
 		}
 		// For games made in the safe-path-aware versions of AGS, report a warning
 		if (_GP(game).options[OPT_SAFEFILEPATHS]) {
@@ -380,7 +374,7 @@ bool MakeSaveGameDir(const String &newFolder, ResolvedPath &rp) {
 
 bool SetCustomSaveParent(const String &path) {
 	if (SetSaveGameDirectoryPath(path, true)) {
-		saveGameParent = path;
+		_G(saveGameParent) = path;
 		return true;
 	}
 	return false;
@@ -413,7 +407,7 @@ bool SetSaveGameDirectoryPath(const char *newFolder, bool explicit_path) {
 		return false;
 
 	// copy the Restart Game file, if applicable
-	String restartGamePath = String::FromFormat("%s""agssave.%d%s", saveGameDirectory.GetCStr(), RESTART_POINT_SAVE_GAME_NUMBER, saveGameSuffix.GetCStr());
+	String restartGamePath = String::FromFormat("%s""agssave.%d%s", _G(_G(saveGameDirectory)).GetCStr(), RESTART_POINT_SAVE_GAME_NUMBER, _G(saveGameSuffix).GetCStr());
 	Stream *restartGameFile = Shared::File::OpenFileRead(restartGamePath);
 	if (restartGameFile != nullptr) {
 		long fileSize = restartGameFile->GetLength();
@@ -421,14 +415,14 @@ bool SetSaveGameDirectoryPath(const char *newFolder, bool explicit_path) {
 		restartGameFile->Read(mbuffer, fileSize);
 		delete restartGameFile;
 
-		restartGamePath.Format("%s""agssave.%d%s", newSaveGameDir.GetCStr(), RESTART_POINT_SAVE_GAME_NUMBER, saveGameSuffix.GetCStr());
+		restartGamePath.Format("%s""agssave.%d%s", newSaveGameDir.GetCStr(), RESTART_POINT_SAVE_GAME_NUMBER, _G(saveGameSuffix).GetCStr());
 		restartGameFile = Shared::File::CreateFile(restartGamePath);
 		restartGameFile->Write(mbuffer, fileSize);
 		delete restartGameFile;
 		free(mbuffer);
 	}
 
-	saveGameDirectory = newSaveGameDir;
+	_G(_G(saveGameDirectory)) = newSaveGameDir;
 	return true;
 #endif
 }
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 1d5ce97192..aaf4d836a2 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -34,6 +34,7 @@
 #include "ags/shared/gui/guilistbox.h"
 #include "ags/shared/gui/guislider.h"
 #include "ags/shared/gui/guitextbox.h"
+#include "ags/shared/util/directory.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
 #include "ags/engine/ac/gamesetup.h"
@@ -126,6 +127,7 @@ Globals::Globals() {
 	_scrRegion = new ScriptRegion[MAX_ROOM_REGIONS];
 	_scrInv = new ScriptInvItem[MAX_INV];
 	_objcache = new ObjectCache[MAX_ROOM_OBJECTS];
+	_saveGameDirectory = AGS::Shared::SAVE_FOLDER_PREFIX;
 
 	// game_init.cpp globals
 	_StaticCharacterArray = new StaticArray();
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index eaac6713f8..0caec08569 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -248,6 +248,9 @@ public:
 	ObjectCache *_objcache;
 	MoveList *_mls = nullptr;
 	GameSetup *_usetup;
+	AGS::Shared::String _saveGameDirectory;
+	AGS::Shared::String _saveGameParent;
+	AGS::Shared::String _saveGameSuffix;
 
 	 /**@}*/
 


Commit: 07c005ff9a94e10bce8a6a0e952dc18f571b12dd
    https://github.com/scummvm/scummvm/commit/07c005ff9a94e10bce8a6a0e952dc18f571b12dd
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-05T21:52:56-08:00

Commit Message:
AGS: Remove unused LastOldFormatVersion

Changed paths:
    engines/ags/shared/util/version.cpp
    engines/ags/shared/util/version.h


diff --git a/engines/ags/shared/util/version.cpp b/engines/ags/shared/util/version.cpp
index 40ef6bd313..1685d50291 100644
--- a/engines/ags/shared/util/version.cpp
+++ b/engines/ags/shared/util/version.cpp
@@ -27,8 +27,6 @@ namespace AGS3 {
 namespace AGS {
 namespace Shared {
 
-const Version Version::LastOldFormatVersion(3, 2, 2, 1120);
-
 Version::Version()
 	: Major(0)
 	, Minor(0)
diff --git a/engines/ags/shared/util/version.h b/engines/ags/shared/util/version.h
index 829540a97c..3d5fc030fe 100644
--- a/engines/ags/shared/util/version.h
+++ b/engines/ags/shared/util/version.h
@@ -49,9 +49,6 @@ struct Version {
 	String  ShortString;
 	String  BackwardCompatibleString;
 
-	// Last engine version, using different version format than AGS Editor (3.22.1120 / 3.2.2.1120)
-	static const Version LastOldFormatVersion;
-
 	Version();
 	Version(int32_t major, int32_t minor, int32_t release);
 	Version(int32_t major, int32_t minor, int32_t release, int32_t revision);




More information about the Scummvm-git-logs mailing list