[Scummvm-cvs-logs] SF.net SVN: scummvm:[38340] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Feb 16 02:58:30 CET 2009


Revision: 38340
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38340&view=rev
Author:   fingolfin
Date:     2009-02-16 01:58:30 +0000 (Mon, 16 Feb 2009)

Log Message:
-----------
Reimplemented reg_t_hashmap using Common::HashMap

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/gc.cpp
    scummvm/trunk/engines/sci/engine/gc.h
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/module.mk
    scummvm/trunk/engines/sci/sci.h

Removed Paths:
-------------
    scummvm/trunk/engines/sci/include/reg_t_hashmap.h
    scummvm/trunk/engines/sci/scicore/reg_t_hashmap.cpp

Modified: scummvm/trunk/engines/sci/engine/gc.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/gc.cpp	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/engine/gc.cpp	2009-02-16 01:58:30 UTC (rev 38340)
@@ -45,9 +45,8 @@
 }
 
 static void
-worklist_push(worklist_t **wlp, reg_t_hash_map_ptr hashmap, reg_t reg) {
+worklist_push(worklist_t **wlp, reg_t_hash_map *hashmap, reg_t reg) {
 	worklist_t *wl = *wlp;
-	char added;
 
 	if (!reg.segment) /* No numbers */
 		return;
@@ -56,11 +55,12 @@
 	sciprintf("[GC] Adding "PREG"\n", PRINT_REG(reg));
 #endif
 
-	reg_t_hash_map_check_value(hashmap, reg, 1, &added);
-
-	if (!added)
+	
+	if (hashmap->contains(reg))
 		return; /* already dealt with it */
 
+	hashmap->setVal(reg, true);
+
 	if (!wl || wl->used == WORKLIST_CHUNK_SIZE)
 		*wlp = wl = fresh_worklist(wl);
 
@@ -101,41 +101,29 @@
 	}
 }
 
