diff options
author | whiterandrek | 2018-06-20 11:15:30 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | e2ac931ccba6f193fa20cd2febb5f919da1b20b2 (patch) | |
tree | 0881148f31fc1cec89c67a3ca5c082be3615c251 | |
parent | cfc5538f95f5b642c7037eb142999f67d72ca111 (diff) | |
download | scummvm-rg350-e2ac931ccba6f193fa20cd2febb5f919da1b20b2.tar.gz scummvm-rg350-e2ac931ccba6f193fa20cd2febb5f919da1b20b2.tar.bz2 scummvm-rg350-e2ac931ccba6f193fa20cd2febb5f919da1b20b2.zip |
PINK: rework scripting system
-rw-r--r-- | engines/pink/objects/actors/actor.cpp | 5 | ||||
-rw-r--r-- | engines/pink/objects/actors/actor.h | 4 | ||||
-rw-r--r-- | engines/pink/objects/actors/lead_actor.cpp | 4 | ||||
-rw-r--r-- | engines/pink/objects/handlers/handler.cpp | 2 | ||||
-rw-r--r-- | engines/pink/objects/sequences/seq_timer.cpp | 8 | ||||
-rw-r--r-- | engines/pink/objects/sequences/seq_timer.h | 8 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence.cpp | 76 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence.h | 50 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_context.cpp | 55 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_context.h | 42 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_item.cpp | 25 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequence_item.h | 36 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequencer.cpp | 140 | ||||
-rw-r--r-- | engines/pink/objects/sequences/sequencer.h | 34 |
14 files changed, 239 insertions, 250 deletions
diff --git a/engines/pink/objects/actors/actor.cpp b/engines/pink/objects/actors/actor.cpp index 7abab3cb9a..0fc6e89a3c 100644 --- a/engines/pink/objects/actors/actor.cpp +++ b/engines/pink/objects/actors/actor.cpp @@ -124,9 +124,8 @@ void Actor::setAction(Action *newAction) { } } -void Actor::setAction(Action *newAction, bool unk) { - if (unk) { - //assert(0); // want to see this +void Actor::setAction(Action *newAction, bool loadingSave) { + if (loadingSave) { _isActionEnded = 1; _action = newAction; } else { diff --git a/engines/pink/objects/actors/actor.h b/engines/pink/objects/actors/actor.h index cd84fd2d2d..480aa78b72 100644 --- a/engines/pink/objects/actors/actor.h +++ b/engines/pink/objects/actors/actor.h @@ -50,7 +50,7 @@ public: virtual void init(bool paused); bool initPalette(Director *director); - void toConsole() override ; + void toConsole() override; bool isPlaying() { return !_isActionEnded; } virtual void pause(bool paused); @@ -84,7 +84,7 @@ public: void setAction(const Common::String &name) { setAction(findAction(name)); } void setAction(Action *newAction); - void setAction(Action *newAction, bool unk); + void setAction(Action *newAction, bool loadingSave); void setPage(Page *page) { _page = page;} diff --git a/engines/pink/objects/actors/lead_actor.cpp b/engines/pink/objects/actors/lead_actor.cpp index 7bc34565c0..579015d6be 100644 --- a/engines/pink/objects/actors/lead_actor.cpp +++ b/engines/pink/objects/actors/lead_actor.cpp @@ -127,7 +127,7 @@ void LeadActor::update() { break; case kPlayingSequence: _sequencer->update(); - if (!_sequencer->_context) { + if (!_sequencer->isPlaying()) { _state = _nextState; _nextState = kUndefined; forceUpdateCursor(); @@ -141,7 +141,7 @@ void LeadActor::update() { break; case kPlayingExitSequence: _sequencer->update(); - if (!_sequencer->_context) { + if (!_sequencer->isPlaying()) { _state = kUndefined; _page->getGame()->changeScene(); } diff --git a/engines/pink/objects/handlers/handler.cpp b/engines/pink/objects/handlers/handler.cpp index 019d349527..1c9cc4bbed 100644 --- a/engines/pink/objects/handlers/handler.cpp +++ b/engines/pink/objects/handlers/handler.cpp @@ -87,7 +87,7 @@ void HandlerSequences::handle(Actor *actor) { } void HandlerStartPage::execute(Sequence *sequence) { - sequence->_unk = 1; + sequence->allowSkipping(); } void HandlerStartPage::toConsole() { diff --git a/engines/pink/objects/sequences/seq_timer.cpp b/engines/pink/objects/sequences/seq_timer.cpp index 8ac43fbe3a..8d639acb85 100644 --- a/engines/pink/objects/sequences/seq_timer.cpp +++ b/engines/pink/objects/sequences/seq_timer.cpp @@ -46,15 +46,15 @@ void SeqTimer::toConsole() { } void SeqTimer::update() { - Common::RandomSource &rnd = _sequencer->_page->getGame()->getRnd(); + Page *page = _sequencer->getPage(); + Common::RandomSource &rnd = page->getGame()->getRnd(); if (_updatesToMessage--) return; _updatesToMessage = _range ? _period + rnd.getRandomNumber(_range) : _period; - Actor *actor = _sequencer->_page->findActor(_actor); - if (actor && !_sequencer->findMainSequenceActorState(actor->getName()) && - !_sequencer->findParralelSequenceActorState(actor->getName())) { + Actor *actor = page->findActor(_actor); + if (actor && !_sequencer->findState(_actor)) { actor->onTimerMessage(); } } diff --git a/engines/pink/objects/sequences/seq_timer.h b/engines/pink/objects/sequences/seq_timer.h index 9af706f6c8..d784ae72f1 100644 --- a/engines/pink/objects/sequences/seq_timer.h +++ b/engines/pink/objects/sequences/seq_timer.h @@ -32,9 +32,11 @@ class Sequencer; class SeqTimer : public Object { public: SeqTimer(); - virtual void deserialize(Archive &archive); - virtual void toConsole(); - virtual void update(); + + void deserialize(Archive &archive) override; + void toConsole() override; + + void update(); private: Common::String _actor; diff --git a/engines/pink/objects/sequences/sequence.cpp b/engines/pink/objects/sequences/sequence.cpp index 7674cee416..a700e99196 100644 --- a/engines/pink/objects/sequences/sequence.cpp +++ b/engines/pink/objects/sequences/sequence.cpp @@ -34,7 +34,7 @@ namespace Pink { Sequence::Sequence() - : _unk(0), _context(nullptr), + : _canBeSkipped(0), _context(nullptr), _sequencer(nullptr) {} Sequence::~Sequence() { @@ -57,52 +57,42 @@ void Sequence::toConsole() { } } -void Sequence::init(int unk) { - assert(_items.size()); - assert(dynamic_cast<SequenceItemLeader*>(_items[0])); // first item must always be a leader - start(unk); -} - -void Sequence::start(int unk) { - if (_context->_nextItemIndex >= _items.size() || - !_items[_context->_nextItemIndex]->execute(_context->_index, this, unk)) { +void Sequence::start(bool loadingSave) { + uint nextItemIndex = _context->getNextItemIndex(); + if (nextItemIndex >= _items.size() || + !_items[nextItemIndex]->execute(_context->getSegment(), this, loadingSave)) { debug("Sequence %s ended", _name.c_str()); end(); return; } - uint i; - for (i = _context->_nextItemIndex + 1; i <_items.size(); ++i){ - if (_items[i]->isLeader()) + uint i = nextItemIndex + 1; + while (i < _items.size()) { + if (_items[i]->isLeader()) { break; - _items[i]->execute(_context->_index, this, unk); + } + _items[i++]->execute(_context->getSegment(), this, loadingSave); } - _context->_nextItemIndex = i; - - Common::Array<SequenceActorState> &states = _context->_states; - for (uint j = 0; j < states.size(); ++j) { - states[j].check(_context->_index, this, unk); - } - _context->_index++; + _context->execute(i, loadingSave); } void Sequence::update() { - if (!_context->_actor->isPlaying()) { + if (!_context->getActor()->isPlaying()) { debug("Sequence step ended"); start(0); } } void Sequence::end() { - _context->_actor = 0; - _unk = 1; + _context->setActor(nullptr); + _canBeSkipped = 1; _sequencer->removeContext(_context); } void Sequence::restart() { _context->setNextItemIndex(0); - _context->clearActionsFromActorStates(); + _context->clearDefaultActions(); start(0); } @@ -113,23 +103,28 @@ void Sequence::skip() { for (int i = _items.size() - 1; i >= 0; --i) { if (_items[i]->isLeader()) { _context->setNextItemIndex(i); - _context->clearActionsFromActorStates(); - skipItemsTo(i); + _context->clearDefaultActions(); + for (int j = 0; j < i; ++j) { + _items[j]->skip(this); + } start(0); break; } } } -void Sequence::skipItemsTo(int index) { - for (int i = 0; i < index; ++i) { - _items[i]->skip(this); - } +void Sequence::skipSubSequence() { + if (_context->getNextItemIndex() < _items.size()) + this->start(0); } -void Sequence::skipSubSequence() { - if (_context->getNextItemIndex() < _context->getSequence()->getItems().size()) - _context->getSequence()->start(0); +void Sequence::forceEnd() { + skip(); + end(); +} + +void Sequence::init(bool loadingSave) { + start(loadingSave); } void SequenceAudio::deserialize(Archive &archive) { @@ -145,8 +140,8 @@ void SequenceAudio::toConsole() { } } -void SequenceAudio::start(int unk) { - Sequence::start(unk); +void SequenceAudio::start(bool loadingSave) { + Sequence::start(loadingSave); uint index = _context->getNextItemIndex(); if (index < _items.size()) { SequenceItemLeaderAudio* leaderAudio = (SequenceItemLeaderAudio*) _items[index]; @@ -166,14 +161,15 @@ void SequenceAudio::update() { start(0); } -void SequenceAudio::init(int unk) { +void SequenceAudio::init(bool loadingSave) { _sample = 0; - _sound.play(_sequencer->_page->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType); - Sequence::init(unk); + _sound.play(_sequencer->getPage()->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType); + start(loadingSave); } void SequenceAudio::restart() { - _sound.play(_sequencer->_page->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType); + _sample = 0; + _sound.play(_sequencer->getPage()->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType); Sequence::restart(); } diff --git a/engines/pink/objects/sequences/sequence.h b/engines/pink/objects/sequences/sequence.h index a5e19eae6d..05a3f88cd5 100644 --- a/engines/pink/objects/sequences/sequence.h +++ b/engines/pink/objects/sequences/sequence.h @@ -35,51 +35,55 @@ class SequenceContext; class Sequence : public NamedObject { public: Sequence(); - virtual ~Sequence(); - virtual void deserialize(Archive &archive); + ~Sequence(); - virtual void toConsole(); + void deserialize(Archive &archive) override ; + void toConsole() override; - Common::Array<SequenceItem *> &getItems() { return _items; } +public: + virtual void init(bool loadingSave); - void setContext(SequenceContext *context) { _context = context; } - virtual void init(int unk); - virtual void start(int unk); + virtual void start(bool loadingSave); virtual void end(); + virtual void restart(); + + void forceEnd(); virtual void update(); - virtual void restart(); + virtual void skipSubSequence(); virtual void skip(); - void skipItemsTo(int index); + void allowSkipping() { _canBeSkipped = true; } + bool isSkippingAllowed() { return _canBeSkipped; } -public: - bool canAddContext(const Common::String name); + SequenceContext *getContext() const { return _context; } + Sequencer *getSequencer() const { return _sequencer; } + Common::Array<SequenceItem *> &getItems() { return _items; } + void setContext(SequenceContext *context) { _context = context; } +protected: SequenceContext *_context; Sequencer *_sequencer; Array<SequenceItem *> _items; - int _unk; + bool _canBeSkipped; }; -class Sound; - class SequenceAudio : public Sequence { public: - virtual void deserialize(Archive &archive); - virtual void toConsole(); + void deserialize(Archive &archive) override; + void toConsole() override; - virtual void init(int unk); - virtual void start(int unk); - virtual void end(); + void init(bool loadingSave) override; + void start(bool loadingSave) override; + void end() override; - virtual void update(); - virtual void restart(); + void update() override; + void restart() override; - virtual void skipSubSequence() {}; - virtual void skip(); + void skipSubSequence() override {} + void skip() override; private: Common::String _soundName; diff --git a/engines/pink/objects/sequences/sequence_context.cpp b/engines/pink/objects/sequences/sequence_context.cpp index 61ac13ce97..143a46c07e 100644 --- a/engines/pink/objects/sequences/sequence_context.cpp +++ b/engines/pink/objects/sequences/sequence_context.cpp @@ -31,22 +31,19 @@ namespace Pink { -SequenceActorState::SequenceActorState(const Common::String &name) - :_actorName(name), _index(0) {} - -void SequenceActorState::check(int index, Sequence *sequence, bool unk) { - Actor *actor = sequence->_sequencer->_page->findActor(_actorName); - debug("%s %s", _actorName.c_str(), _actionName.c_str()); - if (_index != index && !_actionName.empty()) { - Action *action = actor->findAction(_actionName); - if (actor->getAction() != action) - actor->setAction(action, unk); +void SequenceActorState::execute(uint segment, Sequence *sequence, bool loadingSave) const { + Actor *actor = sequence->getSequencer()->getPage()->findActor(this->actor); + if (actor && this->segment != segment && !defaultAction.empty()) { + Action *action = actor->findAction(defaultAction); + if (action && actor->getAction() != action) { + actor->setAction(action, loadingSave); + } } } -SequenceContext::SequenceContext(Sequence *sequence, Sequencer *sequencer) - : _sequence(sequence), _sequencer(sequencer), - _nextItemIndex(0), _index(1), _actor(nullptr) +SequenceContext::SequenceContext(Sequence *sequence) + : _sequence(sequence), _nextItemIndex(0), + _segment(1), _actor(nullptr) { sequence->setContext(this); Common::Array<SequenceItem*> &items = sequence->getItems(); @@ -55,7 +52,7 @@ SequenceContext::SequenceContext(Sequence *sequence, Sequencer *sequencer) 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()) { + if (items[i]->getActor() == _states[j].actor) { found = 1; break; } @@ -67,10 +64,36 @@ SequenceContext::SequenceContext(Sequence *sequence, Sequencer *sequencer) } } -void SequenceContext::clearActionsFromActorStates() { +void SequenceContext::execute(uint nextItemIndex, bool loadingSave) { + for (uint j = 0; j < _states.size(); ++j) { + _states[j].execute(_segment, _sequence, loadingSave); + } + + _nextItemIndex = nextItemIndex; + _segment++; +} + + +void SequenceContext::clearDefaultActions() { + for (uint i = 0; i < _states.size(); ++i) { + _states[i].defaultAction.clear(); + } +} + +SequenceActorState *SequenceContext::findState(const Common::String &actor) { + for (uint i = 0; i < _states.size(); ++i) { + if (_states[i].actor == actor) + return &_states[i]; + } + return nullptr; +} + +bool SequenceContext::isConflictsWith(SequenceContext *context) { for (uint i = 0; i < _states.size(); ++i) { - _states[i]._actionName.clear(); + if (context->findState(_states[i].actor)) + return true; } + return false; } } // End of namespace Pink diff --git a/engines/pink/objects/sequences/sequence_context.h b/engines/pink/objects/sequences/sequence_context.h index 5ba608154f..931c9462dd 100644 --- a/engines/pink/objects/sequences/sequence_context.h +++ b/engines/pink/objects/sequences/sequence_context.h @@ -30,39 +30,45 @@ namespace Pink { class Sequence; class Sequencer; -class SequenceActorState { -public: - SequenceActorState(const Common::String &name); +struct SequenceActorState { + SequenceActorState(const Common::String actorName) + : actor(actorName), segment(0) {} - const Common::String &getActor() const { return _actorName; } - void check(int index, Sequence *sequence, bool unk); + void execute(uint segment, Sequence *sequence, bool loadingSave) const; -public: - Common::String _actorName; - Common::String _actionName; - int _index; + Common::String actor; + Common::String defaultAction; + uint segment; }; class Actor; class SequenceContext { public: - SequenceContext(Sequence *sequence, Sequencer* sequencer); + SequenceContext(Sequence *sequence); - uint getNextItemIndex() const { return _nextItemIndex; } - Sequence *getSequence() const { return _sequence; } + void execute(uint nextItemIndex, bool loadingSave); - void setNextItemIndex(int index) { _nextItemIndex = index; } + bool isConflictsWith(SequenceContext *context); - void clearActionsFromActorStates(); + void clearDefaultActions(); -public: + SequenceActorState *findState(const Common::String &actor); + + Sequence *getSequence() const { return _sequence; } + Actor *getActor() const { return _actor; } + uint getNextItemIndex() const { return _nextItemIndex; } + uint getSegment() const { return _segment; } + + void setActor(Actor *actor) { _actor = actor; } + void setNextItemIndex(uint index) { _nextItemIndex = index; } + +private: Sequence *_sequence; - Sequencer *_sequencer; - uint _nextItemIndex; Actor *_actor; Common::Array<SequenceActorState> _states; - int _index; + uint _nextItemIndex; + uint _segment; }; } diff --git a/engines/pink/objects/sequences/sequence_item.cpp b/engines/pink/objects/sequences/sequence_item.cpp index 72fb452432..ee4094765b 100644 --- a/engines/pink/objects/sequences/sequence_item.cpp +++ b/engines/pink/objects/sequences/sequence_item.cpp @@ -42,20 +42,20 @@ void SequenceItem::toConsole() { debug("\t\t\t\tSequenceItem: _actor=%s, _action=%s", _actor.c_str(), _action.c_str()); } -bool SequenceItem::execute(int index, Sequence *sequence, bool unk2) { - Actor *actor; +bool SequenceItem::execute(uint segment, Sequence *sequence, bool loadingSave) { + Actor *actor = sequence->getSequencer()->getPage()->findActor(_actor); Action *action; - if (!(actor = sequence->_sequencer->_page->findActor(_actor)) || - !(action = actor->findAction(_action))) + if (!actor || !(action = actor->findAction(_action))) return false; - actor->setAction(action, unk2); + actor->setAction(action, loadingSave); - SequenceActorState *state = sequence->_sequencer->findMainSequenceActorState(_actor); + SequenceContext *context = sequence->getContext(); + SequenceActorState *state = context->findState(_actor); if (state) - state->_index = index; - sequence->_context->_actor = isLeader() ? actor : sequence->_context->_actor; - + state->segment = segment; + if (isLeader()) + context->setActor(actor); return true; } @@ -81,9 +81,10 @@ void SequenceItemLeaderAudio::toConsole() { debug("\t\t\t\tSequenceItemLeaderAudio: _actor=%s, _action=%s _sample=%d", _actor.c_str(), _action.c_str(), _sample); } -bool SequenceItemDefaultAction::execute(int index, Sequence *sequence, bool unk2) { - SequenceActorState *state = sequence->_sequencer->findMainSequenceActorState(_actor); - state->_actionName = _action; +bool SequenceItemDefaultAction::execute(uint segment, Sequence *sequence, bool loadingSave) { + SequenceActorState *state = sequence->getContext()->findState(_actor); + if (state) + state->defaultAction = _action; return true; } diff --git a/engines/pink/objects/sequences/sequence_item.h b/engines/pink/objects/sequences/sequence_item.h index d67e0f5939..4005331783 100644 --- a/engines/pink/objects/sequences/sequence_item.h +++ b/engines/pink/objects/sequences/sequence_item.h @@ -31,17 +31,16 @@ class Sequence; class SequenceItem : public Object { public: - virtual void deserialize(Archive &archive); + void deserialize(Archive &archive) override; - virtual void toConsole(); + void toConsole() override; - const Common::String &getActor() const { return _actor; } - const Common::String &getAction() const { return _action; } - - virtual bool execute(int index, Sequence *sequence, bool unk2); + virtual bool execute(uint segment, Sequence *sequence, bool loadingSave); virtual bool isLeader(); virtual void skip(Sequence *sequence) {}; + const Common::String &getActor() const { return _actor; } + protected: Common::String _actor; Common::String _action; @@ -49,14 +48,15 @@ protected: class SequenceItemLeader : public SequenceItem { public: - virtual void toConsole(); - virtual bool isLeader(); + void toConsole() override; + bool isLeader() override; }; class SequenceItemLeaderAudio : public SequenceItemLeader { public: - virtual void deserialize(Archive &archive); - virtual void toConsole(); + void deserialize(Archive &archive) override; + void toConsole() override; + uint32 getSample() { return _sample; } private: @@ -65,22 +65,12 @@ private: class SequenceItemDefaultAction : public SequenceItem { public: - virtual bool execute(int index, Sequence *sequence, bool unk2); - virtual void skip(Sequence *sequence); + void toConsole() override; - virtual void toConsole(); + bool execute(uint segment, Sequence *sequence, bool loadingSave) override; + void skip(Sequence *sequence) override; }; -/* 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 -}; - */ - } // End of namespace Pink #endif diff --git a/engines/pink/objects/sequences/sequencer.cpp b/engines/pink/objects/sequences/sequencer.cpp index a98512e076..b10d41437e 100644 --- a/engines/pink/objects/sequences/sequencer.cpp +++ b/engines/pink/objects/sequences/sequencer.cpp @@ -43,7 +43,10 @@ Sequencer::~Sequencer() { for (uint i = 0; i < _timers.size(); ++i) { delete _timers[i]; } - removeContext(_context); + delete _context; + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + delete _parrallelContexts[i]; + } } void Sequencer::deserialize(Archive &archive) { @@ -59,58 +62,39 @@ Sequence *Sequencer::findSequence(const Common::String &name) { return nullptr; } -void Sequencer::authorSequence(Sequence *sequence, bool unk) { - assert(!_context); +void Sequencer::authorSequence(Sequence *sequence, bool loadingSave) { + if (_context) + _context->getSequence()->forceEnd(); if (sequence) { - SequenceContext *context = new SequenceContext(sequence, this); + SequenceContext *context = new SequenceContext(sequence); SequenceContext *confilct; - while(confilct = isContextConflicts(context)) - confilct->_sequence->end(); + while(confilct = findConfilictingContextWith(context)) + confilct->getSequence()->forceEnd(); _context = context; - _currentSequenceName = sequence->getName(); - sequence->init(unk); + sequence->init(loadingSave); } } -void Sequencer::authorParallelSequence(Sequence *seqeunce, bool unk) { - if (_context && _context->_sequence == seqeunce) +void Sequencer::authorParallelSequence(Sequence *seqeunce, bool loadingSave) { + if (_context && _context->getSequence() == seqeunce) return; for (uint i = 0; i < _parrallelContexts.size(); ++i) { - if (_parrallelContexts[i]->_sequence == seqeunce) + if (_parrallelContexts[i]->getSequence() == seqeunce) return; } const Common::String leadName = _page->getLeadActor()->getName(); + SequenceContext *context = new SequenceContext(seqeunce); - SequenceContext *context = new SequenceContext(seqeunce, this); - - for (uint i = 0; i < context->_states.size(); ++i) { - if (context->_states[i].getActor() == leadName) { - delete context; - return; - } - } - - for (uint i = 0; i < context->_states.size(); ++i) { - if (findMainSequenceActorState(context->_states[i].getActor())) { - delete context; - return; - } - } - - for (uint i = 0; i < context->_states.size(); ++i) { - if (findParralelSequenceActorState(context->_states[i].getActor())) { - delete context; - return; - } - } - - _parrallelContexts.push_back(context); - seqeunce->start(unk); + if (!context->findState(leadName) && !findConfilictingContextWith(context)) { + _parrallelContexts.push_back(context); + seqeunce->init(loadingSave); + } else + delete context; } @@ -126,13 +110,19 @@ void Sequencer::toConsole() { void Sequencer::update() { if (_context) - _context->_sequence->update(); + _context->getSequence()->update(); for (uint i = 0; i < _parrallelContexts.size(); ++i) { - _parrallelContexts[i]->_sequence->update(); + _parrallelContexts[i]->getSequence()->update(); } - updateTimers(); + uint time = _page->getGame()->getTotalPlayTime(); + if (time - _time > kTimersUpdateTime) { + _time = time; + for (uint i = 0; i < _timers.size(); ++i) { + _timers[i]->update(); + } + } } void Sequencer::removeContext(SequenceContext *context) { @@ -143,7 +133,8 @@ void Sequencer::removeContext(SequenceContext *context) { } for (uint i = 0; i < _parrallelContexts.size(); ++i) { - if (context == _parrallelContexts[i]->_sequence->_context) { + if (context == _parrallelContexts[i]) { + delete _parrallelContexts[i]; _parrallelContexts.remove_at(i); break; } @@ -156,50 +147,15 @@ void Sequencer::skipSubSequence() { } void Sequencer::restartSequence() { - _context->getSequence()->restart(); + if (_context) + _context->getSequence()->restart(); } void Sequencer::skipSequence() { - if (_context->getSequence()->_unk) + if (_context && _context->getSequence()->isSkippingAllowed()) _context->getSequence()->skip(); } -void Sequencer::updateTimers() { - uint time = _page->getGame()->getTotalPlayTime(); - if (time - _time <= kTimersUpdateTime) { - return; - } - - _time = time; - for (uint i = 0; i < _timers.size(); ++i) { - _timers[i]->update(); - } -} - -SequenceActorState *Sequencer::findMainSequenceActorState(const Common::String &name) { - if (!_context) - return nullptr; - - for (uint i = 0; i < _context->_states.size(); ++i) { - if (_context->_states[i].getActor() == name) - return &_context->_states[i]; - } - - return nullptr; -} - -SequenceActorState *Sequencer::findParralelSequenceActorState(const Common::String &name) { - for (uint i = 0; i < _parrallelContexts.size(); ++i) { - for (uint j = 0; j < _parrallelContexts[i]->_states.size(); ++j) { - if (_parrallelContexts[i]->_states[j].getActor() == name) - return &_parrallelContexts[i]->_states[j]; - } - } - - return nullptr; -} - - void Sequencer::loadState(Archive &archive) { Sequence *sequence = findSequence(archive.readString()); authorSequence(sequence, 1); @@ -208,21 +164,33 @@ void Sequencer::loadState(Archive &archive) { void Sequencer::saveState(Archive &archive) { Common::String sequenceName; if (_context) - sequenceName = _context->_sequence->getName(); + sequenceName = _context->getSequence()->getName(); archive.writeString(sequenceName); // add pokus specific } -SequenceContext * Sequencer::isContextConflicts(SequenceContext *context) { +SequenceContext *Sequencer::findConfilictingContextWith(SequenceContext *context) { + if (_context && _context->isConflictsWith(context)) { + return _context; + } for (uint i = 0; i < _parrallelContexts.size(); ++i) { - for (uint j = 0; j < _parrallelContexts[i]->_states.size(); ++j) { - for (int k = 0; k < context->_states.size(); ++k) { - if (_parrallelContexts[i]->_states[j].getActor() == context->_states[k].getActor()) - return _parrallelContexts[i]; - } - } + if (_parrallelContexts[i]->isConflictsWith(context)) + return _parrallelContexts[i]; } return nullptr; } +SequenceActorState *Sequencer::findState(const Common::String &name) { + SequenceActorState *state = nullptr; + if (_context && (state = _context->findState(name))) + return state; + + for (uint i = 0; i < _parrallelContexts.size(); ++i) { + state = _parrallelContexts[i]->findState(name); + if (state) + break; + } + return state; +} + } // End of namespace Pink diff --git a/engines/pink/objects/sequences/sequencer.h b/engines/pink/objects/sequences/sequencer.h index 3a421f7edf..7bb848b24c 100644 --- a/engines/pink/objects/sequences/sequencer.h +++ b/engines/pink/objects/sequences/sequencer.h @@ -38,38 +38,38 @@ public: Sequencer(GamePage *page); ~Sequencer(); - virtual void toConsole(); + void toConsole() override; + void deserialize(Archive &archive) override; - virtual void deserialize(Archive &archive); - Sequence *findSequence(const Common::String &name); - SequenceActorState *findMainSequenceActorState(const Common::String &name); - SequenceActorState *findParralelSequenceActorState(const Common::String &name); - - void authorSequence(Sequence *sequence, bool unk); - void authorParallelSequence(Sequence *seqeunce, bool unk); - - void removeContext(SequenceContext *context); +public: + void loadState(Archive &archive); + void saveState(Archive &archive); + bool isPlaying() { return _context != nullptr; } void update(); + void authorSequence(Sequence *sequence, bool loadingSave); + void authorParallelSequence(Sequence *seqeunce, bool loadingSave); + void skipSubSequence(); void restartSequence(); void skipSequence(); - void loadState(Archive &archive); - void saveState(Archive &archive); + void removeContext(SequenceContext *context); -public: - void updateTimers(); - SequenceContext * isContextConflicts(SequenceContext *context); + SequenceContext *findConfilictingContextWith(SequenceContext *context); + Sequence *findSequence(const Common::String &name); + SequenceActorState *findState(const Common::String &name); + + GamePage *getPage() const { return _page; } +private: SequenceContext *_context; + GamePage *_page; Common::Array<SequenceContext *> _parrallelContexts; Array<Sequence *> _sequences; Array<SeqTimer *> _timers; - Common::String _currentSequenceName; - GamePage *_page; uint _time; }; |