diff options
Diffstat (limited to 'engines/sci')
44 files changed, 578 insertions, 573 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 7b329864ce..4637004616 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -381,7 +381,7 @@ const char *selector_name(EngineState *s, int selector) { } bool Console::cmdGetVersion(int argc, const char **argv) { - DebugPrintf("Resource file version: %s\n", versionNames[_vm->getResMgr()->sciVersion()]); + DebugPrintf("Resource file version: %s\n", versionNames[_vm->getresourceManager()->sciVersion()]); DebugPrintf("Emulated interpreter version: %s\n", versionNames[_vm->getVersion()]); return true; @@ -580,7 +580,7 @@ bool Console::cmdHexDump(int argc, const char **argv) { if (res == kResourceTypeInvalid) DebugPrintf("Resource type '%s' is not valid\n", argv[1]); else { - Resource *resource = _vm->getResMgr()->findResource(ResourceId(res, resNum), 0); + Resource *resource = _vm->getresourceManager()->findResource(ResourceId(res, resNum), 0); if (resource) { Common::hexdump(resource->data, resource->size, 16, 0); DebugPrintf("Resource %s.%03d has been dumped to standard output\n", argv[1], resNum); @@ -636,7 +636,7 @@ bool Console::cmdResourceSize(int argc, const char **argv) { if (res == kResourceTypeInvalid) DebugPrintf("Resource type '%s' is not valid\n", argv[1]); else { - Resource *resource = _vm->getResMgr()->findResource(ResourceId(res, resNum), 0); + Resource *resource = _vm->getresourceManager()->findResource(ResourceId(res, resNum), 0); if (resource) { DebugPrintf("Resource size: %d\n", resource->size); } else { @@ -706,7 +706,7 @@ bool Console::cmdHexgrep(int argc, const char **argv) { } for (; resNumber <= resMax; resNumber++) { - if ((script = _vm->getResMgr()->findResource(ResourceId(restype, resNumber), 0))) { + if ((script = _vm->getresourceManager()->findResource(ResourceId(restype, resNumber), 0))) { unsigned int seeker = 0, seekerold = 0; uint32 comppos = 0; int output_script_name = 0; @@ -761,7 +761,7 @@ bool Console::cmdList(int argc, const char **argv) { number = atoi(argv[2]); } - Common::List<ResourceId> *resources = _vm->getResMgr()->listResources(res, number); + Common::List<ResourceId> *resources = _vm->getresourceManager()->listResources(res, number); sort(resources->begin(), resources->end(), ResourceIdLess()); Common::List<ResourceId>::iterator itr = resources->begin(); @@ -889,11 +889,11 @@ bool Console::cmdRestartGame(int argc, const char **argv) { bool Console::cmdClassTable(int argc, const char **argv) { DebugPrintf("Available classes:\n"); - for (uint i = 0; i < _vm->_gamestate->seg_manager->_classtable.size(); i++) { - if (_vm->_gamestate->seg_manager->_classtable[i].reg.segment) { + for (uint i = 0; i < _vm->_gamestate->segmentManager->_classtable.size(); i++) { + if (_vm->_gamestate->segmentManager->_classtable[i].reg.segment) { DebugPrintf(" Class 0x%x at %04x:%04x (script 0x%x)\n", i, - PRINT_REG(_vm->_gamestate->seg_manager->_classtable[i].reg), - _vm->_gamestate->seg_manager->_classtable[i].script); + PRINT_REG(_vm->_gamestate->segmentManager->_classtable[i].reg), + _vm->_gamestate->segmentManager->_classtable[i].script); } } @@ -1307,8 +1307,8 @@ bool Console::cmdStatusBarColors(int argc, const char **argv) { bool Console::cmdPrintSegmentTable(int argc, const char **argv) { DebugPrintf("Segment table:\n"); - for (uint i = 0; i < _vm->_gamestate->seg_manager->_heap.size(); i++) { - MemObject *mobj = _vm->_gamestate->seg_manager->_heap[i]; + for (uint i = 0; i < _vm->_gamestate->segmentManager->_heap.size(); i++) { + MemObject *mobj = _vm->_gamestate->segmentManager->_heap[i]; if (mobj && mobj->getType()) { DebugPrintf(" [%04x] ", i); @@ -1358,7 +1358,7 @@ bool Console::cmdPrintSegmentTable(int argc, const char **argv) { break; } - DebugPrintf(" seg_ID = %d \n", mobj->getSegMgrId()); + DebugPrintf(" seg_ID = %d \n", mobj->getSegmentManagerId()); } } DebugPrintf("\n"); @@ -1369,10 +1369,10 @@ bool Console::cmdPrintSegmentTable(int argc, const char **argv) { bool Console::segmentInfo(int nr) { DebugPrintf("[%04x] ", nr); - if ((nr < 0) || ((uint)nr >= _vm->_gamestate->seg_manager->_heap.size()) || !_vm->_gamestate->seg_manager->_heap[nr]) + if ((nr < 0) || ((uint)nr >= _vm->_gamestate->segmentManager->_heap.size()) || !_vm->_gamestate->segmentManager->_heap[nr]) return false; - MemObject *mobj = _vm->_gamestate->seg_manager->_heap[nr]; + MemObject *mobj = _vm->_gamestate->segmentManager->_heap[nr]; switch (mobj->getType()) { @@ -1395,10 +1395,10 @@ bool Console::segmentInfo(int nr) { for (uint i = 0; i < scr->_objects.size(); i++) { DebugPrintf(" "); // Object header - Object *obj = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, scr->_objects[i].pos); + Object *obj = obj_get(_vm->_gamestate->segmentManager, scr->_objects[i].pos); if (obj) DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(scr->_objects[i].pos), - obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, + obj_get_name(_vm->_gamestate->segmentManager, scr->_objects[i].pos), obj->_variables.size(), obj->methods_nr); } } @@ -1440,12 +1440,12 @@ bool Console::segmentInfo(int nr) { reg_t objpos; objpos.offset = i; objpos.segment = nr; - DebugPrintf(" [%04x] %s; copy of ", i, obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, objpos)); + DebugPrintf(" [%04x] %s; copy of ", i, obj_get_name(_vm->_gamestate->segmentManager, objpos)); // Object header - Object *obj = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, ct->_table[i].pos); + Object *obj = obj_get(_vm->_gamestate->segmentManager, ct->_table[i].pos); if (obj) DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(ct->_table[i].pos), - obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, ct->_table[i].pos), + obj_get_name(_vm->_gamestate->segmentManager, ct->_table[i].pos), obj->_variables.size(), obj->methods_nr); } } @@ -1512,7 +1512,7 @@ bool Console::cmdSegmentInfo(int argc, const char **argv) { } if (!scumm_stricmp(argv[1], "all")) { - for (uint i = 0; i < _vm->_gamestate->seg_manager->_heap.size(); i++) + for (uint i = 0; i < _vm->_gamestate->segmentManager->_heap.size(); i++) segmentInfo(i); } else { int nr = atoi(argv[1]); @@ -1531,7 +1531,7 @@ bool Console::cmdKillSegment(int argc, const char **argv) { return true; } - _vm->_gamestate->seg_manager->getScript(atoi(argv[1]))->setLockers(0); + _vm->_gamestate->segmentManager->getScript(atoi(argv[1]))->setLockers(0); return true; } @@ -1636,14 +1636,14 @@ bool Console::cmdGCShowReachable(int argc, const char **argv) { return true; } - MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->seg_manager, addr.segment); + MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->segmentManager, addr.segment); if (!mobj) { DebugPrintf("Unknown segment : %x\n", addr.segment); return 1; } DebugPrintf("Reachable from %04x:%04x:\n", PRINT_REG(addr)); - mobj->listAllOutgoingReferences(_vm->_gamestate, addr, NULL, _print_address); + mobj->listAllOutgoingReferences(addr, NULL, _print_address, _vm->_gamestate->resourceManager->sciVersion()); return true; } @@ -1665,7 +1665,7 @@ bool Console::cmdGCShowFreeable(int argc, const char **argv) { return true; } - MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->seg_manager, addr.segment); + MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->segmentManager, addr.segment); if (!mobj) { DebugPrintf("Unknown segment : %x\n", addr.segment); return true; @@ -1695,13 +1695,13 @@ bool Console::cmdGCNormalize(int argc, const char **argv) { return true; } - MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->seg_manager, addr.segment); + MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->segmentManager, addr.segment); if (!mobj) { DebugPrintf("Unknown segment : %x\n", addr.segment); return true; } - addr = mobj->findCanonicAddress(_vm->_gamestate->seg_manager, addr); + addr = mobj->findCanonicAddress(_vm->_gamestate->segmentManager, addr); DebugPrintf(" %04x:%04x\n", PRINT_REG(addr)); return true; @@ -1817,7 +1817,7 @@ bool Console::cmdValueType(int argc, const char **argv) { return true; } - int t = determine_reg_type(_vm->_gamestate, val, true); + int t = determine_reg_type(_vm->_gamestate->segmentManager, val, true); int invalid = t & KSIG_INVALID; switch (t & ~KSIG_INVALID) { @@ -1892,7 +1892,7 @@ bool Console::cmdViewReference(int argc, const char **argv) { } } - int type_mask = determine_reg_type(_vm->_gamestate, reg, 1); + int type_mask = determine_reg_type(_vm->_gamestate->segmentManager, reg, 1); int filter; int found = 0; @@ -1942,7 +1942,7 @@ bool Console::cmdViewReference(int argc, const char **argv) { break; case KSIG_REF: { int size; - unsigned char *block = _vm->_gamestate->seg_manager->dereference(reg, &size); + unsigned char *block = _vm->_gamestate->segmentManager->dereference(reg, &size); DebugPrintf("raw data\n"); @@ -2048,7 +2048,7 @@ bool Console::cmdBacktrace(int argc, const char **argv) { for (iter = _vm->_gamestate->_executionStack.begin(); iter != _vm->_gamestate->_executionStack.end(); ++iter, ++i) { ExecStack &call = *iter; - const char *objname = obj_get_name(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, call.sendp); + const char *objname = obj_get_name(_vm->_gamestate->segmentManager, call.sendp); int paramc, totalparamc; switch (call.type) { @@ -2098,7 +2098,7 @@ bool Console::cmdBacktrace(int argc, const char **argv) { printf(" argp:ST:%04x", (unsigned)(call.variables_argp - _vm->_gamestate->stack_base)); if (call.type == EXEC_STACK_TYPE_CALL) - printf(" script: %d", (*(Script *)_vm->_gamestate->seg_manager->_heap[call.addr.pc.segment]).nr); + printf(" script: %d", (*(Script *)_vm->_gamestate->segmentManager->_heap[call.addr.pc.segment]).nr); printf("\n"); } @@ -2190,7 +2190,7 @@ bool Console::cmdDissassemble(int argc, const char **argv) { return true; } - Object *obj = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, objAddr); + Object *obj = obj_get(_vm->_gamestate->segmentManager, objAddr); int selector_id = _vm->getKernel()->findSelector(argv[2]); reg_t addr; @@ -2204,7 +2204,7 @@ bool Console::cmdDissassemble(int argc, const char **argv) { return true; } - if (lookup_selector(_vm->_gamestate, objAddr, selector_id, NULL, &addr) != kSelectorMethod) { + if (lookup_selector(_vm->_gamestate->segmentManager, objAddr, selector_id, NULL, &addr) != kSelectorMethod) { DebugPrintf("Not a method."); return true; } @@ -2239,7 +2239,7 @@ bool Console::cmdDissassembleAddress(int argc, const char **argv) { return true; } - _vm->_gamestate->seg_manager->dereference(vpc, &size); + _vm->_gamestate->segmentManager->dereference(vpc, &size); size += vpc.offset; // total segment size for (int i = 2; i < argc; i++) { @@ -2298,13 +2298,13 @@ bool Console::cmdSend(int argc, const char **argv) { return true; } - o = obj_get(_vm->_gamestate->seg_manager, _vm->_gamestate->_version, object); + o = obj_get(_vm->_gamestate->segmentManager, object); if (o == NULL) { DebugPrintf("Address \"%04x:%04x\" is not an object\n", PRINT_REG(object)); return true; } - SelectorType selector_type = lookup_selector(_vm->_gamestate, object, selector_id, 0, &fptr); + SelectorType selector_type = lookup_selector(_vm->_gamestate->segmentManager, object, selector_id, 0, &fptr); if (selector_type == kSelectorNone) { DebugPrintf("Object does not support selector: \"%s\"\n", selector_name); @@ -2500,7 +2500,7 @@ bool Console::cmdIsSample(int argc, const char **argv) { return true; } - Resource *song = _vm->getResMgr()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0); + Resource *song = _vm->getresourceManager()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0); SongIterator *songit; Audio::AudioStream *data; @@ -2538,7 +2538,7 @@ bool Console::cmdSfx01Header(int argc, const char **argv) { return true; } - Resource *song = _vm->getResMgr()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0); + Resource *song = _vm->getresourceManager()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0); if (!song) { DebugPrintf("Doesn't exist\n"); @@ -2703,7 +2703,7 @@ bool Console::cmdSfx01Track(int argc, const char **argv) { return true; } - Resource *song = _vm->getResMgr()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0); + Resource *song = _vm->getresourceManager()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0); int offset = atoi(argv[2]); @@ -2838,7 +2838,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on if (*endptr) return 1; - dest->segment = s->seg_manager->segGet(script_nr); + dest->segment = s->segmentManager->segGet(script_nr); if (!dest->segment) { return 1; @@ -2874,8 +2874,8 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on str_objname = str + 1; // Now all values are available; iterate over all objects. - for (i = 0; i < s->seg_manager->_heap.size(); i++) { - MemObject *mobj = s->seg_manager->_heap[i]; + for (i = 0; i < s->segmentManager->_heap.size(); i++) { + MemObject *mobj = s->segmentManager->_heap[i]; int idx = 0; int max_index = 0; @@ -2903,7 +2903,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on } if (valid) { - const char *objname = obj_get_name(s->seg_manager, s->_version, objpos); + const char *objname = obj_get_name(s->segmentManager, objpos); if (!strcmp(objname, str_objname)) { // Found a match! if ((index < 0) && (times_found > 0)) { @@ -2977,7 +2977,7 @@ void Console::printList(List *l) { while (!pos.isNull()) { Node *node; - NodeTable *nt = (NodeTable *)GET_SEGMENT(*_vm->_gamestate->seg_manager, pos.segment, MEM_OBJ_NODES); + NodeTable *nt = (NodeTable *)GET_SEGMENT(*_vm->_gamestate->segmentManager, pos.segment, MEM_OBJ_NODES); if (!nt || !nt->isValidEntry(pos.offset)) { DebugPrintf(" WARNING: %04x:%04x: Doesn't contain list node!\n", @@ -3004,7 +3004,7 @@ void Console::printList(List *l) { } int Console::printNode(reg_t addr) { - MemObject *mobj = GET_SEGMENT(*_vm->_gamestate->seg_manager, addr.segment, MEM_OBJ_LISTS); + MemObject *mobj = GET_SEGMENT(*_vm->_gamestate->segmentManager, addr.segment, MEM_OBJ_LISTS); if (mobj) { ListTable *lt = (ListTable *)mobj; @@ -3021,7 +3021,7 @@ int Console::printNode(reg_t addr) { } else { NodeTable *nt; Node *node; - mobj = GET_SEGMENT(*_vm->_gamestate->seg_manager, addr.segment, MEM_OBJ_NODES); + mobj = GET_SEGMENT(*_vm->_gamestate->segmentManager, addr.segment, MEM_OBJ_NODES); if (!mobj) { DebugPrintf("Segment #%04x is not a list or node segment\n", addr.segment); @@ -3045,10 +3045,10 @@ int Console::printNode(reg_t addr) { int Console::printObject(reg_t pos) { EngineState *s = _vm->_gamestate; // for the several defines in this function - Object *obj = obj_get(s->seg_manager, s->_version, pos); + Object *obj = obj_get(s->segmentManager, pos); Object *var_container = obj; int i; - SciVersion version = s->_version; // for the selector defines + SciVersion version = s->resourceManager->sciVersion(); // for the selector defines if (!obj) { DebugPrintf("[%04x:%04x]: Not an object.", PRINT_REG(pos)); @@ -3056,11 +3056,11 @@ int Console::printObject(reg_t pos) { } // Object header - DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(pos), obj_get_name(s->seg_manager, s->_version, pos), + DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(pos), obj_get_name(s->segmentManager, pos), obj->_variables.size(), obj->methods_nr); if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) - var_container = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); + var_container = obj_get(s->segmentManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); DebugPrintf(" -- member variables:\n"); for (i = 0; (uint)i < obj->_variables.size(); i++) { printf(" "); @@ -3072,9 +3072,9 @@ int Console::printObject(reg_t pos) { reg_t val = obj->_variables[i]; DebugPrintf("%04x:%04x", PRINT_REG(val)); - Object *ref = obj_get(s->seg_manager, s->_version, val); + Object *ref = obj_get(s->segmentManager, val); if (ref) - DebugPrintf(" (%s)", obj_get_name(s->seg_manager, s->_version, val)); + DebugPrintf(" (%s)", obj_get_name(s->segmentManager, val)); DebugPrintf("\n"); } @@ -3083,8 +3083,8 @@ int Console::printObject(reg_t pos) { reg_t fptr = VM_OBJECT_READ_FUNCTION(obj, i); DebugPrintf(" [%03x] %s = %04x:%04x\n", VM_OBJECT_GET_FUNCSELECTOR(obj, i), selector_name(s, VM_OBJECT_GET_FUNCSELECTOR(obj, i)), PRINT_REG(fptr)); } - if (s->seg_manager->_heap[pos.segment]->getType() == MEM_OBJ_SCRIPT) - DebugPrintf("\nOwner script:\t%d\n", s->seg_manager->getScript(pos.segment)->nr); + if (s->segmentManager->_heap[pos.segment]->getType() == MEM_OBJ_SCRIPT) + DebugPrintf("\nOwner script:\t%d\n", s->segmentManager->getScript(pos.segment)->nr); return 0; } @@ -3126,7 +3126,7 @@ static void viewobjinfo(EngineState *s, HeapPtr pos) { int have_rects = 0; Common::Rect nsrect, nsrect_clipped, brrect; - if (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL) == kSelectorVariable) { + if (lookup_selector(s->segmentManager, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL) == kSelectorVariable) { GETRECT(nsLeft, nsRight, nsBottom, nsTop); GETRECT(lsLeft, lsRight, lsBottom, lsTop); GETRECT(brLeft, brRight, brBottom, brTop); @@ -3204,10 +3204,10 @@ static int c_gfx_draw_viewobj(EngineState *s, const Common::Array<cmd_param_t> & } - is_view = (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.x, NULL) == kSelectorVariable) && - (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL) == kSelectorVariable) && - (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, NULL) == kSelectorVariable) && - (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL) == kSelectorVariable); + is_view = (lookup_selector(s->segmentManager, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.x, NULL) == kSelectorVariable) && + (lookup_selector(s->segmentManager, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL) == kSelectorVariable) && + (lookup_selector(s->segmentManager, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, NULL) == kSelectorVariable) && + (lookup_selector(s->segmentManager, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL) == kSelectorVariable); if (!is_view) { printf("Not a dynamic View object.\n"); diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp index ef229c8a19..5971d1d384 100644 --- a/engines/sci/detection.cpp +++ b/engines/sci/detection.cpp @@ -340,21 +340,23 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl return 0; } - ResourceManager *resMgr = new ResourceManager(fslist); - SciVersion version = resMgr->sciVersion(); - ViewType gameViews = resMgr->getViewType(); + ResourceManager *resourceManager = new ResourceManager(fslist); + SciVersion version = resourceManager->sciVersion(); + ViewType gameViews = resourceManager->getViewType(); // Have we identified the game views? If not, stop here if (gameViews == kViewUnknown) { SearchMan.remove("SCI_detection"); + delete resourceManager; return (const ADGameDescription *)&s_fallbackDesc; } #ifndef ENABLE_SCI32 // Is SCI32 compiled in? If not, and this is a SCI32 game, // stop here - if (resMgr->sciVersion() == SCI_VERSION_32) { + if (resourceManager->sciVersion() == SCI_VERSION_32) { SearchMan.remove("SCI_detection"); + delete resourceManager; return (const ADGameDescription *)&s_fallbackDesc; } #endif @@ -363,7 +365,7 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl if (gameViews == kViewEga) s_fallbackDesc.desc.extra = "EGA"; - SegManager *segManager = new SegManager(resMgr, version); + SegManager *segManager = new SegManager(resourceManager); if (exePlatform == Common::kPlatformUnknown) { // Try to determine the platform from game resources @@ -385,20 +387,20 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl s_fallbackDesc.desc.platform = exePlatform; // Determine the game id - if (!script_instantiate(resMgr, segManager, version, 0)) { + if (!script_instantiate(resourceManager, segManager, 0)) { warning("fallbackDetect(): Could not instantiate script 0"); SearchMan.remove("SCI_detection"); delete segManager; - delete resMgr; + delete resourceManager; return 0; } reg_t game_obj = script_lookup_export(segManager, 0, 0); - Common::String gameName = obj_get_name(segManager, version, game_obj); + Common::String gameName = obj_get_name(segManager, game_obj); debug(2, "Detected ID: \"%s\" at %04x:%04x", gameName.c_str(), PRINT_REG(game_obj)); gameName.toLowercase(); s_fallbackDesc.desc.gameid = strdup(convertSierraGameId(gameName).c_str()); delete segManager; - delete resMgr; + delete resourceManager; SearchMan.remove("SCI_detection"); diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 994054f6a7..6f36e40440 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -43,7 +43,7 @@ int _reset_graphics_input(EngineState *s) { gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 }; debug(2, "Initializing graphics"); - if (s->resmgr->getViewType() == kViewEga) { + if (s->resourceManager->getViewType() == kViewEga) { for (int i = 0; i < 16; i++) { if (gfxop_set_color(s->gfx_state, &(s->ega_colors[i]), gfx_sci0_image_colors[sci0_palette][i].r, gfx_sci0_image_colors[sci0_palette][i].g, gfx_sci0_image_colors[sci0_palette][i].b, 0, -1, -1)) { @@ -62,13 +62,13 @@ int _reset_graphics_input(EngineState *s) { s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1_amiga(file)); file.close(); } else { - resource = s->resmgr->findResource(ResourceId(kResourceTypePalette, 999), 1); + resource = s->resourceManager->findResource(ResourceId(kResourceTypePalette, 999), 1); if (resource) { - if (s->_version < SCI_VERSION_1_1) + if (s->resourceManager->sciVersion() < SCI_VERSION_1_1) s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1(999, resource->data, resource->size)); else s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal11(999, resource->data, resource->size)); - s->resmgr->unlockResource(resource); + s->resourceManager->unlockResource(resource); } else { debug(2, "Couldn't find the default palette!"); } @@ -94,7 +94,7 @@ int _reset_graphics_input(EngineState *s) { font_nr = -1; do { - resource = s->resmgr->testResource(ResourceId(kResourceTypeFont, ++font_nr)); + resource = s->resourceManager->testResource(ResourceId(kResourceTypeFont, ++font_nr)); } while ((!resource) && (font_nr < 65536)); if (!resource) { @@ -109,7 +109,7 @@ int _reset_graphics_input(EngineState *s) { s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent); s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH; - if (s->resmgr->isVGA()) { + if (s->resourceManager->isVGA()) { // This bit sets the foreground and background colors in VGA SCI games gfx_color_t fgcolor; gfx_color_t bgcolor; @@ -179,11 +179,11 @@ static void _free_graphics_input(EngineState *s) { } int game_init_sound(EngineState *s, int sound_flags) { - if (s->resmgr->sciVersion() > SCI_VERSION_0_LATE) + if (s->resourceManager->sciVersion() > SCI_VERSION_0_LATE) sound_flags |= SFX_STATE_FLAG_MULTIPLAY; s->sfx_init_flags = sound_flags; - s->_sound.sfx_init(s->resmgr, sound_flags); + s->_sound.sfx_init(s->resourceManager, sound_flags); return 0; } @@ -191,20 +191,20 @@ int game_init_sound(EngineState *s, int sound_flags) { // Architectural stuff: Init/Unintialize engine int script_init_engine(EngineState *s) { s->kernel_opt_flags = 0; - s->seg_manager = new SegManager(s->resmgr, s->_version); + s->segmentManager = new SegManager(s->resourceManager); s->gc_countdown = GC_INTERVAL - 1; - SegmentId script_000_segment = s->seg_manager->getSegment(0, SCRIPT_GET_LOCK); + SegmentId script_000_segment = s->segmentManager->getSegment(0, SCRIPT_GET_LOCK); if (script_000_segment <= 0) { debug(2, "Failed to instantiate script.000"); return 1; } - s->script_000 = s->seg_manager->getScript(script_000_segment); + s->script_000 = s->segmentManager->getScript(script_000_segment); - s->sys_strings = s->seg_manager->allocateSysStrings(&s->sys_strings_segment); - s->string_frag_segment = s->seg_manager->allocateStringFrags(); + s->sys_strings = s->segmentManager->allocateSysStrings(&s->sys_strings_segment); + s->string_frag_segment = s->segmentManager->allocateStringFrags(); // Allocate static buffer for savegame and CWD directories SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR]; @@ -227,9 +227,9 @@ int script_init_engine(EngineState *s) { s->have_bp = 0; if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) - s->seg_manager->setExportWidth(1); + s->segmentManager->setExportWidth(1); else - s->seg_manager->setExportWidth(0); + s->segmentManager->setExportWidth(0); debug(2, "Engine initialized"); @@ -252,8 +252,8 @@ void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int le void script_free_vm_memory(EngineState *s) { debug(2, "Freeing VM memory"); - if (s->seg_manager) - s->seg_manager->_classtable.clear(); + if (s->segmentManager) + s->segmentManager->_classtable.clear(); // Close all opened file handles s->_fileHandles.clear(); @@ -290,11 +290,11 @@ int game_init(EngineState *s) { // FIXME Use new VM instantiation code all over the place" DataStack *stack; - stack = s->seg_manager->allocateStack(VM_STACK_SIZE, &s->stack_segment); + stack = s->segmentManager->allocateStack(VM_STACK_SIZE, &s->stack_segment); s->stack_base = stack->entries; s->stack_top = s->stack_base + VM_STACK_SIZE; - if (!script_instantiate(s->resmgr, s->seg_manager, s->_version, 0)) { + if (!script_instantiate(s->resourceManager, s->segmentManager, 0)) { warning("game_init(): Could not instantiate script 0"); return 1; } @@ -310,7 +310,7 @@ int game_init(EngineState *s) { s->successor = NULL; // No successor s->_statusBarText.clear(); // Status bar is blank s->status_bar_foreground = 0; - s->status_bar_background = !s->resmgr->isVGA() ? 15 : 255; + s->status_bar_background = !s->resourceManager->isVGA() ? 15 : 255; SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE]; str->name = strdup("parser-base"); @@ -328,8 +328,8 @@ int game_init(EngineState *s) { // script_dissect(0, s->_selectorNames); // The first entry in the export table of script 0 points to the game object - s->game_obj = script_lookup_export(s->seg_manager, 0, 0); - s->_gameName = obj_get_name(s->seg_manager, s->_version, s->game_obj); + s->game_obj = script_lookup_export(s->segmentManager, 0, 0); + s->_gameName = obj_get_name(s->segmentManager, s->game_obj); debug(2, " \"%s\" at %04x:%04x", s->_gameName.c_str(), PRINT_REG(s->game_obj)); @@ -357,9 +357,9 @@ int game_exit(EngineState *s) { game_init_sound(s, SFX_STATE_FLAG_NOSOUND); } - s->seg_manager->_classtable.clear(); - delete s->seg_manager; - s->seg_manager = 0; + s->segmentManager->_classtable.clear(); + delete s->segmentManager; + s->segmentManager = 0; s->_synonyms.clear(); diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp index 63a20ddf25..41d454d637 100644 --- a/engines/sci/engine/gc.cpp +++ b/engines/sci/engine/gc.cpp @@ -71,7 +71,7 @@ void add_outgoing_refs(void *refcon, reg_t addr) { } reg_t_hash_map *find_all_used_references(EngineState *s) { - SegManager *sm = s->seg_manager; + SegManager *sm = s->segmentManager; reg_t_hash_map *normal_map = NULL; WorklistManager wm; uint i; @@ -134,7 +134,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { if (reg.segment != s->stack_segment) { // No need to repeat this one debugC(2, kDebugLevelGC, "[GC] Checking %04x:%04x\n", PRINT_REG(reg)); if (reg.segment < sm->_heap.size() && sm->_heap[reg.segment]) - sm->_heap[reg.segment]->listAllOutgoingReferences(s, reg, &wm, add_outgoing_refs); + sm->_heap[reg.segment]->listAllOutgoingReferences(reg, &wm, add_outgoing_refs, s->resourceManager->sciVersion()); } } @@ -145,7 +145,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { } struct deallocator_t { - SegManager *segmgr; + SegManager *segManager; MemObject *mobj; #ifdef DEBUG_GC char *segnames[MEM_OBJ_MAX + 1]; @@ -160,7 +160,7 @@ void free_unless_used(void *refcon, reg_t addr) { if (!use_map->contains(addr)) { // Not found -> we can free it - deallocator->mobj->freeAtAddress(deallocator->segmgr, addr); + deallocator->mobj->freeAtAddress(deallocator->segManager, addr); #ifdef DEBUG_GC debugC(2, kDebugLevelGC, "[GC] Deallocating %04x:%04x\n", PRINT_REG(addr)); deallocator->segcount[deallocator->mobj->getType()]++; @@ -172,14 +172,14 @@ void free_unless_used(void *refcon, reg_t addr) { void run_gc(EngineState *s) { uint seg_nr; deallocator_t deallocator; - SegManager *sm = s->seg_manager; + SegManager *sm = s->segmentManager; #ifdef DEBUG_GC debugC(2, kDebugLevelGC, "[GC] Running...\n"); memset(&(deallocator.segcount), 0, sizeof(int) * (MEM_OBJ_MAX + 1)); #endif - deallocator.segmgr = sm; + deallocator.segManager = sm; deallocator.use_map = find_all_used_references(s); for (seg_nr = 1; seg_nr < sm->_heap.size(); seg_nr++) { diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 687e621405..013d8cb65b 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -363,7 +363,7 @@ static const char *argtype_description[] = { "Arithmetic" }; -Kernel::Kernel(ResourceManager *resmgr) : _resmgr(resmgr) { +Kernel::Kernel(ResourceManager *resourceManager) : _resourceManager(resourceManager) { memset(&_selectorMap, 0, sizeof(_selectorMap)); // FIXME: Remove this once/if we C++ify selector_map_t loadSelectorNames(); @@ -379,7 +379,7 @@ Kernel::~Kernel() { } void Kernel::detectSciFeatures() { - SciVersion version = _resmgr->sciVersion(); + SciVersion version = _resourceManager->sciVersion(); features = 0; @@ -421,7 +421,7 @@ void Kernel::detectSciFeatures() { } void Kernel::loadSelectorNames() { - Resource *r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0); + Resource *r = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0); if (!r) { // No such resource? // Check if we have a table for this game @@ -433,7 +433,7 @@ void Kernel::loadSelectorNames() { for (uint32 i = 0; i < staticSelectorTable.size(); i++) { _selectorNames.push_back(staticSelectorTable[i]); - if (_resmgr->sciVersion() == SCI_VERSION_0_EARLY) + if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) _selectorNames.push_back(staticSelectorTable[i]); } @@ -452,14 +452,14 @@ void Kernel::loadSelectorNames() { // Early SCI versions used the LSB in the selector ID as a read/write // toggle. To compensate for that, we add every selector name twice. - if (_resmgr->sciVersion() == SCI_VERSION_0_EARLY) + if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) _selectorNames.push_back(tmp); } } bool Kernel::loadOpcodes() { int count, i = 0; - Resource* r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES), 0); + Resource* r = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES), 0); _opcodes.clear(); @@ -484,18 +484,18 @@ bool Kernel::loadOpcodes() { } // Allocates a set amount of memory for a specified use and returns a handle to it. -reg_t kalloc(EngineState *s, const char *type, int space) { +reg_t kalloc(SegManager *segManager, const char *type, int space) { reg_t reg; - s->seg_manager->alloc_hunk_entry(type, space, ®); + segManager->alloc_hunk_entry(type, space, ®); debugC(2, kDebugLevelMemory, "Allocated %d at hunk %04x:%04x (%s)\n", space, PRINT_REG(reg), type); return reg; } // Returns a pointer to the memory indicated by the specified handle -byte *kmem(EngineState *s, reg_t handle) { - HunkTable *ht = (HunkTable *)GET_SEGMENT(*s->seg_manager, handle.segment, MEM_OBJ_HUNK); +byte *kmem(SegManager *segManager, reg_t handle) { + HunkTable *ht = (HunkTable *)GET_SEGMENT(*segManager, handle.segment, MEM_OBJ_HUNK); if (!ht || !ht->isValidEntry(handle.offset)) { warning("Error: kmem() with invalid handle"); @@ -506,8 +506,8 @@ byte *kmem(EngineState *s, reg_t handle) { } // Frees the specified handle. Returns 0 on success, 1 otherwise. -int kfree(EngineState *s, reg_t handle) { - s->seg_manager->free_hunk_entry(handle); +int kfree(SegManager *segManager, reg_t handle) { + segManager->free_hunk_entry(handle); return 0; } @@ -649,7 +649,7 @@ void Kernel::mapFunctions() { return; } -int determine_reg_type(EngineState *s, reg_t reg, bool allow_invalid) { +int determine_reg_type(SegManager *segManager, reg_t reg, bool allow_invalid) { MemObject *mobj; int type = 0; @@ -661,12 +661,12 @@ int determine_reg_type(EngineState *s, reg_t reg, bool allow_invalid) { return type; } - if ((reg.segment >= s->seg_manager->_heap.size()) || !s->seg_manager->_heap[reg.segment]) + if ((reg.segment >= segManager->_heap.size()) || !segManager->_heap[reg.segment]) return 0; // Invalid - mobj = s->seg_manager->_heap[reg.segment]; + mobj = segManager->_heap[reg.segment]; - SciVersion version = s->_version; // for the offset defines + SciVersion version = segManager->sciVersion(); // for the offset defines switch (mobj->getType()) { case MEM_OBJ_SCRIPT: @@ -721,7 +721,7 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r while (*sig && argc) { if ((*sig & KSIG_ANY) != KSIG_ANY) { - int type = determine_reg_type(s, *argv, *sig & KSIG_ALLOW_INV); + int type = determine_reg_type(s->segmentManager, *argv, *sig & KSIG_ALLOW_INV); if (!type) { warning("[KERN] Could not determine type of ref %04x:%04x; failing signature check", PRINT_REG(*argv)); @@ -752,7 +752,7 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r static void *_kernel_dereference_pointer(EngineState *s, reg_t pointer, int entries, int align) { int maxsize; - void *retval = s->seg_manager->dereference(pointer, &maxsize); + void *retval = s->segmentManager->dereference(pointer, &maxsize); if (!retval) return NULL; @@ -781,7 +781,7 @@ reg_t *kernel_dereference_reg_pointer(EngineState *s, reg_t pointer, int entries void Kernel::setDefaultKernelNames() { _kernelNames = Common::StringList(sci_default_knames, SCI_KNAMES_DEFAULT_ENTRIES_NR); - switch (_resmgr->sciVersion()) { + switch (_resourceManager->sciVersion()) { case SCI_VERSION_0_EARLY: case SCI_VERSION_0_LATE: // Insert SCI0 file functions after SetCursor (0x28) @@ -817,7 +817,7 @@ void Kernel::setDefaultKernelNames() { } #ifdef ENABLE_SCI32 -//static void vocab_get_knames11(ResourceManager *resmgr, Common::StringList &names) { +//static void vocab_get_knames11(ResourceManager *resourceManager, Common::StringList &names) { /* 999.voc format for SCI1.1 games: [b] # of kernel functions @@ -829,7 +829,7 @@ void Kernel::setDefaultKernelNames() { */ /* //unsigned int size = 64, pos = 3; int len; - Resource *r = resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES), 0); + Resource *r = resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES), 0); if(r == NULL) // failed to open vocab.999 (happens with SCI1 demos) return; // FIXME: should return a default table for this engine const byte nCnt = *r->data; diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index a85025f514..3ad54c9d48 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -68,7 +68,7 @@ public: /** * Initializes the SCI kernel */ - Kernel(ResourceManager *resmgr); + Kernel(ResourceManager *resourceManager); ~Kernel(); uint getOpcodesSize() const { return _opcodes.size(); } @@ -95,16 +95,6 @@ public: bool hasKernelFunction(const char *functionName) const; /** - * Applies to all versions before 0.000.395 (i.e. KQ4 old, XMAS 1988 and LSL2). - * Old SCI versions used two word header for script blocks (first word equal - * to 0x82, meaning of the second one unknown). New SCI versions used one - * word header. - * Also, old SCI versions assign 120 degrees to left & right, and 60 to up - * and down. Later versions use an even 90 degree distribution. - */ - bool hasOldScriptHeader() const { return (features & kFeatureOldScriptHeader); } - - /** * Applies to all versions before 0.000.502 * Old SCI versions used to interpret the third DrawPic() parameter inversely, * with the opposite default value (obviously). @@ -177,7 +167,7 @@ private: */ bool loadOpcodes(); - ResourceManager *_resmgr; + ResourceManager *_resourceManager; uint32 features; // Kernel-related lists @@ -256,7 +246,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index); * @parm obj The address to check * @return True if it is an object, false otherwise */ -bool is_object(EngineState *s, reg_t obj); +bool is_object(SegManager *segManager, reg_t obj); /******************** Kernel function parameter macros ********************/ diff --git a/engines/sci/engine/kernel_types.h b/engines/sci/engine/kernel_types.h index 8927586a8e..c8281a1fdd 100644 --- a/engines/sci/engine/kernel_types.h +++ b/engines/sci/engine/kernel_types.h @@ -79,14 +79,14 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r /** * Determines the type of the object indicated by reg. - * @param s state to operate on + * @param segManager the Segment manager * @param reg register to check * @param allow_invalid determines whether invalid pointer (=offset) values are allowed * @return one of KSIG_* below KSIG_NULL. * KSIG_INVALID set if the type of reg can be determined, but is invalid. * 0 on error. */ -int determine_reg_type(EngineState *s, reg_t reg, bool allow_invalid); +int determine_reg_type(SegManager *segManager, reg_t reg, bool allow_invalid); /** * Returns a textual description of the type of an object. diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index b3b8d3d53b..bac1d08d78 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -40,7 +40,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t obj = argv[1]; sci_event_t e; int oldx, oldy; - int modifier_mask = s->_version <= SCI_VERSION_01 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK; + int modifier_mask = s->resourceManager->sciVersion() <= SCI_VERSION_01 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK; // If there's a simkey pending, and the game wants a keyboard event, use the // simkey instead of a normal event diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index ffc14716a5..ab5cd57c34 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -203,8 +203,8 @@ int _find_priority_band(EngineState *s, int nr) { } reg_t graph_save_box(EngineState *s, rect_t area) { - reg_t handle = kalloc(s, "graph_save_box()", sizeof(gfxw_snapshot_t *)); - gfxw_snapshot_t **ptr = (gfxw_snapshot_t **)kmem(s, handle); + reg_t handle = kalloc(s->segmentManager, "graph_save_box()", sizeof(gfxw_snapshot_t *)); + gfxw_snapshot_t **ptr = (gfxw_snapshot_t **)kmem(s->segmentManager, handle); // FIXME: gfxw_make_snapshot returns a pointer. Now why do we store a // pointer to real memory inside the SCI heap? @@ -225,7 +225,7 @@ void graph_restore_box(EngineState *s, reg_t handle) { return; } - ptr = (gfxw_snapshot_t **)kmem(s, handle); + ptr = (gfxw_snapshot_t **)kmem(s->segmentManager, handle); if (!ptr) { warning("Attempt to restore invalid handle %04x:%04x", PRINT_REG(handle)); @@ -265,11 +265,11 @@ void graph_restore_box(EngineState *s, reg_t handle) { free(*ptr); *ptr = NULL; - kfree(s, handle); + kfree(s->segmentManager, handle); } PaletteEntry get_pic_color(EngineState *s, int color) { - if (!s->resmgr->isVGA()) + if (!s->resourceManager->isVGA()) return s->ega_colors[color].visual; if (color == -1 || color == 255) // -1 occurs in Eco Quest 1. Not sure if this is the best approach, but it seems to work @@ -286,7 +286,7 @@ PaletteEntry get_pic_color(EngineState *s, int color) { static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int control) { gfx_color_t retval; - if (!s->resmgr->isVGA()) { + if (!s->resourceManager->isVGA()) { retval = s->ega_colors[(color >=0 && color < 16)? color : 0]; gfxop_set_color(s->gfx_state, &retval, (color < 0) ? -1 : retval.visual.r, retval.visual.g, retval.visual.b, (color == -1) ? 255 : 0, priority, control); @@ -302,11 +302,13 @@ static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int } reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { + SciVersion version = s->resourceManager->sciVersion(); + switch (argc) { case 1 : - if (s->_version < SCI_VERSION_1_LATE) { + if (version < SCI_VERSION_1_LATE) { GFX_ASSERT(gfxop_set_pointer_cursor(s->gfx_state, argv[0].toSint16())); - } else if (s->_version < SCI_VERSION_1_1) { + } else if (version < SCI_VERSION_1_1) { if (argv[0].toSint16() <= 1) { // Newer (SCI1.1) semantics: show/hide cursor CursorMan.showMouse(argv[0].toSint16() != 0); @@ -320,10 +322,10 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { } break; case 2 : - if (s->_version < SCI_VERSION_1_LATE) { + if (version < SCI_VERSION_1_LATE) { GFX_ASSERT(gfxop_set_pointer_cursor(s->gfx_state, argv[1].toSint16() == 0 ? GFXOP_NO_POINTER : argv[0].toSint16())); - } else if (s->_version < SCI_VERSION_1_1) { + } else if (version < SCI_VERSION_1_1) { // Pre-SCI1.1: set cursor according to the first parameter, and toggle its // visibility based on the second parameter // Some late SCI1 games actually use the SCI1.1 version of this call (EcoQuest 1 @@ -502,7 +504,7 @@ reg_t kGraph(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_GRAPH_GET_COLORS_NR: - return make_reg(0, !s->resmgr->isVGA() ? 0x10 : 0x100); + return make_reg(0, !s->resourceManager->isVGA() ? 0x10 : 0x100); break; case K_GRAPH_DRAW_LINE: { @@ -691,13 +693,14 @@ void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc, int signal = GET_SEL32V(obj, signal); int loop; int maxloops; + bool oldScriptHeader = (s->resourceManager->sciVersion() == SCI_VERSION_0_EARLY); if (signal & _K_VIEW_SIG_FLAG_DOESNT_TURN) return; angle %= 360; - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { + if (!oldScriptHeader) { if (angle < 45) loop = 3; else if (angle < 136) @@ -827,7 +830,7 @@ reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t *argv) { while (widget) { if (widget->_ID && (widget->signal & _K_VIEW_SIG_FLAG_STOPUPD) && ((widget->_ID != obj.segment) || (widget->_subID != obj.offset)) - && is_object(s, make_reg(widget->_ID, widget->_subID))) + && is_object(s->segmentManager, make_reg(widget->_ID, widget->_subID))) if (collides_with(s, abs_zone, make_reg(widget->_ID, widget->_subID), 1, GASEOUS_VIEW_MASK_ACTIVE, funct_nr, argc, argv)) return not_register(s, NULL_REG); @@ -853,7 +856,7 @@ reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t other_obj = node->value; debugC(2, kDebugLevelBresen, " comparing against %04x:%04x\n", PRINT_REG(other_obj)); - if (!is_object(s, other_obj)) { + if (!is_object(s->segmentManager, other_obj)) { warning("CanBeHere() cliplist contains non-object %04x:%04x", PRINT_REG(other_obj)); } else if (other_obj != obj) { // Clipping against yourself is not recommended @@ -1134,7 +1137,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, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable) + if (lookup_selector(s->segmentManager, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable) return; // non-fatal // Note: there was a check here for a very old version of SCI, which supposedly needed @@ -1142,7 +1145,7 @@ void _k_base_setter(EngineState *s, reg_t object) { // does not exist (earliest one was KQ4 SCI, version 0.000.274). This code is left here // for reference only #if 0 - if (s->_version <= SCI_VERSION_0) + if (s->resourceManager->sciVersion() <= SCI_VERSION_0) --absrect.top; // Compensate for early SCI OB1 'bug' #endif @@ -1239,7 +1242,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, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) { + if (lookup_selector(s->segmentManager, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) { return; } // This isn't fatal @@ -1329,7 +1332,7 @@ static void _k_draw_control(EngineState *s, reg_t obj, int inverse); static void _k_disable_delete_for_now(EngineState *s, reg_t obj) { reg_t text_pos = GET_SEL32(obj, text); - char *text = text_pos.isNull() ? NULL : (char *)s->seg_manager->dereference(text_pos, NULL); + char *text = text_pos.isNull() ? NULL : (char *)s->segmentManager->dereference(text_pos, NULL); int type = GET_SEL32V(obj, type); int state = GET_SEL32V(obj, state); @@ -1353,7 +1356,7 @@ static void _k_disable_delete_for_now(EngineState *s, reg_t obj) { * that game - bringing the save/load dialog on a par with SCI0. */ if (type == K_CONTROL_BUTTON && text && (s->_gameName == "sq4") && - s->_version < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) { + s->resourceManager->sciVersion() < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) { PUT_SEL32V(obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled); } } @@ -1418,7 +1421,7 @@ reg_t kEditControl(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t text_pos = GET_SEL32(obj, text); int display_offset = 0; - char *text = (char *)s->seg_manager->dereference(text_pos, NULL); + char *text = (char *)s->segmentManager->dereference(text_pos, NULL); int textlen; if (!text) { @@ -1580,7 +1583,7 @@ static void _k_draw_control(EngineState *s, reg_t obj, int inverse) { int font_nr = GET_SEL32V(obj, font); reg_t text_pos = GET_SEL32(obj, text); - const char *text = text_pos.isNull() ? NULL : (char *)s->seg_manager->dereference(text_pos, NULL); + const char *text = text_pos.isNull() ? NULL : (char *)s->segmentManager->dereference(text_pos, NULL); int view = GET_SEL32V(obj, view); int cel = sign_extend_byte(GET_SEL32V(obj, cel)); int loop = sign_extend_byte(GET_SEL32V(obj, loop)); @@ -1702,7 +1705,7 @@ static void draw_rect_to_control_map(EngineState *s, Common::Rect abs_zone) { static void draw_obj_to_control_map(EngineState *s, GfxDynView *view) { reg_t obj = make_reg(view->_ID, view->_subID); - if (!is_object(s, obj)) + if (!is_object(s->segmentManager, obj)) warning("View %d does not contain valid object reference %04x:%04x", view->_ID, PRINT_REG(obj)); reg_t* sp = view->signalp.getPointer(s); @@ -1725,7 +1728,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, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; + int has_nsrect = lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; if (has_nsrect) { int temp; @@ -1747,7 +1750,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, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL)); + fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL)); #endif if (widget->signal & _K_VIEW_SIG_FLAG_HIDDEN) @@ -1806,7 +1809,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in reg_t obj = make_reg(widget->_ID, widget->_subID); reg_t under_bits = NULL_REG; - if (!is_object(s, obj)) { + if (!is_object(s->segmentManager, obj)) { error("Non-object %04x:%04x present in view list during delete time", PRINT_REG(obj)); obj = NULL_REG; } else { @@ -1815,7 +1818,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in reg_t mem_handle = *ubp; if (mem_handle.segment) { - if (!kfree(s, mem_handle)) { + if (!kfree(s->segmentManager, mem_handle)) { *ubp = make_reg(0, widget->under_bits = 0); } else { warning("Treating viewobj %04x:%04x as no longer present", PRINT_REG(obj)); @@ -1824,7 +1827,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in } } } - if (is_object(s, obj)) { + if (is_object(s->segmentManager, obj)) { if (invoke_selector(INV_SEL(obj, delete_, kContinueOnInvalidSelector), 0)) warning("Object at %04x:%04x requested deletion, but does not have a delete funcselector", PRINT_REG(obj)); if (_k_animate_ran) { @@ -1924,7 +1927,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i } ObjVarRef under_bitsp; - if (lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) { + if (lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) { under_bitsp.obj = NULL_REG; under_bits = NULL_REG; debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no underBits\n", PRINT_REG(obj)); @@ -1932,7 +1935,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i under_bits = *under_bitsp.getPointer(s); ObjVarRef signalp; - if (lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) { + if (lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) { signalp.obj = NULL_REG; signal = 0; debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no signal selector\n", PRINT_REG(obj)); @@ -2025,7 +2028,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, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; + int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; int oldsignal = view->signal; _k_set_now_seen(s, obj); @@ -2503,7 +2506,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { int16 bgColor = (argc > 8 + argextra) ? argv[8 + argextra].toSint16() : 255; if (bgColor >= 0) { - if (!s->resmgr->isVGA()) + if (!s->resourceManager->isVGA()) bgcolor.visual = get_pic_color(s, MIN<int>(bgColor, 15)); else bgcolor.visual = get_pic_color(s, bgColor); @@ -2529,7 +2532,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { black.alpha = 0; black.control = -1; black.priority = -1; - lWhite.visual = get_pic_color(s, !s->resmgr->isVGA() ? 15 : 255); + lWhite.visual = get_pic_color(s, !s->resourceManager->isVGA() ? 15 : 255); lWhite.mask = GFX_MASK_VISUAL; lWhite.alpha = 0; lWhite.priority = -1; @@ -3150,7 +3153,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { bg_color = port->_bgcolor; // TODO: in SCI1VGA the default colors for text and background are #0 (black) // SCI0 case should be checked - if (s->resmgr->isVGA()) { + if (s->resourceManager->isVGA()) { // This priority check fixes the colors in the menus in KQ5 // TODO/FIXME: Is this correct? if (color0.priority >= 0) @@ -3192,10 +3195,10 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { temp = argv[argpt++].toSint16(); debugC(2, kDebugLevelGraphics, "Display: set_color(%d)\n", temp); - if (!s->resmgr->isVGA() && temp >= 0 && temp <= 15) + if (!s->resourceManager->isVGA() && temp >= 0 && temp <= 15) color0 = (s->ega_colors[temp]); else - if (s->resmgr->isVGA() && temp >= 0 && temp < 256) { + if (s->resourceManager->isVGA() && temp >= 0 && temp < 256) { color0.visual = get_pic_color(s, temp); color0.mask = GFX_MASK_VISUAL; } else @@ -3209,10 +3212,10 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { temp = argv[argpt++].toSint16(); debugC(2, kDebugLevelGraphics, "Display: set_bg_color(%d)\n", temp); - if (!s->resmgr->isVGA() && temp >= 0 && temp <= 15) + if (!s->resourceManager->isVGA() && temp >= 0 && temp <= 15) bg_color = s->ega_colors[temp]; else - if (s->resmgr->isVGA() && temp >= 0 && temp <= 256) { + if (s->resourceManager->isVGA() && temp >= 0 && temp <= 256) { bg_color.visual = get_pic_color(s, temp); bg_color.mask = GFX_MASK_VISUAL; } else diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp index a9ae77972f..bdf9115c84 100644 --- a/engines/sci/engine/klists.cpp +++ b/engines/sci/engine/klists.cpp @@ -32,7 +32,7 @@ Node *lookup_node(EngineState *s, reg_t addr) { if (!addr.offset && !addr.segment) return NULL; // Non-error null - MemObject *mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_NODES); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, addr.segment, MEM_OBJ_NODES); if (!mobj) { // FIXME: This occurs right at the beginning of SQ4, when walking north from the first screen. It doesn't // seem to have any apparent ill-effects, though, so it's been changed to non-fatal, for now @@ -52,7 +52,7 @@ Node *lookup_node(EngineState *s, reg_t addr) { } List *lookup_list(EngineState *s, reg_t addr) { - MemObject *mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_LISTS); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, addr.segment, MEM_OBJ_LISTS); if (!mobj) { error("Attempt to use non-list %04x:%04x as list", PRINT_REG(addr)); @@ -135,7 +135,7 @@ int sane_listp(EngineState *s, reg_t addr) { reg_t kNewList(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t listbase; List *l; - l = s->seg_manager->alloc_List(&listbase); + l = s->segmentManager->alloc_List(&listbase); l->first = l->last = NULL_REG; debugC(2, kDebugLevelNodes, "New listbase at %04x:%04x\n", PRINT_REG(listbase)); @@ -159,19 +159,19 @@ reg_t kDisposeList(EngineState *s, int funct_nr, int argc, reg_t *argv) { while (!n_addr.isNull()) { // Free all nodes Node *n = lookup_node(s, n_addr); - s->seg_manager->free_Node(n_addr); + s->segmentManager->free_Node(n_addr); n_addr = n->succ; } } - s->seg_manager->free_list(argv[0]); + s->segmentManager->free_list(argv[0]); */ return s->r_acc; } reg_t _k_new_node(EngineState *s, reg_t value, reg_t key) { reg_t nodebase; - Node *n = s->seg_manager->alloc_Node(&nodebase); + Node *n = s->segmentManager->alloc_Node(&nodebase); if (!n) { error("[Kernel] Out of memory while creating a node"); @@ -401,7 +401,7 @@ reg_t kDeleteKey(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!n->succ.isNull()) lookup_node(s, n->succ)->pred = n->pred; - //s->seg_manager->free_Node(node_pos); + //s->segmentManager->free_Node(node_pos); return make_reg(0, 1); // Signal success } @@ -444,7 +444,7 @@ reg_t kSort(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; if (output_data.isNull()) { - list = s->seg_manager->alloc_List(&output_data); + list = s->segmentManager->alloc_List(&output_data); list->first = list->last = NULL_REG; PUT_SEL32(dest, elements, output_data); } diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index 90ae88b73f..7f6f95347b 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -180,16 +180,16 @@ enum { reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (argv[0].toUint16()) { case K_MEMORY_ALLOCATE_CRITICAL : - if (!s->seg_manager->allocDynmem(argv[1].toUint16(), "kMemory() critical", &s->r_acc)) { + if (!s->segmentManager->allocDynmem(argv[1].toUint16(), "kMemory() critical", &s->r_acc)) { error("Critical heap allocation failed"); } return s->r_acc; break; case K_MEMORY_ALLOCATE_NONCRITICAL : - s->seg_manager->allocDynmem(argv[1].toUint16(), "kMemory() non-critical", &s->r_acc); + s->segmentManager->allocDynmem(argv[1].toUint16(), "kMemory() non-critical", &s->r_acc); break; case K_MEMORY_FREE : - if (s->seg_manager->freeDynmem(argv[1])) { + if (s->segmentManager->freeDynmem(argv[1])) { error("Attempt to kMemory::free() non-dynmem pointer %04x:%04x", PRINT_REG(argv[1])); } break; @@ -219,7 +219,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { warning("Attempt to peek invalid memory at %04x:%04x", PRINT_REG(argv[1])); return s->r_acc; } - if (s->seg_manager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) + if (s->segmentManager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) return *((reg_t *) ref); else return make_reg(0, (int16)READ_LE_UINT16(ref)); @@ -233,7 +233,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; } - if (s->seg_manager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) + if (s->segmentManager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) *((reg_t *) ref) = argv[2]; else { if (argv[2].segment) { diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp index 58dc3b73f1..2c0dd1500b 100644 --- a/engines/sci/engine/kmovement.cpp +++ b/engines/sci/engine/kmovement.cpp @@ -257,7 +257,7 @@ static void bresenham_autodetect(EngineState *s) { reg_t motion_class; if (!parse_reg_t(s, "?Motion", &motion_class)) { - Object *obj = obj_get(s->seg_manager, s->_version, motion_class); + Object *obj = obj_get(s->segmentManager, motion_class); reg_t fptr; byte *buf; @@ -267,14 +267,14 @@ static void bresenham_autodetect(EngineState *s) { return; } - if (lookup_selector(s, motion_class, ((SciEngine*)g_engine)->getKernel()->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) { + if (lookup_selector(s->segmentManager, motion_class, ((SciEngine*)g_engine)->getKernel()->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) { warning("bresenham_autodetect failed"); handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess return; } - buf = s->seg_manager->getScript(fptr.segment)->buf + fptr.offset; - handle_movecnt = (s->_version <= SCI_VERSION_01 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT; + buf = s->segmentManager->getScript(fptr.segment)->buf + fptr.offset; + handle_movecnt = (s->segmentManager->sciVersion() <= SCI_VERSION_01 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT; printf("b-moveCnt action based on checksum: %s\n", handle_movecnt == IGNORE_MOVECNT ? "ignore" : "increment"); } else { warning("bresenham_autodetect failed"); @@ -293,7 +293,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) { int completed = 0; int max_movcnt = GET_SEL32V(client, moveSpeed); - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) signal &= ~_K_VIEW_SIG_FLAG_HIT_OBSTACLE; if (handle_movecnt == UNINITIALIZED) @@ -380,7 +380,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) { completed = 1; } - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) if (completed) invoke_selector(INV_SEL(mover, moveDone, kStopOnInvalidSelector), 0); diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp index ad14202257..8d6142166a 100644 --- a/engines/sci/engine/kpathing.cpp +++ b/engines/sci/engine/kpathing.cpp @@ -1588,7 +1588,7 @@ static reg_t output_path(PathfindingState *p, EngineState *s) { if (unreachable) { // If pathfinding failed we only return the path up to vertex_start - oref = s->seg_manager->allocDynmem(POLY_POINT_SIZE * 3, AVOIDPATH_DYNMEM_STRING, &output); + oref = s->segmentManager->allocDynmem(POLY_POINT_SIZE * 3, AVOIDPATH_DYNMEM_STRING, &output); if (p->_prependPoint) POLY_SET_POINT(oref, 0, *p->_prependPoint); @@ -1608,7 +1608,7 @@ static reg_t output_path(PathfindingState *p, EngineState *s) { } // Allocate memory for path, plus 3 extra for appended point, prepended point and sentinel - oref = s->seg_manager->allocDynmem(POLY_POINT_SIZE * (path_len + 3), AVOIDPATH_DYNMEM_STRING, &output); + oref = s->segmentManager->allocDynmem(POLY_POINT_SIZE * (path_len + 3), AVOIDPATH_DYNMEM_STRING, &output); int offset = 0; @@ -1700,7 +1700,7 @@ reg_t kAvoidPath(EngineState *s, int funct_nr, int argc, reg_t *argv) { printf("[avoidpath] Error: pathfinding failed for following input:\n"); print_input(s, poly_list, start, end, opt); printf("[avoidpath] Returning direct path from start point to end point\n"); - oref = s->seg_manager->allocDynmem(POLY_POINT_SIZE * 3, + oref = s->segmentManager->allocDynmem(POLY_POINT_SIZE * 3, AVOIDPATH_DYNMEM_STRING, &output); POLY_SET_POINT(oref, 0, start); diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index 41eb9f624d..d59ed9b29d 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -34,7 +34,7 @@ namespace Sci { reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const char *file, int line) { ObjVarRef address; - if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) + if (lookup_selector(s->segmentManager, object, selector_id, &address, NULL) != kSelectorVariable) return NULL_REG; else return *address.getPointer(s); @@ -49,7 +49,7 @@ void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t va return; } - if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) + if (lookup_selector(s->segmentManager, object, selector_id, &address, NULL) != kSelectorVariable) warning("Selector '%s' of object at %04x:%04x could not be" " written to (%s L%d)", ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line); else @@ -68,7 +68,7 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc stackframe[0] = make_reg(0, selector_id); // The selector we want to call stackframe[1] = make_reg(0, argc); // Argument count - slc_type = lookup_selector(s, object, selector_id, NULL, &address); + slc_type = lookup_selector(s->segmentManager, object, selector_id, NULL, &address); if (slc_type == kSelectorNone) { warning("Selector '%s' of object at %04x:%04x could not be invoked (%s L%d)", @@ -107,8 +107,8 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc return 0; } -bool is_object(EngineState *s, reg_t object) { - return obj_get(s->seg_manager, s->_version, object) != NULL; +bool is_object(SegManager *segManager, reg_t object) { + return obj_get(segManager, object) != NULL; } // Loads arbitrary resources of type 'restype' with resource numbers 'resnrs' @@ -119,7 +119,7 @@ reg_t kLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { // Request to dynamically allocate hunk memory for later use if (restype == kResourceTypeMemory) - return kalloc(s, "kLoad()", resnr); + return kalloc(s->segmentManager, "kLoad()", resnr); return make_reg(0, ((restype << 11) | resnr)); // Return the resource identifier as handle } @@ -133,18 +133,18 @@ reg_t kLock(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (state) { case 1 : - s->resmgr->findResource(id, 1); + s->resourceManager->findResource(id, 1); break; case 0 : - which = s->resmgr->findResource(id, 0); + which = s->resourceManager->findResource(id, 0); if (which) - s->resmgr->unlockResource(which); + s->resourceManager->unlockResource(which); else { if (id.type == kResourceTypeInvalid) - warning("[Resmgr] Attempt to unlock resource %i of invalid type %i", id.number, type); + warning("[resourceManager] Attempt to unlock resource %i of invalid type %i", id.number, type); else - warning("[Resmgr] Attempt to unlock non-existant resource %s", id.toString().c_str()); + warning("[resourceManager] Attempt to unlock non-existant resource %s", id.toString().c_str()); } break; } @@ -157,7 +157,7 @@ reg_t kUnLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t resnr = argv[1]; if (restype == kResourceTypeMemory) - kfree(s, resnr); + kfree(s->segmentManager, resnr); return s->r_acc; } @@ -173,10 +173,10 @@ reg_t kResCheck(EngineState *s, int funct_nr, int argc, reg_t *argv) { uint cond = argv[4].toUint16() & 0xff; uint seq = argv[5].toUint16() & 0xff; - res = s->resmgr->testResource(ResourceId(restype, argv[1].toUint16(), noun, verb, cond, seq)); + res = s->resourceManager->testResource(ResourceId(restype, argv[1].toUint16(), noun, verb, cond, seq)); } } else { - res = s->resmgr->testResource(ResourceId(restype, argv[1].toUint16())); + res = s->resourceManager->testResource(ResourceId(restype, argv[1].toUint16())); } return make_reg(0, res != NULL); @@ -184,7 +184,7 @@ reg_t kResCheck(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t parent_addr = argv[0]; - Object *parent_obj = obj_get(s->seg_manager, s->_version, parent_addr); + Object *parent_obj = obj_get(s->segmentManager, parent_addr); reg_t clone_addr; Clone *clone_obj; // same as Object* @@ -195,7 +195,7 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { debugC(2, kDebugLevelMemory, "Attempting to clone from %04x:%04x\n", PRINT_REG(parent_addr)); - clone_obj = s->seg_manager->alloc_Clone(&clone_addr); + clone_obj = s->segmentManager->alloc_Clone(&clone_addr); if (!clone_obj) { error("Cloning %04x:%04x failed-- internal error", PRINT_REG(parent_addr)); @@ -205,15 +205,15 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { *clone_obj = *parent_obj; clone_obj->flags = 0; - SciVersion version = s->_version; // for the selector defines + SciVersion version = s->resourceManager->sciVersion(); // for the selector defines // Mark as clone clone_obj->_variables[SCRIPT_INFO_SELECTOR].offset = SCRIPT_INFO_CLONE; clone_obj->_variables[SCRIPT_SPECIES_SELECTOR] = clone_obj->pos; if (IS_CLASS(parent_obj)) clone_obj->_variables[SCRIPT_SUPERCLASS_SELECTOR] = parent_obj->pos; - s->seg_manager->getScript(parent_obj->pos.segment)->incrementLockers(); - s->seg_manager->getScript(clone_obj->pos.segment)->incrementLockers(); + s->segmentManager->getScript(parent_obj->pos.segment)->incrementLockers(); + s->segmentManager->getScript(clone_obj->pos.segment)->incrementLockers(); return clone_addr; } @@ -222,7 +222,7 @@ extern void _k_view_list_mark_free(EngineState *s, reg_t off); reg_t kDisposeClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t victim_addr = argv[0]; - Clone *victim_obj = obj_get(s->seg_manager, s->_version, victim_addr); + Clone *victim_obj = obj_get(s->segmentManager, victim_addr); uint16 underBits; if (!victim_obj) { @@ -231,7 +231,7 @@ reg_t kDisposeClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; } - SciVersion version = s->_version; // for the selector defines + SciVersion version = s->resourceManager->sciVersion(); // for the selector defines if (victim_obj->_variables[SCRIPT_INFO_SELECTOR].offset != SCRIPT_INFO_CLONE) { //warning("Attempt to dispose something other than a clone at %04x", offset); @@ -264,7 +264,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { int script = argv[0].toUint16(); int index = (argc > 1) ? argv[1].toUint16() : 0; - SegmentId scriptid = s->seg_manager->getSegment(script, SCRIPT_GET_LOAD); + SegmentId scriptid = s->segmentManager->getSegment(script, SCRIPT_GET_LOAD); Script *scr; if (argv[0].segment) @@ -273,7 +273,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!scriptid) return NULL_REG; - scr = s->seg_manager->getScript(scriptid); + scr = s->segmentManager->getScript(scriptid); if (!scr->exports_nr) { // FIXME: Is this fatal? This occurs in SQ4CD @@ -286,7 +286,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { return NULL_REG; } - return make_reg(scriptid, s->seg_manager->validateExportFunc(index, scriptid)); + return make_reg(scriptid, s->segmentManager->validateExportFunc(index, scriptid)); } reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) { @@ -296,21 +296,21 @@ reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (argv[0].segment) return s->r_acc; - int id = s->seg_manager->segGet(script); - Script *scr = s->seg_manager->getScriptIfLoaded(id); + int id = s->segmentManager->segGet(script); + Script *scr = s->segmentManager->getScriptIfLoaded(id); if (scr) { if (s->_executionStack.back().addr.pc.segment != id) scr->setLockers(1); } - script_uninstantiate(s->seg_manager, s->_version, script); + script_uninstantiate(s->segmentManager, script); s->_executionStackPosChanged = true; return s->r_acc; } int is_heap_object(EngineState *s, reg_t pos) { - Object *obj = obj_get(s->seg_manager, s->_version, pos); - return (obj != NULL && (!(obj->flags & OBJECT_FLAG_FREED)) && (!s->seg_manager->scriptIsMarkedAsDeleted(pos.segment))); + Object *obj = obj_get(s->segmentManager, pos); + return (obj != NULL && (!(obj->flags & OBJECT_FLAG_FREED)) && (!s->segmentManager->scriptIsMarkedAsDeleted(pos.segment))); } reg_t kIsObject(EngineState *s, int funct_nr, int argc, reg_t *argv) { @@ -324,7 +324,7 @@ reg_t kRespondsTo(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t obj = argv[0]; int selector = argv[1].toUint16(); - return make_reg(0, is_heap_object(s, obj) && lookup_selector(s, obj, selector, NULL, NULL) != kSelectorNone); + return make_reg(0, is_heap_object(s, obj) && lookup_selector(s->segmentManager, obj, selector, NULL, NULL) != kSelectorNone); } } // End of namespace Sci diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 44b2404e41..06da533003 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -123,7 +123,7 @@ enum AudioSyncCommands { static void script_set_priority(EngineState *s, reg_t obj, int priority) { int song_nr = GET_SEL32V(obj, number); - Resource *song = s->resmgr->findResource(ResourceId(kResourceTypeSound, song_nr), 0); + Resource *song = s->resourceManager->findResource(ResourceId(kResourceTypeSound, song_nr), 0); int flags = GET_SEL32V(obj, flags); if (priority == -1) { @@ -140,7 +140,7 @@ static void script_set_priority(EngineState *s, reg_t obj, int priority) { } SongIterator *build_iterator(EngineState *s, int song_nr, SongIteratorType type, songit_id_t id) { - Resource *song = s->resmgr->findResource(ResourceId(kResourceTypeSound, song_nr), 0); + Resource *song = s->resourceManager->findResource(ResourceId(kResourceTypeSound, song_nr), 0); if (!song) return NULL; @@ -157,13 +157,13 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their SongHandle handle; int cue; - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) return; /* SCI1 and later explicitly poll for everything */ while ((result = s->_sound.sfx_poll(&handle, &cue))) { reg_t obj = DEFROBNICATE_HANDLE(handle); - if (!is_object(s, obj)) { + if (!is_object(s->segmentManager, obj)) { warning("Non-object %04x:%04x received sound signal (%d/%d)", PRINT_REG(obj), result, cue); return; } @@ -506,7 +506,7 @@ reg_t kDoSoundSci1Early(EngineState *s, int funct_nr, int argc, reg_t *argv) { //int vol = GET_SEL32V(obj, vol); //int pri = GET_SEL32V(obj, pri); - if (obj.segment && (s->resmgr->testResource(ResourceId(kResourceTypeSound, number)))) { + if (obj.segment && (s->resourceManager->testResource(ResourceId(kResourceTypeSound, number)))) { debugC(2, kDebugLevelSound, "Initializing song number %d\n", number); s->_sound.sfx_add_song(build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), 0, handle, number); @@ -815,8 +815,8 @@ reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) { // a relevant audio resource, play it, otherwise switch to synthesized // effects. If the resource exists, play it using map 65535 (sound // effects map) - if (s->resmgr->testResource(ResourceId(kResourceTypeAudio, number)) && - s->_version >= SCI_VERSION_1_1) { + if (s->resourceManager->testResource(ResourceId(kResourceTypeAudio, number)) && + s->resourceManager->sciVersion() >= SCI_VERSION_1_1) { // Found a relevant audio resource, play it s->_sound.stopAudio(); warning("Initializing audio resource instead of requested sound resource %d\n", number); @@ -824,7 +824,7 @@ reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) { // Also create iterator, that will fire SI_FINISHED event, when the sound is done playing s->_sound.sfx_add_song(build_timeriterator(s, sampleLen), 0, handle, number); } else { - if (!s->resmgr->testResource(ResourceId(kResourceTypeSound, number))) { + if (!s->resourceManager->testResource(ResourceId(kResourceTypeSound, number))) { warning("Could not open song number %d", number); // Send a "stop handle" event so that the engine won't wait forever here s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); @@ -858,7 +858,7 @@ reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) { s->_sound.sfx_remove_song(handle); } - if (obj.segment && (s->resmgr->testResource(ResourceId(kResourceTypeSound, number)))) { + if (obj.segment && (s->resourceManager->testResource(ResourceId(kResourceTypeSound, number)))) { debugC(2, kDebugLevelSound, "Initializing song number %d\n", number); s->_sound.sfx_add_song(build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), 0, handle, number); @@ -1051,7 +1051,7 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) { // In SCI1.1: tests for digital audio support return make_reg(0, 1); } else { - s->resmgr->setAudioLanguage(argv[1].toSint16()); + s->resourceManager->setAudioLanguage(argv[1].toSint16()); } break; default: @@ -1067,7 +1067,7 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) { ResourceId id; if (s->_sound._syncResource) { - s->resmgr->unlockResource(s->_sound._syncResource); + s->resourceManager->unlockResource(s->_sound._syncResource); s->_sound._syncResource = NULL; } @@ -1082,7 +1082,7 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; } - s->_sound._syncResource = s->resmgr->findResource(id, 1); + s->_sound._syncResource = s->resourceManager->findResource(id, 1); if (s->_sound._syncResource) { PUT_SEL32V(argv[1], syncCue, 0); @@ -1114,7 +1114,7 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) { } case kSciAudioSyncStop: if (s->_sound._syncResource) { - s->resmgr->unlockResource(s->_sound._syncResource); + s->resourceManager->unlockResource(s->_sound._syncResource); s->_sound._syncResource = NULL; } break; diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 6e5a19bba9..7a936f3cb4 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -48,7 +48,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) { else { int textlen; int _index = index; - textres = s->resmgr->findResource(ResourceId(kResourceTypeText, address.offset), 0); + textres = s->resourceManager->findResource(ResourceId(kResourceTypeText, address.offset), 0); if (!textres) { error("text.%03d not found", address.offset); @@ -144,15 +144,15 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) { int synonyms_nr = 0; script = GET_SEL32V(objpos, number); - seg = s->seg_manager->segGet(script); + seg = s->segmentManager->segGet(script); if (seg >= 0) - synonyms_nr = s->seg_manager->getScript(seg)->getSynonymsNr(); + synonyms_nr = s->segmentManager->getScript(seg)->getSynonymsNr(); if (synonyms_nr) { byte *synonyms; - synonyms = s->seg_manager->getScript(seg)->getSynonyms(); + synonyms = s->segmentManager->getScript(seg)->getSynonyms(); if (synonyms) { debugC(2, kDebugLevelParser, "Setting %d synonyms for script.%d\n", synonyms_nr, script); @@ -305,7 +305,7 @@ reg_t kStrCpy(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (length >= 0) strncpy(dest, src, length); else { - if (s->seg_manager->_heap[argv[0].segment]->getType() == MEM_OBJ_DYNMEM) { + if (s->segmentManager->_heap[argv[0].segment]->getType() == MEM_OBJ_DYNMEM) { reg_t *srcp = (reg_t *) src; int i; @@ -368,7 +368,7 @@ reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) { if ((argc == 2) && /* Our pathfinder already works around the issue we're trying to fix */ - (strcmp(s->seg_manager->getDescription(argv[0]), AVOIDPATH_DYNMEM_STRING) != 0) && + (strcmp(s->segmentManager->getDescription(argv[0]), AVOIDPATH_DYNMEM_STRING) != 0) && ((strlen(dst) < 2) || (!lsl5PasswordWorkaround && !is_print_str(dst)))) { // SQ4 array handling detected #ifndef SCUMM_BIG_ENDIAN @@ -642,7 +642,7 @@ reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv) { - Resource *textres = s->resmgr->findResource(ResourceId(kResourceTypeText, argv[0].toUint16()), 0); + Resource *textres = s->resourceManager->findResource(ResourceId(kResourceTypeText, argv[0].toUint16()), 0); char *seeker; int counter = argv[1].toUint16(); @@ -713,7 +713,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t retval; if (func == K_MESSAGE_GET) { - s->_msgState.loadRes(s->resmgr, argv[1].toUint16(), true); + s->_msgState.loadRes(s->resourceManager, argv[1].toUint16(), true); s->_msgState.findTuple(tuple); if (isGetMessage) @@ -758,7 +758,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_MESSAGE_SIZE: { MessageState tempState; - if (tempState.loadRes(s->resmgr, argv[1].toUint16(), false) && tempState.findTuple(tuple) && tempState.getMessage()) + if (tempState.loadRes(s->resourceManager, argv[1].toUint16(), false) && tempState.findTuple(tuple) && tempState.getMessage()) return make_reg(0, tempState.getText().size() + 1); else return NULL_REG; @@ -768,7 +768,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_MESSAGE_REFNOUN: { MessageState tempState; - if (tempState.loadRes(s->resmgr, argv[1].toUint16(), false) && tempState.findTuple(tuple)) { + if (tempState.loadRes(s->resourceManager, argv[1].toUint16(), false) && tempState.findTuple(tuple)) { MessageTuple t = tempState.getRefTuple(); switch (func) { case K_MESSAGE_REFCOND: diff --git a/engines/sci/engine/memobj.cpp b/engines/sci/engine/memobj.cpp index 34432521a0..7b28bde663 100644 --- a/engines/sci/engine/memobj.cpp +++ b/engines/sci/engine/memobj.cpp @@ -224,12 +224,12 @@ byte *SystemStrings::dereference(reg_t pointer, int *size) { //-------------------- script -------------------- -reg_t Script::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t Script::findCanonicAddress(SegManager *segManager, reg_t addr) { addr.offset = 0; return addr; } -void Script::freeAtAddress(SegManager *segmgr, reg_t addr) { +void Script::freeAtAddress(SegManager *segManager, reg_t addr) { /* debugC(2, kDebugLevelGC, "[GC] Freeing script %04x:%04x\n", PRINT_REG(addr)); if (locals_segment) @@ -237,16 +237,15 @@ void Script::freeAtAddress(SegManager *segmgr, reg_t addr) { */ if (_markedAsDeleted) - segmgr->deallocateScript(nr); + segManager->deallocateScript(nr); } void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { (*note)(param, make_reg(segId, 0)); } -void Script::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void Script::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { Script *script = this; - SciVersion version = s->_version; // for the offset defines if (addr.offset <= script->buf_size && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(script->buf + addr.offset)) { int idx = RAW_GET_CLASS_INDEX(script, addr); @@ -270,7 +269,7 @@ void Script::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, //-------------------- clones -------------------- -void CloneTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { CloneTable *clone_table = this; Clone *clone; @@ -293,7 +292,7 @@ void CloneTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *par //debugC(2, kDebugLevelGC, "[GC] Reporting clone-pos %04x:%04x\n", PRINT_REG(clone->pos)); } -void CloneTable::freeAtAddress(SegManager *segmgr, reg_t addr) { +void CloneTable::freeAtAddress(SegManager *segManager, reg_t addr) { CloneTable *clone_table = this; Object *victim_obj; @@ -318,16 +317,16 @@ void CloneTable::freeAtAddress(SegManager *segmgr, reg_t addr) { //-------------------- locals -------------------- -reg_t LocalVariables::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t LocalVariables::findCanonicAddress(SegManager *segManager, reg_t addr) { // Reference the owning script - SegmentId owner_seg = segmgr->segGet(script_id); + SegmentId owner_seg = segManager->segGet(script_id); assert(owner_seg >= 0); return make_reg(owner_seg, 0); } -void LocalVariables::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void LocalVariables::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { // assert(addr.segment == _segId); for (uint i = 0; i < _locals.size(); i++) @@ -336,12 +335,12 @@ void LocalVariables::listAllOutgoingReferences(EngineState *s, reg_t addr, void //-------------------- stack -------------------- -reg_t DataStack::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t DataStack::findCanonicAddress(SegManager *segManager, reg_t addr) { addr.offset = 0; return addr; } -void DataStack::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void DataStack::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { fprintf(stderr, "Emitting %d stack entries\n", nr); for (int i = 0; i < nr; i++) (*note)(param, entries[i]); @@ -350,11 +349,11 @@ void DataStack::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- lists -------------------- -void ListTable::freeAtAddress(SegManager *segmgr, reg_t sub_addr) { +void ListTable::freeAtAddress(SegManager *segManager, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void ListTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void ListTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { if (!isValidEntry(addr.offset)) { warning("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; @@ -370,11 +369,11 @@ void ListTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- nodes -------------------- -void NodeTable::freeAtAddress(SegManager *segmgr, reg_t sub_addr) { +void NodeTable::freeAtAddress(SegManager *segManager, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void NodeTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void NodeTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { if (!isValidEntry(addr.offset)) { warning("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; @@ -394,7 +393,7 @@ void NodeTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- dynamic memory -------------------- -reg_t DynMem::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t DynMem::findCanonicAddress(SegManager *segManager, reg_t addr) { addr.offset = 0; return addr; } diff --git a/engines/sci/engine/memobj.h b/engines/sci/engine/memobj.h index efe7f26f1c..52d0b7859e 100644 --- a/engines/sci/engine/memobj.h +++ b/engines/sci/engine/memobj.h @@ -52,7 +52,7 @@ enum MemObjectType { struct MemObject : public Common::Serializable { MemObjectType _type; - int _segmgrId; /**< Internal value used by the seg_manager's hash map */ + int _segManagerId; /**< Internal value used by the segmentManager's hash map */ typedef void (*NoteCallback)(void *param, reg_t addr); // FIXME: Bad choice of name @@ -63,7 +63,7 @@ public: virtual ~MemObject() {} inline MemObjectType getType() const { return _type; } - inline int getSegMgrId() const { return _segmgrId; } + inline int getSegmentManagerId() const { return _segManagerId; } /** * Check whether the given offset into this memory object is valid, @@ -87,13 +87,13 @@ public: * * @param sub_addr base address whose canonic address is to be found */ - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr) { return sub_addr; } + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr) { return sub_addr; } /** * Deallocates all memory associated with the specified address. * @param sub_addr address (within the given segment) to deallocate */ - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr) {} + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr) {} /** * Iterates over and reports all addresses within the current segment. @@ -109,7 +109,7 @@ public: * @param note Invoked for each outgoing reference within the object * Note: This function may also choose to report numbers (segment 0) as adresses */ - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note) {} + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version) {} }; @@ -191,8 +191,8 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -218,16 +218,16 @@ struct CodeBlock { }; #define VM_OBJECT_GET_VARSELECTOR(obj, i) \ - (s->_version < SCI_VERSION_1_1 ? \ + (version < SCI_VERSION_1_1 ? \ READ_LE_UINT16(obj->base_obj + obj->_variables.size() * 2 + i*2) : \ *(obj->base_vars + i)) #define VM_OBJECT_READ_PROPERTY(obj, i) (obj->_variables[i]) #define VM_OBJECT_GET_FUNCSELECTOR(obj, i) \ - (s->_version < SCI_VERSION_1_1 ? \ + (version < SCI_VERSION_1_1 ? \ READ_LE_UINT16((byte *) (obj->base_method + i)) : \ READ_LE_UINT16((byte *) (obj->base_method + i*2 + 1))) #define VM_OBJECT_READ_FUNCTION(obj, i) \ - (s->_version < SCI_VERSION_1_1 ? \ + (version < SCI_VERSION_1_1 ? \ make_reg(obj->pos.segment, \ READ_LE_UINT16((byte *) (obj->base_method \ + obj->methods_nr + 1 \ @@ -301,10 +301,10 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); virtual void listAllDeallocatable(SegmentId segId, void *param, NoteCallback note); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); @@ -416,8 +416,8 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -513,8 +513,8 @@ public: /* CloneTable */ struct CloneTable : public Table<Clone> { - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -522,8 +522,8 @@ struct CloneTable : public Table<Clone> { /* NodeTable */ struct NodeTable : public Table<Node> { - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -531,8 +531,8 @@ struct NodeTable : public Table<Node> { /* ListTable */ struct ListTable : public Table<List> { - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -567,7 +567,7 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); virtual void listAllDeallocatable(SegmentId segId, void *param, NoteCallback note); virtual void saveLoadWithSerializer(Common::Serializer &ser); diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index a55d692afe..fe122e960f 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -220,7 +220,7 @@ int MessageState::getLength() { return strlen(stringptr); } -int MessageState::loadRes(ResourceManager *resmgr, int module, bool lock) { +int MessageState::loadRes(ResourceManager *resourceManager, int module, bool lock) { if (_locked) { // We already have a locked resource if (_module == module) { @@ -229,11 +229,11 @@ int MessageState::loadRes(ResourceManager *resmgr, int module, bool lock) { } // Otherwise, free the old resource - resmgr->unlockResource(_currentResource); + resourceManager->unlockResource(_currentResource); _locked = false; } - _currentResource = resmgr->findResource(ResourceId(kResourceTypeMessage, module), lock); + _currentResource = resourceManager->findResource(ResourceId(kResourceTypeMessage, module), lock); if (_currentResource == NULL || _currentResource->data == NULL) { warning("Message: failed to load %d.msg", module); diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h index 5e30095a0c..5a9dab6684 100644 --- a/engines/sci/engine/message.h +++ b/engines/sci/engine/message.h @@ -59,7 +59,7 @@ public: int getLength(); MessageTuple &getLastTuple(); int getLastModule(); - int loadRes(ResourceManager *resmgr, int module, bool lock); + int loadRes(ResourceManager *resourceManager, int module, bool lock); private: void initCursor(); diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index b53e9d522c..2e06afa3cd 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -205,13 +205,11 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) { } static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) { - SciVersion version = SCI_VERSION_AUTODETECT; - ResourceManager *resMgr = 0; + ResourceManager *resourceManager = 0; if (s.isSaving()) { assert(obj); - version = obj->_version; - resMgr = obj->_resMgr; + resourceManager = obj->_resourceManager; } s.skip(1); // obsolete: used to be a flag indicating if we got sci11 or not @@ -219,7 +217,7 @@ static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) { if (s.isLoading()) { // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. delete obj; - obj = new SegManager(resMgr, version); + obj = new SegManager(resourceManager); } obj->saveLoadWithSerializer(s); @@ -244,7 +242,7 @@ static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) s.syncString(obj.savegame_name); s.syncAsSint32LE(obj.savegame_version); s.syncString(obj.game_version); - s.syncAsSint32LE(obj.version); + s.skip(4); // obsolete: used to be game version s.syncAsSint32LE(obj.savegame_date); s.syncAsSint32LE(obj.savegame_time); } @@ -266,9 +264,9 @@ void EngineState::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(status_bar_foreground); s.syncAsSint32LE(status_bar_background); - sync_SegManagerPtr(s, seg_manager); + sync_SegManagerPtr(s, segmentManager); - syncArray<Class>(s, seg_manager->_classtable); + syncArray<Class>(s, segmentManager->_classtable); sync_sfx_state_t(s, _sound); } @@ -445,7 +443,7 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&mobj) { assert(mobj); } - s.syncAsSint32LE(mobj->_segmgrId); + s.syncAsSint32LE(mobj->_segManagerId); mobj->saveLoadWithSerializer(s); } @@ -460,7 +458,6 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename SavegameMetadata meta; meta.savegame_version = CURRENT_SAVEGAME_VERSION; meta.savegame_name = savename; - meta.version = s->_version; meta.game_version = s->game_version; meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); meta.savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF); @@ -499,7 +496,9 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) { } static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { - if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + bool oldScriptHeader = (s->resourceManager->sciVersion() == SCI_VERSION_0_EARLY); + + if (oldScriptHeader) buf += 2; do { @@ -518,8 +517,8 @@ static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { // FIXME: This should probably be turned into an EngineState method static void reconstruct_stack(EngineState *retval) { - SegmentId stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); - DataStack *stack = (DataStack *)(retval->seg_manager->_heap[stack_seg]); + SegmentId stack_seg = find_unique_seg_by_type(retval->segmentManager, MEM_OBJ_STACK); + DataStack *stack = (DataStack *)(retval->segmentManager->_heap[stack_seg]); retval->stack_segment = stack_seg; retval->stack_base = stack->entries; @@ -540,18 +539,18 @@ static bool clone_entry_used(CloneTable *table, int n) { static void load_script(EngineState *s, SegmentId seg) { Resource *script, *heap = NULL; - Script *scr = (Script *)(s->seg_manager->_heap[seg]); + Script *scr = (Script *)(s->segmentManager->_heap[seg]); assert(scr); scr->buf = (byte *)malloc(scr->buf_size); assert(scr->buf); - script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scr->nr), 0); - if (s->_version >= SCI_VERSION_1_1) - heap = s->resmgr->findResource(ResourceId(kResourceTypeHeap, scr->nr), 0); + script = s->resourceManager->findResource(ResourceId(kResourceTypeScript, scr->nr), 0); + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) + heap = s->resourceManager->findResource(ResourceId(kResourceTypeHeap, scr->nr), 0); memcpy(scr->buf, script->data, script->size); - if (s->seg_manager->_version == SCI_VERSION_1_1) + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) memcpy(scr->buf + scr->script_size, heap->data, heap->size); } @@ -559,7 +558,7 @@ static void load_script(EngineState *s, SegmentId seg) { static void reconstruct_scripts(EngineState *s, SegManager *self) { uint i, j; MemObject *mobj; - SciVersion version = s->_version; // for the selector defines + SciVersion version = self->sciVersion(); // for the selector defines for (i = 0; i < self->_heap.size(); i++) { if (self->_heap[i]) { @@ -570,8 +569,8 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { // FIXME: Unify this code with script_instantiate_* load_script(s, i); - scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->seg_manager->_heap[scr->locals_segment]); - if (s->seg_manager->_version == SCI_VERSION_1_1) { + scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->segmentManager->_heap[scr->locals_segment]); + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) { scr->export_table = 0; scr->synonyms = 0; if (READ_LE_UINT16(scr->buf + 6) > 0) { @@ -607,7 +606,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { for (j = 0; j < scr->_objects.size(); j++) { byte *data = scr->buf + scr->_objects[j].pos.offset; - if (self->_version == SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) { uint16 *funct_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 6 )); uint16 *prop_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 4 )); @@ -617,7 +616,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { int funct_area = READ_LE_UINT16( data + SCRIPT_FUNCTAREAPTR_OFFSET ); Object *base_obj; - base_obj = obj_get(s->seg_manager, s->_version, scr->_objects[j]._variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(s->segmentManager, scr->_objects[j]._variables[SCRIPT_SPECIES_SELECTOR]); if (!base_obj) { warning("Object without a base class: Script %d, index %d (reg address %04x:%04x", @@ -641,8 +640,8 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { } // FIXME: The following should likely become a SegManager method -static void reconstruct_clones(EngineState *s, SegManager *self) { - SciVersion version = s->_version; // for the selector defines +static void reconstruct_clones(SegManager *self) { + SciVersion version = self->sciVersion(); // for the selector defines for (uint i = 0; i < self->_heap.size(); i++) { if (self->_heap[i]) { @@ -673,7 +672,7 @@ static void reconstruct_clones(EngineState *s, SegManager *self) { continue; } CloneTable::Entry &seeker = ct->_table[j]; - base_obj = obj_get(s->seg_manager, s->_version, seeker._variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(self, seeker._variables[SCRIPT_SPECIES_SELECTOR]); if (!base_obj) { printf("Clone entry without a base class: %d\n", j); seeker.base = seeker.base_obj = NULL; @@ -701,7 +700,7 @@ static void reconstruct_sounds(EngineState *s) { Song *seeker; SongIteratorType it_type; - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) it_type = SCI_SONG_ITERATOR_TYPE_SCI1; else it_type = SCI_SONG_ITERATOR_TYPE_SCI0; @@ -765,7 +764,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. - retval = new EngineState(s->resmgr, s->_version, s->_flags); + retval = new EngineState(s->resourceManager, s->_flags); // Copy some old data retval->gfx_state = s->gfx_state; @@ -786,20 +785,20 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->old_screen = 0; temp = retval->_sound._songlib; - retval->_sound.sfx_init(retval->resmgr, s->sfx_init_flags); + retval->_sound.sfx_init(retval->resourceManager, s->sfx_init_flags); retval->sfx_init_flags = s->sfx_init_flags; retval->_sound._songlib.freeSounds(); retval->_sound._songlib = temp; _reset_graphics_input(retval); reconstruct_stack(retval); - reconstruct_scripts(retval, retval->seg_manager); - reconstruct_clones(retval, retval->seg_manager); + reconstruct_scripts(retval, retval->segmentManager); + reconstruct_clones(retval->segmentManager); retval->game_obj = s->game_obj; - retval->script_000 = retval->seg_manager->getScript(retval->seg_manager->getSegment(0, SCRIPT_GET_DONT_LOAD)); + retval->script_000 = retval->segmentManager->getScript(retval->segmentManager->getSegment(0, SCRIPT_GET_DONT_LOAD)); retval->gc_countdown = GC_INTERVAL - 1; - retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS); - retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); + retval->sys_strings_segment = find_unique_seg_by_type(retval->segmentManager, MEM_OBJ_SYS_STRINGS); + retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segmentManager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); // Restore system strings SystemString *str; @@ -836,7 +835,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->successor = NULL; retval->pic_priority_table = (int *)gfxop_get_pic_metainfo(retval->gfx_state); - retval->_gameName = obj_get_name(retval->seg_manager, retval->_version, retval->game_obj); + retval->_gameName = obj_get_name(retval->segmentManager, retval->game_obj); retval->_sound._it = NULL; retval->_sound._flags = s->_sound._flags; diff --git a/engines/sci/engine/savegame.h b/engines/sci/engine/savegame.h index f53dbb4956..b238b7730a 100644 --- a/engines/sci/engine/savegame.h +++ b/engines/sci/engine/savegame.h @@ -40,7 +40,6 @@ struct SavegameMetadata { Common::String savegame_name; int savegame_version; Common::String game_version; - sci_version_t version; int savegame_date; int savegame_time; }; diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 6e47a73b18..12d721ecc5 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -285,7 +285,7 @@ void Kernel::dumpScriptClass(char *data, int seeker, int objsize) { void Kernel::dissectScript(int scriptNumber, Vocabulary *vocab) { int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; unsigned int _seeker = 0; - Resource *script = _resmgr->findResource(ResourceId(kResourceTypeScript, scriptNumber), 0); + Resource *script = _resourceManager->findResource(ResourceId(kResourceTypeScript, scriptNumber), 0); if (!script) { warning("dissectScript(): Script not found!\n"); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index fd7219bc85..28e22cb56e 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -36,11 +36,11 @@ extern const char *selector_name(EngineState *s, int selector); ScriptState scriptState; -int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { - Object *obj = obj_get(s->seg_manager, s->_version, objp); +int propertyOffsetToId(SegManager *segManager, int prop_ofs, reg_t objp) { + Object *obj = obj_get(segManager, objp); byte *selectoroffset; int selectors; - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines if (!obj) { warning("Applied propertyOffsetToId on non-object at %04x:%04x", PRINT_REG(objp)); @@ -49,11 +49,11 @@ int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { selectors = obj->_variables.size(); - if (s->_version < SCI_VERSION_1_1) + if (segManager->sciVersion() < SCI_VERSION_1_1) selectoroffset = ((byte *)(obj->base_obj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2; else { if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) { - obj = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); + obj = obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); selectoroffset = (byte *)obj->base_vars; } else selectoroffset = (byte *)obj->base_vars; @@ -70,7 +70,7 @@ int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecode) { // Disassembles one command from the heap, returns address of next command or 0 if a ret was encountered. - MemObject *mobj = GET_SEGMENT(*s->seg_manager, pos.segment, MEM_OBJ_SCRIPT); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, pos.segment, MEM_OBJ_SCRIPT); Script *script_entity = NULL; byte *scr; int scr_size; @@ -226,7 +226,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if ((opcode == op_pTos) || (opcode == op_sTop) || (opcode == op_pToa) || (opcode == op_aTop) || (opcode == op_dpToa) || (opcode == op_ipToa) || (opcode == op_dpTos) || (opcode == op_ipTos)) { int prop_ofs = scr[pos.offset + 1]; - int prop_id = propertyOffsetToId(s, prop_ofs, scriptState.xs->objp); + int prop_id = propertyOffsetToId(s->segmentManager, prop_ofs, scriptState.xs->objp); printf(" (%s)", selector_name(s, prop_id)); } @@ -238,8 +238,9 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if (opcode == op_callk) { int stackframe = (scr[pos.offset + 2] >> 1) + (scriptState.restAdjust); int argc = ((scriptState.xs->sp)[- stackframe - 1]).offset; + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + if (!oldScriptHeader) argc += (scriptState.restAdjust); printf(" Kernel params: ("); @@ -269,14 +270,14 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod selector = sb[- stackframe].offset; - name = obj_get_name(s->seg_manager, s->_version, called_obj_addr); + name = obj_get_name(s->segmentManager, called_obj_addr); if (!name) name = "<invalid>"; printf(" %s::%s[", name, (selector > ((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize()) ? "<invalid>" : selector_name(s, selector)); - switch (lookup_selector(s, called_obj_addr, selector, 0, &fun_ref)) { + switch (lookup_selector(s->segmentManager, called_obj_addr, selector, 0, &fun_ref)) { case kSelectorMethod: printf("FUNCT"); argc += restmod; @@ -328,7 +329,7 @@ void script_debug(EngineState *s, bool bp) { #endif if (scriptState.seeking && !bp) { // Are we looking for something special? - MemObject *mobj = GET_SEGMENT(*s->seg_manager, scriptState.xs->addr.pc.segment, MEM_OBJ_SCRIPT); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, scriptState.xs->addr.pc.segment, MEM_OBJ_SCRIPT); if (mobj) { Script *scr = (Script *)mobj; diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 0c88481125..53b4b039a3 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -48,11 +48,11 @@ namespace Sci { //#define GC_DEBUG // Debug garbage collection //#define GC_DEBUG_VERBOSE // Debug garbage verbosely -#undef DEBUG_SEG_MANAGER // Define to turn on debugging +#undef DEBUG_segmentManager // Define to turn on debugging #define INVALID_SCRIPT_ID -1 -SegManager::SegManager(ResourceManager *resMgr, SciVersion version) { +SegManager::SegManager(ResourceManager *resourceManager) { id_seg_map = new IntMapper(); reserved_id = INVALID_SCRIPT_ID; id_seg_map->checkKey(reserved_id, true); // reserve entry 0 for INVALID_SCRIPT_ID @@ -66,8 +66,7 @@ SegManager::SegManager(ResourceManager *resMgr, SciVersion version) { Hunks_seg_id = 0; exports_wide = 0; - _version = version; - _resMgr = resMgr; + _resourceManager = resourceManager; int result = 0; @@ -137,19 +136,19 @@ Script *SegManager::allocateScript(int script_nr, SegmentId *seg_id) { } void SegManager::setScriptSize(Script &scr, int script_nr) { - Resource *script = _resMgr->findResource(ResourceId(kResourceTypeScript, script_nr), 0); - Resource *heap = _resMgr->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); + Resource *script = _resourceManager->findResource(ResourceId(kResourceTypeScript, script_nr), 0); + Resource *heap = _resourceManager->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); scr.script_size = script->size; scr.heap_size = 0; // Set later - if (!script || (_version >= SCI_VERSION_1_1 && !heap)) { + if (!script || (_resourceManager->sciVersion() >= SCI_VERSION_1_1 && !heap)) { error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap"); } - if (_version == SCI_VERSION_0_EARLY) { // check if we got an old script header + if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) { // check if we got an old script header scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2; //locals_size = READ_LE_UINT16(script->data) * 2; - } else if (_version < SCI_VERSION_1_1) { + } else if (_resourceManager->sciVersion() < SCI_VERSION_1_1) { scr.buf_size = script->size; } else { scr.buf_size = script->size + heap->size; @@ -177,7 +176,7 @@ int SegManager::initialiseScript(Script &scr, int script_nr) { setScriptSize(scr, script_nr); scr.buf = (byte *)malloc(scr.buf_size); -#ifdef DEBUG_SEG_MANAGER +#ifdef DEBUG_segmentManager printf("scr.buf = %p ", scr.buf); #endif if (!scr.buf) { @@ -199,7 +198,7 @@ int SegManager::initialiseScript(Script &scr, int script_nr) { scr.obj_indices = new IntMapper(); - if (_version >= SCI_VERSION_1_1) + if (_resourceManager->sciVersion() >= SCI_VERSION_1_1) scr.heap_start = scr.buf + scr.script_size; else scr.heap_start = scr.buf; @@ -212,7 +211,7 @@ int SegManager::deallocate(SegmentId seg, bool recursive) { VERIFY(check(seg), "invalid seg id"); mobj = _heap[seg]; - id_seg_map->removeKey(mobj->getSegMgrId()); + id_seg_map->removeKey(mobj->getSegmentManagerId()); if (mobj->getType() == MEM_OBJ_SCRIPT) { Script *scr = (Script *)mobj; @@ -254,7 +253,7 @@ MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, MemObjectTyp _heap.push_back(0); } - mem->_segmgrId = hash_id; + mem->_segManagerId = hash_id; // hook it to the heap _heap[segid] = mem; @@ -327,7 +326,7 @@ int SegManager::relocateBlock(Common::Array<reg_t> &block, int block_location, S return 0; } block[idx].segment = segment; // Perform relocation - if (_version == SCI_VERSION_1_1) + if (_resourceManager->sciVersion() == SCI_VERSION_1_1) block[idx].offset += getScript(segment)->script_size; return 1; @@ -441,7 +440,7 @@ SegmentId SegManager::getSegment(int script_nr, SCRIPT_GET load) { SegmentId segment; if ((load & SCRIPT_GET_LOAD) == SCRIPT_GET_LOAD) - script_instantiate(_resMgr, this, _version, script_nr); + script_instantiate(_resourceManager, this, script_nr); segment = segGet(script_nr); @@ -481,7 +480,7 @@ reg_t SegManager::get_class_address(int classnr, SCRIPT_GET lock, reg_t caller) Object *SegManager::scriptObjInit0(reg_t obj_pos) { Object *obj; int id; - SciVersion version = _version; // for the offset defines + SciVersion version = _resourceManager->sciVersion(); // for the offset defines unsigned int base = obj_pos.offset - SCRIPT_OBJECT_MAGIC_OFFSET; reg_t temp; @@ -590,7 +589,7 @@ Object *SegManager::scriptObjInit11(reg_t obj_pos) { } Object *SegManager::scriptObjInit(reg_t obj_pos) { - if (_version != SCI_VERSION_1_1) + if (_resourceManager->sciVersion() != SCI_VERSION_1_1) return scriptObjInit0(obj_pos); else return scriptObjInit11(obj_pos); @@ -634,7 +633,7 @@ void SegManager::scriptInitialiseLocals(reg_t location) { VERIFY(location.offset + 1 < (uint16)scr->buf_size, "Locals beyond end of script\n"); - if (_version == SCI_VERSION_1_1) + if (_resourceManager->sciVersion() == SCI_VERSION_1_1) count = READ_LE_UINT16(scr->buf + location.offset - 2); else count = (READ_LE_UINT16(scr->buf + location.offset - 2) - 4) >> 1; @@ -676,7 +675,7 @@ void SegManager::scriptRelocateExportsSci11(SegmentId seg) { void SegManager::scriptInitialiseObjectsSci11(SegmentId seg) { Script *scr = getScript(seg); byte *seeker = scr->heap_start + 4 + READ_LE_UINT16(scr->heap_start + 2) * 2; - SciVersion version = _version; // for the selector defines + SciVersion version = _resourceManager->sciVersion(); // for the selector defines while (READ_LE_UINT16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) { if (READ_LE_UINT16(seeker + 14) & SCRIPT_INFO_CLASS) { @@ -707,7 +706,7 @@ void SegManager::scriptInitialiseObjectsSci11(SegmentId seg) { #if 0 if (obj->_variables[5].offset != 0xffff) { obj->_variables[5] = INST_LOOKUP_CLASS(obj->_variables[5].offset); - base_obj = obj_get(s->seg_manager, s->_version, obj->_variables[5]); + base_obj = obj_get(s->segmentManager, obj->_variables[5]); obj->variable_names_nr = base_obj->variables_nr; obj->base_obj = base_obj->base_obj; } @@ -913,7 +912,7 @@ int SegManager::freeDynmem(reg_t addr) { } int SegManager::createClassTable() { - Resource *vocab996 = _resMgr->findResource(ResourceId(kResourceTypeVocab, 996), 1); + Resource *vocab996 = _resourceManager->findResource(ResourceId(kResourceTypeVocab, 996), 1); if (!vocab996) error("SegManager: failed to open vocab 996"); @@ -928,7 +927,7 @@ int SegManager::createClassTable() { _classtable[classNr].script = scriptNr; } - _resMgr->unlockResource(vocab996); + _resourceManager->unlockResource(vocab996); return 0; } diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 27c8ad446a..57a7bbe447 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -23,8 +23,8 @@ * */ -#ifndef SCI_ENGINE_SEG_MANAGER_H -#define SCI_ENGINE_SEG_MANAGER_H +#ifndef SCI_ENGINE_segmentManager_H +#define SCI_ENGINE_segmentManager_H #include "common/scummsys.h" #include "common/serializer.h" @@ -58,7 +58,7 @@ public: /** * Initialize the segment manager */ - SegManager(ResourceManager *resMgr, SciVersion version); + SegManager(ResourceManager *resourceManager); /** * Deallocate all memory associated with the segment manager @@ -340,15 +340,16 @@ public: void scriptInitialiseObjectsSci11(SegmentId seg); int initialiseScript(Script &scr, int script_nr); + SciVersion sciVersion() { return _resourceManager->sciVersion(); } + private: IntMapper *id_seg_map; ///< id - script id; seg - index of heap public: // TODO: make private Common::Array<MemObject *> _heap; int reserved_id; int exports_wide; - SciVersion _version; - ResourceManager *_resMgr; Common::Array<Class> _classtable; /**< Table of all classes */ + ResourceManager *_resourceManager; SegmentId Clones_seg_id; ///< ID of the (a) clones segment SegmentId Lists_seg_id; ///< ID of the (a) list segment @@ -384,4 +385,4 @@ private: } // End of namespace Sci -#endif // SCI_ENGINE_SEG_MANAGER +#endif // SCI_ENGINE_segmentManager diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index baa51bcb58..c9ba939a4c 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -29,8 +29,8 @@ namespace Sci { -EngineState::EngineState(ResourceManager *res, SciVersion version, uint32 flags) -: resmgr(res), _version(version), _flags(flags), _dirseeker(this) { +EngineState::EngineState(ResourceManager *res, uint32 flags) +: resourceManager(res), _flags(flags), _dirseeker(this) { widget_serial_counter = 0; game_version = 0; @@ -112,12 +112,12 @@ EngineState::EngineState(ResourceManager *res, SciVersion version, uint32 flags) game_obj = NULL_REG; - seg_manager = 0; + segmentManager = 0; gc_countdown = 0; successor = 0; - speedThrottler = new SpeedThrottler(version); + speedThrottler = new SpeedThrottler(res->sciVersion()); _doSoundType = kDoSoundTypeUnknown; } @@ -187,7 +187,7 @@ kLanguage EngineState::getLanguage() { lang = (kLanguage)GET_SEL32V(s->game_obj, printLang); - if ((_version == SCI_VERSION_1_1) || (lang == K_LANG_NONE)) { + if ((s->resourceManager->sciVersion() == SCI_VERSION_1_1) || (lang == K_LANG_NONE)) { // If language is set to none, we use the language from the game detector. // SSCI reads this from resource.cfg (early games do not have a language // setting in resource.cfg, but instead have the secondary language number @@ -254,11 +254,11 @@ EngineState::DoSoundType EngineState::detectDoSoundType() { if (!parse_reg_t(this, "?Sound", &soundClass)) { reg_t fptr; - Object *obj = obj_get(seg_manager, _version, soundClass); - SelectorType sel = lookup_selector(this, soundClass, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play, NULL, &fptr); + Object *obj = obj_get(segmentManager, soundClass); + SelectorType sel = lookup_selector(this->segmentManager, soundClass, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play, NULL, &fptr); if (obj && (sel == kSelectorMethod)) { - Script *script = seg_manager->getScript(fptr.segment); + Script *script = segmentManager->getScript(fptr.segment); if (fptr.offset > checkBytes) { // Go to the last portion of Sound::init, should be right before the play function @@ -289,9 +289,9 @@ EngineState::DoSoundType EngineState::detectDoSoundType() { if (_doSoundType == kDoSoundTypeUnknown) { warning("DoSound detection failed, taking an educated guess"); - if (_version >= SCI_VERSION_1_MIDDLE) + if (resourceManager->sciVersion() >= SCI_VERSION_1_MIDDLE) _doSoundType = kDoSoundTypeSci1Late; - else if (_version > SCI_VERSION_01) + else if (resourceManager->sciVersion() > SCI_VERSION_01) _doSoundType = kDoSoundTypeSci1Early; else _doSoundType = kDoSoundTypeSci0; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index a3983f6ae4..50a7a4c5ae 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -161,7 +161,7 @@ private: struct EngineState : public Common::Serializable { public: - EngineState(ResourceManager *res, SciVersion version, uint32 flags); + EngineState(ResourceManager *res, uint32 flags); virtual ~EngineState(); enum DoSoundType { @@ -177,9 +177,8 @@ public: public: int widget_serial_counter; /**< Used for savegames */ - ResourceManager *resmgr; /**< The resource manager */ + ResourceManager *resourceManager; /**< The resource manager */ - const SciVersion _version; /**< The approximated patchlevel of the version to emulate */ const uint32 _flags; /**< Specific game flags */ Common::String _gameName; /**< Designation of the primary object (which inherits from Game) */ @@ -305,7 +304,7 @@ public: reg_t game_obj; /**< Pointer to the game object */ - SegManager *seg_manager; + SegManager *segmentManager; int gc_countdown; /**< Number of kernel calls until next gc */ MessageState _msgState; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index fbdb3d1c85..67b15cd212 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -204,15 +204,15 @@ static void validate_write_var(reg_t *r, reg_t *stack_base, int type, int max, i #define GET_OP_SIGNED_FLEX() ((opcode & 1)? GET_OP_SIGNED_BYTE() : GET_OP_SIGNED_WORD()) ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp) { - int seg = s->seg_manager->segGet(script); - Script *scr = s->seg_manager->getScriptIfLoaded(seg); + int seg = s->segmentManager->segGet(script); + Script *scr = s->segmentManager->getScriptIfLoaded(seg); if (!scr) // Script not present yet? - seg = script_instantiate(s->resmgr, s->seg_manager, s->_version, script); + seg = script_instantiate(s->resourceManager, s->segmentManager, script); else scr->unmarkDeleted(); - int temp = s->seg_manager->validateExportFunc(pubfunct, seg); + int temp = s->segmentManager->validateExportFunc(pubfunct, seg); if (!temp) { error("Request for invalid exported function 0x%x of script 0x%x", pubfunct, script); return NULL; @@ -285,7 +285,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt Breakpoint *bp; char method_name [256]; - sprintf(method_name, "%s::%s", obj_get_name(s->seg_manager, s->_version, send_obj), ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str()); + sprintf(method_name, "%s::%s", obj_get_name(s->segmentManager, send_obj), ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str()); bp = s->bp_list; while (bp) { @@ -310,7 +310,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt #endif // VM_DEBUG_SEND ObjVarRef varp; - switch (lookup_selector(s, send_obj, selector, &varp, &funcp)) { + switch (lookup_selector(s->segmentManager, send_obj, selector, &varp, &funcp)) { case kSelectorNone: error("Send to invalid selector 0x%x of object at %04x:%04x", 0xffff & selector, PRINT_REG(send_obj)); @@ -467,7 +467,7 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file) { } static reg_t pointer_add(EngineState *s, reg_t base, int offset) { - MemObject *mobj = GET_SEGMENT_ANY(*s->seg_manager, base.segment); + MemObject *mobj = GET_SEGMENT_ANY(*s->segmentManager, base.segment); if (!mobj) { error("[VM] Error: Attempt to add %d to invalid pointer %04x:%04x", offset, PRINT_REG(base)); @@ -520,8 +520,8 @@ void run_vm(EngineState *s, int restoring) { // Current execution data: scriptState.xs = &(s->_executionStack.back()); ExecStack *xs_new = NULL; - Object *obj = obj_get(s->seg_manager, s->_version, scriptState.xs->objp); - Script *local_script = s->seg_manager->getScriptIfLoaded(scriptState.xs->local_segment); + Object *obj = obj_get(s->segmentManager, scriptState.xs->objp); + Script *local_script = s->segmentManager->getScriptIfLoaded(scriptState.xs->local_segment); int old_execution_stack_base = s->execution_stack_base; // Used to detect the stack bottom, for "physical" returns const byte *code_buf = NULL; // (Avoid spurious warning) @@ -567,7 +567,7 @@ void run_vm(EngineState *s, int restoring) { scriptState.xs = &(s->_executionStack.back()); s->_executionStackPosChanged = false; - scr = s->seg_manager->getScriptIfLoaded(scriptState.xs->addr.pc.segment); + scr = s->segmentManager->getScriptIfLoaded(scriptState.xs->addr.pc.segment); if (!scr) { // No script? Implicit return via fake instruction buffer warning("Running on non-existant script in segment %x", scriptState.xs->addr.pc.segment); @@ -580,12 +580,12 @@ void run_vm(EngineState *s, int restoring) { scr = NULL; obj = NULL; } else { - obj = obj_get(s->seg_manager, s->_version, scriptState.xs->objp); + obj = obj_get(s->segmentManager, scriptState.xs->objp); code_buf = scr->buf; #ifndef DISABLE_VALIDATIONS code_buf_size = scr->buf_size; #endif - local_script = s->seg_manager->getScriptIfLoaded(scriptState.xs->local_segment); + local_script = s->segmentManager->getScriptIfLoaded(scriptState.xs->local_segment); if (!local_script) { warning("Could not find local script from segment %x", scriptState.xs->local_segment); local_script = NULL; @@ -917,17 +917,22 @@ void run_vm(EngineState *s, int restoring) { gc_countdown(s); scriptState.xs->sp -= (opparams[1] >> 1) + 1; - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { - scriptState.xs->sp -= scriptState.restAdjust; - s->restAdjust = 0; // We just used up the scriptState.restAdjust, remember? + + { + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); + if (!oldScriptHeader) { + scriptState.xs->sp -= scriptState.restAdjust; + s->restAdjust = 0; // We just used up the scriptState.restAdjust, remember? + } } if (opparams[0] >= (int)((SciEngine*)g_engine)->getKernel()->_kernelFuncs.size()) { error("Invalid kernel function 0x%x requested", opparams[0]); } else { int argc = ASSERT_ARITHMETIC(scriptState.xs->sp[0]); + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + if (!oldScriptHeader) argc += scriptState.restAdjust; if (((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature @@ -947,8 +952,11 @@ void run_vm(EngineState *s, int restoring) { xs_new = &(s->_executionStack.back()); s->_executionStackPosChanged = true; - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) - scriptState.restAdjust = s->restAdjust; + { + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); + if (!oldScriptHeader) + scriptState.restAdjust = s->restAdjust; + } } break; @@ -1038,7 +1046,7 @@ void run_vm(EngineState *s, int restoring) { break; case 0x28: // class - s->r_acc = s->seg_manager->get_class_address((unsigned)opparams[0], SCRIPT_GET_LOCK, + s->r_acc = s->segmentManager->get_class_address((unsigned)opparams[0], SCRIPT_GET_LOCK, scriptState.xs->addr.pc); break; @@ -1058,7 +1066,7 @@ void run_vm(EngineState *s, int restoring) { break; case 0x2b: // super - r_temp = s->seg_manager->get_class_address(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc); + r_temp = s->segmentManager->get_class_address(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc); if (!r_temp.segment) error("[VM]: Invalid superclass in object"); @@ -1156,7 +1164,7 @@ void run_vm(EngineState *s, int restoring) { case 0x39: // lofsa s->r_acc.segment = scriptState.xs->addr.pc.segment; - if (s->_version >= SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) { s->r_acc.offset = opparams[0] + local_script->script_size; } else { if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) @@ -1176,7 +1184,7 @@ void run_vm(EngineState *s, int restoring) { case 0x3a: // lofss r_temp.segment = scriptState.xs->addr.pc.segment; - if (s->_version >= SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) { r_temp.offset = opparams[0] + local_script->script_size; } else { if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) @@ -1390,12 +1398,12 @@ void run_vm(EngineState *s, int restoring) { } } -static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { +static int _obj_locate_varselector(SegManager *segManager, Object *obj, Selector slc) { // Determines if obj explicitly defines slc as a varselector // Returns -1 if not found - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines - if (s->_version < SCI_VERSION_1_1) { + if (version < SCI_VERSION_1_1) { int varnum = obj->variable_names_nr; int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET; int i; @@ -1414,7 +1422,7 @@ static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { int varnum = obj->_variables[1].offset; if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) - buf = ((byte *) obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR])->base_vars); + buf = ((byte *) obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR])->base_vars); for (i = 0; i < varnum; i++) if (READ_LE_UINT16(buf + (i << 1)) == slc) // Found it? @@ -1424,7 +1432,7 @@ static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { } } -static int _class_locate_funcselector(EngineState *s, Object *obj, Selector slc) { +static int _class_locate_funcselector(Object *obj, Selector slc, SciVersion version) { // Determines if obj is a class and explicitly defines slc as a funcselector // Does NOT say anything about obj's superclasses, i.e. failure may be // returned even if one of the superclasses defines the funcselector. @@ -1438,14 +1446,14 @@ static int _class_locate_funcselector(EngineState *s, Object *obj, Selector slc) return -1; // Failed } -static SelectorType _lookup_selector_function(EngineState *s, int seg_id, Object *obj, Selector selector_id, reg_t *fptr) { +static SelectorType _lookup_selector_function(SegManager *segManager, int seg_id, Object *obj, Selector selector_id, reg_t *fptr) { int index; - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines // "recursive" lookup while (obj) { - index = _class_locate_funcselector(s, obj, selector_id); + index = _class_locate_funcselector(obj, selector_id, version); if (index >= 0) { if (fptr) { @@ -1455,22 +1463,23 @@ static SelectorType _lookup_selector_function(EngineState *s, int seg_id, Object return kSelectorMethod; } else { seg_id = obj->_variables[SCRIPT_SUPERCLASS_SELECTOR].segment; - obj = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); + obj = obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); } } return kSelectorNone; } -SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector selector_id, ObjVarRef *varp, reg_t *fptr) { - Object *obj = obj_get(s->seg_manager, s->_version, obj_location); +SelectorType lookup_selector(SegManager *segManager, reg_t obj_location, Selector selector_id, ObjVarRef *varp, reg_t *fptr) { + Object *obj = obj_get(segManager, obj_location); Object *species; int index; - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines + bool oldScriptHeader = (version == SCI_VERSION_0_EARLY); // Early SCI versions used the LSB in the selector ID as a read/write // toggle, meaning that we must remove it for selector lookup. - if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + if (oldScriptHeader) selector_id &= ~1; if (!obj) { @@ -1481,7 +1490,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select if (IS_CLASS(obj)) species = obj; else - species = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SPECIES_SELECTOR]); + species = obj_get(segManager, obj->_variables[SCRIPT_SPECIES_SELECTOR]); if (!obj) { @@ -1490,7 +1499,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select return kSelectorNone; } - index = _obj_locate_varselector(s, obj, selector_id); + index = _obj_locate_varselector(segManager, obj, selector_id); if (index >= 0) { // Found it as a variable @@ -1501,7 +1510,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select return kSelectorVariable; } - return _lookup_selector_function(s, obj_location.segment, obj, selector_id, fptr); + return _lookup_selector_function(segManager, obj_location.segment, obj, selector_id, fptr); } reg_t script_lookup_export(SegManager *segManager, int script_nr, int export_index) { @@ -1512,19 +1521,19 @@ reg_t script_lookup_export(SegManager *segManager, int script_nr, int export_ind #define INST_LOOKUP_CLASS(id) ((id == 0xffff)? NULL_REG : segManager->get_class_address(id, SCRIPT_GET_LOCK, reg)) -int script_instantiate_common(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr, Resource **script, Resource **heap, int *was_new) { +int script_instantiate_common(ResourceManager *resourceManager, SegManager *segManager, int script_nr, Resource **script, Resource **heap, int *was_new) { int seg_id; reg_t reg; *was_new = 1; - *script = resMgr->findResource(ResourceId(kResourceTypeScript, script_nr), 0); - if (version >= SCI_VERSION_1_1) - *heap = resMgr->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); + *script = resourceManager->findResource(ResourceId(kResourceTypeScript, script_nr), 0); + if (resourceManager->sciVersion() >= SCI_VERSION_1_1) + *heap = resourceManager->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); - if (!*script || (version >= SCI_VERSION_1_1 && !heap)) { + if (!*script || (resourceManager->sciVersion() >= SCI_VERSION_1_1 && !heap)) { warning("Script 0x%x requested but not found", script_nr); - if (version >= SCI_VERSION_1_1) { + if (resourceManager->sciVersion() >= SCI_VERSION_1_1) { if (*heap) warning("Inconsistency: heap resource WAS found"); else if (*script) @@ -1566,7 +1575,7 @@ int script_instantiate_common(ResourceManager *resMgr, SegManager *segManager, S return seg_id; } -int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, SciVersion version, bool oldScriptHeader, int script_nr) { +int script_instantiate_sci0(ResourceManager *resourceManager, SegManager *segManager, int script_nr) { int objtype; unsigned int objlength; reg_t reg; @@ -1575,8 +1584,10 @@ int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, Sci int magic_pos_adder; // Usually 0; 2 for older SCI versions Resource *script; int was_new; + SciVersion version = resourceManager->sciVersion(); + bool oldScriptHeader = (version == SCI_VERSION_0_EARLY); - seg_id = script_instantiate_common(resMgr, segManager, version, script_nr, &script, NULL, &was_new); + seg_id = script_instantiate_common(resourceManager, segManager, script_nr, &script, NULL, &was_new); if (was_new) return seg_id; @@ -1690,7 +1701,7 @@ int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, Sci // Instantiate the superclass, if neccessary obj->_variables[SCRIPT_SPECIES_SELECTOR] = INST_LOOKUP_CLASS(obj->_variables[SCRIPT_SPECIES_SELECTOR].offset); - base_obj = obj_get(segManager, version, obj->_variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(segManager, obj->_variables[SCRIPT_SPECIES_SELECTOR]); obj->variable_names_nr = base_obj->_variables.size(); obj->base_obj = base_obj->base_obj; // Copy base from species class, as we need its selector IDs @@ -1716,14 +1727,14 @@ int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, Sci return reg.segment; // instantiation successful } -int script_instantiate_sci11(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr) { +int script_instantiate_sci11(ResourceManager *resourceManager, SegManager *segManager, int script_nr) { Resource *script, *heap; int seg_id; int heap_start; reg_t reg; int was_new; - seg_id = script_instantiate_common(resMgr, segManager, version, script_nr, &script, &heap, &was_new); + seg_id = script_instantiate_common(resourceManager, segManager, script_nr, &script, &heap, &was_new); if (was_new) return seg_id; @@ -1753,17 +1764,19 @@ int script_instantiate_sci11(ResourceManager *resMgr, SegManager *segManager, Sc return seg_id; } -int script_instantiate(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr) { - if (version >= SCI_VERSION_1_1) - return script_instantiate_sci11(resMgr, segManager, version, script_nr); +int script_instantiate(ResourceManager *resourceManager, SegManager *segManager, int script_nr) { + if (resourceManager->sciVersion() >= SCI_VERSION_1_1) + return script_instantiate_sci11(resourceManager, segManager, script_nr); else - return script_instantiate_sci0(resMgr, segManager, version, (version == SCI_VERSION_0_EARLY), script_nr); + return script_instantiate_sci0(resourceManager, segManager, script_nr); } -void script_uninstantiate_sci0(SegManager *segManager, SciVersion version, int script_nr, SegmentId seg) { - reg_t reg = make_reg(seg, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader() ? 2 : 0); +void script_uninstantiate_sci0(SegManager *segManager, int script_nr, SegmentId seg) { + bool oldScriptHeader = (segManager->sciVersion() == SCI_VERSION_0_EARLY); + reg_t reg = make_reg(seg, oldScriptHeader ? 2 : 0); int objtype, objlength; Script *scr = segManager->getScript(seg); + SciVersion version = segManager->sciVersion(); // Make a pass over the object in order uninstantiate all superclasses objlength = 0; @@ -1792,7 +1805,7 @@ void script_uninstantiate_sci0(SegManager *segManager, SciVersion version, int s if (scr->getLockers()) scr->decrementLockers(); // Decrease lockers if this is us ourselves } else - script_uninstantiate(segManager, version, superclass_script); + script_uninstantiate(segManager, superclass_script); // Recurse to assure that the superclass lockers number gets decreased } @@ -1804,7 +1817,7 @@ void script_uninstantiate_sci0(SegManager *segManager, SciVersion version, int s } while (objtype != 0); } -void script_uninstantiate(SegManager *segManager, SciVersion version, int script_nr) { +void script_uninstantiate(SegManager *segManager, int script_nr) { SegmentId segment = segManager->segGet(script_nr); Script *scr = segManager->getScriptIfLoaded(segment); @@ -1824,8 +1837,8 @@ void script_uninstantiate(SegManager *segManager, SciVersion version, int script if (segManager->_classtable[i].reg.segment == segment) segManager->_classtable[i].reg = NULL_REG; - if (version < SCI_VERSION_1_1) - script_uninstantiate_sci0(segManager, version, script_nr, segment); + if (segManager->sciVersion() < SCI_VERSION_1_1) + script_uninstantiate_sci0(segManager, script_nr, segment); else warning("FIXME: Add proper script uninstantiation for SCI 1.1"); @@ -1917,8 +1930,9 @@ int game_run(EngineState **_s) { return 0; } -Object *obj_get(SegManager *segManager, SciVersion version, reg_t offset) { +Object *obj_get(SegManager *segManager, reg_t offset) { MemObject *mobj = GET_OBJECT_SEGMENT(*segManager, offset.segment); + SciVersion version = segManager->sciVersion(); Object *obj = NULL; int idx; @@ -1941,8 +1955,9 @@ Object *obj_get(SegManager *segManager, SciVersion version, reg_t offset) { return obj; } -const char *obj_get_name(SegManager *segManager, SciVersion version, reg_t pos) { - Object *obj = obj_get(segManager, version, pos); +const char *obj_get_name(SegManager *segManager, reg_t pos) { + Object *obj = obj_get(segManager, pos); + SciVersion version = segManager->sciVersion(); if (!obj) return "<no such object>"; @@ -1974,7 +1989,7 @@ void shrink_execution_stack(EngineState *s, uint size) { } reg_t* ObjVarRef::getPointer(EngineState *s) const { - Object *o = obj_get(s->seg_manager, s->_version, obj); + Object *o = obj_get(s->segmentManager, obj); if (!o) return 0; return &(o->_variables[varindex]); } diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index c8f94d5446..e6597c8f4c 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -37,7 +37,6 @@ namespace Sci { class SegManager; struct EngineState; -typedef int sci_version_t; struct IntMapper; struct Object; class ResourceManager; @@ -448,7 +447,7 @@ void script_free_vm_memory(EngineState *s); /** * Looks up a selector and returns its type and value * varindex is written to iff it is non-NULL and the selector indicates a property of the object. - * @param[in] s The EngineState to use + * @param[in] segManager The Segment Manager * @param[in] obj Address of the object to look the selector up in * @param[in] selectorid The selector to look up * @param[out] varp A reference to the selector, if it is a @@ -465,7 +464,7 @@ void script_free_vm_memory(EngineState *s); * kSelectorMethod if the selector represents a * method */ -SelectorType lookup_selector(EngineState *s, reg_t obj, Selector selectorid, +SelectorType lookup_selector(SegManager *segManager, reg_t obj, Selector selectorid, ObjVarRef *varp, reg_t *fptr); /** @@ -483,13 +482,12 @@ reg_t script_lookup_export(SegManager *segManager, int script_nr, int export_ind * increased. All scripts containing superclasses of this script are loaded * recursively as well, unless 'recursive' is set to zero. The * complementary function is "script_uninstantiate()" below. - * @param[in] resMgr The resource manager + * @param[in] resourceManager The resource manager * @param[in] segManager The segment manager - * @param[in] version The SCI version to use * @param[in] script_nr The script number to load * @return The script's segment ID or 0 if out of heap */ -int script_instantiate(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr); +int script_instantiate(ResourceManager *resourceManager, SegManager *segManager, int script_nr); /** * Decreases the numer of lockers of a script and unloads it if that number @@ -500,7 +498,7 @@ int script_instantiate(ResourceManager *resMgr, SegManager *segManager, SciVersi * @param[in] version The SCI version to use * @param[in] script_nr The script number that is requestet to be unloaded */ -void script_uninstantiate(SegManager *segManager, SciVersion version, int script_nr); +void script_uninstantiate(SegManager *segManager, int script_nr); /** * Initializes an SCI game @@ -568,28 +566,28 @@ void quit_vm(); /** * Allocates "kernel" memory and returns a handle suitable to be passed on * to SCI scripts - * @param[in] s Pointer to the EngineState to operate on - * @param[in] type A free-form type description string (static) - * @param[in] space The space to allocate - * @return The handle + * @param[in] segManager The Segment Manager + * @param[in] type A free-form type description string (static) + * @param[in] space The space to allocate + * @return The handle */ -reg_t kalloc(EngineState *s, const char *type, int space); +reg_t kalloc(SegManager *segManager, const char *type, int space); /** * Returns a pointer to "kernel" memory based on the handle - * @param[in] s Pointer to the EngineState to operate on - * @param[in] handle The handle to use - * @return A pointer to the allocated memory + * @param[in] segManager The Segment Manager + * @param[in] handle The handle to use + * @return A pointer to the allocated memory */ -byte *kmem(EngineState *s, reg_t handle); +byte *kmem(SegManager *segManager, reg_t handle); /** * Frees all "kernel" memory associated with a handle - * @param[in] s Pointer to the EngineState to operate on - * @param[in] handle The handle to free - * @return 0 on success, 1 otherwise + * @param[in] segManager The Segment Manager + * @param[in] handle The handle to free + * @return 0 on success, 1 otherwise */ -int kfree(EngineState *s, reg_t handle); +int kfree(SegManager *segManager, reg_t handle); /** * Determines the name of an object @@ -600,7 +598,7 @@ int kfree(EngineState *s, reg_t handle); * in a static buffer and need not be freed (neither may * it be modified). */ -const char *obj_get_name(SegManager *segManager, SciVersion version, reg_t pos); +const char *obj_get_name(SegManager *segManager, reg_t pos); /** * Retrieves an object from the specified location @@ -608,7 +606,7 @@ const char *obj_get_name(SegManager *segManager, SciVersion version, reg_t pos); * @param[in] offset The object's offset * @return The object in question, or NULL if there is none */ -Object *obj_get(SegManager *segManager, SciVersion version, reg_t offset); +Object *obj_get(SegManager *segManager, reg_t offset); /** * Shrink execution stack to size. diff --git a/engines/sci/gfx/gfx_resmgr.cpp b/engines/sci/gfx/gfx_resmgr.cpp index 8ce7a50ed5..9c8a54d642 100644 --- a/engines/sci/gfx/gfx_resmgr.cpp +++ b/engines/sci/gfx/gfx_resmgr.cpp @@ -50,19 +50,18 @@ struct param_struct { }; GfxResManager::GfxResManager(gfx_options_t *options, GfxDriver *driver, ResourceManager *resManager) : - _options(options), _driver(driver), _resManager(resManager), + _options(options), _driver(driver), _resourceManager(resManager), _lockCounter(0), _tagLockCounter(0), _staticPalette(0) { gfxr_init_static_palette(); _portBounds = Common::Rect(0, 10, 320, 200); // default value, with a titlebar of 10px - _version = resManager->sciVersion(); - if (!_resManager->isVGA()) { + if (!_resourceManager->isVGA()) { _staticPalette = gfx_sci0_pic_colors->getref(); - } else if (_version == SCI_VERSION_1_1) { + } else if (_resourceManager->sciVersion() == SCI_VERSION_1_1) { debugC(2, kDebugLevelGraphics, "Palettes are not yet supported in this SCI version\n"); #ifdef ENABLE_SCI32 - } else if (_version == SCI_VERSION_32) { + } else if (_resourceManager->sciVersion() == SCI_VERSION_32) { debugC(2, kDebugLevelGraphics, "Palettes are not yet supported in this SCI version\n"); #endif } else { @@ -78,7 +77,7 @@ GfxResManager::~GfxResManager() { } int GfxResManager::calculatePic(gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic, int flags, int default_palette, int nr) { - Resource *res = _resManager->findResource(ResourceId(kResourceTypePic, nr), 0); + Resource *res = _resourceManager->findResource(ResourceId(kResourceTypePic, nr), 0); int need_unscaled = unscaled_pic != NULL; gfxr_pic0_params_t style, basic_style; @@ -97,21 +96,21 @@ int GfxResManager::calculatePic(gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic return GFX_ERROR; if (need_unscaled) { - if (_version == SCI_VERSION_1_1) + if (_resourceManager->sciVersion() == SCI_VERSION_1_1) gfxr_draw_pic11(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id.number, _staticPalette, _portBounds); else - gfxr_draw_pic01(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id.number, _resManager->getViewType(), _staticPalette, _portBounds); + gfxr_draw_pic01(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id.number, _resourceManager->getViewType(), _staticPalette, _portBounds); } if (scaled_pic && scaled_pic->undithered_buffer) memcpy(scaled_pic->visual_map->index_data, scaled_pic->undithered_buffer, scaled_pic->undithered_buffer_size); - if (_version == SCI_VERSION_1_1) + if (_resourceManager->sciVersion() == SCI_VERSION_1_1) gfxr_draw_pic11(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id.number, _staticPalette, _portBounds); else - gfxr_draw_pic01(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id.number, _resManager->getViewType(), _staticPalette, _portBounds); + gfxr_draw_pic01(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id.number, _resourceManager->getViewType(), _staticPalette, _portBounds); - if (_version <= SCI_VERSION_1_EGA) { + if (_resourceManager->sciVersion() <= SCI_VERSION_1_EGA) { if (need_unscaled) gfxr_remove_artifacts_pic0(scaled_pic, unscaled_pic); @@ -145,7 +144,7 @@ int GfxResManager::getOptionsHash(gfx_resource_type_t type) { case GFX_RESOURCE_TYPE_PIC: #ifdef CUSTOM_GRAPHICS_OPTIONS - if (_resManager->isVGA()) + if (_resourceManager->isVGA()) // NOTE: here, it is assumed that the upper port bound is always 10, but this doesn't seem to matter for the // generated options hash anyway return 10; @@ -154,7 +153,7 @@ int GfxResManager::getOptionsHash(gfx_resource_type_t type) { | (_options->pic0_dither_pattern << 8) | (_options->pic0_brush_mode << 4) | (_options->pic0_line_mode); #else - if (_resManager->isVGA()) + if (_resourceManager->isVGA()) return 10; else return 0x10000 | (GFXR_DITHER_PATTERN_SCALED << 8) | (GFX_BRUSH_MODE_RANDOM_ELLIPSES << 4) | GFX_LINE_MODE_CORRECT; @@ -343,12 +342,12 @@ gfxr_pic_t *GfxResManager::getPic(int num, int maps, int flags, int default_pale #ifdef CUSTOM_GRAPHICS_OPTIONS if (_options->pic0_unscaled) { need_unscaled = 0; - pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resManager->isVGA()); + pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resourceManager->isVGA()); } else - pic = gfxr_init_pic(_driver->getMode(), GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resManager->isVGA()); + pic = gfxr_init_pic(_driver->getMode(), GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resourceManager->isVGA()); #else need_unscaled = 0; - pic = gfxr_init_pic(_driver->getMode(), GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resManager->isVGA()); + pic = gfxr_init_pic(_driver->getMode(), GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resourceManager->isVGA()); #endif if (!pic) { @@ -359,7 +358,7 @@ gfxr_pic_t *GfxResManager::getPic(int num, int maps, int flags, int default_pale gfxr_clear_pic0(pic, SCI_TITLEBAR_SIZE); if (need_unscaled) { - unscaled_pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resManager->isVGA()); + unscaled_pic = gfxr_init_pic(&mode_1x1_color_index, GFXR_RES_ID(GFX_RESOURCE_TYPE_PIC, num), _resourceManager->isVGA()); if (!unscaled_pic) { error("Failed to allocate unscaled pic"); return NULL; @@ -527,15 +526,15 @@ gfxr_view_t *GfxResManager::getView(int nr, int *loop, int *cel, int palette) { res = resMap.contains(nr) ? resMap[nr] : NULL; if (!res || res->mode != hash) { - Resource *viewRes = _resManager->findResource(ResourceId(kResourceTypeView, nr), 0); + Resource *viewRes = _resourceManager->findResource(ResourceId(kResourceTypeView, nr), 0); if (!viewRes || !viewRes->data) return NULL; int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_VIEW, nr); - ViewType viewType = _resManager->getViewType(); + ViewType viewType = _resourceManager->getViewType(); if (viewType == kViewEga) { - int pal = (_version <= SCI_VERSION_01) ? -1 : palette; + int pal = (_resourceManager->sciVersion() <= SCI_VERSION_01) ? -1 : palette; view = getEGAView(resid, viewRes->data, viewRes->size, pal); } else { view = getVGAView(resid, viewRes->data, viewRes->size, viewType); @@ -620,13 +619,13 @@ gfx_bitmap_font_t *GfxResManager::getFont(int num, bool scaled) { // Workaround: LSL1VGA mixes its own internal fonts with the global // SCI ones, so we translate them here, by removing their extra bits - if (!resMap.contains(num) && !_resManager->testResource(ResourceId(kResourceTypeFont, num))) + if (!resMap.contains(num) && !_resourceManager->testResource(ResourceId(kResourceTypeFont, num))) num = num & 0x7ff; res = resMap.contains(num) ? resMap[num] : NULL; if (!res || res->mode != hash) { - Resource *fontRes = _resManager->findResource(ResourceId(kResourceTypeFont, num), 0); + Resource *fontRes = _resourceManager->findResource(ResourceId(kResourceTypeFont, num), 0); if (!fontRes || !fontRes->data) return NULL; @@ -663,17 +662,17 @@ gfx_pixmap_t *GfxResManager::getCursor(int num) { res = resMap.contains(num) ? resMap[num] : NULL; if (!res || res->mode != hash) { - Resource *cursorRes = _resManager->findResource(ResourceId(kResourceTypeCursor, num), 0); + Resource *cursorRes = _resourceManager->findResource(ResourceId(kResourceTypeCursor, num), 0); if (!cursorRes || !cursorRes->data) return NULL; - if (_version >= SCI_VERSION_1_1) { + if (_resourceManager->sciVersion() >= SCI_VERSION_1_1) { warning("[GFX] Attempt to retrieve cursor in SCI1.1 or later"); return NULL; } gfx_pixmap_t *cursor = gfxr_draw_cursor(GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, num), - cursorRes->data, cursorRes->size, _version > SCI_VERSION_01); + cursorRes->data, cursorRes->size, _resourceManager->sciVersion() > SCI_VERSION_01); if (!cursor) return NULL; diff --git a/engines/sci/gfx/gfx_resmgr.h b/engines/sci/gfx/gfx_resmgr.h index 75072f5ede..af34a42360 100644 --- a/engines/sci/gfx/gfx_resmgr.h +++ b/engines/sci/gfx/gfx_resmgr.h @@ -23,8 +23,8 @@ * */ -#ifndef SCI_GFX_GFX_RESMGR_H -#define SCI_GFX_GFX_RESMGR_H +#ifndef SCI_GFX_GFX_resourceManager_H +#define SCI_GFX_GFX_resourceManager_H // FIXME/TODO: The name "(Graphics) resource manager", and the associated // filenames, are misleading. This should be renamed to "Graphics manager" @@ -303,13 +303,7 @@ public: return _staticPalette ? _staticPalette->size() : 0; } - /** - * Returns the resource version that the resource manager is using - */ - int getVersion() { return _version; } - private: - int _version; gfx_options_t *_options; GfxDriver *_driver; Palette *_staticPalette; @@ -321,7 +315,7 @@ private: Common::Rect _portBounds; IntResMap _resourceMaps[GFX_RESOURCE_TYPES_NR]; - ResourceManager *_resManager; + ResourceManager *_resourceManager; }; } // End of namespace Sci diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index e07b904324..d6996a0f3d 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -40,7 +40,7 @@ namespace Sci { #undef SCI_REQUIRE_RESOURCE_FILES -//#define SCI_VERBOSE_RESMGR 1 +//#define SCI_VERBOSE_resourceManager 1 static const char *sci_error_types[] = { "No error", @@ -103,7 +103,7 @@ void Resource::unalloc() { status = kResStatusNoMalloc; } -//-- Resmgr helper functions -- +//-- resourceManager helper functions -- // Resource source list management @@ -510,8 +510,8 @@ void ResourceManager::init() { _mapVersion = _volVersion; } - debug("Resmgr: Detected resource map version %d: %s", _mapVersion, versionDescription(_mapVersion)); - debug("Resmgr: Detected volume version %d: %s", _volVersion, versionDescription(_volVersion)); + debug("resourceManager: Detected resource map version %d: %s", _mapVersion, versionDescription(_mapVersion)); + debug("resourceManager: Detected volume version %d: %s", _volVersion, versionDescription(_volVersion)); scanNewSources(); addInternalSources(); @@ -520,25 +520,25 @@ void ResourceManager::init() { _sciVersion = detectSciVersion(); if (_sciVersion != SCI_VERSION_AUTODETECT) - debug("Resmgr: Detected %s", versionNames[_sciVersion]); + debug("resourceManager: Detected %s", versionNames[_sciVersion]); else - warning("Resmgr: Couldn't determine SCI version"); + warning("resourceManager: Couldn't determine SCI version"); switch (_viewType) { case kViewEga: - debug("Resmgr: Detected EGA graphic resources"); + debug("resourceManager: Detected EGA graphic resources"); break; case kViewVga: - debug("Resmgr: Detected VGA graphic resources"); + debug("resourceManager: Detected VGA graphic resources"); break; case kViewVga11: - debug("Resmgr: Detected SCI1.1 VGA graphic resources"); + debug("resourceManager: Detected SCI1.1 VGA graphic resources"); break; case kViewAmiga: - debug("Resmgr: Detected Amiga graphic resources"); + debug("resourceManager: Detected Amiga graphic resources"); break; default: - warning("Resmgr: Couldn't determine view type"); + warning("resourceManager: Couldn't determine view type"); } } @@ -561,7 +561,7 @@ ResourceManager::~ResourceManager() { void ResourceManager::removeFromLRU(Resource *res) { if (res->status != kResStatusEnqueued) { - warning("Resmgr: trying to remove resource that isn't enqueued"); + warning("resourceManager: trying to remove resource that isn't enqueued"); return; } _LRU.remove(res); @@ -571,12 +571,12 @@ void ResourceManager::removeFromLRU(Resource *res) { void ResourceManager::addToLRU(Resource *res) { if (res->status != kResStatusAllocated) { - warning("Resmgr: trying to enqueue resource with state %d", res->status); + warning("resourceManager: trying to enqueue resource with state %d", res->status); return; } _LRU.push_front(res); _memoryLRU += res->size; -#if SCI_VERBOSE_RESMGR +#if SCI_VERBOSE_resourceManager debug("Adding %s.%03d (%d bytes) to lru control: %d bytes total", getResourceTypeName(res->type), res->number, res->size, mgr->_memoryLRU); @@ -607,8 +607,8 @@ void ResourceManager::freeOldResources() { Resource *goner = *_LRU.reverse_begin(); removeFromLRU(goner); goner->unalloc(); -#ifdef SCI_VERBOSE_RESMGR - printf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n", getResourceTypeName(goner->type), goner->number, goner->size); +#ifdef SCI_VERBOSE_resourceManager + printf("resourceManager-debug: LRU: Freeing %s.%03d (%d bytes)\n", getResourceTypeName(goner->type), goner->number, goner->size); #endif } } @@ -656,7 +656,7 @@ Resource *ResourceManager::findResource(ResourceId id, bool lock) { if (retval->data) return retval; else { - warning("Resmgr: Failed to read %s", retval->id.toString().c_str()); + warning("resourceManager: Failed to read %s", retval->id.toString().c_str()); return NULL; } } @@ -665,7 +665,7 @@ void ResourceManager::unlockResource(Resource *res) { assert(res); if (res->status != kResStatusLocked) { - warning("[Resmgr] Attempt to unlock unlocked resource %s", res->id.toString().c_str()); + warning("[resourceManager] Attempt to unlock unlocked resource %s", res->id.toString().c_str()); return; } @@ -1567,7 +1567,7 @@ ViewType ResourceManager::detectViewType() { } } - warning("Resmgr: Couldn't find any views"); + warning("resourceManager: Couldn't find any views"); return kViewUnknown; } @@ -1661,7 +1661,7 @@ bool ResourceManager::hasOldScriptHeader() { Resource *res = findResource(ResourceId(kResourceTypeScript, 0), 0); if (!res) { - warning("Resmgr: Failed to find script.000"); + warning("resourceManager: Failed to find script.000"); return false; } diff --git a/engines/sci/resource.h b/engines/sci/resource.h index 5ba2d03beb..707e941b0f 100644 --- a/engines/sci/resource.h +++ b/engines/sci/resource.h @@ -420,13 +420,22 @@ protected: void readResourcePatches(ResourceSource *source); void processPatch(ResourceSource *source, ResourceType restype, int resnumber); + /** + * Applies to all versions before 0.000.395 (i.e. KQ4 old, XMAS 1988 and LSL2). + * Old SCI versions used two word header for script blocks (first word equal + * to 0x82, meaning of the second one unknown). New SCI versions used one + * word header. + * Also, old SCI versions assign 120 degrees to left & right, and 60 to up + * and down. Later versions use an even 90 degree distribution. + */ + bool hasOldScriptHeader(); + void printLRU(); void addToLRU(Resource *res); void removeFromLRU(Resource *res); ResourceCompression getViewCompression(); ViewType detectViewType(); - bool hasOldScriptHeader(); bool hasSci0Voc999(); bool hasSci1Voc900(); SciVersion detectSciVersion(); diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 3f148f54e7..f5b1f79215 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -107,7 +107,7 @@ SciEngine::~SciEngine() { delete _kernel; delete _vocabulary; delete _console; - delete _resmgr; + delete _resourceManager; } Common::Error SciEngine::run() { @@ -141,19 +141,18 @@ Common::Error SciEngine::run() { const uint32 flags = getFlags(); - _resmgr = new ResourceManager(); - _version = _resmgr->sciVersion(); + _resourceManager = new ResourceManager(); - if (!_resmgr) { + if (!_resourceManager) { printf("No resources found, aborting...\n"); return Common::kNoGameDataFoundError; } - _kernel = new Kernel(_resmgr); - _vocabulary = new Vocabulary(_resmgr); - script_adjust_opcode_formats(_version); + _kernel = new Kernel(_resourceManager); + _vocabulary = new Vocabulary(_resourceManager); + script_adjust_opcode_formats(_resourceManager->sciVersion()); - _gamestate = new EngineState(_resmgr, _version, flags); + _gamestate = new EngineState(_resourceManager, flags); if (script_init_engine(_gamestate)) return Common::kUnknownError; @@ -196,7 +195,7 @@ Common::Error SciEngine::run() { // Default config ends #endif - if (gfxop_init(_resmgr->sciVersion(), &gfx_state, &gfx_options, _resmgr, gfxmode, 1, 1)) { + if (gfxop_init(_resourceManager->sciVersion(), &gfx_state, &gfx_options, _resourceManager, gfxmode, 1, 1)) { warning("Graphics initialization failed. Aborting..."); return Common::kUnknownError; } @@ -211,7 +210,7 @@ Common::Error SciEngine::run() { return Common::kUnknownError; } - printf("Emulating SCI version %s\n", versionNames[_version]); + printf("Emulating SCI version %s\n", versionNames[_resourceManager->sciVersion()]); game_run(&_gamestate); // Run the game @@ -250,7 +249,7 @@ const char* SciEngine::getGameID() const { } SciVersion SciEngine::getVersion() const { - return _version; + return _resourceManager->sciVersion(); } Common::Language SciEngine::getLanguage() const { diff --git a/engines/sci/sci.h b/engines/sci/sci.h index 4781af5870..9af7b35667 100644 --- a/engines/sci/sci.h +++ b/engines/sci/sci.h @@ -97,7 +97,7 @@ public: Common::Language getLanguage() const; Common::Platform getPlatform() const; uint32 getFlags() const; - ResourceManager *getResMgr() const { return _resmgr; } + ResourceManager *getresourceManager() const { return _resourceManager; } Kernel *getKernel() const { return _kernel; } Vocabulary *getVocabulary() const { return _vocabulary; } @@ -112,8 +112,7 @@ public: private: const SciGameDescription *_gameDescription; - SciVersion _version; - ResourceManager *_resmgr; + ResourceManager *_resourceManager; EngineState *_gamestate; Kernel *_kernel; Vocabulary *_vocabulary; diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index c8cf773eae..bc5dd02878 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -87,12 +87,12 @@ public: ~SfxPlayer(); /* Initializes the player - ** Parameters: (ResourceManager *) resmgr: A resource manager for driver initialization + ** Parameters: (ResourceManager *) resourceManager: A resource manager for driver initialization ** (int) expected_latency: Expected delay in between calls to 'maintenance' ** (in microseconds) ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure */ - Common::Error init(ResourceManager *resmgr, int expected_latency); + Common::Error init(ResourceManager *resourceManager, int expected_latency); /* Adds an iterator to the song player ** Parameters: (songx_iterator_t *) it: The iterator to play @@ -223,7 +223,7 @@ void SfxPlayer::player_timer_callback(void *refCon) { /* API implementation */ -Common::Error SfxPlayer::init(ResourceManager *resmgr, int expected_latency) { +Common::Error SfxPlayer::init(ResourceManager *resourceManager, int expected_latency) { MidiDriverType musicDriver = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_ADLIB); switch(musicDriver) { @@ -252,7 +252,7 @@ Common::Error SfxPlayer::init(ResourceManager *resmgr, int expected_latency) { _mutex = new Common::Mutex(); _mididrv->setTimerCallback(this, player_timer_callback); - _mididrv->open(resmgr); + _mididrv->open(resourceManager); _mididrv->setVolume(_volume); return Common::kNoError; @@ -354,7 +354,7 @@ SfxState::SfxState() { SfxState::~SfxState() { if (_syncResource) - _resMgr->unlockResource(_syncResource); + _resourceManager->unlockResource(_syncResource); } @@ -639,7 +639,7 @@ static int sfx_play_iterator_pcm(SongIterator *it, SongHandle handle) { #define DELAY (1000000 / SFX_TICKS_PER_SEC) -void SfxState::sfx_init(ResourceManager *resmgr, int flags) { +void SfxState::sfx_init(ResourceManager *resourceManager, int flags) { _songlib._lib = 0; _song = NULL; _flags = flags; @@ -661,7 +661,7 @@ void SfxState::sfx_init(ResourceManager *resmgr, int flags) { /* Initialise player */ /*-------------------*/ - if (!resmgr) { + if (!resourceManager) { warning("[SFX] Warning: No resource manager present, cannot initialise player"); return; } @@ -673,13 +673,13 @@ void SfxState::sfx_init(ResourceManager *resmgr, int flags) { return; } - if (player->init(resmgr, DELAY / 1000)) { + if (player->init(resourceManager, DELAY / 1000)) { warning("[SFX] Song player reported error, disabled"); delete player; player = NULL; } - _resMgr = resmgr; + _resourceManager = resourceManager; } void SfxState::sfx_exit() { @@ -1137,13 +1137,13 @@ Audio::AudioStream* SfxState::getAudioStream(uint32 number, uint32 volume, int * Sci::Resource* audioRes; if (volume == 65535) { - audioRes = _resMgr->findResource(ResourceId(kResourceTypeAudio, number), false); + audioRes = _resourceManager->findResource(ResourceId(kResourceTypeAudio, number), false); if (!audioRes) { warning("Failed to find audio entry %i", number); return NULL; } } else { - audioRes = _resMgr->findResource(ResourceId(kResourceTypeAudio36, volume, number), false); + audioRes = _resourceManager->findResource(ResourceId(kResourceTypeAudio36, volume, number), false); if (!audioRes) { warning("Failed to find audio entry (%i, %i, %i, %i, %i)", volume, (number >> 24) & 0xff, (number >> 16) & 0xff, (number >> 8) & 0xff, number & 0xff); diff --git a/engines/sci/sfx/core.h b/engines/sci/sfx/core.h index e7eba85c99..fc480aa452 100644 --- a/engines/sci/sfx/core.h +++ b/engines/sci/sfx/core.h @@ -52,7 +52,7 @@ public: // FIXME, make private bool _suspended; /**< Whether we are suspended */ Resource *_syncResource; /**< Used by kDoSync for speech syncing in CD talkie games */ uint _syncOffset; - ResourceManager *_resMgr; + ResourceManager *_resourceManager; public: SfxState(); @@ -63,10 +63,10 @@ public: /***********/ /* Initializes the sound engine - ** Parameters: (ResourceManager *) resmgr: Resource manager for initialization + ** Parameters: (ResourceManager *) resourceManager: Resource manager for initialization ** (int) flags: SFX_STATE_FLAG_* */ - void sfx_init(ResourceManager *resmgr, int flags); + void sfx_init(ResourceManager *resourceManager, int flags); /** Deinitializes the sound subsystem. */ void sfx_exit(); diff --git a/engines/sci/sfx/sci_midi.h b/engines/sci/sfx/sci_midi.h index ed97c9db1a..7cff14bdb0 100644 --- a/engines/sci/sfx/sci_midi.h +++ b/engines/sci/sfx/sci_midi.h @@ -67,7 +67,7 @@ protected: MidiDriver *_driver; public: int open() { return open(NULL); } - virtual int open(ResourceManager *resmgr) { return _driver->open(); } + virtual int open(ResourceManager *resourceManager) { return _driver->open(); } virtual void close() { _driver->close(); } virtual void send(uint32 b) { _driver->send(b); } uint32 getBaseTempo() { return _driver->getBaseTempo(); } diff --git a/engines/sci/sfx/softseq/adlib.cpp b/engines/sci/sfx/softseq/adlib.cpp index 33ccc28360..ba5d364cc5 100644 --- a/engines/sci/sfx/softseq/adlib.cpp +++ b/engines/sci/sfx/softseq/adlib.cpp @@ -623,11 +623,11 @@ void MidiDriver_Adlib::loadResource(Resource *res) { } } -int MidiPlayer_Adlib::open(ResourceManager *resmgr) { - assert(resmgr != NULL); +int MidiPlayer_Adlib::open(ResourceManager *resourceManager) { + assert(resourceManager != NULL); // Load up the patch.003 file, parse out the instruments - Resource *res = resmgr->findResource(ResourceId(kResourceTypePatch, 3), 0); + Resource *res = resourceManager->findResource(ResourceId(kResourceTypePatch, 3), 0); if (!res) { warning("ADLIB: Failed to load patch.003"); @@ -641,7 +641,7 @@ int MidiPlayer_Adlib::open(ResourceManager *resmgr) { static_cast<MidiDriver_Adlib *>(_driver)->loadResource(res); - return static_cast<MidiDriver_Adlib *>(_driver)->open(resmgr->sciVersion() <= SCI_VERSION_0_LATE); + return static_cast<MidiDriver_Adlib *>(_driver)->open(resourceManager->sciVersion() <= SCI_VERSION_0_LATE); } } // End of namespace Sci diff --git a/engines/sci/sfx/softseq/adlib.h b/engines/sci/sfx/softseq/adlib.h index 38f755bec0..bf72c2e15a 100644 --- a/engines/sci/sfx/softseq/adlib.h +++ b/engines/sci/sfx/softseq/adlib.h @@ -146,7 +146,7 @@ private: class MidiPlayer_Adlib : public MidiPlayer { public: MidiPlayer_Adlib() { _driver = new MidiDriver_Adlib(g_system->getMixer()); } - int open(ResourceManager *resmgr); + int open(ResourceManager *resourceManager); int getPlayMask() const { return 0x04; } int getPolyphony() const { return MidiDriver_Adlib::kVoices; } bool hasRhythmChannel() const { return false; } diff --git a/engines/sci/sfx/softseq/pcjr.h b/engines/sci/sfx/softseq/pcjr.h index 8bfa5ab8b1..9a88812c94 100644 --- a/engines/sci/sfx/softseq/pcjr.h +++ b/engines/sci/sfx/softseq/pcjr.h @@ -67,7 +67,7 @@ private: class MidiPlayer_PCJr : public MidiPlayer { public: MidiPlayer_PCJr() { _driver = new MidiDriver_PCJr(g_system->getMixer()); } - int open(ResourceManager *resmgr) { return static_cast<MidiDriver_PCJr *>(_driver)->open(getPolyphony()); } + int open(ResourceManager *resourceManager) { return static_cast<MidiDriver_PCJr *>(_driver)->open(getPolyphony()); } int getPlayMask() const { return 0x10; } int getPolyphony() const { return 3; } bool hasRhythmChannel() const { return false; } diff --git a/engines/sci/vocabulary.cpp b/engines/sci/vocabulary.cpp index 69b7bc3393..517413db4b 100644 --- a/engines/sci/vocabulary.cpp +++ b/engines/sci/vocabulary.cpp @@ -57,12 +57,12 @@ const char *class_names[] = {"", "" }; -int *vocab_get_classes(ResourceManager *resmgr, int* count) { +int *vocab_get_classes(ResourceManager *resourceManager, int* count) { Resource* r; int *c; unsigned int i; - if ((r = resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_CLASSES), 0)) == NULL) + if ((r = resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_CLASSES), 0)) == NULL) return 0; c = (int *)malloc(sizeof(int) * r->size / 2); @@ -74,10 +74,10 @@ int *vocab_get_classes(ResourceManager *resmgr, int* count) { return c; } -int vocab_get_class_count(ResourceManager *resmgr) { +int vocab_get_class_count(ResourceManager *resourceManager) { Resource* r; - if ((r = resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_CLASSES), 0)) == 0) + if ((r = resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_CLASSES), 0)) == 0) return 0; return r->size / 4; @@ -85,13 +85,13 @@ int vocab_get_class_count(ResourceManager *resmgr) { #endif -Vocabulary::Vocabulary(ResourceManager *resmgr) : _resmgr(resmgr) { +Vocabulary::Vocabulary(ResourceManager *resourceManager) : _resourceManager(resourceManager) { _parserRules = NULL; _vocabVersion = kVocabularySCI0; debug(2, "Initializing vocabulary"); - if (_resmgr->sciVersion() <= SCI_VERSION_1_EGA && loadParserWords()) { + if (_resourceManager->sciVersion() <= SCI_VERSION_1_EGA && loadParserWords()) { loadSuffixes(); if (loadBranches()) // Now build a GNF grammar out of this @@ -115,11 +115,11 @@ bool Vocabulary::loadParserWords() { int currentwordpos = 0; // First try to load the SCI0 vocab resource. - Resource *resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB), 0); + Resource *resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB), 0); if (!resource) { warning("SCI0: Could not find a main vocabulary, trying SCI01"); - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB), 0); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB), 0); _vocabVersion = kVocabularySCI1; } @@ -198,9 +198,9 @@ bool Vocabulary::loadSuffixes() { Resource* resource = NULL; if (_vocabVersion == kVocabularySCI0) - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 1); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 1); else - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 1); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 1); if (!resource) return false; // No vocabulary found @@ -237,12 +237,12 @@ void Vocabulary::freeSuffixes() { Resource* resource = NULL; if (_vocabVersion == kVocabularySCI0) - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 0); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 0); else - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 0); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 0); if (resource) - _resmgr->unlockResource(resource); + _resourceManager->unlockResource(resource); _parserSuffixes.clear(); } @@ -251,9 +251,9 @@ bool Vocabulary::loadBranches() { Resource *resource = NULL; if (_vocabVersion == kVocabularySCI0) - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES), 0); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES), 0); else - resource = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES), 0); + resource = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES), 0); _parserBranches.clear(); diff --git a/engines/sci/vocabulary.h b/engines/sci/vocabulary.h index 14e3ad6013..edb4288387 100644 --- a/engines/sci/vocabulary.h +++ b/engines/sci/vocabulary.h @@ -180,7 +180,7 @@ enum VocabularyVersions { class Vocabulary { public: - Vocabulary(ResourceManager *resmgr); + Vocabulary(ResourceManager *resourceManager); ~Vocabulary(); /** @@ -286,7 +286,7 @@ private: */ void freeRuleList(parse_rule_list_t *rule_list); - ResourceManager *_resmgr; + ResourceManager *_resourceManager; VocabularyVersions _vocabVersion; // Parser-related lists |