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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun May 31 04:37:25 CEST 2009


Revision: 41057
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41057&view=rev
Author:   thebluegr
Date:     2009-05-31 02:37:24 +0000 (Sun, 31 May 2009)

Log Message:
-----------
More objectification of the Vocabulary functions

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kernel.h
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/engine/kmovement.cpp
    scummvm/trunk/engines/sci/engine/kstring.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/script.cpp
    scummvm/trunk/engines/sci/engine/script.h
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/engine/vm.h
    scummvm/trunk/engines/sci/vocabulary.cpp
    scummvm/trunk/engines/sci/vocabulary.h

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/console.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -243,7 +243,7 @@
 		return true;
 	}
 
-	script_dissect(_vm->getResMgr(), atoi(argv[1]), g_EngineState->_vocabulary->_parserWords, g_EngineState->_vocabulary->_selectorNames);
+	script_dissect(_vm->getResMgr(), atoi(argv[1]), g_EngineState->_vocabulary);
 
 	return true;
 }

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -370,11 +370,9 @@
 	s->_executionStack.clear();    // Start without any execution stack
 	s->execution_stack_base = -1; // No vm is running yet
 
-	s->_vocabulary = new Vocabulary(s);	// TODO: delete
+	s->parser_lastmatch_word = SAID_NO_MATCH;
 
-	// TODO: move this inside the Vocabulary constructor
-	// Map a few special selectors for later use
-	script_map_selectors(s, &(s->selector_map));
+	s->_vocabulary = new Vocabulary(s);
 
 	script_map_kernel(s);
 	// Maps the kernel functions
@@ -425,6 +423,8 @@
 	s->_kfuncTable.clear();
 
 	vocab_free_rule_list(s->parser_rules);
