Skip to content

Commit

Permalink
DREAMWEB: Dynamically allocate GraphicsFile::_frames.
Browse files Browse the repository at this point in the history
This avoids extra memory usage due to the previous commit.
  • Loading branch information
fuzzie authored and wjp committed Feb 23, 2012
1 parent 256d160 commit 6e70f77
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions engines/dreamweb/dreamweb.h
Expand Up @@ -76,6 +76,7 @@ const unsigned int kSymbolx = 64;
const unsigned int kSymboly = 56;
const unsigned int kLengthofvars = 68;
const unsigned int kFrameBlocksize = 2080;
const unsigned int kGraphicsFileFrameSize = 347; // ceil(2080 / sizeof(Frame))
const unsigned int kNumexobjects = 114;
const unsigned int kNumExTexts = kNumexobjects + 2;
const uint16 kExtextlen = 18000;
Expand Down
6 changes: 4 additions & 2 deletions engines/dreamweb/structs.h
Expand Up @@ -339,9 +339,9 @@ struct TextFile {
};

struct GraphicsFile {
GraphicsFile() : _data(0) { }
GraphicsFile() : _data(0), _frames(0) { }

Frame _frames[347];
Frame *_frames;
uint8 *_data;

const uint8 *getFrameData(unsigned int i) const {
Expand All @@ -351,6 +351,8 @@ struct GraphicsFile {
return _data + _frames[i].ptr();
}
void clear() {
delete[] _frames;
_frames = 0;
delete[] _data;
_data = 0;
}
Expand Down
8 changes: 5 additions & 3 deletions engines/dreamweb/stubs.cpp
Expand Up @@ -843,17 +843,18 @@ void DreamWebEngine::loadGraphicsFile(GraphicsFile &file, const char *fileName)
uint16 sizeInBytes = header.len(0);

assert(sizeInBytes >= kFrameBlocksize);
delete[] file._data;
file.clear();
file._data = new uint8[sizeInBytes - kFrameBlocksize];

file._frames = new Frame[kGraphicsFileFrameSize];
f.read((uint8 *)file._frames, kFrameBlocksize);
f.read(file._data, sizeInBytes - kFrameBlocksize);
}

void DreamWebEngine::loadGraphicsSegment(GraphicsFile &file, Common::File &inFile, unsigned int len) {
assert(len >= kFrameBlocksize);
delete[] file._data;
file.clear();
file._data = new uint8[len - kFrameBlocksize];
file._frames = new Frame[kGraphicsFileFrameSize];
inFile.read((uint8 *)file._frames, kFrameBlocksize);
inFile.read(file._data, len - kFrameBlocksize);
}
Expand Down Expand Up @@ -2257,6 +2258,7 @@ void DreamWebEngine::drawFloor() {
void DreamWebEngine::allocateBuffers() {
_exFrames.clear();
_exFrames._data = new uint8[kExframeslen];
_exFrames._frames = new Frame[kGraphicsFileFrameSize];
_exText.clear();
_exText._text = new char[kExtextlen];
}
Expand Down

0 comments on commit 6e70f77

Please sign in to comment.