aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoost Peters2003-10-28 12:42:35 +0000
committerJoost Peters2003-10-28 12:42:35 +0000
commite02fe63f2eab159ab9f35fe270e10435665c9d6b (patch)
tree31487aa97c340b84dbc1e3fa80ff1c13c2578865
parent26a873a2e485c75904ae78e486556ede3ef7030c (diff)
downloadscummvm-rg350-e02fe63f2eab159ab9f35fe270e10435665c9d6b.tar.gz
scummvm-rg350-e02fe63f2eab159ab9f35fe270e10435665c9d6b.tar.bz2
scummvm-rg350-e02fe63f2eab159ab9f35fe270e10435665c9d6b.zip
added loadFileMalloc() method
svn-id: r10988
-rw-r--r--queen/graphics.cpp6
-rw-r--r--queen/logic.cpp2
-rw-r--r--queen/resource.cpp15
-rw-r--r--queen/resource.h1
-rw-r--r--queen/sound.cpp2
-rw-r--r--queen/talk.cpp2
6 files changed, 19 insertions, 9 deletions
diff --git a/queen/graphics.cpp b/queen/graphics.cpp
index 98921031ce..b73533e9b3 100644
--- a/queen/graphics.cpp
+++ b/queen/graphics.cpp
@@ -126,7 +126,7 @@ void Graphics::bankOverpack(uint32 srcframe, uint32 dstframe, uint32 bankslot) {
void Graphics::bankErase(uint32 bankslot) {
debug(9, "Graphics::bankErase(%d)", bankslot);
- free(_banks[bankslot].data);
+ delete[] _banks[bankslot].data;
_banks[bankslot].data = 0;
}
@@ -735,7 +735,7 @@ void Graphics::loadBackdrop(const char* name, uint16 room) {
}
uint32 size = _resource->fileSize(name);
_display->pcxReadBackdrop(pcxbuf, size, room > 114);
- free(pcxbuf);
+ delete[] pcxbuf;
if (room >= 90) {
_cameraBob = 0;
@@ -751,7 +751,7 @@ void Graphics::loadPanel() {
}
uint32 size = _resource->fileSize("panel.pcx");
_display->pcxReadPanel(pcxbuf, size);
- free(pcxbuf);
+ delete[] pcxbuf;
}
diff --git a/queen/logic.cpp b/queen/logic.cpp
index 003f63561e..5929b76fd6 100644
--- a/queen/logic.cpp
+++ b/queen/logic.cpp
@@ -232,7 +232,7 @@ Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay, Input
}
Logic::~Logic() {
- free(_jas);
+ delete[] _jas;
delete _walk;
}
diff --git a/queen/resource.cpp b/queen/resource.cpp
index 2b95f9566d..ed3ef1071d 100644
--- a/queen/resource.cpp
+++ b/queen/resource.cpp
@@ -79,7 +79,7 @@ Resource::~Resource() {
_resourceFile->close();
if(_resourceTable != _resourceTablePEM10)
delete[] _resourceTable;
- free(_JAS2Ptr);
+ delete[] _JAS2Ptr;
}
int32 Resource::resourceIndex(const char *filename) {
@@ -143,9 +143,18 @@ uint32 Resource::fileOffset(const char *filename) {
uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {
uint32 size = fileSize(filename);
- if (dstBuf == NULL) {
+ if (dstBuf == NULL)
+ dstBuf = new byte[size];
+ // skip 'skipBytes' bytes (useful for headers)
+ _resourceFile->seek(fileOffset(filename) + skipBytes, SEEK_SET);
+ _resourceFile->read(dstBuf, size - skipBytes);
+ return dstBuf;
+}
+
+uint8 *Resource::loadFileMalloc(const char *filename, uint32 skipBytes, byte *dstBuf) {
+ uint32 size = fileSize(filename);
+ if (dstBuf == NULL)
dstBuf = (byte *)malloc(size);
- }
// skip 'skipBytes' bytes (useful for headers)
_resourceFile->seek(fileOffset(filename) + skipBytes, SEEK_SET);
_resourceFile->read(dstBuf, size - skipBytes);
diff --git a/queen/resource.h b/queen/resource.h
index cc9e0ac7dc..d5efe5e238 100644
--- a/queen/resource.h
+++ b/queen/resource.h
@@ -61,6 +61,7 @@ public:
Resource(const Common::String &datafilePath, const char *datafileName);
~Resource(void);
uint8 *loadFile(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
+ uint8 *loadFileMalloc(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
char *getJAS2Line();
bool exists(const char *filename);
bool isDemo();
diff --git a/queen/sound.cpp b/queen/sound.cpp
index 15a831b89e..1236da94a4 100644
--- a/queen/sound.cpp
+++ b/queen/sound.cpp
@@ -80,7 +80,7 @@ void SBSound::sfxPlay(const char *base) {
_input->delay(10);
if (_resource->exists(name))
- playSound(_resource->loadFile(name, SB_HEADER_SIZE), _resource->fileSize(name) - SB_HEADER_SIZE);
+ playSound(_resource->loadFileMalloc(name, SB_HEADER_SIZE), _resource->fileSize(name) - SB_HEADER_SIZE);
}
#ifdef USE_MAD
diff --git a/queen/talk.cpp b/queen/talk.cpp
index 2ed77b54ed..50b552d564 100644
--- a/queen/talk.cpp
+++ b/queen/talk.cpp
@@ -78,7 +78,7 @@ Talk::Talk(
}
Talk::~Talk() {
- free(_fileData);
+ delete[] _fileData;
}