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

dreammaster dreammaster at scummvm.org
Sun Mar 7 04:21:20 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:
354441a862 AGS: Remove deprecated assert.h
dfbcfd212c AGS: Move cc_options.cpp globals to Globals
1e327a63f8 AGS: Move cc_script.cpp globals to Globals
497ef2df1a AGS: Move lzw.cpp globals to Globals
07ec21798f AGS: Refactor out global Strings in multifilelib.cpp


Commit: 354441a862465136e363c8f708d115c5ea22979a
    https://github.com/scummvm/scummvm/commit/354441a862465136e363c8f708d115c5ea22979a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T19:51:04-08:00

Commit Message:
AGS: Remove deprecated assert.h

Changed paths:
  R engines/ags/shared/debugging/assert.h
    engines/ags/shared/gfx/allegrobitmap.cpp
    engines/ags/shared/util/alignedstream.cpp
    engines/ags/shared/util/string.h


diff --git a/engines/ags/shared/debugging/assert.h b/engines/ags/shared/debugging/assert.h
deleted file mode 100644
index 22d812bc2d..0000000000
--- a/engines/ags/shared/debugging/assert.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-//=============================================================================
-//
-// Debug assertion tools
-//
-//=============================================================================
-
-#ifndef AGS_SHARED_DEBUGGING_ASSERT_H
-#define AGS_SHARED_DEBUGGING_ASSERT_H
-
-#endif
diff --git a/engines/ags/shared/gfx/allegrobitmap.cpp b/engines/ags/shared/gfx/allegrobitmap.cpp
index 6f1dc56fc4..141c51e89b 100644
--- a/engines/ags/shared/gfx/allegrobitmap.cpp
+++ b/engines/ags/shared/gfx/allegrobitmap.cpp
@@ -22,7 +22,6 @@
 
 #include "ags/shared/gfx/allegrobitmap.h"
 #include "ags/shared/gfx/image.h"
-#include "ags/shared/debugging/assert.h"
 #include "ags/lib/aastr-0.1.1/aastr.h"
 #include "common/savefile.h"
 #include "common/system.h"
diff --git a/engines/ags/shared/util/alignedstream.cpp b/engines/ags/shared/util/alignedstream.cpp
index 8a8c24efa8..da2f3c8c36 100644
--- a/engines/ags/shared/util/alignedstream.cpp
+++ b/engines/ags/shared/util/alignedstream.cpp
@@ -20,7 +20,6 @@
  *
  */
 
-#include "ags/shared/debugging/assert.h"
 #include "ags/shared/util/alignedstream.h"
 #include "ags/shared/util/math.h"
 
diff --git a/engines/ags/shared/util/string.h b/engines/ags/shared/util/string.h
index f0c415d9ae..34afe4c1b0 100644
--- a/engines/ags/shared/util/string.h
+++ b/engines/ags/shared/util/string.h
@@ -49,7 +49,6 @@
 #include "ags/lib/std/vector.h"
 #include "ags/shared/core/platform.h"
 #include "ags/shared/core/types.h"
