aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorFilippos Karapetis2009-05-31 02:37:24 +0000
committerFilippos Karapetis2009-05-31 02:37:24 +0000
commita4d13cef8c48eecb1f73f2d509437261a663ab05 (patch)
treeb4cbf2d09a3a7fb78f982168a513e63e790b8f78 /engines/sci
parent896df6daf337bf83f27193918eb386321c4b0166 (diff)
downloadscummvm-rg350-a4d13cef8c48eecb1f73f2d509437261a663ab05.tar.gz
scummvm-rg350-a4d13cef8c48eecb1f73f2d509437261a663ab05.tar.bz2
scummvm-rg350-a4d13cef8c48eecb1f73f2d509437261a663ab05.zip
More objectification of the Vocabulary functions
svn-id: r41057
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/console.cpp2
-rw-r--r--engines/sci/engine/game.cpp8
-rw-r--r--engines/sci/engine/kernel.h8
-rw-r--r--engines/sci/engine/kgraphics.cpp20
-rw-r--r--engines/sci/engine/kmovement.cpp4
-rw-r--r--engines/sci/engine/kstring.cpp2
-rw-r--r--engines/sci/engine/savegame.cpp2
-rw-r--r--engines/sci/engine/script.cpp21
-rw-r--r--engines/sci/engine/script.h4
-rw-r--r--engines/sci/engine/scriptdebug.cpp18
-rw-r--r--engines/sci/engine/state.cpp2
-rw-r--r--engines/sci/engine/state.h4
-rw-r--r--engines/sci/engine/vm.cpp6
-rw-r--r--engines/sci/engine/vm.h4
-rw-r--r--engines/sci/vocabulary.cpp29
-rw-r--r--engines/sci/vocabulary.h59
16 files changed, 91 insertions, 102 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index c1105e5f5f..feb5977ae8 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -243,7 +243,7 @@ bool Console::cmdDissectScript(int argc, const char **argv) {
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;
}
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 17284ca888..2bacadf769 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -370,11 +370,9 @@ int script_init_engine(EngineState *s, sci_version_t version) {
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 @@ void script_free_engine(EngineState *s) {
s->_kfuncTable.clear();
vocab_free_rule_list(s->parser_rules);
+
+ delete s->_vocabulary;
}
void script_free_breakpoints(EngineState *s) {
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index c27b2aa210..cc13764fa0 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -49,7 +49,7 @@ extern int _debug_step_running;
/******************** 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 @@ extern int _debug_step_running;
** 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 @@ extern int _debug_step_running;
#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.
*/
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 5c7bbdf80f..aa5e3c3cc6 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -1076,7 +1076,7 @@ Common::Rect set_base(EngineState *s, reg_t object) {
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 @@ Common::Rect set_base(EngineState *s, reg_t object) {
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 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) {
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 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) {
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 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) {
* 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 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) {
}
#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 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
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 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
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 @@ static void _k_prepare_view_list(EngineState *s, GfxList *list, int options) {
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);
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index 9b62792073..0410d36974 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -462,7 +462,7 @@ static void bresenham_autodetect(EngineState *s) {
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 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
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);
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 3c1b807848..d34670369b 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -203,7 +203,7 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
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()) {
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 16c6eba0dd..fe6f0f1376 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -834,7 +834,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
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);
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index cf364ebf21..34e4cf05b7 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -108,9 +108,9 @@ void script_adjust_opcode_formats(int res_version) {
}
}
-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 @@ int script_find_selector(EngineState *s, const char *selectorname) {
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 @@ static void script_dump_class(char *data, int seeker, int objsize, const Common:
}
}
-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 @@ void script_dissect(ResourceManager *resmgr, int res_no, WordMap &parserWords, c
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 @@ void script_dissect(ResourceManager *resmgr, int res_no, WordMap &parserWords, c
}
} 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 @@ void script_dissect(ResourceManager *resmgr, int res_no, WordMap &parserWords, c
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: {
diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h
index 037ba3a806..ab7ba7af80 100644
--- a/engines/sci/engine/script.h
+++ b/engines/sci/engine/script.h
@@ -51,7 +51,7 @@ enum ScriptObjectTypes {
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 @@ extern opcode_format g_opcode_formats[128][4];
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
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 766d843876..9f29134b84 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -648,7 +648,7 @@ int c_parse(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
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 @@ static int c_gfx_draw_viewobj(EngineState *s, const Common::Array<cmd_param_t> &
}
- 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_addr(EngineState *s, const Common::Array<cmd_param_t> &cmdPa
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 @@ static int c_send(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
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 @@ static void viewobjinfo(EngineState *s, HeapPtr pos) {
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 @@ static void viewobjinfo(EngineState *s, HeapPtr pos) {
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
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index 10c8afd67f..68b706cfb4 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -121,8 +121,6 @@ EngineState::EngineState() : _dirseeker(this) {
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;
}
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index db3e8f38c0..ee22a9e31d 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -242,8 +242,6 @@ public:
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 @@ public:
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;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index d57f9bc2f4..3fb7bbcdcc 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -1977,7 +1977,7 @@ static EngineState *_game_run(EngineState *s, int restoring) {
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 @@ static EngineState *_game_run(EngineState *s, int restoring) {
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 @@ int game_run(EngineState **_s) {
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) {
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index 736bdff47f..b4a2de4d23 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -1076,9 +1076,9 @@ void quit_vm();
** 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();
diff --git a/engines/sci/vocabulary.cpp b/engines/sci/vocabulary.cpp
index 07fbd2f722..6869a62472 100644
--- a/engines/sci/vocabulary.cpp
+++ b/engines/sci/vocabulary.cpp
@@ -350,9 +350,9 @@ int vocab_get_class_count(ResourceManager *resmgr) {
#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 @@ Vocabulary::Vocabulary(EngineState *s) : _resmgr(s->resmgr), _isOldSci0(s->flags
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 @@ bool Vocabulary::getParserWords() {
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 @@ bool Vocabulary::getBranches() {
}
-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 @@ ResultWord vocab_lookup_word(const char *word, int word_len, const WordMap &word
}
// 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 @@ ResultWord vocab_lookup_word(const char *word, int word_len, const WordMap &word
// ...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 @@ void vocab_decypher_said_block(EngineState *s, byte *addr) {
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 @@ void vocab_decypher_said_block(EngineState *s, byte *addr) {
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 @@ bool vocab_tokenize_string(ResultWordList &retval, const char *sentence, const W
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?
diff --git a/engines/sci/vocabulary.h b/engines/sci/vocabulary.h
index f364a5bda0..cb4bb181d4 100644
--- a/engines/sci/vocabulary.h
+++ b/engines/sci/vocabulary.h
@@ -231,6 +231,31 @@ public:
*/
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;
@@ -238,6 +263,7 @@ public:
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 @@ private:
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,13 +319,6 @@ void vocab_dump_parse_tree(const char *tree_name, parse_tree_node_t *nodes);
*/
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