diff options
author | Kamil Zbróg | 2013-11-08 23:17:20 +0000 |
---|---|---|
committer | Kamil Zbróg | 2013-11-08 23:17:20 +0000 |
commit | 6c0cd59dff1139ff56c366fb3d5d04b3e998d42e (patch) | |
tree | c0ca5f4856dc47252d152de9bfeeaf1fedca5a0a /engines/prince | |
parent | dfdff8db0848429266376941813cb3456b14233e (diff) | |
download | scummvm-rg350-6c0cd59dff1139ff56c366fb3d5d04b3e998d42e.tar.gz scummvm-rg350-6c0cd59dff1139ff56c366fb3d5d04b3e998d42e.tar.bz2 scummvm-rg350-6c0cd59dff1139ff56c366fb3d5d04b3e998d42e.zip |
PRINCE: some memory leaks removed. Initialization moved to separate method
Diffstat (limited to 'engines/prince')
-rw-r--r-- | engines/prince/archive.h | 2 | ||||
-rw-r--r-- | engines/prince/cursor.cpp | 1 | ||||
-rw-r--r-- | engines/prince/graphics.cpp | 5 | ||||
-rw-r--r-- | engines/prince/graphics.h | 1 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 71 | ||||
-rw-r--r-- | engines/prince/prince.h | 22 | ||||
-rw-r--r-- | engines/prince/script.cpp | 6 |
7 files changed, 58 insertions, 50 deletions
diff --git a/engines/prince/archive.h b/engines/prince/archive.h index 8e106693dc..94503b65ce 100644 --- a/engines/prince/archive.h +++ b/engines/prince/archive.h @@ -28,7 +28,7 @@ // This is here just as remainder that archive support is missing namespace Price { -class Archive : public Common::Archive { +class PtcArchive : public Common::Archive { }; } diff --git a/engines/prince/cursor.cpp b/engines/prince/cursor.cpp index 9a9162fd27..414e7ce397 100644 --- a/engines/prince/cursor.cpp +++ b/engines/prince/cursor.cpp @@ -31,6 +31,7 @@ Cursor::Cursor() : _surface(NULL) { } Cursor::~Cursor() { + _surface->free(); delete _surface; _surface = NULL; } diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp index 29d3a331df..025fa70003 100644 --- a/engines/prince/graphics.cpp +++ b/engines/prince/graphics.cpp @@ -35,6 +35,11 @@ GraphicsMan::GraphicsMan(PrinceEngine *vm) _frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); } +GraphicsMan::~GraphicsMan() { + _frontScreen->free(); + delete _frontScreen; +} + void GraphicsMan::update() { if (_changed) { _vm->_system->copyRectToScreen((byte*)_frontScreen->getBasePtr(0,0), 640, 0, 0, 640, 480); diff --git a/engines/prince/graphics.h b/engines/prince/graphics.h index 3ef768a073..884aac2c84 100644 --- a/engines/prince/graphics.h +++ b/engines/prince/graphics.h @@ -34,6 +34,7 @@ class GraphicsMan { public: GraphicsMan(PrinceEngine *vm); + ~GraphicsMan(); void update(); diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 2b4390c755..d184f84518 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -83,9 +83,6 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) gDebugLevel = 10; - _rnd = new Common::RandomSource("prince"); - _debugger = new Debugger(this); - _midiPlayer = new MusicPlayer(this); } @@ -101,6 +98,13 @@ PrinceEngine::~PrinceEngine() { delete _font; delete _roomBmp; delete _walizkaBmp; + delete _variaTxt; + delete[] _talkTxt; + delete _graph; + delete _mobList; + delete _objectList; + _midiPlayer->killMidi(); + delete _midiPlayer; } GUI::Debugger *PrinceEngine::getDebugger() { @@ -137,9 +141,14 @@ bool loadResource(T *resource, const char *resourceName) { return ret; } -Common::Error PrinceEngine::run() { +void PrinceEngine::init() { + _graph = new GraphicsMan(this); + _rnd = new Common::RandomSource("prince"); + _debugger = new Debugger(this); + _midiPlayer = new MusicPlayer(this); + const Common::FSNode gameDataDir(ConfMan.get("path")); debugEngine("Adding all path: %s", gameDataDir.getPath().c_str()); @@ -167,7 +176,7 @@ Common::Error PrinceEngine::run() { Common::SeekableReadStream *talkTxtStream = SearchMan.createReadStreamForMember("talktxt.dat"); if (!talkTxtStream) { error("Can't load talkTxtStream"); - return Common::kPathDoesNotExist; + return; } _talkTxtSize = talkTxtStream->size(); @@ -175,53 +184,27 @@ Common::Error PrinceEngine::run() { talkTxtStream->read(_talkTxt, _talkTxtSize); delete talkTxtStream; +} - MhwanhDecoder *logo = new MhwanhDecoder(); - loadResource(logo, "logo.raw"); - if (logo) - { - _graph->setPalette(logo->getPalette()); - _graph->draw(0, 0, logo->getSurface()); +void PrinceEngine::showLogo() { + MhwanhDecoder logo; + if (loadResource(&logo, "logo.raw")) { + _graph->setPalette(logo.getPalette()); + _graph->draw(0, 0, logo.getSurface()); _graph->update(); _system->delayMillis(700); } - delete logo; - - mainLoop(); - - return Common::kNoError; } -class MobList { -public: - bool loadFromStream(Common::SeekableReadStream &stream); - - Common::Array<Mob> _mobList; -}; - -bool MobList::loadFromStream(Common::SeekableReadStream &stream) -{ - Mob mob; - while (mob.loadFromStream(stream)) - _mobList.push_back(mob); - - return true; -} +Common::Error PrinceEngine::run() { -class ObjectList { -public: - bool loadFromStream(Common::SeekableReadStream &stream); + init(); - Common::Array<Object> _objList; -}; + showLogo(); -bool ObjectList::loadFromStream(Common::SeekableReadStream &stream) -{ - Object obj; - while (obj.loadFromStream(stream)) - _objList.push_back(obj); + mainLoop(); - return true; + return Common::kNoError; } bool PrinceEngine::loadLocation(uint16 locationNr) { @@ -417,8 +400,8 @@ void PrinceEngine::hotspot() { Common::Point mousepos = _system->getEventManager()->getMousePos(); Common::Point mousePosCamera(mousepos.x + _cameraX, mousepos.y); - for (Common::Array<Mob>::const_iterator it = _mobList->_mobList.begin() - ; it != _mobList->_mobList.end() ; ++it) { + for (Common::Array<Mob>::const_iterator it = _mobList->_list.begin() + ; it != _mobList->_list.end() ; ++it) { if (it->_visible) continue; if (it->_rect.contains(mousePosCamera)) { diff --git a/engines/prince/prince.h b/engines/prince/prince.h index 4f2ddf827a..85ed3cec0e 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -42,16 +42,32 @@ #include "video/flic_decoder.h" +#include "prince/mob.h" +#include "prince/object.h" + + namespace Prince { +template <typename ResourceType> +struct ResourceList { + bool loadFromStream(Common::SeekableReadStream &stream) { + ResourceType resource; + while (resource.loadFromStream(stream)) + _list.push_back(resource); + return true; + } + Common::Array<ResourceType> _list; +}; + +typedef ResourceList<Mob> MobList; +typedef ResourceList<Object> ObjectList; + struct PrinceGameDescription; class PrinceEngine; class GraphicsMan; class Script; class Debugger; -class ObjectList; -class MobList; class MusicPlayer; class VariaTxt; class Cursor; @@ -124,6 +140,8 @@ private: void scrollCameraLeft(int16 delta); void drawScreen(); void showTexts(); + void init(); + void showLogo(); uint32 getTextWidth(const char *s); void debugEngine(const char *s, ...); diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index a25e8241e1..94fbcba688 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -246,9 +246,9 @@ void Script::O_CHECKANIMFRAME() { } void Script::O_PUTBACKANIM() { - uint16 roomId = readScript16bits(); - uint16 slot = readScript16bits(); - uint32 animId = readScript32bits(); + uint16 roomId = readScriptValue(); + uint16 slot = readScriptValue(); + int32 animId = readScript32bits(); debugScript("O_PUTBACKANIM roomId %d, slot %d, animId %d", roomId, slot, animId); } |