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

dreammaster dreammaster at scummvm.org
Thu Mar 4 04:25:54 UTC 2021


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

Summary:
e82070c485 AGS: Move dialog.cpp globals to Globals
ae99244e06 AGS: Move game_init.cpp globals to Globals
a51a186387 AGS: Moved guibutton.cpp globals to Globals
de2881e2d1 AGS: Move managedobjectpool.cpp globals to Globals
07e998c98d AGS: Fix drawing partially off-screen sprites


Commit: e82070c4859e37be960f540cf3ded1adf068989e
    https://github.com/scummvm/scummvm/commit/e82070c4859e37be960f540cf3ded1adf068989e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-03T20:25:07-08:00

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

Changed paths:
    engines/ags/engine/ac/dialog.cpp
    engines/ags/engine/game/game_init.cpp
    engines/ags/globals.h
    engines/ags/shared/game/main_game_file.cpp


diff --git a/engines/ags/engine/ac/dialog.cpp b/engines/ags/engine/ac/dialog.cpp
index 03ce5f9d45..ab1dd8fddf 100644
--- a/engines/ags/engine/ac/dialog.cpp
+++ b/engines/ags/engine/ac/dialog.cpp
@@ -81,17 +81,10 @@ ScriptDialogOptionsRendering ccDialogOptionsRendering;
 ScriptDrawingSurface *dialogOptionsRenderingSurface;
 
 int said_speech_line; // used while in dialog to track whether screen needs updating
-
-// Old dialog support
-std::vector< std::shared_ptr<unsigned char> > old_dialog_scripts;
-std::vector<String> old_speech_lines;
-
 int said_text = 0;
 int longestline = 0;
 
 
-
-
 void Dialog_Start(ScriptDialog *sd) {
 	RunDialog(sd->id);
 }
