SCI: Rename Object::flags and pos to _flags and _pos; tweak scriptObjInit0 and scriptObjInit11 to be more similar

svn-id: r44234
This commit is contained in:
Max Horn 2009-09-21 21:35:43 +00:00
parent 47e677ffcc
commit 57dfb9bafd
7 changed files with 58 additions and 60 deletions

View File

@ -1401,10 +1401,10 @@ bool Console::segmentInfo(int nr) {
for (uint i = 0; i < scr->_objects.size(); i++) {
DebugPrintf(" ");
// Object header
Object *obj = _vm->_gamestate->segMan->getObject(scr->_objects[i].pos);
Object *obj = _vm->_gamestate->segMan->getObject(scr->_objects[i]._pos);
if (obj)
DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(scr->_objects[i].pos),
_vm->_gamestate->segMan->getObjectName(scr->_objects[i].pos),
DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(scr->_objects[i]._pos),
_vm->_gamestate->segMan->getObjectName(scr->_objects[i]._pos),
obj->_variables.size(), obj->methods_nr);
}
}
@ -1448,10 +1448,10 @@ bool Console::segmentInfo(int nr) {
objpos.segment = nr;
DebugPrintf(" [%04x] %s; copy of ", i, _vm->_gamestate->segMan->getObjectName(objpos));
// Object header
Object *obj = _vm->_gamestate->segMan->getObject(ct->_table[i].pos);
Object *obj = _vm->_gamestate->segMan->getObject(ct->_table[i]._pos);
if (obj)
DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(ct->_table[i].pos),
_vm->_gamestate->segMan->getObjectName(ct->_table[i].pos),
DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(ct->_table[i]._pos),
_vm->_gamestate->segMan->getObjectName(ct->_table[i]._pos),
obj->_variables.size(), obj->methods_nr);
}
}
@ -2901,7 +2901,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on
if (mobj->getType() == SEG_TYPE_SCRIPT) {
obj = &(*(Script *)mobj)._objects[idx];
objpos.offset = obj->pos.offset;
objpos.offset = obj->_pos.offset;
} else if (mobj->getType() == SEG_TYPE_CLONES) {
obj = &((*(CloneTable *)mobj)._table[idx]);
objpos.offset = idx;

View File

@ -120,7 +120,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) {
// All objects (may be classes, may be indirectly reachable)
for (uint obj_nr = 0; obj_nr < script->_objects.size(); obj_nr++) {
wm.push(script->_objects[obj_nr].pos);
wm.push(script->_objects[obj_nr]._pos);
}
}
}

View File

@ -123,15 +123,15 @@ reg_t kClone(EngineState *s, int, int argc, reg_t *argv) {
}
*clone_obj = *parent_obj;
clone_obj->flags = 0;
clone_obj->_flags = 0;
// Mark as clone
clone_obj->setInfoSelector(make_reg(0, SCRIPT_INFO_CLONE));
clone_obj->setSpeciesSelector(clone_obj->pos);
clone_obj->setSpeciesSelector(clone_obj->_pos);
if (parent_obj->isClass())
clone_obj->setSuperClassSelector(parent_obj->pos);
s->segMan->getScript(parent_obj->pos.segment)->incrementLockers();
s->segMan->getScript(clone_obj->pos.segment)->incrementLockers();
clone_obj->setSuperClassSelector(parent_obj->_pos);
s->segMan->getScript(parent_obj->_pos.segment)->incrementLockers();
s->segMan->getScript(clone_obj->_pos.segment)->incrementLockers();
return clone_addr;
}
@ -169,7 +169,7 @@ reg_t kDisposeClone(EngineState *s, int, int argc, reg_t *argv) {
}
#endif
victim_obj->flags |= OBJECT_FLAG_FREED;
victim_obj->_flags |= OBJECT_FLAG_FREED;
_k_view_list_mark_free(s, victim_addr); // Free on view list, if neccessary

View File