+
+	delete s->_vocabulary;
 }
 
 void script_free_breakpoints(EngineState *s) {

Modified: scummvm/trunk/engines/sci/engine/kernel.h
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.h	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/kernel.h	2009-05-31 02:37:24 UTC (rev 41057)
@@ -49,7 +49,7 @@
 
 /******************** Selector functionality ********************/
 
-#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, s->selector_map._slc_, __FILE__, __LINE__)
+#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, s->_vocabulary->_selectorMap._slc_, __FILE__, __LINE__)
 #define GET_SEL32V(_o_, _slc_) (GET_SEL32(_o_, _slc_).offset)
 #define GET_SEL32SV(_o_, _slc_) ((int16)(GET_SEL32(_o_, _slc_).offset))
 /* Retrieves a selector from an object
@@ -60,8 +60,8 @@
 ** selector_map_t and mapped in script.c.
 */
 
-#define PUT_SEL32(_o_, _slc_, _val_) write_selector(s, _o_, s->selector_map._slc_, _val_, __FILE__, __LINE__)
-#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(s, _o_, s->selector_map._slc_, make_reg(0, _val_), __FILE__, __LINE__)
+#define PUT_SEL32(_o_, _slc_, _val_) write_selector(s, _o_, s->_vocabulary->_selectorMap._slc_, _val_, __FILE__, __LINE__)
+#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(s, _o_, s->_vocabulary->_selectorMap._slc_, make_reg(0, _val_), __FILE__, __LINE__)
 /* Writes a selector value to an object
 ** Parameters: (reg_t) object: The address of the object which the selector should be written to
 **             (selector_name) selector: The selector to read
@@ -73,7 +73,7 @@
 
 
 #define INV_SEL(_object_, _selector_, _noinvalid_) \
-	s, _object_,  s->selector_map._selector_, _noinvalid_, funct_nr, argv, argc, __FILE__, __LINE__
+	s, _object_,  s->_vocabulary->_selectorMap._selector_, _noinvalid_, funct_nr, argv, argc, __FILE__, __LINE__
 /* Kludge for use with invoke_selector(). Used for compatibility with compilers that can't
 ** handle vararg macros.
 */

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -1076,7 +1076,7 @@
 	x = GET_SEL32SV(object, x);
 	original_y = y = GET_SEL32SV(object, y);
 
-	if (s->selector_map.z > -1)
+	if (s->_vocabulary->_selectorMap.z > -1)
 		z = GET_SEL32SV(object, z);
 	else
 		z = 0;
@@ -1130,7 +1130,7 @@
 void _k_base_setter(EngineState *s, reg_t object) {
 	Common::Rect absrect = set_base(s, object);
 
-	if (lookup_selector(s, object, s->selector_map.brLeft, NULL, NULL) != kSelectorVariable)
+	if (lookup_selector(s, object, s->_vocabulary->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable)
 		return; // non-fatal
 
 	// Note: there was a check here for a very old version of SCI, which supposedly needed
@@ -1211,7 +1211,7 @@
 	x = GET_SEL32SV(object, x);
 	y = GET_SEL32SV(object, y);
 
-	if (s->selector_map.z > -1)
+	if (s->_vocabulary->_selectorMap.z > -1)
 		z = GET_SEL32SV(object, z);
 	else
 		z = 0;
@@ -1235,7 +1235,7 @@
 static void _k_set_now_seen(EngineState *s, reg_t object) {
 	Common::Rect absrect = get_nsrect(s, object, 0);
 
-	if (lookup_selector(s, object, s->selector_map.nsTop, NULL, NULL) != kSelectorVariable) {
+	if (lookup_selector(s, object, s->_vocabulary->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) {
 		return;
 	} // This isn't fatal
 
@@ -1720,7 +1720,7 @@
 		 * if ((widget->signal & (_K_VIEW_SIG_FLAG_PRIVATE | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == _K_VIEW_SIG_FLAG_PRIVATE) {
 		 */
 		if ((widget->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == 0) {
-			int has_nsrect = lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == kSelectorVariable;
+			int has_nsrect = lookup_selector(s, obj, s->_vocabulary->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable;
 
 			if (has_nsrect) {
 				int temp;
@@ -1742,7 +1742,7 @@
 			}
 #ifdef DEBUG_LSRECT
 			else
-				fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL));
+				fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s, obj, s->_vocabulary->_selectorMap.nsBottom, NULL, NULL));
 #endif
 
 			if (widget->signal & _K_VIEW_SIG_FLAG_HIDDEN)
@@ -1894,7 +1894,7 @@
 	loop = oldloop = sign_extend_byte(GET_SEL32V(obj, loop));
 	cel = oldcel = sign_extend_byte(GET_SEL32V(obj, cel));
 
-	if (s->selector_map.palette)
+	if (s->_vocabulary->_selectorMap.palette)
 		palette = GET_SEL32V(obj, palette);
 	else
 		palette = 0;
@@ -1916,14 +1916,14 @@
 		PUT_SEL32V(obj, cel, cel);
 	}
 
-	if (lookup_selector(s, obj, s->selector_map.underBits, &(under_bitsp), NULL) != kSelectorVariable) {
+	if (lookup_selector(s, obj, s->_vocabulary->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) {
 		under_bitsp = NULL;
 		under_bits = NULL_REG;
 		debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no underBits\n", PRINT_REG(obj));
 	} else
 		under_bits = *((reg_t *)under_bitsp);
 
-	if (lookup_selector(s, obj, s->selector_map.signal, &(signalp), NULL) != kSelectorVariable) {
+	if (lookup_selector(s, obj, s->_vocabulary->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) {
 		signalp = NULL;
 		signal = 0;
 		debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no signal selector\n", PRINT_REG(obj));
@@ -2015,7 +2015,7 @@
 	while (view) {
 		reg_t obj = make_reg(view->_ID, view->_subID);
 		int priority, _priority;
-		int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == kSelectorVariable;
+		int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s, obj, s->_vocabulary->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable;
 		int oldsignal = view->signal;
 
 		_k_set_now_seen(s, obj);

Modified: scummvm/trunk/engines/sci/engine/kmovement.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmovement.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/kmovement.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -462,7 +462,7 @@
 			return;
 		}
 
-		if (lookup_selector(s, motion_class, s->selector_map.doit, NULL, &fptr) != kSelectorMethod) {
+		if (lookup_selector(s, motion_class, s->_vocabulary->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) {
 			warning("bresenham_autodetect failed");
 			handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess
 			return;
@@ -557,7 +557,7 @@
 
 	debugC(2, kDebugLevelBresen, "New data: (x,y)=(%d,%d), di=%d\n", x, y, bdi);
 
-	if (s->selector_map.cantBeHere != -1)
+	if (s->_vocabulary->_selectorMap.cantBeHere != -1)
 		invoke_selector(INV_SEL(client, cantBeHere, 0), 0);
 	else
 		invoke_selector(INV_SEL(client, canBeHere, 0), 0);

Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -203,7 +203,7 @@
 		return s->r_acc;
 	}
 
-	bool res = vocab_tokenize_string(words, string, s->_vocabulary->_parserWords, s->_vocabulary->_parserSuffixes, &error);
+	bool res = s->_vocabulary->tokenizeString(words, string, &error);
 	s->parser_valid = 0; /* not valid */
 
 	if (res && !words.empty()) {

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -834,7 +834,7 @@
 	retval->_kfuncTable = s->_kfuncTable;
 	retval->_vocabulary->_opcodes = s->_vocabulary->_opcodes;
 
-	memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));
+	memcpy(&(retval->_vocabulary->_selectorMap), &(s->_vocabulary->_selectorMap), sizeof(selector_map_t));
 
 	retval->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
 

Modified: scummvm/trunk/engines/sci/engine/script.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/script.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/script.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -108,9 +108,9 @@
 	}
 }
 
-int script_find_selector(EngineState *s, const char *selectorname) {
-	for (uint pos = 0; pos < s->_vocabulary->_selectorNames.size(); ++pos) {
-		if (s->_vocabulary->_selectorNames[pos] == selectorname)
+int script_find_selector(Common::StringList *selectorNames, const char *selectorname) {
+	for (uint pos = 0; pos < selectorNames->size(); ++pos) {
+		if ((*selectorNames)[pos] == selectorname)
 			return pos;
 	}
 
@@ -119,10 +119,10 @@
 	return -1;
 }
 
-#define FIND_SELECTOR(_slc_) map->_slc_ = script_find_selector(s, #_slc_)
-#define FIND_SELECTOR2(_slc_, _slcstr_) map->_slc_ = script_find_selector(s, _slcstr_)
+#define FIND_SELECTOR(_slc_) map->_slc_ = script_find_selector(selectorNames, #_slc_)
+#define FIND_SELECTOR2(_slc_, _slcstr_) map->_slc_ = script_find_selector(selectorNames, _slcstr_)
 
-void script_map_selectors(EngineState *s, selector_map_t *map) {
+void script_map_selectors(Common::StringList *selectorNames, selector_map_t *map) {
 	FIND_SELECTOR(init);
 	FIND_SELECTOR(play);
 	FIND_SELECTOR(replay);
@@ -303,7 +303,7 @@
 	}
 }
 
-void script_dissect(ResourceManager *resmgr, int res_no, WordMap &parserWords, const Common::StringList &selectorNames) {
+void script_dissect(ResourceManager *resmgr, int res_no, Vocabulary *vocab) {
 	int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 	unsigned int _seeker = 0;
 	Resource *script = resmgr->findResource(kResourceTypeScript, res_no, 0);
@@ -337,7 +337,7 @@
 
 		switch (objtype) {
 		case SCI_OBJ_OBJECT:
-			script_dump_object((char *)script->data, seeker, objsize, selectorNames);
+			script_dump_object((char *)script->data, seeker, objsize, vocab->_selectorNames);
 			break;
 
 		case SCI_OBJ_CODE: {
@@ -396,8 +396,7 @@
 					}
 				} else {
 					nextitem = nextitem << 8 | script->data [seeker++];
-					// TODO
-					sciprintf("%s[%03x] ", vocab_get_any_group_word(nextitem, parserWords), nextitem);
+					sciprintf("%s[%03x] ", vocab->getAnyWordFromGroup(nextitem), nextitem);
 				}
 			}
 			sciprintf("\n");
@@ -415,7 +414,7 @@
 		break;
 
 		case SCI_OBJ_CLASS:
-			script_dump_class((char *)script->data, seeker, objsize, selectorNames);
+			script_dump_class((char *)script->data, seeker, objsize, vocab->_selectorNames);
 			break;
 
 		case SCI_OBJ_EXPORTS: {

Modified: scummvm/trunk/engines/sci/engine/script.h
===================================================================
--- scummvm/trunk/engines/sci/engine/script.h	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/script.h	2009-05-31 02:37:24 UTC (rev 41057)
@@ -51,7 +51,7 @@
 	SCI_OBJ_LOCALVARS
 };
 
-void script_dissect(ResourceManager *resmgr, int res_no, WordMap &parserWords, const Common::StringList &selectorNames);
+void script_dissect(ResourceManager *resmgr, int res_no, Vocabulary *vocab);
 
 /* Opcode formats as used by script.c */
 enum opcode_format {
@@ -203,7 +203,7 @@
 
 void script_adjust_opcode_formats(int res_version);
 
-int script_find_selector(EngineState *s, const char *selector_name);
+int script_find_selector(Common::StringList *selectorNames, const char *selector_name);
 /* Determines the selector ID of a selector by its name
 ** Parameters: (state_t *) s: VM state
 **             (char *) selector_name: Name of the selector to look up

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -648,7 +648,7 @@
 
 	string = cmdParams[0].str;
 	sciprintf("Parsing '%s'\n", string);
-	bool res = vocab_tokenize_string(words, string, s->_vocabulary->_parserWords, s->_vocabulary->_parserSuffixes, &error);
+	bool res = s->_vocabulary->tokenizeString(words, string, &error);
 	if (res && !words.empty()) {
 		int syntax_fail = 0;
 
@@ -1232,10 +1232,10 @@
 	}
 
 
-	is_view = (lookup_selector(s, pos, s->selector_map.x, NULL) == kSelectorVariable) &&
-	    (lookup_selector(s, pos, s->selector_map.brLeft, NULL) == kSelectorVariable) &&
-	    (lookup_selector(s, pos, s->selector_map.signal, NULL) == kSelectorVariable) &&
-	    (lookup_selector(s, pos, s->selector_map.nsTop, NULL) == kSelectorVariable);
+	is_view = (lookup_selector(s, pos, s->_vocabulary->_selectorMap.x, NULL) == kSelectorVariable) &&
+	    (lookup_selector(s, pos, s->_vocabulary->_selectorMap.brLeft, NULL) == kSelectorVariable) &&
+	    (lookup_selector(s, pos, s->_vocabulary->_selectorMap.signal, NULL) == kSelectorVariable) &&
+	    (lookup_selector(s, pos, s->_vocabulary->_selectorMap.nsTop, NULL) == kSelectorVariable);
 
 	if (!is_view) {
 		sciprintf("Not a dynamic View object.\n");
@@ -1318,7 +1318,7 @@
 
 static int c_disasm(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
 	Object *obj = obj_get(s, cmdParams[0].reg);
-	int selector_id = script_find_selector(s, cmdParams[1].str);
+	int selector_id = script_find_selector(&s->_vocabulary->_selectorNames, cmdParams[1].str);
 	reg_t addr;
 
 	if (!obj) {
@@ -1420,7 +1420,7 @@
 	reg_t *vptr;
 	reg_t fptr;
 
-	selector_id = script_find_selector(s, selector_name);
+	selector_id = script_find_selector(&s->_vocabulary->_selectorNames, selector_name);
 
 	if (selector_id < 0) {
 		sciprintf("Unknown selector: \"%s\"\n", selector_name);
@@ -1567,7 +1567,7 @@
 	int have_rects = 0;
 	Common::Rect nsrect, nsrect_clipped, brrect;
 
-	if (lookup_selector(s, pos, s->selector_map.nsBottom, NULL) == kSelectorVariable) {
+	if (lookup_selector(s, pos, s->_vocabulary->_selectorMap.nsBottom, NULL) == kSelectorVariable) {
 		GETRECT(nsLeft, nsRight, nsBottom, nsTop);
 		GETRECT(lsLeft, lsRight, lsBottom, lsTop);
 		GETRECT(brLeft, brRight, brBottom, brTop);
@@ -1581,7 +1581,7 @@
 	x = GET_SELECTOR(pos, x);
 	y = GET_SELECTOR(pos, y);
 	priority = GET_SELECTOR(pos, priority);
-	if (s->selector_map.z > 0) {
+	if (s->_vocabulary->_selectorMap.z > 0) {
 		z = GET_SELECTOR(pos, z);
 		sciprintf("(%d,%d,%d)\n", x, y, z);
 	} else

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -121,8 +121,6 @@
 	seg_manager = 0;
 	gc_countdown = 0;
 
-	memset(&selector_map, 0, sizeof(selector_map));	// FIXME: Remove this once/if we C++ify selector_map_t
-
 	successor = 0;
 }
 

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/state.h	2009-05-31 02:37:24 UTC (rev 41057)
@@ -242,8 +242,6 @@
 
 	Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
 
-	selector_map_t selector_map; /**< Shortcut list for important selectors */
-
 	MessageState _msgState;
 
 	Vocabulary *_vocabulary;
@@ -260,7 +258,7 @@
 PaletteEntry get_pic_color(EngineState *s, int color);
 
 static inline reg_t not_register(EngineState *s, reg_t r) {
-	if (s->selector_map.cantBeHere != -1)
+	if (s->_vocabulary->_selectorMap.cantBeHere != -1)
 		return make_reg(0, !r.offset);
 	else
 		return r;

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -1977,7 +1977,7 @@
 			script_init_engine(s, s->version);
 			game_init(s);
 			sfx_reset_player();
-			_init_stack_base_with_selector(s, s->selector_map.play);
+			_init_stack_base_with_selector(s, s->_vocabulary->_selectorMap.play);
 
 			send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base);
 
@@ -1997,7 +1997,7 @@
 					sciprintf("Restarting with replay()\n");
 					s->_executionStack.clear(); // Restart with replay
 
-					_init_stack_base_with_selector(s, s->selector_map.replay);
+					_init_stack_base_with_selector(s, s->_vocabulary->_selectorMap.replay);
 
 					send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base);
 				}
@@ -2018,7 +2018,7 @@
 	EngineState *s = *_s;
 
 	sciprintf(" Calling %s::play()\n", s->_gameName.c_str());
-	_init_stack_base_with_selector(s, s->selector_map.play); // Call the play selector
+	_init_stack_base_with_selector(s, s->_vocabulary->_selectorMap.play); // Call the play selector
 
 	// Now: Register the first element on the execution stack-
 	if (!send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base) || script_error_flag) {

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/engine/vm.h	2009-05-31 02:37:24 UTC (rev 41057)
@@ -1076,9 +1076,9 @@
 ** Returns   : (void)
 */
 
-void script_map_selectors(EngineState *s, selector_map_t *map);
+void script_map_selectors(Common::StringList *selectorNames, selector_map_t *map);
 /* Maps special selectors
-** Parameters: (EngineState *) s: The state from which the selector information should be taken
+** Parameters: (Common::StringList *) selectorNames: The selector information
 **             (selector_map_t *) map: Pointer to the selector map to map
 ** Returns   : (void)
 ** Called by script_run();

Modified: scummvm/trunk/engines/sci/vocabulary.cpp
===================================================================
--- scummvm/trunk/engines/sci/vocabulary.cpp	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/vocabulary.cpp	2009-05-31 02:37:24 UTC (rev 41057)
@@ -350,9 +350,9 @@
 #endif
 
 Vocabulary::Vocabulary(EngineState *s) : _resmgr(s->resmgr), _isOldSci0(s->flags & GF_SCI0_OLD) {
-	s->parser_lastmatch_word = SAID_NO_MATCH;
 	s->parser_rules = NULL;
 	_vocabVersion = 0;
+	memset(&_selectorMap, 0, sizeof(_selectorMap));	// FIXME: Remove this once/if we C++ify selector_map_t
 
 	debug(2, "Initializing vocabulary");
 
@@ -372,6 +372,9 @@
 		error("Vocabulary: Could not retrieve selector names");
 	}
 
+	// Map a few special selectors for later use
+	script_map_selectors(&_selectorNames, &_selectorMap);
+
 	getKernelNames();
 }
 
@@ -512,11 +515,11 @@
 	return true;
 }
 
-const char *vocab_get_any_group_word(int group, const WordMap &words) {
+const char *Vocabulary::getAnyWordFromGroup(int group) {
 	if (group == VOCAB_MAGIC_NUMBER_GROUP)
 		return "{number}";
 
-	for (WordMap::const_iterator i = words.begin(); i != words.end(); ++i)
+	for (WordMap::const_iterator i = _parserWords.begin(); i != _parserWords.end(); ++i)
 		if (i->_value._group == group)
 			return i->_key.c_str();
 
@@ -617,7 +620,7 @@
 }
 
 
-ResultWord vocab_lookup_word(const char *word, int word_len, const WordMap &words, const SuffixList &suffixes) {
+ResultWord Vocabulary::lookupWord(const char *word, int word_len) {
 	Common::String tempword(word, word_len);
 
 	// Remove all dashes from tempword
@@ -629,15 +632,15 @@
 	}
 
 	// Look it up:
-	WordMap::iterator dict_word = words.find(tempword);
+	WordMap::iterator dict_word = _parserWords.find(tempword);
 
 	// Match found? Return it!
-	if (dict_word != words.end()) {
+	if (dict_word != _parserWords.end()) {
 		return dict_word->_value;
 	}
 
 	// Now try all suffixes
-	for (SuffixList::const_iterator suffix = suffixes.begin(); suffix != suffixes.end(); ++suffix)
+	for (SuffixList::const_iterator suffix = _parserSuffixes.begin(); suffix != _parserSuffixes.end(); ++suffix)
 		if (suffix->alt_suffix_length <= word_len) {
 
 			int suff_index = word_len - suffix->alt_suffix_length;
@@ -650,9 +653,9 @@
 				// ...and append "correct" suffix
 				tempword2 += Common::String(suffix->word_suffix, suffix->word_suffix_length);
 
-				dict_word = words.find(tempword2);
+				dict_word = _parserWords.find(tempword2);
 
-				if ((dict_word != words.end()) && (dict_word->_value._class & suffix->class_mask)) { // Found it?
+				if ((dict_word != _parserWords.end()) && (dict_word->_value._class & suffix->class_mask)) { // Found it?
 					// Use suffix class
 					ResultWord tmp = dict_word->_value;
 					tmp._class = suffix->result_class;
@@ -681,7 +684,7 @@
 
 		if (nextitem < 0xf0) {
 			nextitem = nextitem << 8 | *addr++;
-			sciprintf(" %s[%03x]", vocab_get_any_group_word(nextitem, s->_vocabulary->_parserWords), nextitem);
+			sciprintf(" %s[%03x]", s->_vocabulary->getAnyWordFromGroup(nextitem), nextitem);
 
 			nextitem = 42; // Make sure that group 0xff doesn't abort
 		} else switch (nextitem) {
@@ -723,8 +726,7 @@
 	sciprintf("\n");
 }
 
-bool vocab_tokenize_string(ResultWordList &retval, const char *sentence, const WordMap &words,
-	const SuffixList &suffixes, char **error) {
+bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, char **error) {
 	const char *lastword = sentence;
 	int pos_in_sentence = 0;
 	char c;
@@ -744,8 +746,7 @@
 		else {
 			if (wordlen) { // Finished a word?
 
-				ResultWord lookup_result =
-				    vocab_lookup_word(lastword, wordlen, words, suffixes);
+				ResultWord lookup_result = lookupWord(lastword, wordlen);
 				// Look it up
 
 				if (lookup_result._class == -1) { // Not found?

Modified: scummvm/trunk/engines/sci/vocabulary.h
===================================================================
--- scummvm/trunk/engines/sci/vocabulary.h	2009-05-31 02:15:43 UTC (rev 41056)
+++ scummvm/trunk/engines/sci/vocabulary.h	2009-05-31 02:37:24 UTC (rev 41057)
@@ -231,13 +231,39 @@
 	 */
 	bool getBranches();
 
+	/**
+	 * Gets any word from the specified group. For debugging only.
+	 * @param group		Group number
+	 */
+	const char *getAnyWordFromGroup(int group);
 
+
+	/* Looks up a single word in the words and suffixes list
+	** Parameters: (char *) word: Pointer to the word to look up
+	**             (int) word_len: Length of the word to look up
+	** Returns   : (const ResultWordList &) A list containing 1 or 0 words
+	*/
+	ResultWord lookupWord(const char *word, int word_len);
+
+
+	/* Tokenizes a string and compiles it into word_ts.
+	** Parameters: (char *) sentence: The sentence to examine
+	**             (char **) error: Points to a malloc'd copy of the offending text or to NULL on error
+	**             (ResultWordList) retval: A list of word_ts containing the result, or NULL.
+	** Returns   : true on success, false on failure
+	** On error, NULL is returned. If *error is NULL, the sentence did not contain any useful words;
+	** if not, *error points to a malloc'd copy of the offending word.
+	** The returned list may contain anywords.
+	*/
+	bool tokenizeString(ResultWordList &retval, const char *sentence, char **error);
+
 	Common::StringList _selectorNames;
 	Common::Array<opcode> _opcodes;
 	Common::StringList _kernelNames;
 	WordMap _parserWords;
 	SuffixList _parserSuffixes;
 	Common::Array<parse_tree_branch_t> _parserBranches;
+	selector_map_t _selectorMap; /**< Shortcut list for important selectors */
 
 private:
 	ResourceManager *_resmgr;
@@ -245,32 +271,6 @@
 	int _vocabVersion;
 };
 
-/* Looks up a single word in the words and suffixes list
-** Parameters: (char *) word: Pointer to the word to look up
-**             (int) word_len: Length of the word to look up
-**             (const WordMap &) words: List of words
-**             (SuffixList) suffixes: List of suffixes
-** Returns   : (const ResultWordList &) A list containing 1 or 0 words
-*/
-ResultWord vocab_lookup_word(const char *word, int word_len,
-	const WordMap &words, const SuffixList &suffixes);
-
-
-/* Tokenizes a string and compiles it into word_ts.
-** Parameters: (char *) sentence: The sentence to examine
-**             (const WordMap &) words: The words to scan for
-**             (SuffixList) suffixes: suffixes to scan for
-**             (char **) error: Points to a malloc'd copy of the offending text or to NULL on error
-**             (ResultWordList) retval: A list of word_ts containing the result, or NULL.
-** Returns   : true on success, false on failure
-** On error, NULL is returned. If *error is NULL, the sentence did not contain any useful words;
-** if not, *error points to a malloc'd copy of the offending word.
-** The returned list may contain anywords.
-*/
-bool vocab_tokenize_string(ResultWordList &retval, const char *sentence,
-	const WordMap &words, const SuffixList &suffixes, char **error);
-
-
 /* Constructs the Greibach Normal Form of the grammar supplied in 'branches'
 ** Parameters: (parse_tree_branch_t *) branches: The parser's branches
 ** Returns   : (parse_rule_list_t *): Pointer to a list of singly linked
@@ -319,14 +319,7 @@
 */
 int said(EngineState *s, byte *spec, int verbose);
 
-/**
- * Gets any word from the specified group. For debugging only.
- * @param group		Group number
- * @param words		List of words
- */
-const char *vocab_get_any_group_word(int group, const WordMap &words);
 
-
 /* Decyphers a said block and dumps its content via sciprintf.
 ** Parameters: (EngineState *) s: The state to use
 **             (byte *) pos: Pointer to the data to dump


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