SCI: Make SegManager::_heap private

svn-id: r50552
This commit is contained in:
Max Horn 2010-07-01 16:05:29 +00:00
parent c822cd67cb
commit b8904a48ed
3 changed files with 19 additions and 18 deletions

View File

@ -51,12 +51,12 @@ struct WorklistManager {
}
};
static reg_t_hash_map *normalise_hashmap_ptrs(SegManager *segMan, reg_t_hash_map &nonnormal_map) {
static reg_t_hash_map *normalizeAddresses(SegManager *segMan, reg_t_hash_map &nonnormal_map) {
reg_t_hash_map *normal_map = new reg_t_hash_map();
for (reg_t_hash_map::iterator i = nonnormal_map.begin(); i != nonnormal_map.end(); ++i) {
reg_t reg = i->_key;
SegmentObj *mobj = (reg.segment < segMan->_heap.size()) ? segMan->_heap[reg.segment] : NULL;
SegmentObj *mobj = segMan->getSegmentObj(reg.segment);
if (mobj) {
reg = mobj->findCanonicAddress(segMan, reg);
@ -113,11 +113,12 @@ reg_t_hash_map *find_all_used_references(EngineState *s) {
debugC(2, kDebugLevelGC, "[GC] -- Finished adding execution stack");
const Common::Array<SegmentObj *> &heap = segMan->getSegments();
// Init: Explicitly loaded scripts
for (i = 1; i < segMan->_heap.size(); i++) {
if (segMan->_heap[i]
&& segMan->_heap[i]->getType() == SEG_TYPE_SCRIPT) {
Script *script = (Script *)segMan->_heap[i];
for (i = 1; i < heap.size(); i++) {
if (heap[i] && heap[i]->getType() == SEG_TYPE_SCRIPT) {
Script *script = (Script *)heap[i];
if (script->getLockers()) { // Explicitly loaded?
wm.pushArray(script->listObjectReferences());
@ -134,15 +135,15 @@ reg_t_hash_map *find_all_used_references(EngineState *s) {
wm._worklist.pop_back();
if (reg.segment != stack_seg) { // No need to repeat this one
debugC(2, kDebugLevelGC, "[GC] Checking %04x:%04x", PRINT_REG(reg));
if (reg.segment < segMan->_heap.size() && segMan->_heap[reg.segment]) {
if (reg.segment < heap.size() && heap[reg.segment]) {
// Valid heap object? Find its outgoing references!
wm.pushArray(segMan->_heap[reg.segment]->listAllOutgoingReferences(reg));
wm.pushArray(heap[reg.segment]->listAllOutgoingReferences(reg));
}
}
}
// Normalise
normal_map = normalise_hashmap_ptrs(segMan, wm._map);
normal_map = normalizeAddresses(segMan, wm._map);
return normal_map;
}
@ -162,8 +163,9 @@ void run_gc(EngineState *s) {
// Iterate over all segments, and check for each whether it
// contains stuff that can be collected.
for (uint seg = 1; seg < segMan->_heap.size(); seg++) {
SegmentObj *mobj = segMan->_heap[seg];
const Common::Array<SegmentObj *> &heap = segMan->getSegments();
for (uint seg = 1; seg < heap.size(); seg++) {
SegmentObj *mobj = heap[seg];
if (mobj != NULL) {
const SegmentType type = mobj->getType();
segnames[type] = SegmentObj::getSegmentTypeName(type);

View File

@ -553,7 +553,7 @@ static void *derefPtr(SegManager *segMan, reg_t pointer, int entries, bool wantR
if (ret.isRaw != wantRaw) {
warning("Dereferencing pointer %04x:%04x (type %d) which is %s, but expected %s", PRINT_REG(pointer),
segMan->_heap[pointer.segment]->getType(),
segMan->getSegmentType(pointer.segment),
ret.isRaw ? "raw" : "not raw",
wantRaw ? "raw" : "not raw");
}

View File

@ -438,8 +438,8 @@ public:
*/
reg_t findObjectByName(const Common::String &name, int index = -1);
uint32 classTableSize() { return _classTable.size(); }
Class getClass(int index) { return _classTable[index]; }
uint32 classTableSize() const { return _classTable.size(); }
Class getClass(int index) const { return _classTable[index]; }
void setClassOffset(int index, reg_t offset) { _classTable[index].reg = offset; }
void resizeClassTable(uint32 size) { _classTable.resize(size); }
@ -460,9 +460,6 @@ public:
return &_sysStrings->_strings[idx];
}
public: // TODO: make private
Common::Array<SegmentObj *> _heap;
#ifdef ENABLE_SCI32
SciArray<reg_t> *allocateArray(reg_t *addr);
SciArray<reg_t> *lookupArray(reg_t addr);
@ -473,8 +470,10 @@ public: // TODO: make private
SegmentId getStringSegmentId() { return _stringSegId; }
#endif
const Common::Array<SegmentObj *> &getSegments() const { return _heap; }
private:
// Only accessible from saveLoadWithSerializer()
Common::Array<SegmentObj *> _heap;
Common::Array<Class> _classTable; /**< Table of all classes */
/** Map script ids to segment ids. */
Common::HashMap<int, SegmentId> _scriptSegMap;