@ -319,8 +319,8 @@ void LocalVariables::saveLoadWithSerializer(Common::Serializer &s) {
template <>
void syncWithSerializer(Common::Serializer &s, Object &obj) {
s.syncAsSint32LE(obj.flags);
sync_reg_t(s, obj.pos);
s.syncAsSint32LE(obj._flags);
sync_reg_t(s, obj._pos);
s.syncAsSint32LE(obj.variable_names_nr);
s.syncAsSint32LE(obj.methods_nr);
@ -580,7 +580,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) {
scr->_codeBlocks.clear();
for (j = 0; j < scr->_objects.size(); j++) {
byte *data = scr->_buf + scr->_objects[j].pos.offset;
byte *data = scr->_buf + scr->_objects[j]._pos.offset;
scr->_objects[j].base = scr->_buf;
scr->_objects[j].base_obj = data;
}
@ -600,7 +600,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) {
Script *scr = (Script *)mobj;
for (j = 0; j < scr->_objects.size(); j++) {
byte *data = scr->_buf + scr->_objects[j].pos.offset;
byte *data = scr->_buf + scr->_objects[j]._pos.offset;
if (s->resMan->sciVersion() >= SCI_VERSION_1_1) {
uint16 *funct_area = (uint16 *) (scr->_buf + READ_LE_UINT16( data + 6 ));

View File

@ -189,7 +189,7 @@ bool SegManager::isHeapObject(reg_t pos) {
Object *obj = getObject(pos);
if (obj == NULL)
return false;
if (obj->flags & OBJECT_FLAG_FREED)
if (obj->_flags & OBJECT_FLAG_FREED)
return false;
Script *scr = getScriptIfLoaded(pos.segment);
return !(scr && scr->_markedAsDeleted);
@ -324,7 +324,7 @@ int Script::relocateLocal(SegmentId segment, int location) {
}
int Script::relocateObject(Object *obj, SegmentId segment, int location) {
return relocateBlock(obj->_variables, obj->pos.offset, segment, location);
return relocateBlock(obj->_variables, obj->_pos.offset, segment, location);
}
void Script::scriptAddCodeBlock(reg_t location) {
@ -368,7 +368,7 @@ void Script::scriptRelocate(reg_t block) {
else
printf("- No locals\n");
for (k = 0; k < _objects.size(); k++)
printf("- obj#%d at %04x w/ %d vars\n", k, _objects[k].pos.offset, _objects[k]._variables.size());
printf("- obj#%d at %04x w/ %d vars\n", k, _objects[k]._pos.offset, _objects[k]._variables.size());
// SQ3 script 71 has broken relocation entries.
printf("Trying to continue anyway...\n");
}
@ -405,7 +405,7 @@ void Script::heapRelocate(reg_t block) {
else
printf("- No locals\n");
for (k = 0; k < _objects.size(); k++)
printf("- obj#%d at %04x w/ %d vars\n", k, _objects[k].pos.offset, _objects[k]._variables.size());
printf("- obj#%d at %04x w/ %d vars\n", k, _objects[k]._pos.offset, _objects[k]._variables.size());
error("Breakpoint in %s, line %d", __FILE__, __LINE__);
}
}
@ -459,44 +459,44 @@ reg_t SegManager::getClassAddress(int classnr, ScriptLoadType lock, reg_t caller
Object *Script::scriptObjInit0(reg_t obj_pos) {
Object *obj;
uint base = obj_pos.offset - SCRIPT_OBJECT_MAGIC_OFFSET;
VERIFY(base < _bufSize, "Attempt to initialize object beyond end of script\n");
obj_pos.offset -= SCRIPT_OBJECT_MAGIC_OFFSET;
VERIFY(obj_pos.offset < _bufSize, "Attempt to initialize object beyond end of script\n");
obj = allocateObject(base);
obj = allocateObject(obj_pos.offset);
VERIFY(base + SCRIPT_FUNCTAREAPTR_OFFSET < _bufSize, "Function area pointer stored beyond end of script\n");
VERIFY(obj_pos.offset + SCRIPT_FUNCTAREAPTR_OFFSET < (int)_bufSize, "Function area pointer stored beyond end of script\n");
{
byte *data = (byte *)(_buf + base);
int funct_area = READ_LE_UINT16(data + SCRIPT_FUNCTAREAPTR_OFFSET);
byte *data = (byte *)(_buf + obj_pos.offset);
uint16 *funct_area = (uint16 *)(data + READ_LE_UINT16(data + SCRIPT_FUNCTAREAPTR_OFFSET));
int variables_nr;
int functions_nr;
int is_class;
int i;
obj->flags = 0;
obj->pos = make_reg(obj_pos.segment, base);
obj->_flags = 0;
obj->_pos = obj_pos;
VERIFY(base + funct_area < _bufSize, "Function area pointer references beyond end of script");
VERIFY((byte *)funct_area < _buf + _bufSize, "Function area pointer references beyond end of script");
variables_nr = READ_LE_UINT16(data + SCRIPT_SELECTORCTR_OFFSET);
functions_nr = READ_LE_UINT16(data + funct_area - 2);
functions_nr = READ_LE_UINT16(funct_area - 1);
is_class = READ_LE_UINT16(data + SCRIPT_INFO_OFFSET) & SCRIPT_INFO_CLASS;
VERIFY(base + funct_area + functions_nr * 2
obj->base_method = funct_area;
obj->base_vars = NULL;
VERIFY((byte *)funct_area + functions_nr * 2
// add again for classes, since those also store selectors
+ (is_class ? functions_nr * 2 : 0) < _bufSize, "Function area extends beyond end of script");
+ (is_class ? functions_nr * 2 : 0) < _buf + _bufSize, "Function area extends beyond end of script");
obj->_variables.resize(variables_nr);
obj->methods_nr = functions_nr;
obj->base = _buf;
obj->base_obj = data;
obj->base_method = (uint16 *)(data + funct_area);
obj->base_vars = NULL;
for (i = 0; i < variables_nr; i++)
for (int i = 0; i < variables_nr; i++)
obj->_variables[i] = make_reg(0, READ_LE_UINT16(data + (i * 2)));
}
@ -505,25 +505,23 @@ Object *Script::scriptObjInit0(reg_t obj_pos) {
Object *Script::scriptObjInit11(reg_t obj_pos) {
Object *obj;
uint base = obj_pos.offset;
VERIFY(base < _bufSize, "Attempt to initialize object beyond end of script\n");
VERIFY(obj_pos.offset < _bufSize, "Attempt to initialize object beyond end of script\n");
obj = allocateObject(base);
obj = allocateObject(obj_pos.offset);
VERIFY(base + SCRIPT_FUNCTAREAPTR_OFFSET < _bufSize, "Function area pointer stored beyond end of script\n");
VERIFY(obj_pos.offset + SCRIPT_FUNCTAREAPTR_OFFSET < (int)_bufSize, "Function area pointer stored beyond end of script\n");
{
byte *data = (byte *)(_buf + base);
byte *data = (byte *)(_buf + obj_pos.offset);
uint16 *funct_area = (uint16 *)(_buf + READ_LE_UINT16(data + 6));
uint16 *prop_area = (uint16 *)(_buf + READ_LE_UINT16(data + 4));
int variables_nr;
int functions_nr;
int is_class;
int i;
obj->flags = 0;
obj->pos = obj_pos;
obj->_flags = 0;
obj->_pos = obj_pos;
VERIFY((byte *)funct_area < _buf + _bufSize, "Function area pointer references beyond end of script");
@ -543,7 +541,7 @@ Object *Script::scriptObjInit11(reg_t obj_pos) {
obj->base = _buf;
obj->base_obj = data;
for (i = 0; i < variables_nr; i++)
for (int i = 0; i < variables_nr; i++)
obj->_variables[i] = make_reg(0, READ_LE_UINT16(data + (i * 2)));
}

View File

@ -362,7 +362,7 @@ void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback
(*note)(param, clone->_variables[i]);
// Note that this also includes the 'base' object, which is part of the script and therefore also emits the locals.
(*note)(param, clone->pos);
(*note)(param, clone->_pos);
//debugC(2, kDebugLevelGC, "[GC] Reporting clone-pos %04x:%04x\n", PRINT_REG(clone->pos));
}
@ -374,7 +374,7 @@ void CloneTable::freeAtAddress(SegManager *segMan, reg_t addr) {
victim_obj = &(_table[addr.offset]);
if (!(victim_obj->flags & OBJECT_FLAG_FREED))
if (!(victim_obj->_flags & OBJECT_FLAG_FREED))
warning("[GC] Clone %04x:%04x not reachable and not freed (freeing now)", PRINT_REG(addr));
#ifdef GC_DEBUG_VERBOSE
else

View File

@ -185,8 +185,8 @@ public:
// TODO: convert to class, perhaps?
struct Object {
int flags;
reg_t pos; /**< Object offset within its script; for clones, this is their base */
int _flags;
reg_t _pos; /**< Object offset within its script; for clones, this is their base */
int variable_names_nr; /**< Number of variable names, may be less than variables_nr */
int methods_nr;
byte *base; /**< Points to a buffer all relative references (code, strings) point to */
@ -249,7 +249,7 @@ struct Object {
reg_t getFunction(uint16 i) {
uint16 offset = (getSciVersion() < SCI_VERSION_1_1) ? methods_nr + 1 + i : i * 2 + 2;
return make_reg(pos.segment, READ_LE_UINT16((byte *) (base_method + offset)));
return make_reg(_pos.segment, READ_LE_UINT16((byte *) (base_method + offset)));
}
bool isClass() {