-#include "ags/shared/debugging/assert.h"
 #include "common/str.h"
 
 namespace AGS3 {


Commit: dfbcfd212cc7d6359b9ce29e69aec200ed0aa8aa
    https://github.com/scummvm/scummvm/commit/dfbcfd212cc7d6359b9ce29e69aec200ed0aa8aa
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T20:02:23-08:00

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

Changed paths:
    engines/ags/globals.cpp
    engines/ags/globals.h
    engines/ags/shared/font/ttffontrenderer.cpp
    engines/ags/shared/script/cc_options.cpp


diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 574be23846..3f8253e4d2 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -35,6 +35,7 @@
 #include "ags/shared/gui/guilistbox.h"
 #include "ags/shared/gui/guislider.h"
 #include "ags/shared/gui/guitextbox.h"
+#include "ags/shared/script/cc_options.h"
 #include "ags/shared/util/directory.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/draw_software.h"
@@ -92,6 +93,9 @@ Globals::Globals() {
 	// TODO: double check that ambient sounds array actually needs +1
 	_ambient = new std::array<AmbientSound>(MAX_SOUND_CHANNELS + 1);
 
+	// cc_options.cpp globals
+	_ccCompOptions = SCOPT_LEFTTORIGHT;
+
 	// debug.cpp globals
 	_fps = std::numeric_limits<float>::quiet_undefined();
 	_display_fps = kFPS_Hide;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 2166acfd70..f351523865 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -155,6 +155,15 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup cc_options globals
+	 * @{
+	 */
+
+	int _ccCompOptions;
+
+	/**@}*/
+
 	/**
 	 * \defgroup debug globals
 	 * @{
diff --git a/engines/ags/shared/font/ttffontrenderer.cpp b/engines/ags/shared/font/ttffontrenderer.cpp
index b19b413f76..0cb6cb4169 100644
--- a/engines/ags/shared/font/ttffontrenderer.cpp
+++ b/engines/ags/shared/font/ttffontrenderer.cpp
@@ -42,7 +42,7 @@ using namespace AGS::Shared;
 // project-specific implementation
 extern bool ShouldAntiAliasText();
 
-ALFONT_FONT *tempttffnt;
+static ALFONT_FONT *tempttffnt;
 ALFONT_FONT *get_ttf_block(unsigned char *fontptr) {
 	memcpy(&tempttffnt, &fontptr[4], sizeof(tempttffnt));
 	return tempttffnt;
diff --git a/engines/ags/shared/script/cc_options.cpp b/engines/ags/shared/script/cc_options.cpp
index d0b8c1b1e8..df1b959e6f 100644
--- a/engines/ags/shared/script/cc_options.cpp
+++ b/engines/ags/shared/script/cc_options.cpp
@@ -21,20 +21,19 @@
  */
 
 #include "ags/shared/script/cc_options.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
-int ccCompOptions = SCOPT_LEFTTORIGHT;
-
 void ccSetOption(int optbit, int onoroff) {
 	if (onoroff)
-		ccCompOptions |= optbit;
+		_G(ccCompOptions) |= optbit;
 	else
-		ccCompOptions &= ~optbit;
+		_G(ccCompOptions) &= ~optbit;
 }
 
 int ccGetOption(int optbit) {
-	if (ccCompOptions & optbit)
+	if (_G(ccCompOptions) & optbit)
 		return 1;
 
 	return 0;


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

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

Changed paths:
    engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
    engines/ags/engine/ac/dynobj/managedobjectpool.cpp
    engines/ags/engine/debugging/debug.cpp
    engines/ags/engine/script/cc_instance.cpp
    engines/ags/engine/script/script_engine.cpp
    engines/ags/globals.h
    engines/ags/shared/script/cc_error.cpp
    engines/ags/shared/script/cc_script.cpp
    engines/ags/shared/script/script_common.h


diff --git a/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp b/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
index 1c8074c9fb..e17b6ab77a 100644
--- a/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
+++ b/engines/ags/engine/ac/dynobj/cc_dynamicobject.cpp
@@ -104,7 +104,7 @@ int32_t ccGetObjectHandleFromAddress(const char *address) {
 
 	int32_t handl = _GP(pool).AddressToHandle(address);
 
-	ManagedObjectLog("Line %d WritePtr: %08X to %d", currentline, address, handl);
+	ManagedObjectLog("Line %d WritePtr: %08X to %d", _G(currentline), address, handl);
 
 	if (handl == 0) {
 		cc_error("Pointer cast failure: the object being pointed to is not in the managed object pool");
@@ -119,7 +119,7 @@ const char *ccGetObjectAddressFromHandle(int32_t handle) {
 	}
 	const char *addr = _GP(pool).HandleToAddress(handle);
 
-	ManagedObjectLog("Line %d ReadPtr: %d to %08X", currentline, handle, addr);
+	ManagedObjectLog("Line %d ReadPtr: %d to %08X", _G(currentline), handle, addr);
 
 	if (addr == nullptr) {
 		cc_error("Error retrieving pointer: invalid handle %d", handle);
diff --git a/engines/ags/engine/ac/dynobj/managedobjectpool.cpp b/engines/ags/engine/ac/dynobj/managedobjectpool.cpp
index 79fad80b3a..9e8516c75a 100644
--- a/engines/ags/engine/ac/dynobj/managedobjectpool.cpp
+++ b/engines/ags/engine/ac/dynobj/managedobjectpool.cpp
@@ -56,7 +56,7 @@ int ManagedObjectPool::Remove(ManagedObject &o, bool force) {
 	handleByAddress.erase(o.addr);
 	o = ManagedObject();
 
-	ManagedObjectLog("Line %d Disposed managed object handle=%d", currentline, handle);
+	ManagedObjectLog("Line %d Disposed managed object handle=%d", _G(currentline), handle);
 
 	return 1;
 }
@@ -71,7 +71,7 @@ int32_t ManagedObjectPool::AddRef(int32_t handle) {
 	}
 
 	o.refCount += 1;
-	ManagedObjectLog("Line %d AddRef: handle=%d new refcount=%d", currentline, o.handle, o.refCount);
+	ManagedObjectLog("Line %d AddRef: handle=%d new refcount=%d", _G(currentline), o.handle, o.refCount);
 	return o.refCount;
 }
 
@@ -105,7 +105,7 @@ int32_t ManagedObjectPool::SubRef(int32_t handle) {
 		CheckDispose(handle);
 	}
 	// object could be removed at this point, don't use any values.
-	ManagedObjectLog("Line %d SubRef: handle=%d new refcount=%d canBeDisposed=%d", currentline, handle, newRefCount, canBeDisposed);
+	ManagedObjectLog("Line %d SubRef: handle=%d new refcount=%d canBeDisposed=%d", _G(currentline), handle, newRefCount, canBeDisposed);
 	return newRefCount;
 }
 
diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index 9e12ac0779..13de177f31 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -282,7 +282,7 @@ void debug_script_print(const String &msg, MessageType mt) {
 			scriptname = "D ";
 		else
 			scriptname = "? ";
-		script_ref.Format("[%s%d]", scriptname.GetCStr(), currentline);
+		script_ref.Format("[%s%d]", scriptname.GetCStr(), _G(currentline));
 	}
 
 	Debug::Printf(kDbgGroup_Game, mt, "(room:%d)%s %s", displayed_room, script_ref.GetCStr(), msg.GetCStr());
diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index 0f8e94831b..dee0606c56 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -277,7 +277,7 @@ void ccInstance::AbortAndDestroy() {
 
 int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const RuntimeScriptValue *params) {
 	_G(ccError) = 0;
-	currentline = 0;
+	_G(currentline) = 0;
 
 	if (numargs > 0 && !params) {
 		cc_error("internal error in ccInstance::CallScriptFunction");
@@ -402,7 +402,7 @@ int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const
 	} \
 	callStackSize--;\
 	line_number = callStackLineNumber[callStackSize];\
-	currentline = line_number
+	_G(currentline) = line_number
 
 #define MAXNEST 50  // number of recursive function calls allowed
 int ccInstance::Run(int32_t curpc) {
@@ -531,9 +531,9 @@ int ccInstance::Run(int32_t curpc) {
 		switch (codeOp.Instruction.Code) {
 		case SCMD_LINENUM:
 			line_number = arg1.IValue;
-			currentline = arg1.IValue;
+			_G(currentline) = arg1.IValue;
 			if (new_line_hook)
-				new_line_hook(this, currentline);
+				new_line_hook(this, _G(currentline));
 			break;
 		case SCMD_ADD:
 			// If the the register is SREG_SP, we are allocating new variable on the stack
@@ -1288,7 +1288,7 @@ bool ccInstance::IsBeingRun() const {
 
 bool ccInstance::_Create(PScript scri, ccInstance *joined) {
 	int i;
-	currentline = -1;
+	_G(currentline) = -1;
 	if ((scri == nullptr) && (joined != nullptr))
 		scri = joined->instanceof;
 
diff --git a/engines/ags/engine/script/script_engine.cpp b/engines/ags/engine/script/script_engine.cpp
index 23ec48e8de..72957e11a2 100644
--- a/engines/ags/engine/script/script_engine.cpp
+++ b/engines/ags/engine/script/script_engine.cpp
@@ -35,6 +35,7 @@
 #include "ags/shared/script/cc_error.h"
 #include "ags/shared/util/file.h"
 #include "ags/shared/util/stream.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
@@ -47,12 +48,11 @@ class RoomStruct;
 using namespace AGS::Shared;
 
 extern void quit(const char *);
-extern int currentline; // in script/script_common
 
 std::pair<String, String> cc_error_at_line(const char *error_msg) {
 	ccInstance *sci = ccInstance::GetCurrentInstance();
 	if (!sci) {
-		return std::make_pair(String::FromFormat("Error (line %d): %s", currentline, error_msg), String());
+		return std::make_pair(String::FromFormat("Error (line %d): %s", _G(currentline), error_msg), String());
 	} else {
 		return std::make_pair(String::FromFormat("Error: %s\n", error_msg), ccInstance::GetCurrentInstance()->GetCallStack(5));
 	}
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index f351523865..242741291d 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -164,6 +164,18 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup cc_script globals
+	 * @{
+	 */
+
+	// currently executed line
+	int _currentline = 0;
+	// script file format signature
+	const char _scfilesig[5] = "SCOM";
+
+	/**@}*/
+
 	/**
 	 * \defgroup debug globals
 	 * @{
diff --git a/engines/ags/shared/script/cc_error.cpp b/engines/ags/shared/script/cc_error.cpp
index 4c3c9d527d..b435eb297e 100644
--- a/engines/ags/shared/script/cc_error.cpp
+++ b/engines/ags/shared/script/cc_error.cpp
@@ -46,7 +46,7 @@ void cc_error(const char *descr, ...) {
 	String displbuf = String::FromFormatV(descr, ap);
 	va_end(ap);
 
-	if (currentline > 0) {
+	if (_G(currentline) > 0) {
 		// [IKM] Implementation is project-specific
 		std::pair<String, String> errinfo = cc_error_at_line(displbuf);
 		_G(ccErrorString) = errinfo.first;
@@ -57,7 +57,7 @@ void cc_error(const char *descr, ...) {
 	}
 
 	_G(ccError) = 1;
-	_G(ccErrorLine) = currentline;
+	_G(ccErrorLine) = _G(currentline);
 }
 
 } // namespace AGS3
diff --git a/engines/ags/shared/script/cc_script.cpp b/engines/ags/shared/script/cc_script.cpp
index 5a0411651b..1f6513c64d 100644
--- a/engines/ags/shared/script/cc_script.cpp
+++ b/engines/ags/shared/script/cc_script.cpp
@@ -25,16 +25,12 @@
 #include "ags/shared/script/script_common.h"
 #include "ags/shared/util/stream.h"
 #include "ags/shared/util/string_compat.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
 using AGS::Shared::Stream;
 
-// currently executed line
-int currentline;
-// script file format signature
-const char scfilesig[5] = "SCOM";
-
 // [IKM] I reckon this function is almost identical to fgetstring in string_utils
 void freadstring(char **strptr, Stream *in) {
 	static char ibuffer[300];
@@ -177,7 +173,7 @@ ccScript::~ccScript() {
 
 void ccScript::Write(Shared::Stream *out) {
 	int n;
-	out->Write(scfilesig, 4);
+	out->Write(_G(scfilesig), 4);
 	out->WriteInt32(SCOM_VERSION);
 	out->WriteInt32(globaldatasize);
 	out->WriteInt32(codesize);
@@ -213,14 +209,14 @@ bool ccScript::Read(Shared::Stream *in) {
 	instances = 0;
 	int n;
 	char gotsig[5];
-	currentline = -1;
+	_G(currentline) = -1;
 	// MACPORT FIX: swap 'size' and 'nmemb'
 	in->Read(gotsig, 4);
 	gotsig[4] = 0;
 
 	int fileVer = in->ReadInt32();
 
-	if ((strcmp(gotsig, scfilesig) != 0) || (fileVer > SCOM_VERSION)) {
+	if ((strcmp(gotsig, _G(scfilesig)) != 0) || (fileVer > SCOM_VERSION)) {
 		cc_error("file was not written by ccScript::Write or seek position is incorrect");
 		return false;
 	}
diff --git a/engines/ags/shared/script/script_common.h b/engines/ags/shared/script/script_common.h
index 3e95067c86..f6b52760a3 100644
--- a/engines/ags/shared/script/script_common.h
+++ b/engines/ags/shared/script/script_common.h
@@ -132,12 +132,6 @@ namespace AGS3 {
 #define FIXUP_DATADATA    5     // globaldata[fixup] += &globaldata[0]
 #define FIXUP_STACK       6     // code[fixup] += &stack[0]
 
-
-
-
-extern int currentline;
-// Script file signature
-extern const char scfilesig[5];
 #define ENDFILESIG 0xbeefcafe
 
 } // namespace AGS3


Commit: 497ef2df1a0ed8c9c15b2d516f2856918bb9cdd1
    https://github.com/scummvm/scummvm/commit/497ef2df1a0ed8c9c15b2d516f2856918bb9cdd1
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-03-06T20:15:51-08:00

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

Changed paths:
    engines/ags/globals.h
    engines/ags/shared/util/compress.cpp
    engines/ags/shared/util/lzw.cpp
    engines/ags/shared/util/lzw.h


diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 242741291d..a2be9f6483 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -454,6 +454,18 @@ public:
 
 	/**@}*/
 
+	/**
+	 * \defgroup lzw globals
+	 * @{
+	 */
+
+	char *_lzbuffer = nullptr;
+	int *_node = nullptr;
+	int _pos = 0;
+	long _outbytes = 0, _maxsize = 0, _putbytes = 0;
+
+	/**@}*/
+
 	/**
 	 * \defgroup main globals
 	 * @{
diff --git a/engines/ags/shared/util/compress.cpp b/engines/ags/shared/util/compress.cpp
index e491a601e0..8767f9bf4e 100644
--- a/engines/ags/shared/util/compress.cpp
+++ b/engines/ags/shared/util/compress.cpp
@@ -26,6 +26,7 @@
 #include "ags/shared/util/lzw.h"
 #include "ags/shared/util/misc.h"
 #include "ags/shared/util/stream.h"
+#include "ags/globals.h"
 #if AGS_PLATFORM_ENDIAN_BIG
 #include "ags/shared/util/bbop.h"
 #endif
@@ -322,12 +323,12 @@ void load_lzw(Stream *in, Bitmap **dst_bmp, int dst_bpp, color *pall) {
 	int           arin;
 
 	in->SafeReadArray(&pall[0], PALETTE_COUNT);
-	maxsize = in->ReadInt32();
+	_G(maxsize) = in->ReadInt32();
 	uncompsiz = in->ReadInt32();
 
 	uncompsiz += in->GetPosition();
-	outbytes = 0;
-	putbytes = 0;
+	_G(outbytes) = 0;
+	_G(putbytes) = 0;
 
 	update_polled_stuff_if_runtime();
 	membuffer = lzwexpand_to_mem(in);
diff --git a/engines/ags/shared/util/lzw.cpp b/engines/ags/shared/util/lzw.cpp
index 4428d0013d..cf0da2a474 100644
--- a/engines/ags/shared/util/lzw.cpp
+++ b/engines/ags/shared/util/lzw.cpp
@@ -11,7 +11,7 @@
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR_G(pos)E.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
@@ -28,6 +28,7 @@
 
 #include "ags/shared/ac/common.h" // quit
 #include "ags/shared/util/stream.h"
+#include "ags/globals.h"
 
 namespace AGS3 {
 
@@ -46,17 +47,12 @@ void _delete(int);
 #define THRESHOLD 3
 #define min(xx,yy) ((yy<xx) ? yy : xx)
 
-#define dad (node+1)
-#define lson (node+1+N)
-#define rson (node+1+N+N)
-#define root (node+1+N+N+N)
+#define dad (_G(node)+1)
+#define lson (_G(node)+1+N)
+#define rson (_G(node)+1+N+N)
+#define root (_G(node)+1+N+N+N)
 #define NIL -1
 
-char *lzbuffer;
-int *node;
-int pos;
-long outbytes = 0, maxsize = 0, putbytes = 0;
-
 int insert(int i, int run) {
 	int c, j, k, l, n, match;
 	int *p;
@@ -65,14 +61,14 @@ int insert(int i, int run) {
 
 	k = l = 1;
 	match = THRESHOLD - 1;
-	p = &root[(unsigned char)lzbuffer[i]];
+	p = &root[(unsigned char)_G(lzbuffer)[i]];
 	lson[i] = rson[i] = NIL;
 	while ((j = *p) != NIL) {
-		for (n = min(k, l); n < run && (c = (lzbuffer[j + n] - lzbuffer[i + n])) == 0; n++);
+		for (n = min(k, l); n < run && (c = (_G(lzbuffer)[j + n] - _G(lzbuffer)[i + n])) == 0; n++);
 
 		if (n > match) {
 			match = n;
-			pos = j;
+			_G(pos) = j;
 		}
 
 		if (c < 0) {
@@ -83,15 +79,15 @@ int insert(int i, int run) {
 			l = n;
 		} else {
 			dad[j] = NIL;
-			dad[lson[j]] = lson + i - node;
-			dad[rson[j]] = rson + i - node;
+			dad[lson[j]] = lson + i - _G(node);
+			dad[rson[j]] = rson + i - _G(node);
 			lson[i] = lson[j];
 			rson[i] = rson[j];
 			break;
 		}
 	}
 
-	dad[i] = p - node;
+	dad[i] = p - _G(node);
 	*p = i;
 	return match;
 }
@@ -111,18 +107,18 @@ void _delete(int z) {
 					j = rson[j];
 				} while (rson[j] != NIL);
 
-				node[dad[j]] = lson[j];
+				_G(node)[dad[j]] = lson[j];
 				dad[lson[j]] = dad[j];
 				lson[j] = lson[z];
-				dad[lson[z]] = lson + j - node;
+				dad[lson[z]] = lson + j - _G(node);
 			}
 
 			rson[j] = rson[z];
-			dad[rson[z]] = rson + j - node;
+			dad[rson[z]] = rson + j - _G(node);
 		}
 
 		dad[j] = dad[z];
-		node[dad[z]] = j;
+		_G(node)[dad[z]] = j;
 		dad[z] = NIL;
 	}
 }
@@ -131,12 +127,12 @@ void lzwcompress(Stream *lzw_in, Stream *out) {
 	int ch, i, run, len, match, size, mask;
 	char buf[17];
 
-	lzbuffer = (char *)malloc(N + F + (N + 1 + N + N + 256) * sizeof(int));       // 28.5 k !
-	if (lzbuffer == nullptr) {
+	_G(lzbuffer) = (char *)malloc(N + F + (N + 1 + N + N + 256) * sizeof(int));       // 28.5 k !
+	if (_G(lzbuffer) == nullptr) {
 		quit("unable to compress: out of memory");
 	}
 
-	node = (int *)(lzbuffer + N + F);
+	_G(node) = (int *)(_G(lzbuffer) + N + F);
 	for (i = 0; i < 256; i++)
 		root[i] = NIL;
 
@@ -148,7 +144,7 @@ void lzwcompress(Stream *lzw_in, Stream *out) {
 	i = N - F - F;
 
 	for (len = 0; len < F && (ch = lzw_in->ReadByte()) != -1; len++) {
-		lzbuffer[i + F] = ch;
+		_G(lzbuffer)[i + F] = ch;
 		i = (i + 1) & (N - 1);
 	}
 
@@ -158,10 +154,10 @@ void lzwcompress(Stream *lzw_in, Stream *out) {
 		ch = lzw_in->ReadByte();
 		if (i >= N - F) {
 			_delete(i + F - N);
-			lzbuffer[i + F] = lzbuffer[i + F - N] = ch;
+			_G(lzbuffer)[i + F] = _G(lzbuffer)[i + F - N] = ch;
 		} else {
 			_delete(i + F);
-			lzbuffer[i + F] = ch;
+			_G(lzbuffer)[i + F] = ch;
 		}
 
 		match = insert(i, run);
@@ -173,18 +169,18 @@ void lzwcompress(Stream *lzw_in, Stream *out) {
 		if (len++ >= run) {
 			if (match >= THRESHOLD) {
 				buf[0] |= mask;
-				// possible fix: change int* to short* ??
-				*(short *)(buf + size) = ((match - 3) << 12) | ((i - pos - 1) & (N - 1));
+				// _G(pos)sible fix: change int* to short* ??
+				*(short *)(buf + size) = ((match - 3) << 12) | ((i - _G(pos) - 1) & (N - 1));
 				size += 2;
 				len -= match;
 			} else {
-				buf[size++] = lzbuffer[i];
+				buf[size++] = _G(lzbuffer)[i];
 				len--;
 			}
 
 			if (!((mask += mask) & 0xFF)) {
 				out->WriteArray(buf, size, 1);
-				outbytes += size;
+				_G(outbytes) += size;
 				size = mask = 1;
 				buf[0] = 0;
 			}
@@ -194,22 +190,22 @@ void lzwcompress(Stream *lzw_in, Stream *out) {
 
 	if (size > 1) {
 		out->WriteArray(buf, size, 1);
-		outbytes += size;
+		_G(outbytes) += size;
 	}
 
-	free(lzbuffer);
+	free(_G(lzbuffer));
 }
 
 int expand_to_mem = 0;
 unsigned char *membfptr = nullptr;
 void myputc(int ccc, Stream *out) {
-	if (maxsize > 0) {
-		putbytes++;
-		if (putbytes > maxsize)
+	if (_G(maxsize) > 0) {
+		_G(putbytes)++;
+		if (_G(putbytes) > _G(maxsize))
 			return;
 	}
 
-	outbytes++;
+	_G(outbytes)++;
 	if (expand_to_mem) {
 		membfptr[0] = ccc;
 		membfptr++;
@@ -221,7 +217,7 @@ void lzwexpand(Stream *lzw_in, Stream *out) {
 	int bits, ch, i, j, len, mask;
 	char *lzBuffer;
 	//  printf(" UnShrinking: %s ",filena);
-	putbytes = 0;
+	_G(putbytes) = 0;
 
 	lzBuffer = (char *)malloc(N);
 	if (lzBuffer == nullptr) {
@@ -252,14 +248,14 @@ void lzwexpand(Stream *lzw_in, Stream *out) {
 				i = (i + 1) & (N - 1);
 			}
 
-			if ((putbytes >= maxsize) && (maxsize > 0))
+			if ((_G(putbytes) >= _G(maxsize)) && (_G(maxsize) > 0))
 				break;
 
-			if ((lzw_in->EOS()) && (maxsize > 0))
+			if ((lzw_in->EOS()) && (_G(maxsize) > 0))
 				quit("Read error decompressing image - file is corrupt");
 		}                           // end for mask
 
-		if ((putbytes >= maxsize) && (maxsize > 0))
+		if ((_G(putbytes) >= _G(maxsize)) && (_G(maxsize) > 0))
 			break;
 	}
 
@@ -268,7 +264,7 @@ void lzwexpand(Stream *lzw_in, Stream *out) {
 }
 
 unsigned char *lzwexpand_to_mem(Stream *in) {
-	unsigned char *membuff = (unsigned char *)malloc(maxsize + 10);
+	unsigned char *membuff = (unsigned char *)malloc(_G(maxsize) + 10);
 	expand_to_mem = 1;
 	membfptr = membuff;
 	lzwexpand(in, nullptr);
diff --git a/engines/ags/shared/util/lzw.h b/engines/ags/shared/util/lzw.h
index bbb0404647..2703b838c6 100644
--- a/engines/ags/shared/util/lzw.h
+++ b/engines/ags/shared/util/lzw.h
@@ -36,8 +36,6 @@ using namespace AGS; // FIXME later
 void lzwcompress(Shared::Stream *lzw_in, Shared::Stream *out);
 unsigned char *lzwexpand_to_mem(Shared::Stream *in);
 
-extern long outbytes, maxsize, putbytes;
-
 } // namespace AGS3
 
 #endif


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

Commit Message:
AGS: Refactor out global Strings in multifilelib.cpp

Changed paths:
    engines/ags/shared/util/mutifilelib.cpp


diff --git a/engines/ags/shared/util/mutifilelib.cpp b/engines/ags/shared/util/mutifilelib.cpp
index 5d1eac5c5b..2f51655541 100644
--- a/engines/ags/shared/util/mutifilelib.cpp
+++ b/engines/ags/shared/util/mutifilelib.cpp
@@ -31,8 +31,8 @@ namespace Shared {
 
 namespace MFLUtil {
 
-const String HeadSig = "CLIB\x1a";
-const String TailSig = "CLIB\x1\x2\x3\x4SIGE";
+static const char *HEAD_SIG = "CLIB\x1a";
+static const char *TAIL_SIG = "CLIB\x1\x2\x3\x4SIGE";
 
 static const size_t SingleFilePswLen = 13;
 
@@ -106,6 +106,7 @@ MFLUtil::MFLError MFLUtil::ReadHeader(AssetLibInfo &lib, Stream *in) {
 }
 
 MFLUtil::MFLError MFLUtil::ReadSigsAndVersion(Stream *in, MFLVersion *p_lib_version, soff_t *p_abs_offset) {
+	String HeadSig(HEAD_SIG), TailSig(TAIL_SIG);
 	soff_t abs_offset = 0; // library offset in this file
 	String sig;
 	// check multifile lib signature at the beginning of file
@@ -331,7 +332,8 @@ MFLUtil::MFLError MFLUtil::ReadV30(AssetLibInfo &lib, Stream *in, MFLVersion /*
 }
 
 void MFLUtil::WriteHeader(const AssetLibInfo &lib, MFLVersion lib_version, int lib_index, Stream *out) {
-	out->Write(MFLUtil::HeadSig, MFLUtil::HeadSig.GetLength());
+	String HeadSig(HEAD_SIG);
+	out->Write(HeadSig, HeadSig.GetLength());
 	out->WriteByte(lib_version);
 	out->WriteByte(lib_index);   // file number
 
@@ -360,6 +362,8 @@ void MFLUtil::WriteV30(const AssetLibInfo &lib, MFLVersion lib_version, Stream *
 }
 
 void MFLUtil::WriteEnder(soff_t lib_offset, MFLVersion lib_index, Stream *out) {
+	String TailSig(TAIL_SIG);
+
 	if (lib_index < kMFLVersion_MultiV30)
 		out->WriteInt32((int32_t)lib_offset);
 	else




More information about the Scummvm-git-logs mailing list