aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorwhiterandrek2018-04-06 10:03:56 +0300
committerEugene Sandulenko2018-06-28 23:51:32 +0200
commit78c4ed85ab7a84b18c8c7fd2e93c6bf2798acab6 (patch)
treeca77eaa6eb335e6eb57fcbd50e2515d26eb7fffe /engines
parentc29b1d1112b70fcb017359f9a28eb8b7de49a5ab (diff)
downloadscummvm-rg350-78c4ed85ab7a84b18c8c7fd2e93c6bf2798acab6.tar.gz
scummvm-rg350-78c4ed85ab7a84b18c8c7fd2e93c6bf2798acab6.tar.bz2
scummvm-rg350-78c4ed85ab7a84b18c8c7fd2e93c6bf2798acab6.zip
PINK: implemented page state saving
Diffstat (limited to 'engines')
-rw-r--r--engines/pink/archive.cpp47
-rw-r--r--engines/pink/archive.h54
-rw-r--r--engines/pink/cel_decoder.cpp1
-rw-r--r--engines/pink/cel_decoder.h12
-rw-r--r--engines/pink/director.cpp2
-rw-r--r--engines/pink/file.cpp6
-rw-r--r--engines/pink/objects/actions/action_cel.cpp4
-rw-r--r--engines/pink/objects/actions/action_cel.h2
-rw-r--r--engines/pink/objects/actions/action_hide.cpp3
-rw-r--r--engines/pink/objects/actions/action_hide.h2
-rw-r--r--engines/pink/objects/actions/action_play.cpp7
-rw-r--r--engines/pink/objects/actions/action_still.cpp2
-rw-r--r--engines/pink/objects/actors/actor.cpp13
-rw-r--r--engines/pink/objects/actors/actor.h3
-rw-r--r--engines/pink/objects/actors/lead_actor.cpp5
-rw-r--r--engines/pink/objects/actors/supporting_actor.cpp4
-rw-r--r--engines/pink/objects/actors/supporting_actor.h1
-rw-r--r--engines/pink/objects/handlers/handler_mgr.cpp12
-rw-r--r--engines/pink/objects/handlers/handler_mgr.h1
-rw-r--r--engines/pink/objects/module.cpp14
-rw-r--r--engines/pink/objects/pages/game_page.cpp83
-rw-r--r--engines/pink/objects/pages/game_page.h19
-rw-r--r--engines/pink/objects/pages/page.cpp17
-rw-r--r--engines/pink/objects/pages/page.h14
-rw-r--r--engines/pink/pink.h2
-rw-r--r--engines/pink/resource_mgr.cpp7
-rw-r--r--engines/pink/resource_mgr.h1
27 files changed, 253 insertions, 85 deletions
diff --git a/engines/pink/archive.cpp b/engines/pink/archive.cpp
index 4db6d8ed33..ac56b8756b 100644
--- a/engines/pink/archive.cpp
+++ b/engines/pink/archive.cpp
@@ -211,8 +211,15 @@ static Object* createObject(int objectId){
}
}
-Archive::Archive(Common::File &file)
- : _file(file)
+Archive::Archive(Common::SeekableReadStream *stream)
+ : _readStream(stream), _writeStream(nullptr)
+{
+ _objectMap.push_back(0);
+ _objectIdMap.push_back(kNullObject);
+}
+
+Archive::Archive(Common::WriteStream *stream)
+ : _writeStream(stream), _readStream(nullptr)
{
_objectMap.push_back(0);
_objectIdMap.push_back(kNullObject);
@@ -227,10 +234,10 @@ void Archive::mapObject(Object *obj) {
}
int Archive::readCount() {
- int count = _file.readUint16LE();
+ int count = _readStream->readUint16LE();
if (count == 0xffff)
- count = _file.readUint32LE();
+ count = _readStream->readUint32LE();
return count;
}
@@ -251,15 +258,15 @@ Object *Archive::parseObject(bool &isCopyReturned) {
int objectId = 0;
Object *res = nullptr;
- uint obTag = _file.readUint16LE();
+ uint obTag = _readStream->readUint16LE();
if (obTag == 0x0000) {
return nullptr;
} else if (obTag == 0xffff) {
- int schema = _file.readUint16LE();
+ int schema = _readStream->readUint16LE();
- int size = _file.readUint16LE();
- _file.read(className, size);
+ int size = _readStream->readUint16LE();
+ _readStream->read(className, size);
className[size] = '\0';
objectId = findObjectId(className + 1);
@@ -308,18 +315,32 @@ uint Archive::findObjectId(const char *name) {
}
Common::String Archive::readString() {
- char buffer[kMaxStringLength]; // test and lower then
- byte len = _file.readByte();
- _file.read(buffer, len);
+ char buffer[kMaxStringLength];
+ byte len = _readStream->readByte();
+ assert(len <= 64);
+ _readStream->read(buffer, len);
return Common::String(buffer, len);
}
uint32 Archive::readDWORD() {
- return _file.readUint32LE();
+ return _readStream->readUint32LE();
}
uint16 Archive::readWORD() {
- return _file.readUint16LE();
+ return _readStream->readUint16LE();
+}
+
+void Archive::writeDWORD(uint32 val) {
+ _writeStream->writeUint32LE(val);
+}
+
+void Archive::writeWORD(uint16 val) {
+ _writeStream->writeUint16LE(val);
+}
+
+void Archive::writeString(const Common::String &string) {
+ _writeStream->writeByte(string.size());
+ _writeStream->write(string.c_str(), string.size());
}
} // End of namespace Pink
diff --git a/engines/pink/archive.h b/engines/pink/archive.h
index 5e6c091c99..45554b8553 100644
--- a/engines/pink/archive.h
+++ b/engines/pink/archive.h
@@ -25,6 +25,8 @@
#include <engines/pink/objects/object.h>
#include <common/str-array.h>
+#include "common/stream.h"
+#include "common/hash-str.h"
namespace Common {
@@ -36,7 +38,8 @@ namespace Pink {
class Archive {
public:
- Archive(Common::File &file);
+ Archive(Common::SeekableReadStream *stream);
+ Archive(Common::WriteStream *stream);
~Archive();
void mapObject(Object *obj);
@@ -45,8 +48,12 @@ public:
uint32 readDWORD();
uint16 readWORD();
+ void writeDWORD(uint32 val);
+ void writeWORD(uint16 val);
+
Object *readObject();
Common::String readString();
+ void writeString(const Common::String &string);
private:
uint findObjectId(const char *name);
@@ -55,7 +62,8 @@ private:
Common::Array<Object *> _objectMap;
Common::Array<uint> _objectIdMap;
- Common::File &_file;
+ Common::SeekableReadStream *_readStream;
+ Common::WriteStream *_writeStream;
};
template <typename T>
@@ -63,7 +71,8 @@ inline Archive &operator>>(Archive &archive, Common::Array<T> &arr){
uint size = archive.readCount();
arr.resize(size);
for (uint i = 0; i < size; ++i) {
- arr[i] = reinterpret_cast<T> (archive.readObject());
+ arr[i] = dynamic_cast<T>(archive.readObject());
+ assert(arr[i]);
}
return archive;
}
@@ -98,6 +107,45 @@ inline Archive &operator>>(Archive &archive, Common::StringArray &array){
return archive;
}
+inline Archive &operator>>(Archive &archive, Common::StringMap &map){
+ archive.readCount();
+ map.setVal(archive.readString(), archive.readString());
+ return archive;
+}
+
+inline Archive &operator<<(Archive &archive, Common::String &string){
+ archive.writeString(string);
+ return archive;
+}
+
+inline Archive &operator<<(Archive &archive, uint32 &num){
+ archive.writeDWORD(num);
+ return archive;
+}
+
+inline Archive &operator<<(Archive &archive, uint16 &num){
+ archive.writeWORD(num);
+ return archive;
+}
+
+inline Archive &operator<<(Archive &archive, Common::StringArray &array){
+ archive.writeWORD(array.size());
+ for (uint i = 0; i < array.size(); ++i) {
+ archive.writeString(array[i]);
+ }
+ return archive;
+}
+
+inline Archive &operator<<(Archive &archive, Common::StringMap &map){
+ archive.writeWORD(map.size());
+ for (auto &pair : map) {
+ archive.writeString(pair._key);
+ archive.writeString(pair._value);
+ }
+ map.setVal(archive.readString(), archive.readString());
+ return archive;
+}
+
} // End of namespace Pink
#endif
diff --git a/engines/pink/cel_decoder.cpp b/engines/pink/cel_decoder.cpp
index b907f45bca..1e7a36a9ef 100644
--- a/engines/pink/cel_decoder.cpp
+++ b/engines/pink/cel_decoder.cpp
@@ -192,6 +192,7 @@ const Graphics::Surface *CelDecoder::CelVideoTrack::decodeNextFrame() {
if (_curFrame == 0)
_transparentColourIndex = *(byte*)_surface->getBasePtr(0,0);
+
return _surface;
}
diff --git a/engines/pink/cel_decoder.h b/engines/pink/cel_decoder.h
index f0c612d12c..c3ecce0a38 100644
--- a/engines/pink/cel_decoder.h
+++ b/engines/pink/cel_decoder.h
@@ -30,16 +30,16 @@ namespace Pink {
class CelDecoder : public Video::FlicDecoder {
public:
+ virtual bool loadStream(Common::SeekableReadStream *stream);
+
uint32 getX();
uint32 getY();
+ uint16 getTransparentColourIndex();
+
Common::Point getCenter();
Common::Rect &getRectangle();
-
- uint16 getTransparentColourIndex();
const Graphics::Surface *getCurrentFrame();
- virtual bool loadStream(Common::SeekableReadStream *stream);
-
protected:
class CelVideoTrack : public FlicVideoTrack {
public:
@@ -48,10 +48,10 @@ protected:
uint32 getX() const;
uint32 getY() const;
+ uint16 getTransparentColourIndex();
+
Common::Point getCenter();
Common::Rect &getRect();
-
- uint16 getTransparentColourIndex();
const Graphics::Surface *getCurrentFrame();
private:
diff --git a/engines/pink/director.cpp b/engines/pink/director.cpp
index 4003ca5073..25ffa5af94 100644
--- a/engines/pink/director.cpp
+++ b/engines/pink/director.cpp
@@ -32,7 +32,7 @@ Director::Director(OSystem *system)
: _system(system), showBounds(0) {}
void Director::draw() {
- _system->fillScreen(0);
+ //dd_system->fillScreen(0);
for (int i = 0; i < _sprites.size(); ++i) {
drawSprite(_sprites[i]);
}
diff --git a/engines/pink/file.cpp b/engines/pink/file.cpp
index 5158601164..47290329e6 100644
--- a/engines/pink/file.cpp
+++ b/engines/pink/file.cpp
@@ -74,20 +74,20 @@ bool OrbFile::open(const Common::String &name) {
void OrbFile::loadGame(PinkEngine *game) {
seekToObject("PinkGame");
- Archive archive(*this);
+ Archive archive(this);
archive.mapObject(reinterpret_cast<Object*>(game)); // hack
game->load(archive);
}
void OrbFile::loadObject(Object *obj, const Common::String &name) {
seekToObject(name.c_str());
- Archive archive(*this);
+ Archive archive(this);
obj->load(archive);
}
void OrbFile::loadObject(Object *obj, ObjectDescription *objDesc) {
seek(objDesc->objectsOffset);
- Archive archive(*this);
+ Archive archive(this);
obj->load(archive);
}
diff --git a/engines/pink/objects/actions/action_cel.cpp b/engines/pink/objects/actions/action_cel.cpp
index 938d117015..e9e524726c 100644
--- a/engines/pink/objects/actions/action_cel.cpp
+++ b/engines/pink/objects/actions/action_cel.cpp
@@ -79,4 +79,8 @@ void ActionCEL::update() {
}
}
+ActionCEL::~ActionCEL() {
+ delete _decoder;
+}
+
} // End of namespace Pink \ No newline at end of file
diff --git a/engines/pink/objects/actions/action_cel.h b/engines/pink/objects/actions/action_cel.h
index 43fe8476e0..2ae5308d0e 100644
--- a/engines/pink/objects/actions/action_cel.h
+++ b/engines/pink/objects/actions/action_cel.h
@@ -32,6 +32,8 @@ class CelDecoder;
class ActionCEL : public Action {
public:
+ ~ActionCEL() override;
+
ActionCEL();
virtual void deserialize(Archive &archive);
virtual void start(bool unk);
diff --git a/engines/pink/objects/actions/action_hide.cpp b/engines/pink/objects/actions/action_hide.cpp
index b89d4c9627..ed2c903f1d 100644
--- a/engines/pink/objects/actions/action_hide.cpp
+++ b/engines/pink/objects/actions/action_hide.cpp
@@ -23,7 +23,6 @@
#include "action_hide.h"
#include "engines/pink/objects/actors/actor.h"
#include <engines/pink/archive.h>
-#include <common/debug.h>
namespace Pink {
@@ -45,4 +44,6 @@ void ActionHide::toConsole() {
debug("\tActionHide: _name = %s", _name.c_str());
}
+ActionHide::~ActionHide() {}
+
} //End of namespace Pink \ No newline at end of file
diff --git a/engines/pink/objects/actions/action_hide.h b/engines/pink/objects/actions/action_hide.h
index 414d077409..bc62a5fc5f 100644
--- a/engines/pink/objects/actions/action_hide.h
+++ b/engines/pink/objects/actions/action_hide.h
@@ -29,6 +29,8 @@ namespace Pink {
class ActionHide : public Action {
public:
+ ~ActionHide() override;
+
virtual void deserialize(Archive &archive);
virtual void toConsole();
diff --git a/engines/pink/objects/actions/action_play.cpp b/engines/pink/objects/actions/action_play.cpp
index 969eacf035..d3ded9a45a 100644
--- a/engines/pink/objects/actions/action_play.cpp
+++ b/engines/pink/objects/actions/action_play.cpp
@@ -45,10 +45,13 @@ void ActionPlay::end() {
void ActionPlay::onStart() {
debug("Actor %s has now ActionPlay %s", _actor->getName().c_str(), _name.c_str());
- _decoder->seekToFrame(_startFrame);
+ _decoder->start();
+ for (int i = 0; i <= _startFrame; ++i) {
+ _decoder->decodeNextFrame();
+ }
+
if (_stopFrame != -1)
_decoder->setEndFrame(_stopFrame);
- _decoder->start();
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_still.cpp b/engines/pink/objects/actions/action_still.cpp
index 0af57a0fee..fc835f1af5 100644
--- a/engines/pink/objects/actions/action_still.cpp
+++ b/engines/pink/objects/actions/action_still.cpp
@@ -45,7 +45,7 @@ void ActionStill::end() {
void ActionStill::onStart() {
debug("Actor %s has now ActionStill %s", _actor->getName().c_str(), _name.c_str());
- for (int i = 0; i < _startFrame; ++i) {
+ for (int i = 0; i <= _startFrame; ++i) {
_decoder->decodeNextFrame();
}
_decoder->stop();
diff --git a/engines/pink/objects/actors/actor.cpp b/engines/pink/objects/actors/actor.cpp
index 2bd6af4f82..6a20a46f41 100644
--- a/engines/pink/objects/actors/actor.cpp
+++ b/engines/pink/objects/actors/actor.cpp
@@ -130,8 +130,21 @@ void Actor::onMouseOver(Common::Point point, CursorMgr *mgr) {
Actor::~Actor() {
for (int i = 0; i < _actions.size(); ++i) {
+ _actions[i]->toConsole();
delete _actions[i];
+ _actions[i] = nullptr;
}
}
+void Actor::loadState(Archive &archive) {
+ Common::String actionName;
+ archive >> actionName;
+ _action = findAction(actionName);
+}
+
+void Actor::saveState(Archive &archive) {
+ assert(_action);
+ archive.writeString(_action->getName());
+}
+
} // End of namespace Pink
diff --git a/engines/pink/objects/actors/actor.h b/engines/pink/objects/actors/actor.h
index 270ac99914..69cf37b920 100644
--- a/engines/pink/objects/actors/actor.h
+++ b/engines/pink/objects/actors/actor.h
@@ -60,6 +60,9 @@ public:
void setAction(Action *newAction);
void setAction(Action *newAction, bool unk);
+ void loadState(Archive &archive);
+ void saveState(Archive &archive);
+
bool initPallete(Director *director);
virtual void update() {};
diff --git a/engines/pink/objects/actors/lead_actor.cpp b/engines/pink/objects/actors/lead_actor.cpp
index 516569faed..d89ecb4f87 100644
--- a/engines/pink/objects/actors/lead_actor.cpp
+++ b/engines/pink/objects/actors/lead_actor.cpp
@@ -115,6 +115,7 @@ void LeadActor::onKeyboardButtonClick(Common::KeyCode code) {
default:
break;
}
+ break;
case kInDialog1:
case kInDialog2:
case kPlayingVideo:
@@ -242,8 +243,8 @@ void LeadActor::onClick() {
}
else {
if (_state == kMoving) {
- this->_recipient = nullptr;
- this->_nextState = nullptr;
+ _recipient = nullptr;
+ _nextState = kReady;
}
}
diff --git a/engines/pink/objects/actors/supporting_actor.cpp b/engines/pink/objects/actors/supporting_actor.cpp
index e32c89ff84..735e85ee3a 100644
--- a/engines/pink/objects/actors/supporting_actor.cpp
+++ b/engines/pink/objects/actors/supporting_actor.cpp
@@ -73,4 +73,8 @@ const Common::String &SupportingActor::getLocation() const {
return _location;
}
+SupportingActor::~SupportingActor() {
+
+}
+
} // End of namespace Pink \ No newline at end of file
diff --git a/engines/pink/objects/actors/supporting_actor.h b/engines/pink/objects/actors/supporting_actor.h
index 33b469f8aa..fe6dfce9ef 100644
--- a/engines/pink/objects/actors/supporting_actor.h
+++ b/engines/pink/objects/actors/supporting_actor.h
@@ -33,6 +33,7 @@ class InventoryMgr;
class SupportingActor : public Actor {
public:
+ virtual ~SupportingActor();
virtual void deserialize(Archive &archive);
virtual void toConsole();
diff --git a/engines/pink/objects/handlers/handler_mgr.cpp b/engines/pink/objects/handlers/handler_mgr.cpp
index db53c6a5d2..a8a884699e 100644
--- a/engines/pink/objects/handlers/handler_mgr.cpp
+++ b/engines/pink/objects/handlers/handler_mgr.cpp
@@ -90,4 +90,16 @@ Handler *HandlerMgr::findSuitableHandlerUseClick(Actor *actor) {
return nullptr;
}
+HandlerMgr::~HandlerMgr() {
+ for (int i = 0; i < _leftClickHandlers.size(); ++i) {
+ delete _leftClickHandlers[i];
+ }
+ for (int j = 0; j < _useClickHandlers.size(); ++j) {
+ delete _useClickHandlers[j];
+ }
+ for (int k = 0; k < _timerHandlers.size(); ++k) {
+ delete _timerHandlers[k];
+ }
+}
+
}
diff --git a/engines/pink/objects/handlers/handler_mgr.h b/engines/pink/objects/handlers/handler_mgr.h
index 7ff498ec7c..aa1d33456c 100644
--- a/engines/pink/objects/handlers/handler_mgr.h
+++ b/engines/pink/objects/handlers/handler_mgr.h
@@ -40,6 +40,7 @@ class Actor;
class HandlerMgr : public Object {
public:
+ virtual ~HandlerMgr();
virtual void deserialize(Archive &archive);
virtual void toConsole();
diff --git a/engines/pink/objects/module.cpp b/engines/pink/objects/module.cpp
index dc9a06ec1e..621cd8c790 100644
--- a/engines/pink/objects/module.cpp
+++ b/engines/pink/objects/module.cpp
@@ -36,6 +36,12 @@ Module::Module(PinkEngine *game, const Common::String &name)
: NamedObject(name), _game(game), _page(nullptr)
{}
+Module::~Module() {
+ for (int i = 0; i < _pages.size(); ++i) {
+ delete _pages[i];
+ }
+}
+
void Module::load(Archive &archive){
archive.mapObject(this);
NamedObject::deserialize(archive);
@@ -63,7 +69,7 @@ void Module::changePage(const Common::String &pageName) {
page = findPage(pageName);
assert(_page != page);
- //_page->clear
+ _page->clear();
_page = page;
@@ -95,12 +101,6 @@ InventoryMgr *Module::getInventoryMgr() {
return &_invMgr;
}
-Module::~Module() {
- for (int i = 0; i < _pages.size(); ++i) {
- delete _pages[i];
- }
-}
-
} // End of namespace Pink
diff --git a/engines/pink/objects/pages/game_page.cpp b/engines/pink/objects/pages/game_page.cpp
index c878180c4a..d12c034d2a 100644
--- a/engines/pink/objects/pages/game_page.cpp
+++ b/engines/pink/objects/pages/game_page.cpp
@@ -30,6 +30,24 @@
namespace Pink {
+GamePage::GamePage()
+ : _cursorMgr(nullptr), _walkMgr(nullptr), _sequencer(nullptr),
+ _perhapsIsLoaded(false), _memFile(nullptr)
+{}
+
+GamePage::~GamePage() {
+ clear();
+}
+
+void GamePage::toConsole() {
+ Page::toConsole();
+ _walkMgr->toConsole();
+ _sequencer->toConsole();
+ for (int i = 0; i < _handlers.size(); ++i) {
+ _handlers[i]->toConsole();
+ }
+}
+
void GamePage::deserialize(Archive &archive) {
Page::deserialize(archive);
_module = static_cast<Module*>(archive.readObject());
@@ -52,10 +70,9 @@ void GamePage::load(Archive &archive) {
}
void GamePage::init(bool isLoadingSave) {
- if (!isLoadingSave){
- //assert(perhapsIsLoaded == 0);
+ if (!_perhapsIsLoaded)
loadManagers();
- }
+
getGame()->getDirector()->clear();
toConsole();
@@ -91,15 +108,18 @@ bool GamePage::initHandler() {
}
void GamePage::loadManagers() {
- perhapsIsLoaded = true;
+ _perhapsIsLoaded = true;
_cursorMgr = new CursorMgr(_module->getGame(), this);
_walkMgr = new WalkMgr;
_sequencer = new Sequencer(this);
_resMgr.init(_module->getGame(), this);
- // memfile manipulations if from save or page changing
-
+ if (_memFile != nullptr) {
+ loadState();
+ delete _memFile;
+ _memFile = nullptr;
+ }
}
PinkEngine *GamePage::getGame() {
@@ -128,28 +148,49 @@ WalkMgr *GamePage::getWalkMgr() {
return _walkMgr;
}
-void GamePage::toConsole() {
- Page::toConsole();
- _walkMgr->toConsole();
- _sequencer->toConsole();
- for (int i = 0; i < _handlers.size(); ++i) {
- _handlers[i]->toConsole();
+void GamePage::loadState() {
+ Archive archive(static_cast<Common::SeekableReadStream*>(_memFile));
+ archive >> _variables;
+
+ uint16 actorCount;
+ archive >> actorCount;
+
+ Common::String actorName;
+ for (int i = 0; i < actorCount; ++i) {
+ actorName = archive.readString();
+ findActor(actorName)->loadState(archive);
}
}
-GamePage::~GamePage() {
- delete _cursorMgr;
- delete _walkMgr;
- delete _sequencer;
- for (int i = 0; i < _handlers.size(); ++i) {
- delete _handlers[i];
+void GamePage::saveState() {
+ _memFile = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
+ Archive archive(static_cast<Common::WriteStream*>(_memFile));
+ archive << _variables;
+
+ archive.writeWORD(_actors.size());
+ for (int i = 0; i < _actors.size(); ++i) {
+ archive.writeString(_actors[i]->getName());
+ _actors[i]->saveState(archive);
}
}
-GamePage::GamePage()
- : _cursorMgr(nullptr), _walkMgr(nullptr), _sequencer(nullptr)
-{
+void GamePage::unload() {
+ _leadActor->setAction(_leadActor->findAction("Idle"));
+ saveState();
+ clear();
+}
+void GamePage::clear() {
+ Page::clear();
+ _variables.clear(1);
+ for (int i = 0; i < _handlers.size(); ++i) {
+ delete _handlers[i];
+ }
+ _handlers.clear();
+ delete _cursorMgr;
+ delete _sequencer;
+ delete _walkMgr;
}
+
} // End of namespace Pink \ No newline at end of file
diff --git a/engines/pink/objects/pages/game_page.h b/engines/pink/objects/pages/game_page.h
index 705fb32e22..79a4bee4db 100644
--- a/engines/pink/objects/pages/game_page.h
+++ b/engines/pink/objects/pages/game_page.h
@@ -23,6 +23,7 @@
#ifndef PINK_GAME_PAGE_H
#define PINK_GAME_PAGE_H
+#include <common/memstream.h>
#include "page.h"
namespace Pink {
@@ -36,12 +37,12 @@ class GamePage : public Page {
public:
GamePage();
~GamePage();
+ virtual void toConsole();
virtual void deserialize(Archive &archive);
virtual void load(Archive &archive);
-
+ void unload();
void loadManagers();
-
void init(bool isLoadingSave);
PinkEngine *getGame();
@@ -52,25 +53,21 @@ public:
bool checkValueOfVariable(Common::String &variable, Common::String &value);
void setVariable(Common::String &variable, Common::String &value);
- virtual void toConsole();
+ virtual void clear();
private:
bool initHandler();
+ void loadState();
+ void saveState();
-
- int perhapsIsLoaded;
+ bool _perhapsIsLoaded;
+ Common::MemoryReadWriteStream *_memFile;
Module *_module;
CursorMgr *_cursorMgr;
WalkMgr *_walkMgr;
Sequencer *_sequencer;
Common::Array<HandlerStartPage*> _handlers;
Common::StringMap _variables;
-
- /*
- int cunk_1;
- int memfile;
- int unk;
- */
};
}
diff --git a/engines/pink/objects/pages/page.cpp b/engines/pink/objects/pages/page.cpp
index 471cf8736b..e068367d07 100644
--- a/engines/pink/objects/pages/page.cpp
+++ b/engines/pink/objects/pages/page.cpp
@@ -22,10 +22,15 @@
#include "page.h"
#include "engines/pink/objects/actors/lead_actor.h"
+#include "engines/pink/director.h"
namespace Pink {
+Page::~Page() {
+ clear();
+}
+
void Page::load(Archive &archive) {
archive.mapObject(this);
NamedObject::deserialize(archive);
@@ -65,14 +70,18 @@ void Page::init() {
}
}
-Page::~Page() {
+LeadActor *Page::getLeadActor() {
+ return _leadActor;
+}
+
+void Page::clear() {
for (int i = 0; i < _actors.size(); ++i) {
delete _actors[i];
}
+ _actors.clear();
+ _resMgr.clear();
}
-LeadActor *Page::getLeadActor() {
- return _leadActor;
-}
+
} // End of namespace Pink
diff --git a/engines/pink/objects/pages/page.h b/engines/pink/objects/pages/page.h
index 7eb1a335f3..b9820fea75 100644
--- a/engines/pink/objects/pages/page.h
+++ b/engines/pink/objects/pages/page.h
@@ -37,25 +37,23 @@ class LeadActor;
class Page : public NamedObject {
public:
~Page();
+ virtual void toConsole();
+
void load(Archive &archive);
Actor *findActor(Common::String &name);
+ LeadActor *getLeadActor();
+
Sound *loadSound(Common::String &fileName);
CelDecoder *loadCel(Common::String &fileName);
- virtual void toConsole();
-
- LeadActor *getLeadActor();
+ virtual void clear();
protected:
void init();
+
Common::Array<Actor*> _actors;
ResourceMgr _resMgr;
LeadActor *_leadActor;
-
- /*
- int unk_1;
- CString _str;
- */
};
} // End of namespace Pink
diff --git a/engines/pink/pink.h b/engines/pink/pink.h
index 32de7c9f1e..7f993dc0dc 100644
--- a/engines/pink/pink.h
+++ b/engines/pink/pink.h
@@ -79,11 +79,11 @@ public:
void setNextExecutors(const Common::String &nextModule, const Common::String &nextPage);
void setLeadActor(LeadActor *actor) { _actor = actor; };
+ void setCursor(uint cursorIndex);
void setVariable(Common::String &variable, Common::String &value);
bool checkValueOfVariable(Common::String &variable, Common::String &value);
- inline void setCursor(uint cursorIndex);
private:
Common::Error init();
bool loadCursors();
diff --git a/engines/pink/resource_mgr.cpp b/engines/pink/resource_mgr.cpp
index c91101ec67..8695191e65 100644
--- a/engines/pink/resource_mgr.cpp
+++ b/engines/pink/resource_mgr.cpp
@@ -37,7 +37,7 @@ ResourceMgr::ResourceMgr()
_resCount(0) {}
ResourceMgr::~ResourceMgr() {
- delete[] _resDescTable;
+ clear();
}
void ResourceMgr::init(PinkEngine *game, GamePage *page) {
@@ -84,4 +84,9 @@ CelDecoder *ResourceMgr::loadCEL(Common::String &name) {
return decoder;
}
+void ResourceMgr::clear() {
+ delete[] _resDescTable;
+ _resDescTable = nullptr;
+}
+
} // End of namespace Pink
diff --git a/engines/pink/resource_mgr.h b/engines/pink/resource_mgr.h
index cc52ee8bd0..ff451aa832 100644
--- a/engines/pink/resource_mgr.h
+++ b/engines/pink/resource_mgr.h
@@ -47,6 +47,7 @@ public:
~ResourceMgr();
void init(PinkEngine *game, GamePage *page);
+ void clear();
//Common::String loadText(Common::String &name);
Sound *loadSound(Common::String &name);