mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
SCI: Further cleanup of the script code
Merge the init() and load() Script methods and reset the script when necessary
This commit is contained in:
parent
23ed0f1dc8
commit
562a8a980c
@ -189,7 +189,7 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
|
||||
|
||||
assert(mobj);
|
||||
|
||||
// Let the object sync custom data
|
||||
// Let the object sync custom data. Scripts are loaded at this point.
|
||||
mobj->saveLoadWithSerializer(s);
|
||||
|
||||
if (type == SEG_TYPE_SCRIPT) {
|
||||
@ -200,9 +200,6 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
|
||||
// Hook the script up in the script->segment map
|
||||
_scriptSegMap[scr->getScriptNumber()] = i;
|
||||
|
||||
// Now, load the script itself
|
||||
scr->load(g_sci->getResMan());
|
||||
|
||||
ObjMap objects = scr->getObjectMap();
|
||||
for (ObjMap::iterator it = objects.begin(); it != objects.end(); ++it)
|
||||
it->_value.syncBaseObject(scr->getBuf(it->_value.getPos().offset));
|
||||
@ -486,7 +483,7 @@ void Script::saveLoadWithSerializer(Common::Serializer &s) {
|
||||
s.syncAsSint32LE(_nr);
|
||||
|
||||
if (s.isLoading())
|
||||
init(_nr, g_sci->getResMan());
|
||||
load(_nr, g_sci->getResMan());
|
||||
s.skip(4, VER(14), VER(22)); // OBSOLETE: Used to be _bufSize
|
||||
s.skip(4, VER(14), VER(22)); // OBSOLETE: Used to be _scriptSize
|
||||
s.skip(4, VER(14), VER(22)); // OBSOLETE: Used to be _heapSize
|
||||
|
@ -32,12 +32,21 @@
|
||||
|
||||
namespace Sci {
|
||||
|
||||
Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) {
|
||||
Script::Script() : SegmentObj(SEG_TYPE_SCRIPT), _buf(NULL) {
|
||||
freeScript();
|
||||
}
|
||||
|
||||
Script::~Script() {
|
||||
freeScript();
|
||||
}
|
||||
|
||||
void Script::freeScript() {
|
||||
_nr = 0;
|
||||
|
||||
free(_buf);
|
||||
_buf = NULL;
|
||||
_bufSize = 0;
|
||||
_scriptSize = 0;
|
||||
|
||||
_heapStart = NULL;
|
||||
_heapSize = 0;
|
||||
|
||||
@ -52,23 +61,13 @@ Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) {
|
||||
_localsCount = 0;
|
||||
|
||||
_lockers = 1;
|
||||
|
||||
_markedAsDeleted = false;
|
||||
}
|
||||
|
||||
Script::~Script() {
|
||||
freeScript();
|
||||
}
|
||||
|
||||
void Script::freeScript() {
|
||||
free(_buf);
|
||||
_buf = NULL;
|
||||
_bufSize = 0;
|
||||
|
||||
_objects.clear();
|
||||
}
|
||||
|
||||
void Script::init(int script_nr, ResourceManager *resMan) {
|
||||
void Script::load(int script_nr, ResourceManager *resMan) {
|
||||
freeScript();
|
||||
|
||||
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
|
||||
if (!script)
|
||||
error("Script %d not found", script_nr);
|
||||
@ -118,11 +117,6 @@ void Script::init(int script_nr, ResourceManager *resMan) {
|
||||
error("TODO: SCI script %d is over 64KB - it's %d bytes long. This can't "
|
||||
"be handled at the moment, thus stopping", script_nr, script->size);
|
||||
}
|
||||
}
|
||||
|
||||
void Script::load(ResourceManager *resMan) {
|
||||
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, _nr), 0);
|
||||
assert(script != 0);
|
||||
|
||||
uint extraLocalsWorkaround = 0;
|
||||
if (g_sci->getGameId() == GID_FANMADE && _nr == 1 && script->size == 11140) {
|
||||
|
@ -95,8 +95,7 @@ public:
|
||||
~Script();
|
||||
|
||||
void freeScript();
|
||||
void init(int script_nr, ResourceManager *resMan);
|
||||
void load(ResourceManager *resMan);
|
||||
void load(int script_nr, ResourceManager *resMan);
|
||||
|
||||
void matchSignatureAndPatch(uint16 scriptNr, byte *scriptData, const uint32 scriptSize);
|
||||
int32 findSignature(const SciScriptSignature *signature, const byte *scriptData, const uint32 scriptSize);
|
||||
|
@ -977,8 +977,7 @@ int SegManager::instantiateScript(int scriptNum) {
|
||||
scr = allocateScript(scriptNum, &segmentId);
|
||||
}
|
||||
|
||||
scr->init(scriptNum, _resMan);
|
||||
scr->load(_resMan);
|
||||
scr->load(scriptNum, _resMan);
|
||||
scr->initializeLocals(this);
|
||||
scr->initializeClasses(this);
|
||||
scr->initializeObjects(this, segmentId);
|
||||
|
Loading…
Reference in New Issue
Block a user