diff options
author | whitertandrek | 2018-03-17 17:36:18 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | 5d1c4af5f6b1f197eb4c3af7dbc05b591047406d (patch) | |
tree | 9e30e98fc569aaf17ce97259ef7bf2255a07927a /engines | |
parent | d058e5dfe6b146373ce89c5710b6e723de687da5 (diff) | |
download | scummvm-rg350-5d1c4af5f6b1f197eb4c3af7dbc05b591047406d.tar.gz scummvm-rg350-5d1c4af5f6b1f197eb4c3af7dbc05b591047406d.tar.bz2 scummvm-rg350-5d1c4af5f6b1f197eb4c3af7dbc05b591047406d.zip |
PINK: Implemented MFC archive, some pink objects and their initialization
Thanks fullpipe engine developer for MFC archive
Diffstat (limited to 'engines')
-rw-r--r-- | engines/pink/archive.cpp | 213 | ||||
-rw-r--r-- | engines/pink/archive.h | 80 | ||||
-rw-r--r-- | engines/pink/director.cpp | 26 | ||||
-rw-r--r-- | engines/pink/director.h | 41 | ||||
-rw-r--r-- | engines/pink/file.cpp | 74 | ||||
-rw-r--r-- | engines/pink/file.h | 22 | ||||
-rw-r--r-- | engines/pink/module.mk | 3 | ||||
-rw-r--r-- | engines/pink/objects/inventory.h | 40 | ||||
-rw-r--r-- | engines/pink/objects/module.cpp | 90 | ||||
-rw-r--r-- | engines/pink/objects/module.h | 74 | ||||
-rw-r--r-- | engines/pink/objects/named_object.h | 58 | ||||
-rw-r--r-- | engines/pink/objects/object.h | 41 | ||||
-rw-r--r-- | engines/pink/objects/page.h | 87 | ||||
-rw-r--r-- | engines/pink/pink.cpp | 103 | ||||
-rw-r--r-- | engines/pink/pink.h | 34 | ||||
-rw-r--r-- | engines/pink/resource_mgr.cpp | 49 | ||||
-rw-r--r-- | engines/pink/resource_mgr.h | 57 | ||||
-rw-r--r-- | engines/pink/utils.h | 38 |
18 files changed, 1091 insertions, 39 deletions
diff --git a/engines/pink/archive.cpp b/engines/pink/archive.cpp new file mode 100644 index 0000000000..ab6ab781b8 --- /dev/null +++ b/engines/pink/archive.cpp @@ -0,0 +1,213 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <common/debug.h> +#include <common/file.h> +#include "objects/module.h" +#include "objects/page.h" + +namespace Pink { + +enum { + kMaxClassLength = 32, + kMaxStringLength = 64, // adjust + kNullObject = 0 +}; + + +enum { + kActionHide, + kActionLoop, + kActionPlay, + kActionPlayWithSfx, + kActionSfx, + kActionSound, + kActionStill, + kActionTalk, + kActionText, + kActor, + kAudioInfoPDAButton, + kConditionGameVariable, + kConditionInventoryItemOwner, + kConditionModuleVariable, + kConditionNotInventoryItemOwner, + kConditionNotModuleVariable, + kConditionNotPageVariable, + kConditionPageVariable, + kCursorActor, + kGamePage, + kHandlerLeftClick, + kHandlerStartPage, + kHandlerTimer, + kHandlerUseClick, + kInventoryActor, + kInventoryItem, + kLeadActor, + kModuleProxy, + kPDAButtonActor, + kParlSqPink, + kPubPink, + kSeqTimer, + kSequence, + kSequenceAudio, + kSequenceItem, + kSequenceItemDefaultAction, + kSequenceItemLeader, + kSequenceItemLeaderAudio, + kSideEffectExit, + kSideEffectGameVariable, + kSideEffectInventoryItemOwner, + kSideEffectLocation, + kSideEffectModuleVariable, + kSideEffectPageVariable, + kSideEffectRandomPageVariable, + kSupportingActor, + kWalkAction, + kWalkLocation +}; + +static const struct RuntimeClass { + const char *name; + int id; +} classMap[] = { + {"GamePage", kGamePage}, + {"ModuleProxy", kModuleProxy} +}; + +static Object* createObject(int objectId){ + switch (objectId){ + case kGamePage: + return new GamePage(); + case kModuleProxy: + return new ModuleProxy(); + default: + return nullptr; + } +} + + +Archive::Archive(Common::File &file) + : _file(file) +{ + debug("Archive created"); + _objectMap.push_back(0); + _objectIdMap.push_back(kNullObject); +} + +Archive::~Archive() +{ + debug("Archive destroyed"); +} + +void Archive::mapObject(Object *obj) { + _objectMap.push_back(obj); // Basically a hack, but behavior is all correct + _objectIdMap.push_back(0); +} + +int Archive::readCount() { + int count = _file.readUint16LE(); + + if (count == 0xffff) + count = _file.readUint32LE(); + + return count; +} + +Object *Archive::readObject() { + bool isCopyReturned; + Object *res = parseObject(isCopyReturned); + + if (res && !isCopyReturned) + res->deserialize(*this); + + return res; +} + +Object *Archive::parseObject(bool &isCopyReturned) { + char className[kMaxClassLength]; + int objectId = 0; + Object *res = 0; + + uint obTag = _file.readUint16LE(); + + if (obTag == 0x0000) { + return nullptr; + } else if (obTag == 0xffff) { + int schema = _file.readUint16LE(); + + int size = _file.readUint16LE(); + _file.read(className, size); + className[size] = '\0'; + + objectId = findObjectId(className + 1); + + res = createObject(objectId); + _objectMap.push_back(res); + _objectIdMap.push_back(objectId); + + //_objectMap.push_back(res); // Basically a hack, but behavior is all correct + //_objectIdMap.push_back(objectId); + + isCopyReturned = false; + } else if ((obTag & 0x8000) == 0) { + + res = _objectMap[obTag]; + + isCopyReturned = true; + } else { + + obTag &= ~0x8000; + + objectId = _objectIdMap[obTag]; + + res = createObject(objectId); + _objectMap.push_back(res); + _objectIdMap.push_back(objectId); + + isCopyReturned = false; + } + + return res; +} + +uint Archive::findObjectId(const char *name) { + RuntimeClass * found = static_cast<RuntimeClass*> + (bsearch(name, classMap, sizeof(classMap) / sizeof(RuntimeClass) , sizeof(RuntimeClass), [] (const void *a, const void *b) { + return strcmp((const char *) a, *(const char **) b); + })); + + if (!found) + error("Class %s is not implemented", name); + + return found->id; +} + +Common::String Archive::readString() { + char buffer[kMaxStringLength]; // test and lower then + byte len = _file.readByte(); + _file.read(buffer, len); + return Common::String(buffer, len); +} + +} // End of namespace Pink + + diff --git a/engines/pink/archive.h b/engines/pink/archive.h new file mode 100644 index 0000000000..6971b0f1bb --- /dev/null +++ b/engines/pink/archive.h @@ -0,0 +1,80 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_ARCHIVE_H +#define PINK_ARCHIVE_H + +#include <common/array.h> +#include <engines/pink/objects/object.h> + +namespace Common { + +class File; + +} + +namespace Pink { + +class Archive { +public: + Archive(Common::File &file); + ~Archive(); + + void mapObject(Object *obj); + int readCount(); + Object *readObject(); + Common::String readString(); + +private: + uint findObjectId(const char *name); + + Object *parseObject(bool &isCopyReturned); + + Common::Array<Object *> _objectMap; + Common::Array<uint> _objectIdMap; + Common::File &_file; +}; + +template <typename T> +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()); // hack; doesn't know better approach + } + return archive; +} + +template <typename T> +inline Archive &operator>>(Archive &archive, Object &obj){ + obj.load(archive); + return archive; +} + +inline Archive &operator>>(Archive &archive, Common::String &string){ + string = archive.readString(); + return archive; +} + +} // End of namespace Pink + +#endif diff --git a/engines/pink/director.cpp b/engines/pink/director.cpp new file mode 100644 index 0000000000..e34e0bc698 --- /dev/null +++ b/engines/pink/director.cpp @@ -0,0 +1,26 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +namespace Pink { + + +}
\ No newline at end of file diff --git a/engines/pink/director.h b/engines/pink/director.h new file mode 100644 index 0000000000..882164902d --- /dev/null +++ b/engines/pink/director.h @@ -0,0 +1,41 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_DIRECTOR_H +#define PINK_DIRECTOR_H + +namespace Pink { + +class Director { +public: + //void addSoundObject(); + //void removeSound(); + //void updateSoundAction + //CActor *getActorByCoords(); +private: + +}; + +} // End of namespace Pink + + +#endif diff --git a/engines/pink/file.cpp b/engines/pink/file.cpp index 5bcd8cc089..38df98dec6 100644 --- a/engines/pink/file.cpp +++ b/engines/pink/file.cpp @@ -21,6 +21,7 @@ */ #include <common/str.h> +#include "objects/page.h" #include "pink.h" namespace Pink { @@ -30,13 +31,18 @@ OrbFile::OrbFile() _tableOffset(0), _tableSize(0), _table(nullptr) -{} +{ + debug("Object Description size: %u", sizeof(ObjectDescription)); + debug("Resource Description size: %u", sizeof(ResourceDescription)); + debug("OrbFile size: %lu", sizeof(OrbFile)); + debug("BroFile size: %lu", sizeof(BroFile)); +} OrbFile::~OrbFile() { delete[] _table; } -bool OrbFile::open(Common::String &name) { +bool OrbFile::open(const Common::String &name) { if (!File::open(name)) return false; @@ -47,7 +53,9 @@ bool OrbFile::open(Common::String &name) { uint16 minor = readUint16LE(); uint16 major = readUint16LE(); - //output + + debug("Orb v%hu.%hu loaded", major, minor); + if (minor || major != 2){ return false; } @@ -56,39 +64,83 @@ bool OrbFile::open(Common::String &name) { if (!_timestamp){ return false; } - //convert to date - //output into debug _tableOffset = readUint32LE(); _tableSize = readUint32LE(); _table = new ObjectDescription[_tableSize]; + debug("Orb has %u object descriptions", _tableSize); + + seek(_tableOffset); + for (size_t i = 0; i < _tableSize; ++i) { - _table[i].deserialize(*this); + _table[i].load(*this); + debug("Object description %s loaded", _table[i].name); } return true; } -void OrbFile::LoadGame(PinkEngine *game) { +void OrbFile::loadGame(PinkEngine *game) { + seekToObject("PinkGame"); + Archive archive(*this); + archive.mapObject((Object *) game); // hack + + game->load(archive); } -void OrbFile::LoadObject(void *obj, Common::String &name) { +void OrbFile::loadObject(Object *obj, const Common::String &name) { + seekToObject(name.c_str()); + Archive archive(*this); + obj->load(archive); +} +void OrbFile::loadObject(Object *obj, ObjectDescription *objDesc) { + seek(objDesc->objectsOffset); + Archive archive(*this); + obj->load(archive); } + uint32 OrbFile::getTimestamp() { return _timestamp; } +void OrbFile::seekToObject(const char *name) { + ObjectDescription *desc = getObjDesc(name); + seek(desc->objectsOffset); +} + + +ObjectDescription *OrbFile::getObjDesc(const char *name){ + ObjectDescription *desc = static_cast<ObjectDescription*>(bsearch(name, _table, _tableSize, sizeof(ObjectDescription), + [] (const void *a, const void *b) { + return scumm_stricmp((char *) a, (char *) b); })); + assert(desc != nullptr); + return desc; +} + +ResourceDescription *OrbFile::getResDescTable(ObjectDescription *objDesc){ + const uint32 size = objDesc->objectsCount; + ResourceDescription *table = new ResourceDescription[size]; + + for (uint i = 0; i < size; ++i) { + table[i].load(*this); + } + + return table; +} + + bool BroFile::open(Common::String &name, uint32 orbTimestamp) { if (!File::open(name) || readUint32BE() != 'BRO\0') return false; uint16 minor = readUint16LE(); uint16 major = readUint16LE(); - // do output + + debug("Bro v%hu.%hu loaded", major, minor); if (minor || major != 1){ return false; @@ -99,7 +151,7 @@ bool BroFile::open(Common::String &name, uint32 orbTimestamp) { return _timestamp == orbTimestamp; } -void ObjectDescription::deserialize(Common::File &file) { +void ObjectDescription::load(Common::File &file) { file.read(name, sizeof(name)); file.read(&objectsOffset, sizeof(objectsOffset)); file.read(&objectsCount, sizeof(objectsCount)); @@ -107,7 +159,7 @@ void ObjectDescription::deserialize(Common::File &file) { file.read(&resourcesCount, sizeof(resourcesCount)); } -void ResourseDescription::deserialize(Common::File &file) { +void ResourceDescription::load(Common::File &file) { file.read(name, sizeof(name)); file.read(&offset, sizeof(offset)); file.read(&size, sizeof(offset)); diff --git a/engines/pink/file.h b/engines/pink/file.h index 64e3782778..2b1d7cb917 100644 --- a/engines/pink/file.h +++ b/engines/pink/file.h @@ -24,11 +24,12 @@ #define PINK_FILE_H #include <common/file.h> +#include "sound.h" namespace Pink { struct ObjectDescription { - void deserialize(Common::File &file); + void load(Common::File &file); char name[16]; uint32 objectsOffset; @@ -37,8 +38,8 @@ struct ObjectDescription { uint32 resourcesCount; }; -struct ResourseDescription { - void deserialize(Common::File &file); +struct ResourceDescription { + void load(Common::File &file); char name[16]; uint32 offset; @@ -48,20 +49,27 @@ struct ResourseDescription { }; class PinkEngine; +class Object; class OrbFile : public Common::File { public: OrbFile(); virtual ~OrbFile(); - virtual bool open(Common::String &name); + virtual bool open(const Common::String &name); - void LoadGame(PinkEngine *game); - void LoadObject(void *obj, Common::String &name); + void loadGame(PinkEngine *game); + void loadObject(Object *obj, const Common::String &name); + void loadObject(Object *obj, ObjectDescription *objDesc); + + ObjectDescription *getObjDesc(const char *name); + ResourceDescription *getResDescTable(ObjectDescription *objDesc); uint32 getTimestamp(); private: + void seekToObject(const char * name); + uint32 _timestamp; uint32 _tableOffset; uint32 _tableSize; @@ -73,7 +81,7 @@ public: BroFile() = default; virtual ~BroFile() = default; - virtual bool open(Common::String &name, uint32 orbId); + virtual bool open(Common::String &name, uint32 orbTimestamp); }; } // End of namespace Pink diff --git a/engines/pink/module.mk b/engines/pink/module.mk index 754c957feb..a29b18acfa 100644 --- a/engines/pink/module.mk +++ b/engines/pink/module.mk @@ -7,6 +7,9 @@ MODULE_OBJS = \ director.o \ sound.o \ file.o \ + archive.o \ + objects/object.o \ + objects/module.o \ # This module can be built as a plugin diff --git a/engines/pink/objects/inventory.h b/engines/pink/objects/inventory.h new file mode 100644 index 0000000000..8827b4a4bd --- /dev/null +++ b/engines/pink/objects/inventory.h @@ -0,0 +1,40 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_INVENTORY_H +#define PINK_INVENTORY_H + +#include "object.h" + +namespace Pink { + + class InventoryMgr : public Object{ + public: + + private: + // array of inv items + // other fields. haven't RE them yet + }; + +} // End of namespace Pink + +#endif diff --git a/engines/pink/objects/module.cpp b/engines/pink/objects/module.cpp new file mode 100644 index 0000000000..3d33c1625f --- /dev/null +++ b/engines/pink/objects/module.cpp @@ -0,0 +1,90 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "module.h" +#include "page.h" + +namespace Pink { + + +void Module::deserialize(Archive &archive){ + archive.mapObject(this); + NamedObject::deserialize(archive); + archive.readString(); // skip directory + + //_invMgr.load(archive); + // intro has 0 items so we will skip + archive.readCount(); + + archive >> _pages; +} + +void Module::initPage(bool isLoadingSave, const Common::String *pageName) { + // debugging original + // 0 0 - new game + // 0 1 - module changed + // 1 0 - from save + + // 1 1 - haven't seen those values + + //this func will be rewrited after testing + + if (_page) { + debug("loading from save"); + } + if (pageName){ + debug("module changed"); + } + assert(_pages.size() != 0); + + if (pageName) { + uint i; + for (i = 0; i < _pages.size(); ++i) { + if(*pageName == _pages[i]->getName()) { + _page = _pages[i]; + } + } + assert(i < _pages.size()); + } + + if (_page) { + _page->init(isLoadingSave); // module changed or from save + return; + } + + if (_page != _pages[0]) { + if (_page) { + assert(0); // in original code there is call to page func but I've never seen it + return; + } + _page = _pages[0]; + _page->init(isLoadingSave); // new game + return; + } + + assert(0); +} + +} // End of namespace Pink + + + diff --git a/engines/pink/objects/module.h b/engines/pink/objects/module.h new file mode 100644 index 0000000000..c6dbdbe31a --- /dev/null +++ b/engines/pink/objects/module.h @@ -0,0 +1,74 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_MODULE_H +#define PINK_MODULE_H + +#include "../archive.h" +#include <common/str.h> +#include "object.h" +#include "named_object.h" +#include <common/debug.h> +#include <engines/pink/utils.h> +#include <common/hash-str.h> +#include "inventory.h" + +namespace Pink { + +class ModuleProxy : public NamedObject { +public: + ModuleProxy(){}; + ModuleProxy(const Common::String &name) + : NamedObject(name) + {} + + +}; + +class PinkEngine; + +class Module : public NamedObject { +public: + Module(PinkEngine *game, const Common::String &name) + : NamedObject(name), _game(game), _page(nullptr) + {} + + void deserialize(Archive &archive); + void initPage(bool isLoadingSave, const Common::String *pageName); + + void OnLeftButtonDown(); + void OnMouseMove(); + void OnKeyboardButtonClick(); + +private: + PinkEngine *_game; + //Common::String _directory; doesn't need this because it was used when game had data in directories + GamePage *_page; + PagesArray _pages; + InventoryMgr _invMgr; + Common::StringMap _map; // used for saves and maybe for smth else +}; + + +} // End of namespace Pink + +#endif diff --git a/engines/pink/objects/named_object.h b/engines/pink/objects/named_object.h new file mode 100644 index 0000000000..a0136f7b0f --- /dev/null +++ b/engines/pink/objects/named_object.h @@ -0,0 +1,58 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_NAMED_OBJECT_H +#define PINK_NAMED_OBJECT_H + +#include "../archive.h" +#include <common/str.h> +#include "object.h" +#include <common/debug.h> + +namespace Pink { + +class NamedObject : public Object { +public: + NamedObject(){}; + NamedObject(const Common::String &name) + : _name(name) + {} + + void deserialize(Archive &archive){ + _name = archive.readString(); + debug("NamedObject %s loaded", _name.c_str()); + } + void store(Archive &archive){ + + } + + const Common::String &getName() const { + return _name; + } + +private: + Common::String _name; +}; + +} // End of namespace Pink + +#endif
\ No newline at end of file diff --git a/engines/pink/objects/object.h b/engines/pink/objects/object.h new file mode 100644 index 0000000000..f6e1ee79d9 --- /dev/null +++ b/engines/pink/objects/object.h @@ -0,0 +1,41 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_OBJECT_H +#define PINK_OBJECT_H + +namespace Pink { + +class Archive; + +class Object { +public: + virtual ~Object() {}; + virtual void load(Archive &){}; + virtual void store(Archive &){}; + virtual void deserialize(Archive &){}; + virtual void init() {} +}; + +} // End of namespace Pink + +#endif
\ No newline at end of file diff --git a/engines/pink/objects/page.h b/engines/pink/objects/page.h new file mode 100644 index 0000000000..1055a710e1 --- /dev/null +++ b/engines/pink/objects/page.h @@ -0,0 +1,87 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_PAGE_H +#define PINK_PAGE_H + +#include "object.h" +#include "module.h" + +namespace Pink { + +class Archive; + +class Page : public NamedObject { +public: + + + +private: + /* + * + * CLeadActor *_leadActor; + int unk_1; + CObArray actors; + CString _str; + PageResources *_ResourseMgr; + */ +}; + +class GamePage : public Page { +public: + void deserialize(Archive &archive){ + Page::deserialize(archive); + _module = static_cast<Module*>(archive.readObject()); + assert(dynamic_cast<Module*>(_module) != 0); + } + + void load(Archive &archive){ + + } + + + void init(bool isLoadingSave){ + if (isLoadingSave){ + assert(perhapsIsLoaded == 0); + // loadSerialize + } + } +private: + int perhapsIsLoaded; + Module *_module; + /* + int perhaps_notLoaded; + int cunk_1; + int memfile; + CModule *_module; + CCursorMgr *cursor_mgr; + CWalkMgr *walkMgr; + CSequencer *sequencer; + CMapStringToString map; + CObArray handlers; + int unk; + */ +}; + +} // End of namespace Pink + +#endif
\ No newline at end of file diff --git a/engines/pink/pink.cpp b/engines/pink/pink.cpp index f45afbb6e6..aaaa2b13d7 100644 --- a/engines/pink/pink.cpp +++ b/engines/pink/pink.cpp @@ -22,42 +22,60 @@ #include "pink.h" #include "console.h" -#include <audio/mixer.h> #include <engines/util.h> +#include <common/debug-channels.h> +#include "objects/module.h" namespace Pink { Pink::PinkEngine::PinkEngine(OSystem *system, const ADGameDescription *desc) - : Engine(system), _rnd("pink"), _desc(*desc), - _bro(nullptr) + : Engine(system), _console(nullptr), _rnd("pink"), + _desc(*desc), _bro(nullptr), _module(nullptr) { - /* TODO - * setup debug channels - * - */ + debug("PinkEngine constructed"); + + DebugMan.addDebugChannel(kPinkDebugGeneral, "general", "General issues"); + DebugMan.addDebugChannel(kPinkDebugLoadingObjects, "loading_objects", "Serializing objects from Orb"); + DebugMan.addDebugChannel(kPinkDebugLoadingResources, "loading_resources", "Loading resources data"); + DebugMan.addDebugChannel(kPinkDebugGraphics, "graphics", "Graphics handling"); + DebugMan.addDebugChannel(kPinkDebugSound, "sound", "Sound processing"); } Pink::PinkEngine::~PinkEngine() { delete _console; delete _bro; + for (uint i = 0; i < _modules.size(); ++i) { + delete _modules[i]; + } + + DebugMan.clearAllDebugChannels(); } Common::Error PinkEngine::init() { + debug("PinkEngine init"); + initGraphics(640, 480); _console = new Console(this); - if (_desc.filesDescriptions[1].fileName){ + Common::String orbName{_desc.filesDescriptions[0].fileName}; + Common::String broName{_desc.filesDescriptions[1].fileName}; + + if (!broName.empty()){ _bro = new BroFile(); } - - Common::String orbName = _desc.filesDescriptions[0].fileName; - Common::String broName = _desc.filesDescriptions[1].fileName; + else debug("This game doesn't need to use bro"); if (!_orb.open(orbName) || (_bro && !_bro->open(broName, _orb.getTimestamp()))){ return Common::kNoGameDataFoundError; } + // TODO load cursor + + _orb.loadGame(this); + _nextModule = _modules[0]->getName(); + initModule(); + return Common::kNoError; } @@ -73,7 +91,7 @@ Common::Error Pink::PinkEngine::run() { switch (event.type){ case Common::EVENT_QUIT: case Common::EVENT_RTL: - + debug("Quit Event"); return Common::kNoError; case Common::EVENT_MOUSEMOVE: @@ -96,8 +114,67 @@ Common::Error Pink::PinkEngine::run() { g_system->delayMillis(10); } - return Common::kNoError; } +void PinkEngine::load(Archive &archive) { + debug(archive.readString().c_str()); + debug(archive.readString().c_str()); + archive >> _modules; +} + +void PinkEngine::initModule() { + if (_module) { + assert(_module->getName() != _nextModule); + + //call module function (smth with unloading) + + //check additional field of game(unk_1) + uint i; + for (i = 0; i < _modules.size(); ++i) { + if (_module == _modules[i]){ + break; + } + } + assert(i != _modules.size()); + + _modules[i] = new ModuleProxy(_module->getName()); + + delete _module; + _module = nullptr; + } + + assert(_modules.size() != 0); + + uint i; + for (i = 0; i < _modules.size(); ++i) { + assert(dynamic_cast<Module*>(_modules[i]) == 0); + if (_modules[i]->getName() == _nextModule) { + changeProxyToModule(i); + break; + } + } + assert(i < _modules.size()); + + _module = static_cast<Module*>(_modules[i]); + _module->initPage(LoadingNotSave, 0); //TODO change to constants + +} + +void PinkEngine::setNextExecutors(const Common::String &nextModule, const Common::String &nextPage) { + _nextModule = nextModule; + _nextPage = nextPage; +} + +void PinkEngine::changeProxyToModule(int index) { + assert(dynamic_cast<Module*>(_modules[index]) == 0); + + Module *module = new Module(this, _modules[index]->getName()); + + _orb.loadObject(module, module->getName()); + + delete _modules[index]; + _modules[index] = module; +} + }
\ No newline at end of file diff --git a/engines/pink/pink.h b/engines/pink/pink.h index 7f9d39ea6b..4aa691831e 100644 --- a/engines/pink/pink.h +++ b/engines/pink/pink.h @@ -23,11 +23,13 @@ #ifndef PINK_PINK_H #define PINK_PINK_H +#include <engines/pink/objects/named_object.h> #include "common/random.h" #include "engines/engine.h" #include "gui/EventRecorder.h" #include "gui/debugger.h" #include "file.h" +#include "utils.h" /* @@ -35,7 +37,7 @@ * * Status of this engine: In Development * - * Internal name of original name: OxCart Runtime + * Internal name of original engine: OxCart Runtime * * Games using this engine: * - The Pink Panther: Passport to Peril @@ -45,27 +47,40 @@ namespace Pink { class Console; +class Archive; +class Module; enum { kPinkDebugGeneral = 1 << 0, - kPinkDebugLoading = 1 << 1, - kPinkDebugSound = 1 << 2 + kPinkDebugLoadingResources = 1 << 1, + kPinkDebugLoadingObjects = 1 << 2, + kPinkDebugGraphics = 1 << 3, + kPinkDebugSound = 1 << 4 }; -class PinkEngine : public Engine { +enum { + LoadingSave = 1, + LoadingNotSave = 0 +}; + +class PinkEngine : public Engine { public: PinkEngine(OSystem *system, const ADGameDescription *desc); - ~PinkEngine(); virtual Common::Error run(); + void load(Archive &archive); + + void initModule(); + void setNextExecutors(const Common::String &nextModule, const Common::String &nextPage); + + OrbFile *getOrb() { return &_orb; } + BroFile *getBro() { return _bro; } private: Common::Error init(); - - void handleEvent(Common::Event &event); - void update(); + void changeProxyToModule(int index); Console *_console; Common::RandomSource _rnd; @@ -76,6 +91,9 @@ private: OrbFile _orb; BroFile *_bro; + Module *_module; + ModulesArray _modules; + const ADGameDescription _desc; }; diff --git a/engines/pink/resource_mgr.cpp b/engines/pink/resource_mgr.cpp new file mode 100644 index 0000000000..6676b0f9bf --- /dev/null +++ b/engines/pink/resource_mgr.cpp @@ -0,0 +1,49 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "resource_mgr.h" +#include "file.h" +#include "pink.h" +#include "objects/page.h" + +namespace Pink { + +ResourceMgr::ResourceMgr() + : _orb(nullptr), _bro(nullptr), + _resDescTable(nullptr), _resCount(0) +{} + +ResourceMgr::~ResourceMgr() { + delete[] _resDescTable; +} + +void ResourceMgr::init(PinkEngine *game, GamePage *page) { + _orb = game->getOrb(); + _bro = game->getBro(); + + ObjectDescription *objDesc = _orb->getObjDesc(page->getName().c_str()); + _resCount = objDesc->resourcesCount; + _orb->loadObject(page, objDesc); + _resDescTable = _orb->getResDescTable(objDesc); +} + +} // End of namespace Pink diff --git a/engines/pink/resource_mgr.h b/engines/pink/resource_mgr.h new file mode 100644 index 0000000000..7672e84bb0 --- /dev/null +++ b/engines/pink/resource_mgr.h @@ -0,0 +1,57 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <common/scummsys.h> + +#ifndef PINK_RESOURCE_MGR_H +#define PINK_RESOURCE_MGR_H + +namespace Pink { + +class GamePage; +class PinkEngine; +class OrbFile; +class BroFile; + +struct ResourceDescription; + +class ResourceMgr { +public: + ResourceMgr(); + ~ResourceMgr(); + + void init(PinkEngine *game, GamePage *page); + //compiler must do RVO + //Common::String loadText(Common::String &name); + //Sound loadSound(Common::String &name); + // loadCEL(); + +private: + OrbFile *_orb; + BroFile *_bro; + ResourceDescription *_resDescTable; + uint32 _resCount; +}; + +} // End of namespace Pink + +#endif diff --git a/engines/pink/utils.h b/engines/pink/utils.h new file mode 100644 index 0000000000..82fb39d38a --- /dev/null +++ b/engines/pink/utils.h @@ -0,0 +1,38 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef PINK_UTILS_H +#define PINK_UTILS_H + +#include <common/array.h> + +namespace Pink { + class Object; + class NamedObject; + class GamePage; + + using ObArray = Common::Array<Object*>; + using ModulesArray = Common::Array<NamedObject*>; + using PagesArray = Common::Array<GamePage*>; +} + +#endif |