aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorMax Horn2003-05-25 11:39:08 +0000
committerMax Horn2003-05-25 11:39:08 +0000
commit80df4a8a00e7c42edfff351c5e793a3498453ec2 (patch)
tree8d41a985b92cc44359b9daaa3a086c39353c7615 /scumm
parent467666d0fd2b21c1883d89c7a3ffba04feb12203 (diff)
downloadscummvm-rg350-80df4a8a00e7c42edfff351c5e793a3498453ec2.tar.gz
scummvm-rg350-80df4a8a00e7c42edfff351c5e793a3498453ec2.tar.bz2
scummvm-rg350-80df4a8a00e7c42edfff351c5e793a3498453ec2.zip
renamed ContChunk -> MemoryChunk; avoid code duplication by introducing BaseChunk
svn-id: r7935
Diffstat (limited to 'scumm')
-rw-r--r--scumm/smush/chunk.cpp137
-rw-r--r--scumm/smush/chunk.h44
-rw-r--r--scumm/smush/imuse_channel.cpp2
-rw-r--r--scumm/smush/saud_channel.cpp6
4 files changed, 76 insertions, 113 deletions
diff --git a/scumm/smush/chunk.cpp b/scumm/smush/chunk.cpp
index e25f0e7737..79abc223b0 100644
--- a/scumm/smush/chunk.cpp
+++ b/scumm/smush/chunk.cpp
@@ -84,61 +84,29 @@ const char *Chunk::ChunkString(Chunk::type t) {
return data;
}
-FileChunk::FileChunk() :
- _data(0),
+BaseChunk::BaseChunk() :
_type(0),
_size(0),
_curPos(0) {
}
-FileChunk::~FileChunk() {
- if(_data)
- _data->decRef();
+bool BaseChunk::eof() const {
+ return _curPos >= _size;
}
-FileChunk::FileChunk(const char *fname, const char *directory) {
- _data = new FilePtr(fname, directory);
- _data->read(&_type, 4);
- _type = TO_BE_32(_type);
- _data->read(&_size, 4);
- _size = TO_BE_32(_size);
- _offset = _data->tell();
- _curPos = 0;
+uint32 BaseChunk::tell() const {
+ return _curPos;
}
-Chunk::type FileChunk::getType() const {
+Chunk::type BaseChunk::getType() const {
return _type;
}
-uint32 FileChunk::getSize() const {
+uint32 BaseChunk::getSize() const {
return _size;
}
-Chunk *FileChunk::subBlock() {
- FileChunk *ptr = new FileChunk;
- ptr->_data = _data;
- _data->incRef();
- _data->seek(_offset + _curPos);
- uint32 temp;
- _data->read(&temp, 4);
- ptr->_type = TO_BE_32(temp);
- _data->read(&temp, 4);
- ptr->_size = TO_BE_32(temp);
- ptr->_offset = _offset + _curPos + 8;
- ptr->_curPos = 0;
- seek(8 + ptr->getSize());
- return ptr;
-}
-
-bool FileChunk::eof() const {
- return _curPos >= _size;
-}
-
-uint32 FileChunk::tell() const {
- return _curPos;
-}
-
-bool FileChunk::seek(int32 delta, seek_type dir) {
+bool BaseChunk::seek(int32 delta, seek_type dir) {
switch(dir) {
case seek_cur:
_curPos += delta;
@@ -162,6 +130,41 @@ bool FileChunk::seek(int32 delta, seek_type dir) {
return true;
}
+FileChunk::FileChunk() :
+ _data(0) {
+}
+
+FileChunk::FileChunk(const char *fname, const char *directory) {
+ _data = new FilePtr(fname, directory);
+ _data->read(&_type, 4);
+ _type = TO_BE_32(_type);
+ _data->read(&_size, 4);
+ _size = TO_BE_32(_size);
+ _offset = _data->tell();
+ _curPos = 0;
+}
+
+FileChunk::~FileChunk() {
+ if(_data)
+ _data->decRef();
+}
+
+Chunk *FileChunk::subBlock() {
+ FileChunk *ptr = new FileChunk();
+ ptr->_data = _data;
+ _data->incRef();
+ _data->seek(_offset + _curPos);
+ uint32 temp;
+ _data->read(&temp, 4);
+ ptr->_type = TO_BE_32(temp);
+ _data->read(&temp, 4);
+ ptr->_size = TO_BE_32(temp);
+ ptr->_offset = _offset + _curPos + 8;
+ ptr->_curPos = 0;
+ seek(8 + ptr->getSize());
+ return ptr;
+}
+
bool FileChunk::read(void *buffer, uint32 size) {
if(size <= 0 || (_curPos + size) > _size)
error("invalid buffer read request");
@@ -221,7 +224,7 @@ uint32 FileChunk::getDword() {
return TO_LE_32(buffer);
}
-ContChunk::ContChunk(byte *data) {
+MemoryChunk::MemoryChunk(byte *data) {
if(data == 0)
error("Chunk() called with NULL pointer");
@@ -231,49 +234,13 @@ ContChunk::ContChunk(byte *data) {
_curPos = 0;
}
-Chunk::type ContChunk::getType() const {
- return _type;
-}
-
-uint32 ContChunk::getSize() const {
- return _size;
-}
-
-Chunk *ContChunk::subBlock() {
- ContChunk *ptr = new ContChunk(_data + _curPos);
+Chunk *MemoryChunk::subBlock() {
+ MemoryChunk *ptr = new MemoryChunk(_data + _curPos);
seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize());
return ptr;
}
-bool ContChunk::eof() const {
- return _curPos >= _size;
-}
-
-uint32 ContChunk::tell() const {
- return _curPos;
-}
-
-bool ContChunk::seek(int32 delta, seek_type dir) {
- switch(dir) {
- case seek_cur:
- _curPos += delta;
- break;
- case seek_start:
- if(delta < 0) error("invalid seek request");
- _curPos = (uint32)delta;
- break;
- case seek_end:
- if(delta > 0 || _size < (uint32)-delta) error("invalid seek request");
- _curPos = (uint32)(_size + delta);
- break;
- }
- if(_curPos > _size) {
- error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta);
- }
- return true;
-}
-
-bool ContChunk::read(void *buffer, uint32 size) {
+bool MemoryChunk::read(void *buffer, uint32 size) {
if(size <= 0 || (_curPos + size) > _size)
error("invalid buffer read request");
@@ -282,14 +249,14 @@ bool ContChunk::read(void *buffer, uint32 size) {
return true;
}
-int8 ContChunk::getChar() {
+int8 MemoryChunk::getChar() {
if(_curPos >= _size)
error("invalid char read request");
return _data[_curPos++];
}
-byte ContChunk::getByte() {
+byte MemoryChunk::getByte() {
if(_curPos >= _size)
error("invalid byte read request");
@@ -298,7 +265,7 @@ byte ContChunk::getByte() {
return *ptr;
}
-int16 ContChunk::getShort() {
+int16 MemoryChunk::getShort() {
if(_curPos >= _size - 1)
error("invalid int16 read request");
@@ -306,7 +273,7 @@ int16 ContChunk::getShort() {
return *((int16 *)&buffer);
}
-uint16 ContChunk::getWord() {
+uint16 MemoryChunk::getWord() {
if(_curPos >= _size - 1)
error("invalid word read request");
@@ -315,7 +282,7 @@ uint16 ContChunk::getWord() {
return READ_LE_UINT16(ptr);
}
-uint32 ContChunk::getDword() {
+uint32 MemoryChunk::getDword() {
if(_curPos >= _size - 3)
error("invalid dword read request");
diff --git a/scumm/smush/chunk.h b/scumm/smush/chunk.h
index 0549c88716..6b2d2ada98 100644
--- a/scumm/smush/chunk.h
+++ b/scumm/smush/chunk.h
@@ -26,7 +26,6 @@
class Chunk {
public:
-
virtual ~Chunk() {};
enum seek_type { seek_start, seek_end, seek_cur };
typedef uint32 type;
@@ -47,28 +46,35 @@ public:
class FilePtr;
-class FileChunk : public Chunk {
+// Common functionality for concrete chunks (FileChunk, MemoryChunk)
+class BaseChunk : public Chunk {
+protected:
+ Chunk::type _type;
+ uint32 _size;
+ uint32 _curPos;
+
+ BaseChunk();
+
+public:
+ Chunk::type getType() const;
+ uint32 getSize() const;
+ bool eof() const;
+ uint32 tell() const;
+ bool seek(int32 delta, seek_type dir = seek_cur);
+};
+
+class FileChunk : public BaseChunk {
private:
FilePtr *_data;
- type _type;
- uint32 _size;
uint32 _offset;
- uint32 _curPos;
protected:
-
FileChunk();
public:
-
FileChunk(const char *fname, const char *directory);
virtual ~FileChunk();
- type getType() const;
- uint32 getSize() const;
Chunk *subBlock();
- bool eof() const;
- uint32 tell() const;
- bool seek(int32 delta, seek_type dir = seek_cur);
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
@@ -77,23 +83,13 @@ public:
uint32 getDword();
};
-class ContChunk : public Chunk {
+class MemoryChunk : public BaseChunk {
private:
-
byte *_data;
- Chunk::type _type;
- uint32 _size;
- uint32 _curPos;
public:
-
- ContChunk(byte *data);
- Chunk::type getType() const;
- uint32 getSize() const;
+ MemoryChunk(byte *data);
Chunk *subBlock();
- bool eof() const;
- uint32 tell() const;
- bool seek(int32 delta, seek_type dir = seek_cur);
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
diff --git a/scumm/smush/imuse_channel.cpp b/scumm/smush/imuse_channel.cpp
index 9785de15ae..113d6257c1 100644
--- a/scumm/smush/imuse_channel.cpp
+++ b/scumm/smush/imuse_channel.cpp
@@ -216,7 +216,7 @@ bool ImuseChannel::handleSubTags(int32 &offset) {
case TYPE_MAP_:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleMap(c);
}
break;
diff --git a/scumm/smush/saud_channel.cpp b/scumm/smush/saud_channel.cpp
index 386c3b7781..994aac64aa 100644
--- a/scumm/smush/saud_channel.cpp
+++ b/scumm/smush/saud_channel.cpp
@@ -52,7 +52,7 @@ bool SaudChannel::handleSubTags(int32 &offset) {
case TYPE_STRK:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleStrk(c);
}
else
@@ -61,7 +61,7 @@ bool SaudChannel::handleSubTags(int32 &offset) {
case TYPE_SMRK:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleSmrk(c);
}
else
@@ -70,7 +70,7 @@ bool SaudChannel::handleSubTags(int32 &offset) {
case TYPE_SHDR:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleShdr(c);
}
else