aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2007-03-04 15:09:45 +0000
committerNicola Mettifogo2007-03-04 15:09:45 +0000
commit20da7f80f1765bc4b2adb685cde76377ccbb0350 (patch)
tree030f0f9420187c207e46a8ce523fdb60e4d65e2c
parent1c00cc5dc56329debd2d3e3538155f097e96756c (diff)
downloadscummvm-rg350-20da7f80f1765bc4b2adb685cde76377ccbb0350.tar.gz
scummvm-rg350-20da7f80f1765bc4b2adb685cde76377ccbb0350.tar.bz2
scummvm-rg350-20da7f80f1765bc4b2adb685cde76377ccbb0350.zip
made loadScript and loadLocation benefit from Script's ability to dispose of its input buffer
svn-id: r25976
-rw-r--r--engines/parallaction/animation.cpp7
-rw-r--r--engines/parallaction/disk.cpp23
-rw-r--r--engines/parallaction/disk.h5
-rw-r--r--engines/parallaction/location.cpp8
4 files changed, 17 insertions, 26 deletions
diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp
index f6cf8c89f6..3bd987efc8 100644
--- a/engines/parallaction/animation.cpp
+++ b/engines/parallaction/animation.cpp
@@ -251,14 +251,10 @@ void jobEraseAnimations(void *arg_0, Job *j) {
void Parallaction::loadProgram(Animation *a, char *filename) {
// printf("loadProgram(%s)\n", filename);
- // the largest script in Nippon Safes is 3,668 bytes, so 4 kb is well enough
- char* src = (char*)malloc(0x1000);
- _disk->loadScript(filename, src);
+ Script *script = _disk->loadScript(filename);
_numLocals = 0;
- Script *script = new Script(src);
-
fillBuffers(*script);
a->_program = (Program*)malloc(sizeof(Program));
@@ -284,7 +280,6 @@ void Parallaction::loadProgram(Animation *a, char *filename) {
addNode(vD0, &vCC->_node);
delete script;
- free(src);
a->_program->_ip = (Instruction*)a->_program->_node._next;
diff --git a/engines/parallaction/disk.cpp b/engines/parallaction/disk.cpp
index 513afa2739..d7845eca2a 100644
--- a/engines/parallaction/disk.cpp
+++ b/engines/parallaction/disk.cpp
@@ -205,7 +205,7 @@ void Disk::loadTalk(const char *name, Cnv *cnv) {
}
-void Disk::loadLocation(const char *name, char* script) {
+Script* Disk::loadLocation(const char *name) {
char archivefile[PATH_LEN];
@@ -232,14 +232,16 @@ void Disk::loadLocation(const char *name, char* script) {
error("can't find location file '%s'", name);
}
- uint32 count = _archive.size();
- _archive.read(script, count);
- _archive.closeArchivedFile();
- _archive.close();
+ uint32 size = _archive.size();
+ char *buf = (char*)malloc(size+1);
+ _archive.read(buf, size);
+ buf[size] = '\0';
+
+ return new Script(buf, true);
}
-void Disk::loadScript(const char* name, char *script) {
+Script* Disk::loadScript(const char* name) {
char vC8[PATH_LEN];
@@ -249,12 +251,11 @@ void Disk::loadScript(const char* name, char *script) {
errorFileNotFound(vC8);
uint32 size = _archive.size();
+ char *buf = (char*)malloc(size+1);
+ _archive.read(buf, size);
+ buf[size] = '\0';
- _archive.read(script, size);
- script[size] = '\0';
-
- _archive.closeArchivedFile();
-
+ return new Script(buf, true);
}
void Disk::loadHead(const char* name, StaticCnv* cnv) {
diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h
index 3ab56dfcc4..66c4c6598a 100644
--- a/engines/parallaction/disk.h
+++ b/engines/parallaction/disk.h
@@ -39,6 +39,7 @@ namespace Parallaction {
class Parallaction;
class Graphics;
+class Script;
class Archive : public Common::SeekableReadStream {
@@ -98,8 +99,8 @@ public:
void selectArchive(const char *name);
- void loadLocation(const char *name, char* script);
- void loadScript(const char* name, char *script);
+ Script* loadLocation(const char *name);
+ Script* loadScript(const char* name);
void loadTalk(const char *name, Cnv *cnv);
void loadObjects(const char *name, Cnv *cnv);
void loadPointer(StaticCnv* cnv);
diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp
index f92638723e..3f1ebba1e8 100644
--- a/engines/parallaction/location.cpp
+++ b/engines/parallaction/location.cpp
@@ -41,15 +41,11 @@ void Parallaction::parseLocation(const char *filename) {
// printf("parseLocation(%s)", filename);
debugC(1, kDebugLocation, "parseLocation('%s')", filename);
- char *location_src = NULL;
-
uint16 _si = 1;
_vm->_graphics->_proportionalFont = false;
_vm->_graphics->setFont("topaz");
- location_src = (char*)malloc(0x4000);
- _disk->loadLocation(filename, location_src);
- _locationScript = new Script(location_src);
+ _locationScript = _disk->loadLocation(filename);
fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDLOCATION")) {
@@ -164,8 +160,6 @@ void Parallaction::parseLocation(const char *filename) {
delete _locationScript;
_locationScript = NULL;
- free(location_src);
-
return;
}