From 50c8821072b31d24783fba9f058f805a176a4d7a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 3 May 2009 09:30:33 +0000 Subject: SCI: Renamed MemObject::type and ::segmgr_id to _type resp. _segmgrId, and added accessor methods getType() and getSegMgrId() svn-id: r40271 --- engines/sci/engine/kernel.cpp | 6 +++--- engines/sci/engine/klists.cpp | 7 ++----- engines/sci/engine/kstring.cpp | 2 +- engines/sci/engine/savegame.cpp | 18 +++++++++--------- engines/sci/engine/scriptconsole.cpp | 8 ++++---- engines/sci/engine/scriptdebug.cpp | 14 +++++++------- engines/sci/engine/seg_manager.cpp | 36 +++++++++++++++++------------------- engines/sci/engine/seg_manager.h | 4 ++-- engines/sci/engine/vm.cpp | 6 +++--- engines/sci/engine/vm.h | 7 +++++-- 10 files changed, 53 insertions(+), 55 deletions(-) diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index b33ce60f18..39d6ee3c9a 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -455,7 +455,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { SCIkdebug(SCIkERROR, "Attempt to poke invalid memory at "PREG"!\n", PRINT_REG(argv[1])); return s->r_acc; } - if (s->seg_manager->heap[argv[1].segment]->type == MEM_OBJ_LOCALS) + if (s->seg_manager->heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) return *((reg_t *) ref); else return make_reg(0, (int16)READ_LE_UINT16(ref)); @@ -469,7 +469,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]->type == MEM_OBJ_LOCALS) + if (s->seg_manager->heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) *((reg_t *) ref) = argv[2]; else { if (argv[2].segment) { @@ -673,7 +673,7 @@ int determine_reg_type(EngineState *s, reg_t reg, int allow_invalid) { mobj = s->seg_manager->heap[reg.segment]; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: if (reg.offset <= mobj->data.script.buf_size && reg.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(mobj->data.script.buf + reg.offset)) { diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp index bf9e0a4858..fc27067475 100644 --- a/engines/sci/engine/klists.cpp +++ b/engines/sci/engine/klists.cpp @@ -29,13 +29,10 @@ namespace Sci { Node *lookup_node(EngineState *s, reg_t addr, const char *file, int line) { - MemObject *mobj; - NodeTable *nt; - if (!addr.offset && !addr.segment) return NULL; // Non-error null - mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_NODES); + MemObject *mobj = GET_SEGMENT(*s->seg_manager, 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 @@ -45,7 +42,7 @@ Node *lookup_node(EngineState *s, reg_t addr, const char *file, int line) { return NULL; } - nt = &(mobj->data.nodes); + NodeTable *nt = &(mobj->data.nodes); if (!ENTRY_IS_VALID(nt, addr.offset)) { sciprintf("%s, L%d: Attempt to use non-node "PREG" as list node\n", __FILE__, __LINE__, PRINT_REG(addr)); diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 42530bf9d1..9f74a6a47c 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -368,7 +368,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]->type == MEM_OBJ_DYNMEM) { + if (s->seg_manager->heap[argv[0].segment]->getType() == MEM_OBJ_DYNMEM) { reg_t *srcp = (reg_t *) src; int i; diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index dba01f0c0f..198d62e41b 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -432,7 +432,7 @@ static void sync_songlib_t(Common::Serializer &s, songlib_t &obj) { static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj) { // Sync the memobj type - memObjType type = (s.isSaving() && obj) ? obj->type : MEM_OBJ_INVALID; + memObjType type = (s.isSaving() && obj) ? obj->getType() : MEM_OBJ_INVALID; s.syncAsUint32LE(type); // If we were saving and obj == 0, or if we are loading and this is an @@ -445,13 +445,13 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj) { if (s.isLoading()) { //assert(!obj); obj = (MemObject *)sci_calloc(1, sizeof(MemObject)); - obj->type = type; + obj->_type = type; } else { assert(obj); } - s.syncAsSint32LE(obj->segmgr_id); - switch (obj->type) { + s.syncAsSint32LE(obj->_segmgrId); + switch (type) { case MEM_OBJ_SCRIPT: sync_Script(s, obj->data.script); break; @@ -489,7 +489,7 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj) { sync_DynMem(s, obj->data.dynmem); break; default: - error("Unknown MemObject type %d", obj->type); + error("Unknown MemObject type %d", type); break; } } @@ -542,7 +542,7 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) { for (i = 0; i < self->heap_size; i++) if (self->heap[i] && - self->heap[i]->type == type) + self->heap[i]->getType() == type) return i; return -1; } @@ -619,7 +619,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { mobj = self->heap[i]; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: { int j; Script *scr = &mobj->data.script; @@ -651,7 +651,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { mobj = self->heap[i]; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: { int j; Script *scr = &mobj->data.script; @@ -700,7 +700,7 @@ static void reconstruct_clones(EngineState *s, SegManager *self) { for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { mobj = self->heap[i]; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_CLONES: { int j; CloneTable::Entry *seeker = mobj->data.clones.table; diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index 935f3e7418..bbe1b36cb0 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -311,9 +311,9 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on int max_index = 0; if (mobj) { - if (mobj->type == MEM_OBJ_SCRIPT) + if (mobj->getType() == MEM_OBJ_SCRIPT) max_index = mobj->data.script.objects_nr; - else if (mobj->type == MEM_OBJ_CLONES) + else if (mobj->getType() == MEM_OBJ_CLONES) max_index = mobj->data.clones.max_entry; } @@ -324,10 +324,10 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on objpos.offset = 0; objpos.segment = i; - if (mobj->type == MEM_OBJ_SCRIPT) { + if (mobj->getType() == MEM_OBJ_SCRIPT) { obj = mobj->data.script.objects + idx; objpos.offset = obj->pos.offset; - } else if (mobj->type == MEM_OBJ_CLONES) { + } else if (mobj->getType() == MEM_OBJ_CLONES) { obj = &(mobj->data.clones.table[idx]); objpos.offset = idx; valid = clone_is_used(&mobj->data.clones, idx); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 66d5377bef..07d65a6d99 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -288,10 +288,10 @@ int c_segtable(EngineState *s) { sciprintf(" ---- segment table ----\n"); for (i = 0; i < s->seg_manager->heap_size; i++) { MemObject *mobj = s->seg_manager->heap[i]; - if (mobj && mobj->type) { + if (mobj && mobj->getType()) { sciprintf(" [%04x] ", i); - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: sciprintf("S script.%03d l:%d ", mobj->data.script.nr, mobj->data.script.lockers); break; @@ -333,11 +333,11 @@ int c_segtable(EngineState *s) { break; default: - sciprintf("I Invalid (type = %x)", mobj->type); + sciprintf("I Invalid (type = %x)", mobj->getType()); break; } - sciprintf(" seg_ID = %d \n", mobj->segmgr_id); + sciprintf(" seg_ID = %d \n", mobj->getSegMgrId()); } } sciprintf("\n"); @@ -385,7 +385,7 @@ static void print_list(EngineState *s, List *l) { } static void _c_single_seg_info(EngineState *s, MemObject *mobj) { - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: { int i; @@ -495,7 +495,7 @@ static void _c_single_seg_info(EngineState *s, MemObject *mobj) { } default : - sciprintf("Invalid type %d\n", mobj->type); + sciprintf("Invalid type %d\n", mobj->getType()); break; } } @@ -2557,7 +2557,7 @@ int objinfo(EngineState *s, reg_t pos) { reg_t fptr = VM_OBJECT_READ_FUNCTION(obj, i); sciprintf(" [%03x] %s = "PREG"\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]->type == MEM_OBJ_SCRIPT) + if (s->seg_manager->heap[pos.segment]->getType() == MEM_OBJ_SCRIPT) sciprintf("\nOwner script:\t%d\n", s->seg_manager->heap[pos.segment]->data.script.nr); return 0; diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 37f49e762f..c48a6aeb34 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -230,9 +230,9 @@ int SegManager::deallocate(int seg, bool recursive) { int i; mobj = heap[seg]; - id_seg_map->removeKey(mobj->segmgr_id); + id_seg_map->removeKey(mobj->getSegMgrId()); - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: freeScript(mobj->data.script); @@ -293,9 +293,7 @@ int SegManager::deallocate(int seg, bool recursive) { case MEM_OBJ_STRING_FRAG: break; default: - fprintf(stderr, "Deallocating segment type %d not supported!\n", - mobj->type); - BREAKPOINT(); + error("Deallocating segment type %d not supported", mobj->getType()); } free(mobj); @@ -325,7 +323,7 @@ int SegManager::scriptIsMarkedAsDeleted(SegmentId seg) { if (!check(seg)) return 0; - if (heap[seg]->type != MEM_OBJ_SCRIPT) + if (heap[seg]->getType() != MEM_OBJ_SCRIPT) return 0; scr = &(heap[seg]->data.script); @@ -369,8 +367,8 @@ MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, memObjType t memset(heap + oldhs, 0, sizeof(MemObject *) * (heap_size - oldhs)); } - mem->segmgr_id = hash_id; - mem->type = type; + mem->_segmgrId = hash_id; + mem->_type = type; // hook it to the heap heap[segid] = mem; @@ -426,12 +424,12 @@ int16 SegManager::getHeap(reg_t reg) { VERIFY(check(reg.segment), "Invalid seg id"); mem_obj = heap[reg.segment]; - switch (mem_obj->type) { + switch (mem_obj->getType()) { case MEM_OBJ_SCRIPT: VERIFY(reg.offset + 1 < (uint16)mem_obj->data.script.buf_size, "invalid offset\n"); return (mem_obj->data.script.buf[reg.offset] | (mem_obj->data.script.buf[reg.offset+1]) << 8); default: - error("SegManager::getHeap: unsupported mem obj type %d", mem_obj->type); + error("SegManager::getHeap: unsupported mem obj type %d", mem_obj->getType()); break; } return 0; // never get here @@ -451,8 +449,8 @@ Script *SegManager::getScript(const int id, idFlag flag) { if (!heap[seg]) { error("SegManager::getScript(%d,%d): seg id %x is not in memory", id, flag, seg); } - if (heap[seg]->type != MEM_OBJ_SCRIPT) { - error("SegManager::getScript(%d,%d): seg id %x refers to type %d != MEM_OBJ_SCRIPT", id, flag, seg, heap[seg]->type); + if (heap[seg]->getType() != MEM_OBJ_SCRIPT) { + error("SegManager::getScript(%d,%d): seg id %x refers to type %d != MEM_OBJ_SCRIPT", id, flag, seg, heap[seg]->getType()); } return &(heap[seg]->data.script); } @@ -816,7 +814,7 @@ LocalVariables *SegManager::allocLocalsSegment(Script *scr, int count) { if (scr->locals_segment) { mobj = heap[scr->locals_segment]; VERIFY(mobj != NULL, "Re-used locals segment was NULL'd out"); - VERIFY(mobj->type == MEM_OBJ_LOCALS, "Re-used locals segment did not consist of local variables"); + VERIFY(mobj->getType() == MEM_OBJ_LOCALS, "Re-used locals segment did not consist of local variables"); VERIFY(mobj->data.locals.script_id == scr->nr, "Re-used locals segment belonged to other script"); } else mobj = allocNonscriptSegment(MEM_OBJ_LOCALS, &scr->locals_segment); @@ -1158,7 +1156,7 @@ byte *SegManager::dereference(reg_t pointer, int *size) { mobj = heap[pointer.segment]; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: if (pointer.offset > mobj->data.script.buf_size) { sciprintf("Error: Attempt to dereference invalid pointer "PREG" into script segment (script size=%d)\n", @@ -1232,7 +1230,7 @@ const char *SegManager::getDescription(reg_t addr) { if (addr.segment >= heap_size) return ""; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_DYNMEM: return mobj->data.dynmem.description; default: @@ -1241,7 +1239,7 @@ const char *SegManager::getDescription(reg_t addr) { } int SegManager::freeDynmem(reg_t addr) { - if (addr.segment <= 0 || addr.segment >= heap_size || !heap[addr.segment] || heap[addr.segment]->type != MEM_OBJ_DYNMEM) + if (addr.segment <= 0 || addr.segment >= heap_size || !heap[addr.segment] || heap[addr.segment]->getType() != MEM_OBJ_DYNMEM) return 1; // error deallocate(addr.segment, true); @@ -1261,7 +1259,7 @@ void SegManager::dbgPrint(const char* msg, void *i) { // ------------------- Segment interface ------------------ SegInterface::SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId, memObjType typeId) : _segmgr(segmgr), _mobj(mobj), _segId(segId), _typeId(typeId) { - VERIFY(_mobj->type == _typeId, "Invalid MemObject type"); + VERIFY(_mobj->getType() == _typeId, "Invalid MemObject type"); } reg_t SegInterface::findCanonicAddress(reg_t addr) { @@ -1599,7 +1597,7 @@ SegInterface *SegManager::getSegInterface(SegmentId segid) { SegInterface *retval = NULL; MemObject *mobj = heap[segid]; - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_SCRIPT: retval = new SegInterfaceScript(this, mobj, segid); break; @@ -1631,7 +1629,7 @@ SegInterface *SegManager::getSegInterface(SegmentId segid) { retval = new SegInterfaceStringFrag(this, mobj, segid); break; default: - error("Improper segment interface for %d", mobj->type); + error("Improper segment interface for %d", mobj->getType()); } return retval; diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 109c7a9332..679bb947e8 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -39,13 +39,13 @@ enum idFlag { }; #define GET_SEGMENT(mgr, index, rtype) ((index) > 0 && (mgr).heap_size > index) ? \ - (((mgr).heap[index] && (mgr).heap[index]->type == rtype)? (mgr).heap[index] : NULL) : NULL + (((mgr).heap[index] && (mgr).heap[index]->getType() == rtype)? (mgr).heap[index] : NULL) : NULL #define GET_SEGMENT_ANY(mgr, index) ((index) > 0 && (mgr).heap_size > index) ? \ (((mgr).heap[index])? (mgr).heap[index] : NULL) : NULL #define GET_OBJECT_SEGMENT(mgr, index) ((index) > 0 && (mgr).heap_size > index) ? \ - (((mgr).heap[index] && ((mgr).heap[index]->type == MEM_OBJ_SCRIPT || (mgr).heap[index]->type == MEM_OBJ_CLONES))? (mgr).heap[index] \ + (((mgr).heap[index] && ((mgr).heap[index]->getType() == MEM_OBJ_SCRIPT || (mgr).heap[index]->getType() == MEM_OBJ_CLONES))? (mgr).heap[index] \ : NULL): NULL class SegInterface; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index af40f7a522..80be41215c 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -544,7 +544,7 @@ static reg_t pointer_add(EngineState *s, reg_t base, int offset) { return NULL_REG; } - switch (mobj->type) { + switch (mobj->getType()) { case MEM_OBJ_LOCALS: base.offset += 2 * offset; @@ -2088,9 +2088,9 @@ Object *obj_get(EngineState *s, reg_t offset) { int idx; if (memobj != NULL) { - if (memobj->type == MEM_OBJ_CLONES && ENTRY_IS_VALID(&memobj->data.clones, offset.offset)) + if (memobj->getType() == MEM_OBJ_CLONES && ENTRY_IS_VALID(&memobj->data.clones, offset.offset)) obj = &(memobj->data.clones.table[offset.offset]); - else if (memobj->type == MEM_OBJ_SCRIPT) { + else if (memobj->getType() == MEM_OBJ_SCRIPT) { if (offset.offset <= memobj->data.script.buf_size && offset.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(memobj->data.script.buf + offset.offset)) { idx = RAW_GET_CLASS_INDEX(&(memobj->data.script), offset); diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index e317b010df..b8e818b2b6 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -346,8 +346,8 @@ enum memObjType { }; struct MemObject { - memObjType type; - int segmgr_id; /**< Internal value used by the seg_manager's hash map */ + memObjType _type; + int _segmgrId; /**< Internal value used by the seg_manager's hash map */ union { Script script; CloneTable clones; @@ -359,6 +359,9 @@ struct MemObject { HunkTable hunks; DynMem dynmem; } data; + + inline memObjType getType() const { return _type; } + inline int getSegMgrId() const { return _segmgrId; } }; -- cgit v1.2.3