SCI: Changed SegManager to subclass Common::Serializable

svn-id: r40270
This commit is contained in:
Max Horn 2009-05-03 09:25:15 +00:00
parent d695c24b9b
commit ba57b21d09
3 changed files with 26 additions and 26 deletions

View File

@ -32,8 +32,6 @@
namespace Sci {
// Assumes that the ints are relatively evenly distributed
enum {
DCS_INT_HASH_MAX = 256

View File

@ -92,10 +92,6 @@ static void sync_song_t(Common::Serializer &s, song_t &obj) {
}
}
static void sync_IntMapper(Common::Serializer &s, IntMapper &obj) {
obj.saveLoadWithSerializer(s);
}
/**
* Sync a Common::Array using a Common::Serializer.
@ -175,25 +171,25 @@ void Menubar::saveLoadWithSerializer(Common::Serializer &s) {
syncArray<Menu>(s, _menus);
}
static void sync_SegManager(Common::Serializer &s, SegManager &obj) {
int allocated_heap_size = obj.heap_size;
s.syncAsSint32LE(obj.heap_size);
s.syncAsSint32LE(obj.reserved_id);
s.syncAsSint32LE(obj.exports_wide);
s.syncAsSint32LE(obj.gc_mark_bits);
s.syncAsUint32LE(obj.mem_allocated);
void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
int allocated_heap_size = heap_size;
s.syncAsSint32LE(heap_size);
s.syncAsSint32LE(reserved_id);
s.syncAsSint32LE(exports_wide);
s.syncAsSint32LE(gc_mark_bits);
s.syncAsUint32LE(mem_allocated);
sync_IntMapper(s, *obj.id_seg_map);
id_seg_map->saveLoadWithSerializer(s);
assert(obj.heap);
if (allocated_heap_size != obj.heap_size)
obj.heap = (MemObject**)sci_realloc((void *)obj.heap, obj.heap_size * sizeof(MemObject *));
for (int i = 0; i < obj.heap_size; ++i)
sync_MemObjPtr(s, obj.heap[i]);
assert(heap);
if (allocated_heap_size != heap_size)
heap = (MemObject**)sci_realloc((void *)heap, heap_size * sizeof(MemObject *));
for (int i = 0; i < heap_size; ++i)
sync_MemObjPtr(s, heap[i]);
s.syncAsSint32LE(obj.Clones_seg_id);
s.syncAsSint32LE(obj.Lists_seg_id);
s.syncAsSint32LE(obj.Nodes_seg_id);
s.syncAsSint32LE(Clones_seg_id);
s.syncAsSint32LE(Lists_seg_id);
s.syncAsSint32LE(Nodes_seg_id);
}
static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) {
@ -212,7 +208,7 @@ static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) {
obj = new SegManager(sci11);
}
sync_SegManager(s, *obj);
obj->saveLoadWithSerializer(s);
}
@ -365,7 +361,8 @@ static void sync_Script(Common::Serializer &s, Script &obj) {
assert(s.isLoading());
obj.obj_indices = new IntMapper();
}
sync_IntMapper(s, *obj.obj_indices);
obj.obj_indices->saveLoadWithSerializer(s);
s.syncAsSint32LE(obj.exports_nr);
s.syncAsSint32LE(obj.synonyms_nr);

View File

@ -26,6 +26,8 @@
#ifndef SCI_ENGINE_SEG_MANAGER_H
#define SCI_ENGINE_SEG_MANAGER_H
#include "common/scummsys.h"
#include "common/serializer.h"
#include "sci/engine/vm.h"
namespace Sci {
@ -48,7 +50,7 @@ enum idFlag {
class SegInterface;
class SegManager {
class SegManager : public Common::Serializable {
public:
// Initialize the segment manager
SegManager(bool sci1_1);
@ -56,6 +58,8 @@ public:
// Deallocate all memory associated with the segment manager
~SegManager();
virtual void saveLoadWithSerializer(Common::Serializer &ser);
// 1. Scripts
void freeScript(Script &scr);
@ -381,8 +385,9 @@ public:
int scriptMarkedDeleted(int script_nr);
int initialiseScript(Script &scr, EngineState *s, int script_nr);
public: // TODO: make private
private:
IntMapper *id_seg_map; // id - script id; seg - index of heap
public: // TODO: make private
MemObject **heap;
int heap_size; // size of the heap
int reserved_id;