aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2007-03-29 19:03:51 +0000
committerNicola Mettifogo2007-03-29 19:03:51 +0000
commit31eb34c98f7860a21c48a37ab751b3208e5cfbf9 (patch)
treeb677d6d782480ed1c2b2d5e094d99adcba95b933
parent711865ef635cecac9d425976e0f0407ca137f4e5 (diff)
downloadscummvm-rg350-31eb34c98f7860a21c48a37ab751b3208e5cfbf9.tar.gz
scummvm-rg350-31eb34c98f7860a21c48a37ab751b3208e5cfbf9.tar.bz2
scummvm-rg350-31eb34c98f7860a21c48a37ab751b3208e5cfbf9.zip
- changed Cnv to use a single large buffer for frames instead of small chunks of memory, to simplify loading by Disk.
- added a new constructor with parameters to Cnv svn-id: r26318
-rw-r--r--engines/parallaction/defs.h22
-rw-r--r--engines/parallaction/disk.cpp115
-rw-r--r--engines/parallaction/disk.h4
3 files changed, 52 insertions, 89 deletions
diff --git a/engines/parallaction/defs.h b/engines/parallaction/defs.h
index d2c1efdf1f..1601582140 100644
--- a/engines/parallaction/defs.h
+++ b/engines/parallaction/defs.h
@@ -88,34 +88,32 @@ struct StaticCnv {
};
-struct Cnv {
+class Cnv {
+ uint16 _count; // # of frames
uint16 _width; //
uint16 _height; //
byte** field_8; // unused
- uint16 _count; // # of frames
- byte** _array; // frames data
+ byte* _data;
public:
Cnv() {
_width = _height = _count = 0;
- _array = NULL;
+ _data = NULL;
}
- ~Cnv() {
- if (_count == 0 || _array == NULL) return;
+ Cnv(uint16 numFrames, uint16 width, uint16 height, byte* data) : _count(numFrames), _width(width), _height(height), _data(data) {
- for (uint16 _si = 0; _si < _count; _si++) {
- if (_array[_si])
- free(_array[_si]);
- }
+ }
- free(_array);
+ ~Cnv() {
+ if (_count == 0 || _data == NULL) return;
+ free(_data);
}
byte* getFramePtr(uint16 index) {
if (index >= _count)
return NULL;
- return _array[index];
+ return &_data[index * _width * _height];
}
};
diff --git a/engines/parallaction/disk.cpp b/engines/parallaction/disk.cpp
index 01e2132a5d..bc12f480ec 100644
--- a/engines/parallaction/disk.cpp
+++ b/engines/parallaction/disk.cpp
@@ -120,7 +120,7 @@ uint16 DosDisk::decompressChunk(byte *src, byte *dst, uint16 size) {
//
// loads a cnv from an external file
//
-void DosDisk::loadExternalCnv(const char *filename, Cnv *cnv) {
+Cnv* DosDisk::loadExternalCnv(const char *filename) {
// printf("Gfx::loadExternalCnv(%s)...", filename);
char path[PATH_LEN];
@@ -132,22 +132,15 @@ void DosDisk::loadExternalCnv(const char *filename, Cnv *cnv) {
if (!stream.open(path))
errorFileNotFound(path);
- cnv->_count = stream.readByte();
- cnv->_width = stream.readByte();
- cnv->_height = stream.readByte();
-
- cnv->_array = (byte**)malloc(cnv->_count * sizeof(byte*));
-
- uint16 size = cnv->_width*cnv->_height;
- for (uint16 i = 0; i < cnv->_count; i++) {
- cnv->_array[i] = (byte*)malloc(size);
- stream.read(cnv->_array[i], size);
- }
+ uint16 numFrames = stream.readByte();
+ uint16 width = stream.readByte();
+ uint16 height = stream.readByte();
-// printf("done\n");
+ uint32 decsize = numFrames * width * height;
+ byte *data = (byte*)malloc(decsize);
+ stream.read(data, decsize);
-
- return;
+ return new Cnv(numFrames, width, height, data);
}
void DosDisk::loadExternalStaticCnv(const char *filename, StaticCnv *cnv) {
@@ -175,7 +168,7 @@ void DosDisk::loadExternalStaticCnv(const char *filename, StaticCnv *cnv) {
return;
}
-void DosDisk::loadCnv(const char *filename, Cnv *cnv) {
+Cnv* DosDisk::loadCnv(const char *filename) {
// printf("Gfx::loadCnv(%s)\n", filename);
char path[PATH_LEN];
@@ -187,69 +180,50 @@ void DosDisk::loadCnv(const char *filename, Cnv *cnv) {
errorFileNotFound(path);
}
- cnv->_count = _archive.readByte();
- cnv->_width = _archive.readByte();
- cnv->_height = _archive.readByte();
-
- uint16 framesize = cnv->_width*cnv->_height;
+ uint16 numFrames = _archive.readByte();
+ uint16 width = _archive.readByte();
+ uint16 height = _archive.readByte();
- cnv->_array = (byte**)malloc(cnv->_count * sizeof(byte*));
+ uint32 rawsize = _archive.size() - 3;
+ byte *buf = (byte*)malloc(rawsize);
+ _archive.read(buf, rawsize);
- uint32 size = _archive.size() - 3;
+ uint32 decsize = numFrames * width * height;
+ byte *data = (byte*)malloc(decsize);
+ decompressChunk(buf, data, decsize);
- byte *buf = (byte*)malloc(size);
- _archive.read(buf, size);
-
- byte *s = buf;
-
- for (uint16 i = 0; i < cnv->_count; i++) {
- cnv->_array[i] = (byte*)malloc(framesize);
- uint16 read = decompressChunk(s, cnv->_array[i], framesize);
-
-// printf("frame %i decompressed: %i --> %i\n", i, read, framesize);
-
- s += read;
- }
-
- free(buf);
-
- return;
+ return new Cnv(numFrames, width, height, data);
}
Cnv* DosDisk::loadTalk(const char *name) {
- Cnv *cnv = new Cnv;
-
const char *ext = strstr(name, ".talk");
if (ext != NULL) {
// npc talk
- loadCnv(name, cnv);
+ return loadCnv(name);
- } else {
- // character talk
+ }
+
+ // character talk
/*
- if (scumm_stricmp(name, _doughName) &&
- scumm_stricmp(name, _dinoName) &&
- scumm_stricmp(name, _donnaName) &&
- scumm_stricmp(name, _drkiName)) return;
+ if (scumm_stricmp(name, _doughName) &&
+ scumm_stricmp(name, _dinoName) &&
+ scumm_stricmp(name, _donnaName) &&
+ scumm_stricmp(name, _drkiName)) return;
*/
- char v20[PATH_LEN];
- char *v24 = const_cast<char*>(name);
- if (IS_MINI_CHARACTER(v24)) {
- v24+=4;
- }
-
- if (_engineFlags & kEngineTransformedDonna) {
- sprintf(v20, "%stta", v24);
- } else {
- sprintf(v20, "%stal", v24);
- }
-
- loadExternalCnv(v20, cnv);
+ char v20[PATH_LEN];
+ char *v24 = const_cast<char*>(name);
+ if (IS_MINI_CHARACTER(v24)) {
+ v24+=4;
+ }
+ if (_engineFlags & kEngineTransformedDonna) {
+ sprintf(v20, "%stta", v24);
+ } else {
+ sprintf(v20, "%stal", v24);
}
- return cnv;
+ return loadExternalCnv(v20);
}
Script* DosDisk::loadLocation(const char *name) {
@@ -334,12 +308,8 @@ StaticCnv* DosDisk::loadPointer() {
Cnv* DosDisk::loadFont(const char* name) {
char path[PATH_LEN];
-
sprintf(path, "%scnv", name);
-
- Cnv* cnv = new Cnv;
- loadExternalCnv(path, cnv);
- return cnv;
+ return loadExternalCnv(path);
}
// loads character's icons set
@@ -352,10 +322,7 @@ Cnv* DosDisk::loadObjects(const char *name) {
char path[PATH_LEN];
sprintf(path, "%sobj", name);
-
- Cnv* cnv = new Cnv;
- loadExternalCnv(path, cnv);
- return cnv;
+ return loadExternalCnv(path);
}
@@ -391,9 +358,7 @@ StaticCnv* DosDisk::loadStatic(const char* name) {
}
Cnv* DosDisk::loadFrames(const char* name) {
- Cnv* cnv = new Cnv;
- loadCnv(name, cnv);
- return cnv;
+ return loadCnv(name);
}
//
diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h
index 5d2473e4fb..e88443a1ef 100644
--- a/engines/parallaction/disk.h
+++ b/engines/parallaction/disk.h
@@ -111,8 +111,8 @@ class DosDisk : public Disk {
private:
uint16 decompressChunk(byte *src, byte *dst, uint16 size);
void unpackBackgroundScanline(byte *src, byte *screen, byte *mask, byte *path);
- void loadExternalCnv(const char *filename, Cnv *cnv);
- void loadCnv(const char *filename, Cnv *cnv);
+ Cnv* loadExternalCnv(const char *filename);
+ Cnv* loadCnv(const char *filename);
void loadExternalStaticCnv(const char *filename, StaticCnv *cnv);
void loadBackground(const char *filename);
void loadMaskAndPath(const char *name);