diff options
author | whitertandrek | 2018-03-22 07:47:45 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | 467d3f1ab890bfca77629dd239b670ee4797bfe8 (patch) | |
tree | b534737f1dbafc4ec98a044d576f2457dc919517 /engines/pink/objects/sequences | |
parent | 824b3fa38e965e425d09239f2ac81c4853eb43e8 (diff) | |
download | scummvm-rg350-467d3f1ab890bfca77629dd239b670ee4797bfe8.tar.gz scummvm-rg350-467d3f1ab890bfca77629dd239b670ee4797bfe8.tar.bz2 scummvm-rg350-467d3f1ab890bfca77629dd239b670ee4797bfe8.zip |
PINK: did a big file movement for better readability. Almost implemented
conditions and sideEffects. Added more classes. Now engine can play intro's sound.
Diffstat (limited to 'engines/pink/objects/sequences')
-rw-r--r-- | engines/pink/objects/sequences/sequence.cpp | 144 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence.h | 87 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_item.cpp | 109 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_item.h | 85 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequencer.cpp | 76 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequencer.h | 59 |
6 files changed, 560 insertions, 0 deletions
diff --git a/engines/pink/objects/sequences/sequence.cpp b/engines/pink/objects/sequences/sequence.cpp new file mode 100644 index 0000000000..0af8f1a3fa --- /dev/null +++ b/engines/pink/objects/sequences/sequence.cpp @@ -0,0 +1,144 @@ +/* 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 "sequence_item.h" +#include "sequence.h" +#include "sequencer.h" +#include "engines/pink/archive.h" +#include "engines/pink/objects/pages/game_page.h" +#include "engines/pink/objects/actors/actor.h" + +namespace Pink { + +Sequence::Sequence() + : _unk(0), _context(nullptr), + _sequencer(nullptr) {} + +Sequence::~Sequence() { + for (int i = 0; i < _items.size(); ++i) { + delete _items[i]; + } +} + +void Sequence::deserialize(Archive &archive) { + NamedObject::deserialize(archive); + _sequencer = static_cast<Sequencer*>(archive.readObject()); + archive >> _items; +} + +void Sequence::toConsole() { + debug("\t\tSequence %s", _name.c_str()); + debug("\t\t\tItems:"); + for (int i = 0; i < _items.size(); ++i) { + _items[i]->toConsole(); + } +} + +Common::Array<SequenceItem*> &Sequence::getItems() { + return _items; +} + +void Sequence::setContext(SequenceContext *context) { + _context = context; +} + +void Sequence::init(int unk) { + assert(_items.size()); + assert(dynamic_cast<SequenceItemLeader*>(_items[0])); // first item must always be a leader + start(unk); +} + +class Action; + +void Sequence::start(int unk) { + if (_context->_nextItemIndex > _items.size()){ + debug("Sequence %s ended", _name); + //TODO destroy context + return; + } + + if (!_items[_context->_nextItemIndex]->execute(_context->_unk, this, unk)){ + //destroy context; + } + + uint i; + for (i = _context->_nextItemIndex + 1; i <_items.size(); ++i){ + if (_items[i]->isLeader()) + break; + _items[i]->execute(_context->_unk, this, unk); + } + _context->_nextItemIndex = i; + + + Common::Array<SequenceActorState> &states = _context->_states; + for (uint j = 0; j < states.size(); ++j) { + if (states[j]._unk != _context->_unk && + !states[j]._actionName.empty()) { + Actor *actor; + Action *action; + actor = _sequencer->_page->findActor(states[j]._actorName); + assert(actor); + action = actor->findAction(states[j]._actionName); + assert(action); + if (actor->getAction() != action) + actor->setAction(action, unk); + } + } + _context->_unk++; +} + +SequenceContext::SequenceContext(Sequence *sequence, Sequencer *sequencer) + : _sequence(sequence), _sequencer(sequencer), + _nextItemIndex(0), _unk(1), _actor(nullptr) +{ + sequence->setContext(this); + Common::Array<SequenceItem*> &items = sequence->getItems(); + debug("SequenceContext for %s", _sequence->getName().c_str()); + for (uint i = 0; i < items.size(); ++i) { + bool found = 0; + for (uint j = 0; j < _states.size(); ++j) { + if (items[i]->getActor() == _states[j].getActor()){ + found = 1; + break; + } + } + if (!found) { + debug(items[i]->getActor().c_str()); + _states.push_back({items[i]->getActor()}); + } + } +} + +SequenceContext::~SequenceContext() { + +} + +SequenceActorState::SequenceActorState(const Common::String &name) + :_actorName(name), _unk(0) +{} + +const Common::String &SequenceActorState::getActor() const { + return _actorName; +} + +} // End of namespace Pink
\ No newline at end of file diff --git a/engines/pink/objects/sequences/sequence.h b/engines/pink/objects/sequences/sequence.h new file mode 100644 index 0000000000..f2f324b8ca --- /dev/null +++ b/engines/pink/objects/sequences/sequence.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_SEQUENCE_H +#define PINK_SEQUENCE_H + +#include <engines/pink/objects/object.h> +#include <common/array.h> + +namespace Pink { + +class Sequencer; +class SequenceItem; +class SequenceContext; + +class Sequence : public NamedObject { +public: + Sequence(); + virtual ~Sequence(); + virtual void deserialize(Archive &archive); + + virtual void toConsole(); + + Common::Array<SequenceItem*> &getItems(); + + void setContext(SequenceContext *context); + void init(int unk); + void start(int unk); + +public: + SequenceContext *_context; + Sequencer *_sequencer; + Common::Array<SequenceItem*> _items; + int _unk; + +}; + +class SequenceActorState { +public: + SequenceActorState(const Common::String &name); + + const Common::String &getActor() const; + +public: + Common::String _actorName; + Common::String _actionName; // ?state + int _unk; +}; + +class Actor; + +class SequenceContext { +public: + SequenceContext(Sequence *sequence, Sequencer* sequencer); + ~SequenceContext(); + +public: + Sequence *_sequence; + Sequencer *_sequencer; + int _nextItemIndex; + Actor *_actor; + Common::Array<SequenceActorState> _states; + int _unk; +}; + +} // End of namespace Pink + +#endif diff --git a/engines/pink/objects/sequences/sequence_item.cpp b/engines/pink/objects/sequences/sequence_item.cpp new file mode 100644 index 0000000000..732424a075 --- /dev/null +++ b/engines/pink/objects/sequences/sequence_item.cpp @@ -0,0 +1,109 @@ +/* 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 "sequence_item.h" +#include <common/debug.h> +#include <engines/pink/objects/sequences/sequence.h> +#include <engines/pink/objects/sequences/sequencer.h> +#include <engines/pink/objects/actions/action.h> +#include "engines/pink/archive.h" +#include "engines/pink/objects/pages/game_page.h" +#include "engines/pink/objects/actors/actor.h" + +namespace Pink { + +void SequenceItem::deserialize(Archive &archive) { + archive >> _actor >> _action; +} + +void SequenceItem::toConsole() { + debug("\t\t\t\tSequenceItem: _actor=%s, _action=%s", _actor.c_str(), _action.c_str()); +} + +const Common::String &SequenceItem::getActor() const { + return _actor; +} + +const Common::String &SequenceItem::getAction() const { + return _action; +} + +bool SequenceItem::execute(int unk, Sequence *sequence, bool unk2) { + Actor *actor; + Action *action; + if (!(actor = sequence->_sequencer->_page->findActor(_actor)) || + !(action = actor->findAction(_action))) { + assert(0); + return false; + } + + actor->setAction(action, unk2); + Common::Array<SequenceActorState> &states = sequence->_context->_states; + for (int i = 0; i < sequence->_context->_states.size(); ++i) { + if (states[i]._actorName == _actor){ + states[i]._unk = unk; + sequence->_context->_actor = isLeader() ? actor : sequence->_context->_actor; + break; + } + } + + return true; +} + +bool SequenceItem::isLeader() { + return false; +} + +bool SequenceItemLeader::isLeader() { + return true; +} + +void SequenceItemLeader::toConsole() { + debug("\t\t\t\tSequenceItemLeader: _actor=%s, _action=%s", _actor.c_str(), _action.c_str()); +} + + +void SequenceItemLeaderAudio::deserialize(Archive &archive) { + SequenceItem::deserialize(archive); + archive.readDWORD(); +} + +void SequenceItemLeaderAudio::toConsole() { + debug("\t\t\t\tSequenceItemLeaderAudio: _actor=%s, _action=%s", _actor.c_str(), _action.c_str()); +} + +bool SequenceItemDefaultAction::execute(int unk, Sequence *sequence, bool unk2) { + Common::Array<SequenceActorState> &actorStates = sequence->_context->_states; + for (int i = 0; i < actorStates.size(); ++i) { + if (actorStates[i]._actorName == _actor){ + actorStates[i]._actionName = _action; + break; + } + } + return true; +} + +void SequenceItemDefaultAction::toConsole() { + debug("\t\t\t\tSequenceItemDefaultAction: _actor=%s, _action=%s", _actor.c_str(), _action.c_str()); +} + +} // End of namespace Pink
\ No newline at end of file diff --git a/engines/pink/objects/sequences/sequence_item.h b/engines/pink/objects/sequences/sequence_item.h new file mode 100644 index 0000000000..70fc68d9c7 --- /dev/null +++ b/engines/pink/objects/sequences/sequence_item.h @@ -0,0 +1,85 @@ +/* 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_SEQUENCE_ITEM_H +#define PINK_SEQUENCE_ITEM_H + +#include <engines/pink/objects/object.h> + +namespace Pink { + +class Sequence; + +class SequenceItem : public Object { +public: + virtual void deserialize(Archive &archive); + + virtual void toConsole(); + + const Common::String &getActor() const; + const Common::String &getAction() const; + + virtual bool execute(int unk, Sequence *sequence, bool unk2); + virtual bool isLeader(); + +protected: + Common::String _actor; + Common::String _action; +}; + +class SequenceItemLeader : public SequenceItem { +public: + virtual void toConsole(); + + virtual bool isLeader(); +}; + +class SequenceItemLeaderAudio : public SequenceItemLeader { + virtual void deserialize(Archive &archive); + +public: + virtual void toConsole(); + +private: + //uint32 _sample; // zero in data files and not used; +}; + +class SequenceItemDefaultAction : public SequenceItem { +public: + virtual bool execute(int unk, Sequence *sequence, bool unk2); + + virtual void toConsole(); +}; + +/* not used in games but is implemented in engine +class SequenceItemSideEffects : public SequenceItemDefaultAction { +public: + virtual void deserialize(Archive &archive); + virtual bool execute(int unk, Sequence *sequence, bool unk2); +private + Common::Array<SideEffect*> _sideEffects +}; + */ + +} + +#endif diff --git a/engines/pink/objects/sequences/sequencer.cpp b/engines/pink/objects/sequences/sequencer.cpp new file mode 100644 index 0000000000..2bddcbd4f3 --- /dev/null +++ b/engines/pink/objects/sequences/sequencer.cpp @@ -0,0 +1,76 @@ +/* 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 "sequencer.h" +#include "sequence.h" +#include "engines/pink/archive.h" + +namespace Pink { + +Sequencer::Sequencer(GamePage *page) + : _context(nullptr), _page(page) +{} + +Sequencer::~Sequencer() { + for (int i = 0; i < _sequences.size(); ++i) { + delete _sequences[i]; + } +} + +void Sequencer::deserialize(Archive &archive) { + archive >> _sequences; + archive.readCount();// intro have 0 timers; + //serialize timers; + +} + +Sequence *Sequencer::findSequence(const Common::String &name) { + return *Common::find_if(_sequences.begin(), _sequences.end(), [&name] + (Sequence* sequence) { + return name == sequence->getName(); + }); +} + +void Sequencer::authorSequence(Sequence *sequence, bool unk) { + if (_context){ + + } + + if (sequence){ + _context = new SequenceContext(sequence, this); + //unload array of unknown objects + _currentSequenceName = sequence->getName(); + sequence->start(unk); + } + else _currentSequenceName.clear(); +} + +void Sequencer::toConsole() { + debug("Sequencer:"); + for (int i = 0; i < _sequences.size(); ++i) { + _sequences[i]->toConsole(); + } +} + +} // End of namespace Pink
\ No newline at end of file diff --git a/engines/pink/objects/sequences/sequencer.h b/engines/pink/objects/sequences/sequencer.h new file mode 100644 index 0000000000..d292346314 --- /dev/null +++ b/engines/pink/objects/sequences/sequencer.h @@ -0,0 +1,59 @@ +/* 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_SEQUENCER_H +#define PINK_SEQUENCER_H + +#include <common/array.h> +#include "engines/pink/objects/object.h" + +namespace Pink { + +class Sequence; +class SequenceContext; +class GamePage; + +class Sequencer : public Object { +public: + Sequencer(GamePage *page); + ~Sequencer(); + + virtual void toConsole(); + + virtual void deserialize(Archive &archive); + Sequence* findSequence(const Common::String &name); + void authorSequence(Sequence *sequence, bool unk); + +public: + SequenceContext *_context; + // unknown objects array + Common::Array<Sequence*> _sequences; + Common::String _currentSequenceName; + //timers + GamePage *_page; + int unk; +}; + +} // End of namespace Pink + +#endif
\ No newline at end of file |