diff options
-rw-r--r-- | engines/sci/engine/savegame.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 25 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 9 |
3 files changed, 11 insertions, 27 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index b913891d9d..e099d81b88 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -603,9 +603,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { scr->locals_block = scr->locals_segment == 0 ? NULL : (LocalVariables *)(s->seg_manager->_heap[scr->locals_segment]); scr->export_table = (uint16 *) find_unique_script_block(s, scr->buf, sci_obj_exports); scr->synonyms = find_unique_script_block(s, scr->buf, sci_obj_synonyms); - scr->code = NULL; - scr->code_blocks_nr = 0; - scr->code_blocks_allocated = 0; + scr->_codeBlocks.clear(); if (!self->isSci1_1) scr->export_table += 3; diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 57cd0bc576..0878703eb1 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -192,9 +192,7 @@ int SegManager::initialiseScript(Script &scr, EngineState *s, int script_nr) { scr.locals_offset = 0; scr.locals_block = NULL; - scr.code = NULL; - scr.code_blocks_nr = 0; - scr.code_blocks_allocated = 0; + scr._codeBlocks.clear(); scr.nr = script_nr; scr.marked_as_deleted = 0; @@ -373,8 +371,7 @@ void Script::freeScript() { delete obj_indices; obj_indices = 0; - free(code); - code = 0; + _codeBlocks.clear(); } // memory operations @@ -541,14 +538,10 @@ int SegManager::relocateObject(Object *obj, SegmentId segment, int location) { void SegManager::scriptAddCodeBlock(reg_t location) { Script *scr = getScript(location.segment, SEG_ID); - if (++scr->code_blocks_nr > scr->code_blocks_allocated) { - scr->code_blocks_allocated += DEFAULT_OBJECTS_INCREMENT; - scr->code = (CodeBlock *)sci_realloc(scr->code, scr->code_blocks_allocated * sizeof(CodeBlock)); - } - - int index = scr->code_blocks_nr - 1; - scr->code[index].pos = location; - scr->code[index].size = READ_LE_UINT16(scr->buf + location.offset - 2); + CodeBlock cb; + cb.pos = location; + cb.size = READ_LE_UINT16(scr->buf + location.offset - 2); + scr->_codeBlocks.push_back(cb); } void SegManager::scriptRelocate(reg_t block) { @@ -573,9 +566,9 @@ void SegManager::scriptRelocate(reg_t block) { done = true; } - for (k = 0; !done && (int)k < scr->code_blocks_nr; k++) { - if (pos >= scr->code[k].pos.offset && - pos < scr->code[k].pos.offset + scr->code[k].size) + for (k = 0; !done && k < scr->_codeBlocks.size(); k++) { + if (pos >= scr->_codeBlocks[k].pos.offset && + pos < scr->_codeBlocks[k].pos.offset + scr->_codeBlocks[k].size) done = true; } diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 0f3ed5f0ab..f3dc1ce96a 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -277,8 +277,6 @@ struct Object { uint16 *base_method; /**< Pointer to the method selector area for this object */ uint16 *base_vars; /**< Pointer to the varselector area for this object */ reg_t *variables; - - Object() { memset(this, 0, sizeof(*this)); } }; struct CodeBlock { @@ -336,9 +334,7 @@ struct Script : public MemObject { int locals_segment; /**< The local variable segment */ LocalVariables *locals_block; - CodeBlock *code; - int code_blocks_nr; - int code_blocks_allocated; + Common::Array<CodeBlock> _codeBlocks; int relocated; int marked_as_deleted; @@ -360,9 +356,6 @@ public: locals_segment = 0; locals_block = NULL; - code = NULL; - code_blocks_nr = 0; - code_blocks_allocated = 0; relocated = 0; marked_as_deleted = 0; } |