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

dreammaster paulfgilbert at gmail.com
Sun Feb 2 00:57:04 UTC 2020


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

Summary:
be279002b3 NUVIE: Workaround pointer issues with IAVLKey


Commit: be279002b3e6856816a65ce345b0ddf61f32e2c6
    https://github.com/scummvm/scummvm/commit/be279002b3e6856816a65ce345b0ddf61f32e2c6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-02-01T16:56:56-08:00

Commit Message:
NUVIE: Workaround pointer issues with IAVLKey

Changed paths:
    engines/ultima/nuvie/core/obj_manager.cpp
    engines/ultima/nuvie/misc/iavl_tree.h
    engines/ultima/nuvie/script/script.cpp


diff --git a/engines/ultima/nuvie/core/obj_manager.cpp b/engines/ultima/nuvie/core/obj_manager.cpp
index 60cb30d..a530365 100644
--- a/engines/ultima/nuvie/core/obj_manager.cpp
+++ b/engines/ultima/nuvie/core/obj_manager.cpp
@@ -1708,10 +1708,13 @@ inline iAVLKey ObjManager::get_obj_tree_key(Obj *obj) {
 }
 
 iAVLKey ObjManager::get_obj_tree_key(uint16 x, uint16 y, uint8 level) {
+	iAVLKey key;
 	if (level == 0)
-		return y * 1024 + x;
+		key._int = y * 1024 + x;
 	else
-		return y * 256 + x;
+		key._int = y * 256 + x;
+
+	return key;
 }
 
 void ObjManager::update(uint16 x, uint16 y, uint8 z, bool teleport) {
diff --git a/engines/ultima/nuvie/misc/iavl_tree.h b/engines/ultima/nuvie/misc/iavl_tree.h
index 07f7c63..b2467ba 100644
--- a/engines/ultima/nuvie/misc/iavl_tree.h
+++ b/engines/ultima/nuvie/misc/iavl_tree.h
@@ -27,10 +27,15 @@ namespace Ultima {
 namespace Nuvie {
 
 /* typedef the keytype */
-typedef long iAVLKey;
+// TODO: Clean up object manager so it isn't intermixing pointers and ints
+//typedef long iAVLKey;
+union iAVLKey {
+	void *_ptr;
+	long _int;
+};
 
 /* Comparison function for integers is subtraction. */
-#define iAVLKey_cmp(tree, a, b) ((a) - (b))
+#define iAVLKey_cmp(tree, a, b) ((a._int) - (b._int))
 
 
 typedef struct _iAVLNode {
diff --git a/engines/ultima/nuvie/script/script.cpp b/engines/ultima/nuvie/script/script.cpp
index c619ba3..2be650a 100644
--- a/engines/ultima/nuvie/script/script.cpp
+++ b/engines/ultima/nuvie/script/script.cpp
@@ -124,7 +124,7 @@ struct ScriptObjRef {
 
 	ScriptObjRef() {
 		refcount = 0;
-		key = -1;
+		key._int = -1;
 	};
 };
 
@@ -1676,13 +1676,14 @@ int nscript_obj_new(lua_State *L, Obj *obj) {
 
 sint32 nscript_inc_obj_ref_count(Obj *obj) {
 	ScriptObjRef *obj_ref;
-	iAVLKey key = (iAVLKey)obj;
+	iAVLKey key;
+	key._ptr = obj;
 
 	obj_ref = (ScriptObjRef *)iAVLSearch(script_obj_list, key);
 	if (obj_ref == NULL) {
 		obj->set_in_script(true); // mark as being used by script engine.
 		obj_ref =  new ScriptObjRef();
-		obj_ref->key = (iAVLKey)obj;
+		obj_ref->key._ptr = obj;
 		iAVLInsert(script_obj_list, obj_ref);
 	}
 
@@ -1693,7 +1694,8 @@ sint32 nscript_inc_obj_ref_count(Obj *obj) {
 
 sint32 nscript_dec_obj_ref_count(Obj *obj) {
 	ScriptObjRef *obj_ref;
-	iAVLKey key = (iAVLKey)obj;
+	iAVLKey key;
+	key._ptr = obj;
 
 	obj_ref = (ScriptObjRef *)iAVLSearch(script_obj_list, key);
 	if (obj_ref == NULL)




More information about the Scummvm-git-logs mailing list