Skip to content

Commit

Permalink
DIRECTOR: Free memory, fix render text ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Iskrich authored and sev- committed Aug 3, 2016
1 parent 2ad3d3a commit 061f868
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
23 changes: 16 additions & 7 deletions engines/director/director.cpp
Expand Up @@ -52,28 +52,37 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam

// Setup mixer
syncSoundSettings();

_mainArchive = 0;
_macBinary = 0;
_currentPalette = 0;
//FIXME
_sharedMMM = "SHARDCST.MMM";
_sharedCasts = new Common::HashMap<int, Cast *>();
_sharedDIB = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>();
_sharedBMP = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>();
_sharedSTXT = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>();
_sharedSound = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>();

_mainArchive = 0;
_macBinary = 0;
//FIXME
_sharedMMM = "SHARDCST.MMM";
_movies = new Common::HashMap<Common::String, Score *>();

const Common::FSNode gameDataDir(ConfMan.get("path"));
SearchMan.addSubDirectoryMatching(gameDataDir, "data");
SearchMan.addSubDirectoryMatching(gameDataDir, "install");
}

DirectorEngine::~DirectorEngine() {
delete[] _sharedCasts;
delete[] _sharedSound;
delete[] _sharedBMP;
delete[] _sharedSTXT;
delete[] _sharedDIB;
delete[] _movies;

delete _mainArchive;
delete _macBinary;
delete[] _currentPalette;
delete _soundManager;
delete _lingo;
delete _currentScore;
delete _currentPalette;
}

Common::Error DirectorEngine::run() {
Expand Down
31 changes: 25 additions & 6 deletions engines/director/score.cpp
Expand Up @@ -125,7 +125,19 @@ Score::~Score() {
delete _trailSurface;

_movieArchive->close();

delete _surface;
delete _trailSurface;

delete _font;
delete _movieArchive;

delete[] _labels;
delete[] &_frames;
delete[] &_casts;
delete[] &_castsInfo;
delete[] &_actions;
delete[] &_fontMap;
}

void Score::loadPalette(Common::SeekableSubReadStreamEndian &stream) {
Expand Down Expand Up @@ -810,9 +822,9 @@ Frame::Frame(const Frame &frame) {
}

Frame::~Frame() {
for (uint16 i = 0; i < _sprites.size(); i++) {
delete _sprites[i];
}
delete[] &_sprites;
delete[] &_drawRects;
delete _palette;
}

void Frame::readChannel(Common::SeekableSubReadStreamEndian &stream, uint16 offset, uint16 size) {
Expand Down Expand Up @@ -1166,6 +1178,7 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) {
Image::ImageDecoder *img = getImageFrom(_sprites[i]->_castId);

if (!img) {
warning("Image with id %d not found", _sprites[i]->_castId);
continue;
}

Expand Down Expand Up @@ -1241,11 +1254,12 @@ Image::ImageDecoder *Frame::getImageFrom(uint16 spriteId) {


void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID) {
Cast *textCast = _vm->_currentScore->_casts[_sprites[spriteID]->_castId];
uint16 castID = _sprites[spriteID]->_castId;
Cast *textCast = _vm->_currentScore->_casts[castID];
Common::SeekableSubReadStreamEndian *textStream;

if (_vm->_currentScore->_movieArchive->hasResource(MKTAG('S','T','X','T'), spriteID + 1024)) {
textStream = _vm->_currentScore->_movieArchive->getResource(MKTAG('S','T','X','T'), spriteID + 1024);
if (_vm->_currentScore->_movieArchive->hasResource(MKTAG('S','T','X','T'), castID + 1024)) {
textStream = _vm->_currentScore->_movieArchive->getResource(MKTAG('S','T','X','T'), castID + 1024);
} else {
textStream = _vm->getSharedSTXT()->getVal(spriteID + 1024);
}
Expand Down Expand Up @@ -1410,4 +1424,9 @@ Sprite::Sprite(const Sprite &sprite) {
_startPoint.y = sprite._startPoint.y;
}

Sprite::~Sprite() {
delete _cast;
delete &_startPoint;
}

} //End of namespace Director
4 changes: 2 additions & 2 deletions engines/director/score.h
Expand Up @@ -274,7 +274,7 @@ class Sprite {
public:
Sprite();
Sprite(const Sprite &sprite);

~Sprite();
bool _enabled;
byte _castId;
InkType _ink;
Expand All @@ -299,7 +299,7 @@ class Frame {
void playTransition(Score *score);
void playSoundChannel();
void renderSprites(Graphics::ManagedSurface &surface, bool renderTrail);
void renderText(Graphics::ManagedSurface &surface, uint16 spriteID);
void renderText(Graphics::ManagedSurface &surface, uint16 castId);
void readPaletteInfo(Common::SeekableSubReadStreamEndian &stream);
void readSprite(Common::SeekableSubReadStreamEndian &stream, uint16 offset, uint16 size);
void readMainChannels(Common::SeekableSubReadStreamEndian &stream, uint16 offset, uint16 size);
Expand Down

0 comments on commit 061f868

Please sign in to comment.