@@ -199,7 +192,7 @@ int run_dialog_script(DialogTopic *dtpp, int dialogID, int offse, int optionInde
 		if (offse == -1)
 			return result;
 
-		unsigned char *script = old_dialog_scripts[dialogID].get() + offse;
+		unsigned char *script = _G(old_dialog_scripts)[dialogID].get() + offse;
 
 		unsigned short param1 = 0;
 		unsigned short param2 = 0;
@@ -214,9 +207,9 @@ int run_dialog_script(DialogTopic *dtpp, int dialogID, int offse, int optionInde
 					param1 = _GP(game).playercharacter;
 
 				if (param1 == DCHAR_NARRATOR)
-					Display(get_translation(old_speech_lines[param2]));
+					Display(get_translation(_G(old_speech_lines)[param2]));
 				else
-					DisplaySpeech(get_translation(old_speech_lines[param2]), param1);
+					DisplaySpeech(get_translation(_G(old_speech_lines)[param2]), param1);
 
 				said_speech_line = 1;
 				break;
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 5277c8b815..55c32e483f 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -79,10 +79,6 @@ extern StaticArray StaticRegionArray;
 extern StaticArray StaticInventoryArray;
 extern StaticArray StaticDialogArray;
 
-// Old dialog support (defined in ac/dialog)
-extern std::vector< std::shared_ptr<unsigned char> > old_dialog_scripts;
-extern std::vector<String> old_speech_lines;
-
 StaticArray StaticCharacterArray;
 StaticArray StaticObjectArray;
 StaticArray StaticGUIArray;
@@ -366,8 +362,8 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
 	actspswbbmp = (IDriverDependantBitmap **)calloc(actSpsCount, sizeof(IDriverDependantBitmap *));
 	actspswbcache = (CachedActSpsData *)calloc(actSpsCount, sizeof(CachedActSpsData));
 	_GP(play).charProps.resize(_GP(game).numcharacters);
-	old_dialog_scripts = ents.OldDialogScripts;
-	old_speech_lines = ents.OldSpeechLines;
+	_G(old_dialog_scripts) = ents.OldDialogScripts;
+	_G(old_speech_lines) = ents.OldSpeechLines;
 	HError err = InitAndRegisterGameEntities();
 	if (!err)
 		return new GameInitError(kGameInitErr_EntityInitFail, err);
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 5207d12050..c9ce1a8e1e 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -141,6 +141,18 @@ public:
 	 */
 
 	AGS::Shared::DebugManager *_DbgMgr;
+
+	/**@}*/
+
+	/**
+	 * \defgroup dialog globals
+	 * @{
+	 */
+
+	 // Old dialog support
+	std::vector< std::shared_ptr<unsigned char> > _old_dialog_scripts;
+	std::vector<String> _old_speech_lines;
+
 	/**@}*/
 
 	/**
diff --git a/engines/ags/shared/game/main_game_file.cpp b/engines/ags/shared/game/main_game_file.cpp
index 08b901038b..9a360d71dd 100644
--- a/engines/ags/shared/game/main_game_file.cpp
+++ b/engines/ags/shared/game/main_game_file.cpp
@@ -229,10 +229,10 @@ void ReadViews(GameSetupStruct &game, ViewStruct *&views, Stream *in, GameDataVe
 }
 
 void ReadDialogs(DialogTopic *&dialog,
-	std::vector< std::shared_ptr<unsigned char> > &old_dialog_scripts,
-	std::vector<String> &old_dialog_src,
-	std::vector<String> &old_speech_lines,
-	Stream *in, GameDataVersion data_ver, int dlg_count) {
+		std::vector< std::shared_ptr<unsigned char> > &old_dialog_scripts,
+		std::vector<String> &old_dialog_src,
+		std::vector<String> &old_speech_lines,
+		Stream *in, GameDataVersion data_ver, int dlg_count) {
 	// TODO: I suspect +5 was a hacky way to "supress" memory access mistakes;
 	// double check and remove if proved unnecessary
 	dialog = (DialogTopic *)malloc(sizeof(DialogTopic) * dlg_count + 5);


Commit: ae99244e06e151806e1f39bfb216b764195cbdd5
    https://github.com/scummvm/scummvm/commit/ae99244e06e151806e1f39bfb216b764195cbdd5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-03T20:25:07-08:00

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

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


diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 55c32e483f..7656916f33 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -63,31 +63,11 @@ extern IDriverDependantBitmap **actspsbmp;
 extern Bitmap **actspswb;
 extern IDriverDependantBitmap **actspswbbmp;
 extern CachedActSpsData *actspswbcache;
-
-
 extern ScriptAudioChannel scrAudioChannel[MAX_SOUND_CHANNELS + 1];
 extern ScriptDialogOptionsRendering ccDialogOptionsRendering;
 extern ScriptDrawingSurface *dialogOptionsRenderingSurface;
-
 extern AGSStaticObject GlobalStaticManager;
 
-extern StaticArray StaticCharacterArray;
-extern StaticArray StaticObjectArray;
-extern StaticArray StaticGUIArray;
-extern StaticArray StaticHotspotArray;
-extern StaticArray StaticRegionArray;
-extern StaticArray StaticInventoryArray;
-extern StaticArray StaticDialogArray;
-
-StaticArray StaticCharacterArray;
-StaticArray StaticObjectArray;
-StaticArray StaticGUIArray;
-StaticArray StaticHotspotArray;
-StaticArray StaticRegionArray;
-StaticArray StaticInventoryArray;
-StaticArray StaticDialogArray;
-
-
 namespace AGS {
 namespace Engine {
 
@@ -240,21 +220,21 @@ void InitAndRegisterRegions() {
 
 // Registers static entity arrays in the script system
 void RegisterStaticArrays() {
-	StaticCharacterArray.Create(&_GP(ccDynamicCharacter), sizeof(CharacterInfo), sizeof(CharacterInfo));
-	StaticObjectArray.Create(&_GP(ccDynamicObject), sizeof(ScriptObject), sizeof(ScriptObject));
-	StaticGUIArray.Create(&_GP(ccDynamicGUI), sizeof(ScriptGUI), sizeof(ScriptGUI));
-	StaticHotspotArray.Create(&_GP(ccDynamicHotspot), sizeof(ScriptHotspot), sizeof(ScriptHotspot));
-	StaticRegionArray.Create(&_GP(ccDynamicRegion), sizeof(ScriptRegion), sizeof(ScriptRegion));
-	StaticInventoryArray.Create(&_GP(ccDynamicInv), sizeof(ScriptInvItem), sizeof(ScriptInvItem));
-	StaticDialogArray.Create(&_GP(ccDynamicDialog), sizeof(ScriptDialog), sizeof(ScriptDialog));
-
-	ccAddExternalStaticArray("character", &_GP(game).chars[0], &StaticCharacterArray);
-	ccAddExternalStaticArray("object", &_G(scrObj)[0], &StaticObjectArray);
-	ccAddExternalStaticArray("gui", &_G(scrGui)[0], &StaticGUIArray);
-	ccAddExternalStaticArray("hotspot", &_G(scrHotspot)[0], &StaticHotspotArray);
-	ccAddExternalStaticArray("region", &_G(scrRegion)[0], &StaticRegionArray);
-	ccAddExternalStaticArray("inventory", &_G(scrInv)[0], &StaticInventoryArray);
-	ccAddExternalStaticArray("dialog", &_G(scrDialog)[0], &StaticDialogArray);
+	_GP(StaticCharacterArray).Create(&_GP(ccDynamicCharacter), sizeof(CharacterInfo), sizeof(CharacterInfo));
+	_GP(StaticObjectArray).Create(&_GP(ccDynamicObject), sizeof(ScriptObject), sizeof(ScriptObject));
+	_GP(StaticGUIArray).Create(&_GP(ccDynamicGUI), sizeof(ScriptGUI), sizeof(ScriptGUI));
+	_GP(StaticHotspotArray).Create(&_GP(ccDynamicHotspot), sizeof(ScriptHotspot), sizeof(ScriptHotspot));
+	_GP(StaticRegionArray).Create(&_GP(ccDynamicRegion), sizeof(ScriptRegion), sizeof(ScriptRegion));
+	_GP(StaticInventoryArray).Create(&_GP(ccDynamicInv), sizeof(ScriptInvItem), sizeof(ScriptInvItem));
+	_GP(StaticDialogArray).Create(&_GP(ccDynamicDialog), sizeof(ScriptDialog), sizeof(ScriptDialog));
+
+	ccAddExternalStaticArray("character", &_GP(game).chars[0], &_GP(StaticCharacterArray));
+	ccAddExternalStaticArray("object", &_G(scrObj)[0], &_GP(StaticObjectArray));
+	ccAddExternalStaticArray("gui", &_G(scrGui)[0], &_GP(StaticGUIArray));
+	ccAddExternalStaticArray("hotspot", &_G(scrHotspot)[0], &_GP(StaticHotspotArray));
+	ccAddExternalStaticArray("region", &_G(scrRegion)[0], &_GP(StaticRegionArray));
+	ccAddExternalStaticArray("inventory", &_G(scrInv)[0], &_GP(StaticInventoryArray));
+	ccAddExternalStaticArray("dialog", &_G(scrDialog)[0], &_GP(StaticDialogArray));
 }
 
 // Initializes various game entities and registers them in the script system
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 86f8b78030..42cc1f93d2 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -30,6 +30,7 @@
 #include "ags/shared/game/roomstruct.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/gamestate.h"
+#include "ags/engine/ac/objectcache.h"
 #include "ags/engine/ac/roomstatus.h"
 #include "ags/engine/ac/screenoverlay.h"
 #include "ags/engine/ac/spritelistentry.h"
@@ -44,12 +45,12 @@
 #include "ags/engine/ac/dynobj/cc_audiochannel.h"
 #include "ags/engine/ac/dynobj/cc_audioclip.h"
 #include "ags/engine/ac/dynobj/scriptsystem.h"
-#include "ags/engine/ac/objectcache.h"
 #include "ags/engine/ac/dynobj/scripthotspot.h"
 #include "ags/engine/ac/dynobj/scriptinvitem.h"
 #include "ags/engine/ac/dynobj/scriptobject.h"
 #include "ags/engine/ac/dynobj/scriptregion.h"
 #include "ags/engine/ac/dynobj/scriptstring.h"
+#include "ags/engine/ac/statobj/staticarray.h"
 #include "ags/engine/media/audio/ambientsound.h"
 #include "ags/engine/media/audio/audiodefines.h"
 #include "ags/engine/script/executingscript.h"
@@ -108,6 +109,15 @@ Globals::Globals() {
 	_scrInv = new ScriptInvItem[MAX_INV];
 	_objcache = new ObjectCache[MAX_ROOM_OBJECTS];
 
+	// game_init.cpp globals
+	_StaticCharacterArray = new StaticArray();
+	_StaticObjectArray = new StaticArray();
+	_StaticGUIArray = new StaticArray();
+	_StaticHotspotArray = new StaticArray();
+	_StaticRegionArray = new StaticArray();
+	_StaticInventoryArray = new StaticArray();
+	_StaticDialogArray = new StaticArray();
+
 	// overlay.cpp globals
 	_screenover = new std::vector<ScreenOverlay>();
 
@@ -172,6 +182,15 @@ Globals::~Globals() {
 	delete[] _scrInv;
 	delete[] _objcache;
 
+	// game_init.cpp globals
+	delete _StaticCharacterArray;
+	delete _StaticObjectArray;
+	delete _StaticGUIArray;
+	delete _StaticHotspotArray;
+	delete _StaticRegionArray;
+	delete _StaticInventoryArray;
+	delete _StaticDialogArray;
+
 	// overlay.cpp
 	delete _screenover;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index c9ce1a8e1e..305a5fa489 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -86,6 +86,7 @@ struct ScriptString;
 struct ScriptSystem;
 struct SOUNDCLIP;
 struct SpriteListEntry;
+struct StaticArray;
 struct ViewStruct;
 
 class SpriteCache;
@@ -220,6 +221,21 @@ public:
 
 	 /**@}*/
 
+	/**
+	 * \defgroup game_init globals
+	 * @{
+	 */
+
+	StaticArray *_StaticCharacterArray;
+	StaticArray *_StaticObjectArray;
+	StaticArray *_StaticGUIArray;
+	StaticArray *_StaticHotspotArray;
+	StaticArray *_StaticRegionArray;
+	StaticArray *_StaticInventoryArray;
+	StaticArray *_StaticDialogArray;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{


Commit: a51a186387056b9f6ecc203f4ffeacf246d16dde
    https://github.com/scummvm/scummvm/commit/a51a186387056b9f6ecc203f4ffeacf246d16dde
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-03T20:25:07-08:00

Commit Message:
AGS: Moved guibutton.cpp globals to Globals

Changed paths:
    engines/ags/engine/ac/button.cpp
    engines/ags/engine/ac/display.cpp
    engines/ags/engine/ac/dynamicsprite.cpp
    engines/ags/engine/game/savegame.cpp
    engines/ags/engine/game/savegame_components.cpp
    engines/ags/engine/gui/animatingguibutton.h
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/gui/guibutton.cpp
    engines/ags/shared/gui/guibutton.h
    engines/ags/shared/gui/guimain.cpp


diff --git a/engines/ags/engine/ac/button.cpp b/engines/ags/engine/ac/button.cpp
index 59b358c101..54d2cc54e4 100644
--- a/engines/ags/engine/ac/button.cpp
+++ b/engines/ags/engine/ac/button.cpp
@@ -65,8 +65,8 @@ void Button_Animate(GUIButton *butt, int view, int loop, int speed, int repeat)
 
 	int buttonId = _GP(guis)[guin].GetControlID(objn);
 
-	guibuts[buttonId].PushedImage = 0;
-	guibuts[buttonId].MouseOverImage = 0;
+	_GP(guibuts)[buttonId].PushedImage = 0;
+	_GP(guibuts)[buttonId].MouseOverImage = 0;
 
 	animbuts[numAnimButs].ongui = guin;
 	animbuts[numAnimButs].onguibut = objn;
@@ -226,10 +226,10 @@ int UpdateAnimatingButton(int bu) {
 	CheckViewFrame(animbuts[bu].view, animbuts[bu].loop, animbuts[bu].frame);
 
 	// update the button's image
-	guibuts[animbuts[bu].buttonid].Image = tview->loops[animbuts[bu].loop].frames[animbuts[bu].frame].pic;
-	guibuts[animbuts[bu].buttonid].CurrentImage = guibuts[animbuts[bu].buttonid].Image;
-	guibuts[animbuts[bu].buttonid].PushedImage = 0;
-	guibuts[animbuts[bu].buttonid].MouseOverImage = 0;
+	_GP(guibuts)[animbuts[bu].buttonid].Image = tview->loops[animbuts[bu].loop].frames[animbuts[bu].frame].pic;
+	_GP(guibuts)[animbuts[bu].buttonid].CurrentImage = _GP(guibuts)[animbuts[bu].buttonid].Image;
+	_GP(guibuts)[animbuts[bu].buttonid].PushedImage = 0;
+	_GP(guibuts)[animbuts[bu].buttonid].MouseOverImage = 0;
 	guis_need_update = 1;
 
 	animbuts[bu].wait = animbuts[bu].speed + tview->loops[animbuts[bu].loop].frames[animbuts[bu].frame].speed;
diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index c6a3bfa68a..594804287e 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -602,7 +602,7 @@ void do_corner(Bitmap *ds, int sprn, int x, int y, int offx, int offy) {
 
 int get_but_pic(GUIMain *guo, int indx) {
 	int butid = guo->GetControlID(indx);
-	return butid >= 0 ? guibuts[butid].Image : 0;
+	return butid >= 0 ? _GP(guibuts)[butid].Image : 0;
 }
 
 void draw_button_background(Bitmap *ds, int xx1, int yy1, int xx2, int yy2, GUIMain *iep) {
diff --git a/engines/ags/engine/ac/dynamicsprite.cpp b/engines/ags/engine/ac/dynamicsprite.cpp
index 319682475a..f200de2451 100644
--- a/engines/ags/engine/ac/dynamicsprite.cpp
+++ b/engines/ags/engine/ac/dynamicsprite.cpp
@@ -476,17 +476,17 @@ void free_dynamic_sprite(int gotSlot) {
 	_GP(game).SpriteInfos[gotSlot].Height = 0;
 
 	// ensure it isn't still on any GUI buttons
-	for (tt = 0; tt < numguibuts; tt++) {
-		if (guibuts[tt].IsDeleted())
+	for (tt = 0; tt < _G(numguibuts); tt++) {
+		if (_GP(guibuts)[tt].IsDeleted())
 			continue;
-		if (guibuts[tt].Image == gotSlot)
-			guibuts[tt].Image = 0;
-		if (guibuts[tt].CurrentImage == gotSlot)
-			guibuts[tt].CurrentImage = 0;
-		if (guibuts[tt].MouseOverImage == gotSlot)
-			guibuts[tt].MouseOverImage = 0;
-		if (guibuts[tt].PushedImage == gotSlot)
-			guibuts[tt].PushedImage = 0;
+		if (_GP(guibuts)[tt].Image == gotSlot)
+			_GP(guibuts)[tt].Image = 0;
+		if (_GP(guibuts)[tt].CurrentImage == gotSlot)
+			_GP(guibuts)[tt].CurrentImage = 0;
+		if (_GP(guibuts)[tt].MouseOverImage == gotSlot)
+			_GP(guibuts)[tt].MouseOverImage = 0;
+		if (_GP(guibuts)[tt].PushedImage == gotSlot)
+			_GP(guibuts)[tt].PushedImage = 0;
 	}
 
 	// force refresh of any object caches using the sprite
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index 86a98c75b9..dbfb258ad7 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -339,7 +339,7 @@ void DoBeforeRestore(PreservedParams &pp) {
 	// NOTE: sprite 0 is a special constant sprite that cannot be dynamic
 	for (int i = 1; i < _GP(spriteset).GetSpriteSlotCount(); ++i) {
 		if (_GP(game).SpriteInfos[i].Flags & SPF_DYNAMICALLOC) {
-			// do this early, so that it changing guibuts doesn't
+			// do this early, so that it changing _GP(guibuts) doesn't
 			// affect the restored data
 			free_dynamic_sprite(i);
 		}
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index c2d3f1ffb1..90768a2671 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -537,9 +537,9 @@ HSaveError WriteGUI(PStream out) {
 		_GP(guis)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUIButtons");
-	out->WriteInt32(numguibuts);
-	for (int i = 0; i < numguibuts; ++i)
-		guibuts[i].WriteToSavegame(out.get());
+	out->WriteInt32(_G(numguibuts));
+	for (int i = 0; i < _G(numguibuts); ++i)
+		_GP(guibuts)[i].WriteToSavegame(out.get());
 
 	WriteFormatTag(out, "GUILabels");
 	out->WriteInt32(numguilabels);
@@ -587,10 +587,10 @@ HSaveError ReadGUI(PStream in, int32_t cmp_ver, const PreservedParams &pp, Resto
 
 	if (!AssertFormatTagStrict(err, in, "GUIButtons"))
 		return err;
-	if (!AssertGameContent(err, in->ReadInt32(), numguibuts, "GUI Buttons"))
+	if (!AssertGameContent(err, in->ReadInt32(), _G(numguibuts), "GUI Buttons"))
 		return err;
-	for (int i = 0; i < numguibuts; ++i)
-		guibuts[i].ReadFromSavegame(in.get(), svg_ver);
+	for (int i = 0; i < _G(numguibuts); ++i)
+		_GP(guibuts)[i].ReadFromSavegame(in.get(), svg_ver);
 
 	if (!AssertFormatTagStrict(err, in, "GUILabels"))
 		return err;
diff --git a/engines/ags/engine/gui/animatingguibutton.h b/engines/ags/engine/gui/animatingguibutton.h
index 1a0053601a..2c2fd2cebf 100644
--- a/engines/ags/engine/gui/animatingguibutton.h
+++ b/engines/ags/engine/gui/animatingguibutton.h
@@ -37,7 +37,7 @@ class Stream;
 using namespace AGS; // FIXME later
 
 struct AnimatingGUIButton {
-	// index into guibuts array, GUI, button
+	// index into _GP(guibuts) array, GUI, button
 	short buttonid, ongui, onguibut;
 	// current animation status
 	short view, loop, frame;
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 42cc1f93d2..c3c4da89e2 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -28,6 +28,7 @@
 #include "ags/shared/font/ttffontrenderer.h"
 #include "ags/shared/font/wfnfontrenderer.h"
 #include "ags/shared/game/roomstruct.h"
+#include "ags/shared/gui/guibutton.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/gamestate.h"
 #include "ags/engine/ac/objectcache.h"
@@ -118,6 +119,9 @@ Globals::Globals() {
 	_StaticInventoryArray = new StaticArray();
 	_StaticDialogArray = new StaticArray();
 
+	// guibutton.cpp globals
+	_guibuts = new std::vector<AGS::Shared::GUIButton>();
+
 	// overlay.cpp globals
 	_screenover = new std::vector<ScreenOverlay>();
 
@@ -146,19 +150,19 @@ Globals::Globals() {
 Globals::~Globals() {
 	g_globals = nullptr;
 
-	// audio.cpp
+	// audio.cpp globals
 	delete _audioChannels;
 	delete _ambient;
 
-	// debugmanager.cpp
+	// debugmanager.cpp globals
 	delete _DbgMgr;
 
-	// fonts.cpp
+	// fonts.cpp globals
 	delete _fonts;
 	delete _ttfRenderer;
 	delete _wfnRenderer;
 
-	// game.cpp
+	// game.cpp globals
 	delete _ccDynamicGUIObject;
 	delete _ccDynamicCharacter;
 	delete _ccDynamicHotspot;
@@ -191,10 +195,13 @@ Globals::~Globals() {
 	delete _StaticInventoryArray;
 	delete _StaticDialogArray;
 
-	// overlay.cpp
+	// guibutton.cpp globals
+	delete _guibuts;
+
+	// overlay.cpp globals
 	delete _screenover;
 
-	// script.cpp
+	// script.cpp globals
 	delete[] _scripts;
 	delete _gamescript;
 	delete _dialogScriptsScript;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 305a5fa489..faba7f69d2 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -43,6 +43,7 @@ namespace Shared {
 class Bitmap;
 class DebugManager;
 struct Font;
+class GUIButton;
 class RoomStruct;
 
 } // namespace Shared
@@ -236,6 +237,16 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup guibutton globals
+	 * @{
+	 */
+
+	std::vector<AGS::Shared::GUIButton> *_guibuts;
+	int _numguibuts = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/gui/guibutton.cpp b/engines/ags/shared/gui/guibutton.cpp
index e599689fe2..51a6368484 100644
--- a/engines/ags/shared/gui/guibutton.cpp
+++ b/engines/ags/shared/gui/guibutton.cpp
@@ -29,9 +29,6 @@
 
 namespace AGS3 {
 
-std::vector<AGS::Shared::GUIButton> guibuts;
-int numguibuts = 0;
-
 namespace AGS {
 namespace Shared {
 
diff --git a/engines/ags/shared/gui/guibutton.h b/engines/ags/shared/gui/guibutton.h
index 1176faacf4..4d8ebcb5b2 100644
--- a/engines/ags/shared/gui/guibutton.h
+++ b/engines/ags/shared/gui/guibutton.h
@@ -130,9 +130,6 @@ private:
 } // namespace Shared
 } // namespace AGS
 
-extern std::vector<AGS::Shared::GUIButton> guibuts;
-extern int numguibuts;
-
 int UpdateAnimatingButton(int bu);
 void StopButtonAnimation(int idxn);
 
diff --git a/engines/ags/shared/gui/guimain.cpp b/engines/ags/shared/gui/guimain.cpp
index c86681208c..b34db17004 100644
--- a/engines/ags/shared/gui/guimain.cpp
+++ b/engines/ags/shared/gui/guimain.cpp
@@ -331,7 +331,7 @@ HError GUIMain::RebuildArray() {
 			return new Error(String::FromFormat("GUIMain (%d): invalid control ID %d in ref #%d", ID, thisnum, i));
 
 		if (thistype == kGUIButton)
-			_controls[i] = &guibuts[thisnum];
+			_controls[i] = &_GP(guibuts)[thisnum];
 		else if (thistype == kGUILabel)
 			_controls[i] = &guilabels[thisnum];
 		else if (thistype == kGUIInvWindow)
@@ -723,10 +723,10 @@ HError ReadGUI(std::vector<GUIMain> &theGuis, Stream *in, bool is_savegame) {
 	}
 
 	// buttons
-	numguibuts = in->ReadInt32();
-	guibuts.resize(numguibuts);
-	for (int i = 0; i < numguibuts; ++i) {
-		guibuts[i].ReadFromFile(in, GameGuiVersion);
+	_G(numguibuts) = in->ReadInt32();
+	_GP(guibuts).resize(_G(numguibuts));
+	for (int i = 0; i < _G(numguibuts); ++i) {
+		_GP(guibuts)[i].ReadFromFile(in, GameGuiVersion);
 	}
 	// labels
 	numguilabels = in->ReadInt32();
@@ -776,9 +776,9 @@ void WriteGUI(const std::vector<GUIMain> &theGuis, Stream *out) {
 	for (size_t i = 0; i < theGuis.size(); ++i) {
 		theGuis[i].WriteToFile(out);
 	}
-	out->WriteInt32(numguibuts);
-	for (int i = 0; i < numguibuts; ++i) {
-		guibuts[i].WriteToFile(out);
+	out->WriteInt32(_G(numguibuts));
+	for (int i = 0; i < _G(numguibuts); ++i) {
+		_GP(guibuts)[i].WriteToFile(out);
 	}
 	out->WriteInt32(numguilabels);
 	for (int i = 0; i < numguilabels; ++i) {


Commit: de2881e2d170ff7866eb2c48238e17a20320c7bf
    https://github.com/scummvm/scummvm/commit/de2881e2d170ff7866eb2c48238e17a20320c7bf
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-03T20:25:07-08:00

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

Changed paths:
    engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
    engines/ags/engine/ac/dynobj/managedobjectpool.cpp
    engines/ags/engine/script/cc_instance.cpp
    engines/ags/globals.cpp
    engines/ags/globals.h


diff --git a/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp b/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
index 8492137105..2cc89cc3b8 100644
--- a/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
+++ b/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
@@ -44,6 +44,7 @@
 #include "ags/shared/script/cc_error.h"
 #include "ags/shared/script/script_common.h"
 #include "ags/shared/util/stream.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
@@ -59,7 +60,7 @@ void ccSetStringClassImpl(ICCStringClass *theClass) {
 // register a memory handle for the object and allow script
 // pointers to point to it
 int32_t ccRegisterManagedObject(const void *object, ICCDynamicObject *callback, bool plugin_object) {
-	int32_t handl = pool.AddObject((const char *)object, callback, plugin_object);
+	int32_t handl = _GP(pool).AddObject((const char *)object, callback, plugin_object);
 
 	ManagedObjectLog("Register managed object type '%s' handle=%d addr=%08X",
 		((callback == NULL) ? "(unknown)" : callback->GetType()), handl, object);
@@ -69,32 +70,32 @@ int32_t ccRegisterManagedObject(const void *object, ICCDynamicObject *callback,
 
 // register a de-serialized object
 int32_t ccRegisterUnserializedObject(int index, const void *object, ICCDynamicObject *callback, bool plugin_object) {
-	return pool.AddUnserializedObject((const char *)object, callback, plugin_object, index);
+	return _GP(pool).AddUnserializedObject((const char *)object, callback, plugin_object, index);
 }
 
 // unregister a particular object
 int ccUnRegisterManagedObject(const void *object) {
-	return pool.RemoveObject((const char *)object);
+	return _GP(pool).RemoveObject((const char *)object);
 }
 
 // remove all registered objects
 void ccUnregisterAllObjects() {
-	pool.reset();
+	_GP(pool).reset();
 }
 
 // serialize all objects to disk
 void ccSerializeAllObjects(Stream *out) {
-	pool.WriteToDisk(out);
+	_GP(pool).WriteToDisk(out);
 }
 
 // un-serialise all objects (will remove all currently registered ones)
 int ccUnserializeAllObjects(Stream *in, ICCObjectReader *callback) {
-	return pool.ReadFromDisk(in, callback);
+	return _GP(pool).ReadFromDisk(in, callback);
 }
 
 // dispose the object if RefCount==0
 void ccAttemptDisposeObject(int32_t handle) {
-	pool.CheckDispose(handle);
+	_GP(pool).CheckDispose(handle);
 }
 
 // translate between object handles and memory addresses
@@ -103,7 +104,7 @@ int32_t ccGetObjectHandleFromAddress(const char *address) {
 	if (address == nullptr)
 		return 0;
 
-	int32_t handl = pool.AddressToHandle(address);
+	int32_t handl = _GP(pool).AddressToHandle(address);
 
 	ManagedObjectLog("Line %d WritePtr: %08X to %d", currentline, address, handl);
 
@@ -118,7 +119,7 @@ const char *ccGetObjectAddressFromHandle(int32_t handle) {
 	if (handle == 0) {
 		return nullptr;
 	}
-	const char *addr = pool.HandleToAddress(handle);
+	const char *addr = _GP(pool).HandleToAddress(handle);
 
 	ManagedObjectLog("Line %d ReadPtr: %d to %08X", currentline, handle, addr);
 
@@ -135,7 +136,7 @@ ScriptValueType ccGetObjectAddressAndManagerFromHandle(int32_t handle, void *&ob
 		manager = nullptr;
 		return kScValUndefined;
 	}
-	ScriptValueType obj_type = pool.HandleToAddressAndManager(handle, object, manager);
+	ScriptValueType obj_type = _GP(pool).HandleToAddressAndManager(handle, object, manager);
 	if (obj_type == kScValUndefined) {
 		cc_error("Error retrieving pointer: invalid handle %d", handle);
 	}
@@ -146,19 +147,19 @@ int ccAddObjectReference(int32_t handle) {
 	if (handle == 0)
 		return 0;
 
-	return pool.AddRef(handle);
+	return _GP(pool).AddRef(handle);
 }
 
 int ccReleaseObjectReference(int32_t handle) {
 	if (handle == 0)
 		return 0;
 
-	if (pool.HandleToAddress(handle) == nullptr) {
+	if (_GP(pool).HandleToAddress(handle) == nullptr) {
 		cc_error("Error releasing pointer: invalid handle %d", handle);
 		return -1;
 	}
 
-	return pool.SubRef(handle);
+	return _GP(pool).SubRef(handle);
 }
 
 } // namespace AGS3
diff --git a/engines/ags/engine/ac/dynobj/managedobjectpool.cpp b/engines/ags/engine/ac/dynobj/managedobjectpool.cpp
index 1b6b6f08dc..5185cfbb53 100644
--- a/engines/ags/engine/ac/dynobj/managedobjectpool.cpp
+++ b/engines/ags/engine/ac/dynobj/managedobjectpool.cpp
@@ -382,6 +382,4 @@ ManagedObjectPool::ManagedObjectPool() : objectCreationCounter(0), nextHandle(1)
 	handleByAddress.reserve(RESERVED_SIZE);
 }
 
-ManagedObjectPool pool;
-
 } // namespace AGS3
diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index 9366a8f183..abcb1698ad 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -361,7 +361,7 @@ int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const
 	// to be reconsidered, since the GC could be run in the middle
 	// of a RET from a function or something where there is an
 	// object with ref count 0 that is in use
-	pool.RunGarbageCollectionIfAppropriate();
+	_GP(pool).RunGarbageCollectionIfAppropriate();
 
 	if (new_line_hook)
 		new_line_hook(nullptr, 0);
@@ -899,9 +899,9 @@ int ccInstance::Run(int32_t curpc) {
 			// Note: we might be freeing a dynamic array which contains the DisableDispose
 			// object, that will be handled inside the recursive call to SubRef.
 			// CHECKME!! what type of data may reg1 point to?
-			pool.disableDisposeForObject = (const char *)registers[SREG_AX].Ptr;
+			_GP(pool).disableDisposeForObject = (const char *)registers[SREG_AX].Ptr;
 			ccReleaseObjectReference(handle);
-			pool.disableDisposeForObject = nullptr;
+			_GP(pool).disableDisposeForObject = nullptr;
 			registers[SREG_MAR].WriteInt32(0);
 			break;
 		}
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index c3c4da89e2..3655e0ddea 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -45,6 +45,7 @@
 #include "ags/engine/ac/dynobj/cc_object.h"
 #include "ags/engine/ac/dynobj/cc_audiochannel.h"
 #include "ags/engine/ac/dynobj/cc_audioclip.h"
+#include "ags/engine/ac/dynobj/managedobjectpool.h"
 #include "ags/engine/ac/dynobj/scriptsystem.h"
 #include "ags/engine/ac/dynobj/scripthotspot.h"
 #include "ags/engine/ac/dynobj/scriptinvitem.h"
@@ -122,6 +123,9 @@ Globals::Globals() {
 	// guibutton.cpp globals
 	_guibuts = new std::vector<AGS::Shared::GUIButton>();
 
+	// managedobjectpool.cpp globals
+	_pool = new ManagedObjectPool();
+
 	// overlay.cpp globals
 	_screenover = new std::vector<ScreenOverlay>();
 
@@ -198,6 +202,9 @@ Globals::~Globals() {
 	// guibutton.cpp globals
 	delete _guibuts;
 
+	// managedobjectpool.cpp globals
+	delete _pool;
+
 	// overlay.cpp globals
 	delete _screenover;
 
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index faba7f69d2..726e255fcb 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -70,6 +70,7 @@ struct ExecutingScript;
 struct GameSetupStruct;
 struct GameState;
 struct IAGSEditorDebugger;
+struct ManagedObjectPool;
 struct MoveList;
 struct NonBlockingScriptFunction;
 struct ObjectCache;
@@ -297,6 +298,15 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup managedobjectpool globals
+	 * @{
+	 */
+
+	ManagedObjectPool *_pool;
+
+	/**@}*/
+
 	/**
 	 * \defgroup mouse globals
 	 * @{


Commit: 07e998c98da3165f9b345de0e8c3c1d4ce7bed84
    https://github.com/scummvm/scummvm/commit/07e998c98da3165f9b345de0e8c3c1d4ce7bed84
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-03T20:25:08-08:00

Commit Message:
AGS: Fix drawing partially off-screen sprites

Changed paths:
    engines/ags/lib/allegro/surface.cpp


diff --git a/engines/ags/lib/allegro/surface.cpp b/engines/ags/lib/allegro/surface.cpp
index 8d8c24da92..7dadf35715 100644
--- a/engines/ags/lib/allegro/surface.cpp
+++ b/engines/ags/lib/allegro/surface.cpp
@@ -101,19 +101,22 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
 	assert(format.bytesPerPixel == 2 || format.bytesPerPixel == 4 ||
 		(format.bytesPerPixel == 1 && srcBitmap->format.bytesPerPixel == 1));
 
+	// Figure out the dest area that will be updated
+	Common::Rect destRect = dstRect.findIntersectingRect(
+		Common::Rect(cl, ct, cr, cb));
+	if (destRect.isEmpty())
+		// Area is entirely outside the clipping area, so nothing to draw
+		return;
+
 	// Get source and dest surface. Note that for the destination we create
 	// a temporary sub-surface based on the allowed clipping area
 	const Graphics::ManagedSurface &src = **srcBitmap;
-	Graphics::ManagedSurface &allDest = *_owner;
-	Graphics::ManagedSurface dest(allDest, Common::Rect(cl, ct, cr, cb));
-
-	Common::Rect destRect = dstRect;
-	destRect.translate(-cl, -ct);
+	Graphics::ManagedSurface &dest = *_owner;
 	Graphics::Surface destArea = dest.getSubArea(destRect);
 
 	// Define scaling and other stuff used by the drawing loops
-	const int scaleX = SCALE_THRESHOLD * srcRect.width() / destRect.width();
-	const int scaleY = SCALE_THRESHOLD * srcRect.height() / destRect.height();
+	const int scaleX = SCALE_THRESHOLD * srcRect.width() / dstRect.width();
+	const int scaleY = SCALE_THRESHOLD * srcRect.height() / dstRect.height();
 	const int xDir = horizFlip ? -1 : 1;
 	bool useTint = (tintRed >= 0 && tintGreen >= 0 && tintBlue >= 0);
 
@@ -135,24 +138,27 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
 			pal[0] = format.RGBToColor(0xff, 0, 0xff);
 	}
 
-	for (int destY = destRect.top, yCtr = 0, scaleYCtr = 0; yCtr < destArea.h;
+	int xStart = (dstRect.left < destRect.left) ? dstRect.left - destRect.left : 0;
+	int yStart = (dstRect.top < destRect.top) ? dstRect.top - destRect.top : 0;
+
+	for (int destY = yStart, yCtr = 0, scaleYCtr = 0; yCtr < dstRect.height();
 			++destY, ++yCtr, scaleYCtr += scaleY) {
-		if (destY < 0 || destY >= h)
+		if (destY < 0 || destY >= destArea.h)
 			continue;
-		byte *destP = (byte *)destArea.getBasePtr(0, yCtr);
+		byte *destP = (byte *)destArea.getBasePtr(0, destY);
 		const byte *srcP = (const byte *)src.getBasePtr(
 			horizFlip ? srcRect.right - 1 : srcRect.left,
 			vertFlip ? srcRect.bottom - 1 - scaleYCtr / SCALE_THRESHOLD :
 			srcRect.top + scaleYCtr / SCALE_THRESHOLD);
 
 		// Loop through the pixels of the row
-		for (int destX = destRect.left, xCtr = 0, scaleXCtr = 0; xCtr < destArea.w;
+		for (int destX = xStart, xCtr = 0, scaleXCtr = 0; xCtr < dstRect.width();
 				++destX, ++xCtr, scaleXCtr += scaleX) {
-			if (destX < 0 || destX >= w)
+			if (destX < 0 || destX >= destArea.w)
 				continue;
 
 			const byte *srcVal = srcP + xDir * (scaleXCtr / SCALE_THRESHOLD * src.format.bytesPerPixel);
-			byte *destVal = (byte *)&destP[xCtr * format.bytesPerPixel];
+			byte *destVal = (byte *)&destP[destX * format.bytesPerPixel];
 
 			if (src.format.bytesPerPixel == 1 && format.bytesPerPixel == 1) {
 				// TODO: Need to skip transparent color if skip_trans is true?




More information about the Scummvm-git-logs mailing list