-typedef struct {
-	seg_interface_t **interfaces;
-	int interfaces_nr;
-	reg_t_hash_map_ptr normal_map;
-} normaliser_t;
+static reg_t_hash_map *
+normalise_hashmap_ptrs(reg_t_hash_map *nonnormal_map, seg_interface_t **interfaces, int interfaces_nr) {
+	reg_t_hash_map *normal_map = new reg_t_hash_map();
 
-void
-store_normalised(void *pre_normaliser, reg_t reg, int _) {
-	seg_interface_t *interfce;
-	normaliser_t *normaliser = (normaliser_t *) pre_normaliser;
-	interfce = (reg.segment < normaliser->interfaces_nr)
-	           ? normaliser->interfaces[reg.segment]
-	           : NULL;
-
-	if (interfce) {
-		reg = interfce->find_canonic_address(interfce, reg);
-		reg_t_hash_map_check_value(normaliser->normal_map, reg, 1, NULL);
+	for (reg_t_hash_map::iterator i = nonnormal_map->begin(); i != nonnormal_map->end(); ++i) {
+		seg_interface_t *interfce;
+		reg_t reg = i->_key;
+		interfce = (reg.segment < interfaces_nr)
+				   ? interfaces[reg.segment]
+				   : NULL;
+	
+		if (interfce) {
+			reg = interfce->find_canonic_address(interfce, reg);
+			normal_map->setVal(reg, true);
+		}
 	}
-}
 
-static reg_t_hash_map_ptr
-normalise_hashmap_ptrs(reg_t_hash_map_ptr nonnormal_map, seg_interface_t **interfaces, int interfaces_nr) {
-	normaliser_t normaliser;
-
-	normaliser.normal_map = new_reg_t_hash_map();
-	normaliser.interfaces_nr = interfaces_nr;
-	normaliser.interfaces = interfaces;
-	apply_to_reg_t_hash_map(nonnormal_map, &normaliser, &store_normalised);
-
-	return normaliser.normal_map;
+	return normal_map;
 }
 
 
 typedef struct {
-	reg_t_hash_map_ptr nonnormal_map;
+	reg_t_hash_map *nonnormal_map;
 	worklist_t **worklist_ref;
 } worklist_manager_t;
 
@@ -145,12 +133,12 @@
 	worklist_push(wm->worklist_ref, wm->nonnormal_map, addr);
 }
 
-reg_t_hash_map_ptr
+reg_t_hash_map *
 find_all_used_references(state_t *s) {
 	seg_manager_t *sm = &(s->seg_manager);
 	seg_interface_t **interfaces = (seg_interface_t**)sci_calloc(sizeof(seg_interface_t *), sm->heap_size);
-	reg_t_hash_map_ptr nonnormal_map = new_reg_t_hash_map();
-	reg_t_hash_map_ptr normal_map = NULL;
+	reg_t_hash_map *nonnormal_map = new reg_t_hash_map();
+	reg_t_hash_map *normal_map = NULL;
 	worklist_t *worklist = new_worklist();
 	worklist_manager_t worklist_manager;
 	int i;
@@ -248,7 +236,7 @@
 		if (interfaces[i])
 			interfaces[i]->deallocate_self(interfaces[i]);
 	sci_free(interfaces);
-	free_reg_t_hash_map(nonnormal_map);
+	delete nonnormal_map;
 	return normal_map;
 }
 
@@ -259,15 +247,15 @@
 	char *segnames[MEM_OBJ_MAX + 1];
 	int segcount[MEM_OBJ_MAX + 1];
 #endif
-	reg_t_hash_map_ptr use_map;
+	reg_t_hash_map *use_map;
 } deallocator_t;
 
 void
 free_unless_used(void *pre_use_map, reg_t addr) {
 	deallocator_t *deallocator = (deallocator_t *) pre_use_map;
-	reg_t_hash_map_ptr use_map = deallocator->use_map;
+	reg_t_hash_map *use_map = deallocator->use_map;
 
-	if (0 > reg_t_hash_map_check_value(use_map, addr, 0, NULL)) {
+	if (!use_map->contains(addr)) {
 		/* Not found -> we can free it */
 		deallocator->interfce->free_at_address(deallocator->interfce, addr);
 #ifdef DEBUG_GC
@@ -306,7 +294,7 @@
 			deallocator.interfce->deallocate_self(deallocator.interfce);
 		}
 
-	free_reg_t_hash_map(deallocator.use_map);
+	delete deallocator.use_map;
 
 #ifdef DEBUG_GC
 	{

Modified: scummvm/trunk/engines/sci/engine/gc.h
===================================================================
--- scummvm/trunk/engines/sci/engine/gc.h	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/engine/gc.h	2009-02-16 01:58:30 UTC (rev 38340)
@@ -22,14 +22,32 @@
 #ifndef GC_H_
 #define GC_H_
 
-#include "sci/include/reg_t_hashmap.h"
+#include "common/hashmap.h"
+#include "sci/include/vm_types.h"
 #include "sci/include/engine.h"
 
-reg_t_hash_map_ptr
+
+struct reg_t_EqualTo {
+	bool operator()(const reg_t& x, const reg_t& y) const {
+		return (x.segment == y.segment) && (x.offset == y.offset);
+	}
+};
+
+struct reg_t_Hash {
+	uint operator()(const reg_t& x) const {
+		return (x.segment << 3) | x.offset;
+	}
+};
+
+// The reg_t_hash_map is actually really a hashset
+typedef Common::HashMap<reg_t, bool, reg_t_Hash, reg_t_EqualTo> reg_t_hash_map;
+
+
+reg_t_hash_map *
 find_all_used_references(state_t *s);
 /* Finds all used references and normalises them to their memory addresses
 ** Parameters: (state_t *) s: The state to gather all information from
-** Returns   : (reg_t_hash_map_ptr) A hash map containing entries for all used references
+** Returns   : (reg_t_hash_map *) A hash map containing entries for all used references
 */
 
 void

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-02-16 01:58:30 UTC (rev 38340)
@@ -34,7 +34,6 @@
 #include "sci/engine/kernel_types.h"
 #include "sci/include/sci_midi.h"
 #include "sci/include/sci_widgets.h"
-#include "sci/include/reg_t_hashmap.h"
 
 #include "common/util.h"
 
@@ -3278,19 +3277,16 @@
 	return 0;
 }
 
-static void
-print_all_of_them(void *_1, reg_t reg, int _2) {
-	sciprintf(" - "PREG"\n", PRINT_REG(reg));
-}
-
 static int
 c_gc_list_reachable(state_t *s) {
-	reg_t_hash_map_ptr use_map = find_all_used_references(s);
+	reg_t_hash_map *use_map = find_all_used_references(s);
 
 	sciprintf("Reachable references (normalised):\n");
-	apply_to_reg_t_hash_map(use_map, NULL, print_all_of_them);
+	for (reg_t_hash_map::iterator i = use_map->begin(); i != use_map->end(); ++i) {
+		sciprintf(" - "PREG"\n", PRINT_REG(i->_key));
+	}
 
-	free_reg_t_hash_map(use_map);
+	delete use_map;
 	return 0;
 }
 

Deleted: scummvm/trunk/engines/sci/include/reg_t_hashmap.h
===================================================================
--- scummvm/trunk/engines/sci/include/reg_t_hashmap.h	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/include/reg_t_hashmap.h	2009-02-16 01:58:30 UTC (rev 38340)
@@ -1,71 +0,0 @@
-/***************************************************************************
- int_hashmap.h Copyright (C) 2001 Christoph Reichenbach
-
-
- This program may be modified and copied freely according to the terms of
- the GNU general public license (GPL), as long as the above copyright
- notice and the licensing information contained herein are preserved.
-
- Please refer to www.gnu.org for licensing details.
-
- This work is provided AS IS, without warranty of any kind, expressed or
- implied, including but not limited to the warranties of merchantibility,
- noninfringement, and fitness for a specific purpose. The author will not
- be held liable for any damage caused by this work or derivatives of it.
-
- By using this source code, you agree to the licensing terms as stated
- above.
-
-
- Please contact the maintainer for bug reports or inquiries.
-
- Current Maintainer:
-
-    Christoph Reichenbach (CR) <jameson at linuxgames.com>
-
-***************************************************************************/
-
-#ifndef _REG_T_HASHMAP_H_
-#define _REG_T_HASHMAP_H_
-
-#define DCS_REGT_HASH_MAX 512
-
-#include "vm.h"
-#ifdef HASH_MAX
-#  undef HASH_MAX
-#  undef COMP
-#  undef HASH
-#endif
-
-#define HASH_MAX DCS_REGT_HASH_MAX
-#define COMP(x, y) compare_reg_t(x, y)
-#define HASH(x) (((x.segment << 3) | x.offset) & 0x1ff)
-#undef MUST_FREE
-
-#include "hashmap.h"
-DECLARE_STRUCTS(reg_t)
-DECLARE_FUNCTIONS(reg_t)
-
-#ifndef BUILD_MAP_FUNCTIONS
-#  undef HASH_MAX
-#  undef COMP
-#  undef HASH
-#endif
-
-/* see hashmap.h for descriptions of these functions */
-reg_t_hash_map_ptr
-new_reg_t_hash_map(void);
-
-void
-free_reg_t_hash_map(reg_t_hash_map_ptr);
-
-int
-reg_t_hash_map_check_value(reg_t_hash_map_ptr, reg_t value, char add_p, char *added);
-
-int
-reg_t_hash_map_remove_value(reg_t_hash_map_ptr, reg_t value);
-
-void
-apply_to_reg_t_hash_map(reg_t_hash_map_ptr map, void *param, void (*note)(void *param, reg_t name, int value));
-
-#endif /* _INT_HASHMAP_H_ */

Modified: scummvm/trunk/engines/sci/module.mk
===================================================================
--- scummvm/trunk/engines/sci/module.mk	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/module.mk	2009-02-16 01:58:30 UTC (rev 38340)
@@ -58,7 +58,6 @@
 	scicore/exe_lzexe.o \
 	scicore/exe_raw.o \
 	scicore/int_hashmap.o \
-	scicore/reg_t_hashmap.o \
 	scicore/resource.o \
 	scicore/resource_map.o \
 	scicore/resource_patch.o \

Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/sci.h	2009-02-16 01:58:30 UTC (rev 38340)
@@ -1,3 +1,28 @@
+/* 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.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/engines/agi/agi.cpp $
+ * $Id: agi.cpp 36279 2009-02-12 15:13:52Z thebluegr $
+ *
+ */
+
 #ifndef SCI_H
 #define SCI_H
 

Deleted: scummvm/trunk/engines/sci/scicore/reg_t_hashmap.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/reg_t_hashmap.cpp	2009-02-16 01:58:20 UTC (rev 38339)
+++ scummvm/trunk/engines/sci/scicore/reg_t_hashmap.cpp	2009-02-16 01:58:30 UTC (rev 38340)
@@ -1,41 +0,0 @@
-/***************************************************************************
- int_hashmap. Copyright (C) 2001 Christoph Reichenbach
-
-
- This program may be modified and copied freely according to the terms of
- the GNU general public license (GPL), as long as the above copyright
- notice and the licensing information contained herein are preserved.
-
- Please refer to www.gnu.org for licensing details.
-
- This work is provided AS IS, without warranty of any kind, expressed or
- implied, including but not limited to the warranties of merchantibility,
- noninfringement, and fitness for a specific purpose. The author will not
- be held liable for any damage caused by this work or derivatives of it.
-
- By using this source code, you agree to the licensing terms as stated
- above.
-
-
- Please contact the maintainer for bug reports or inquiries.
-
- Current Maintainer:
-
-    Christoph Reichenbach (CR) <jameson at linuxgames.com>
-
-***************************************************************************/
-
-#define BUILD_MAP_FUNCTIONS
-#include "sci/include/reg_t_hashmap.h"
-
-#include "sci/scicore/hashmap.cpp"
-
-static inline int
-compare_reg_t (reg_t lhs, reg_t rhs) {
-	if (lhs.segment == rhs.segment)
-		return lhs.offset - rhs.offset;
-	else
-		return lhs.segment - rhs.segment;
-}
-
-DEFINE_FUNCTIONS(reg_t)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list