Initial commit
This commit is contained in:
62
engines/pink/objects/sequences/seq_timer.cpp
Normal file
62
engines/pink/objects/sequences/seq_timer.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "pink/archive.h"
|
||||
#include "pink/pink.h"
|
||||
#include "pink/objects/actors/supporting_actor.h"
|
||||
#include "pink/objects/pages/game_page.h"
|
||||
#include "pink/objects/sequences/seq_timer.h"
|
||||
#include "pink/objects/sequences/sequencer.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
SeqTimer::SeqTimer()
|
||||
: _sequencer(nullptr), _updatesToMessage(0), _period(0),
|
||||
_range(0) {}
|
||||
|
||||
void SeqTimer::deserialize(Archive &archive) {
|
||||
_actor = archive.readString();
|
||||
_period = archive.readDWORD();
|
||||
_range = archive.readDWORD();
|
||||
_sequencer = static_cast<Sequencer *>(archive.readObject());
|
||||
}
|
||||
|
||||
void SeqTimer::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\tSeqTimer: _actor=%s _period=%u _range=%u", _actor.c_str(), _period, _range);
|
||||
}
|
||||
|
||||
void SeqTimer::update() {
|
||||
Page *page = _sequencer->getPage();
|
||||
Common::RandomSource &rnd = page->getGame()->getRnd();
|
||||
if (_updatesToMessage--)
|
||||
return;
|
||||
|
||||
_updatesToMessage = _range ? _period + rnd.getRandomNumber(_range) : _period;
|
||||
|
||||
Actor *actor = page->findActor(_actor);
|
||||
if (actor && !_sequencer->findState(_actor)) {
|
||||
actor->onTimerMessage();
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Pink
|
||||
50
engines/pink/objects/sequences/seq_timer.h
Normal file
50
engines/pink/objects/sequences/seq_timer.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PINK_SEQ_TIMER_H
|
||||
#define PINK_SEQ_TIMER_H
|
||||
|
||||
#include "pink/objects/object.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
class Sequencer;
|
||||
|
||||
class SeqTimer : public Object {
|
||||
public:
|
||||
SeqTimer();
|
||||
|
||||
void deserialize(Archive &archive) override;
|
||||
void toConsole() const override;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
Common::String _actor;
|
||||
Sequencer *_sequencer;
|
||||
int _period;
|
||||
int _range;
|
||||
int _updatesToMessage;
|
||||
};
|
||||
|
||||
} // End of namespace Pink
|
||||
|
||||
#endif
|
||||
180
engines/pink/objects/sequences/sequence.cpp
Normal file
180
engines/pink/objects/sequences/sequence.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "pink/archive.h"
|
||||
#include "pink/pink.h"
|
||||
#include "pink/sound.h"
|
||||
#include "pink/objects/actors/actor.h"
|
||||
#include "pink/objects/pages/game_page.h"
|
||||
#include "pink/objects/sequences/sequence.h"
|
||||
#include "pink/objects/sequences/sequence_context.h"
|
||||
#include "pink/objects/sequences/sequencer.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
Sequence::Sequence()
|
||||
: _canBeSkipped(false), _context(nullptr),
|
||||
_sequencer(nullptr) {}
|
||||
|
||||
Sequence::~Sequence() {
|
||||
for (uint i = 0; i < _items.size(); ++i) {
|
||||
delete _items[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::deserialize(Archive &archive) {
|
||||
NamedObject::deserialize(archive);
|
||||
_sequencer = static_cast<Sequencer *>(archive.readObject());
|
||||
_items.deserialize(archive);
|
||||
}
|
||||
|
||||
void Sequence::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\tSequence %s", _name.c_str());
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\t\tItems:");
|
||||
for (uint i = 0; i < _items.size(); ++i) {
|
||||
_items[i]->toConsole();
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::start(bool loadingSave) {
|
||||
uint nextItemIndex = _context->getNextItemIndex();
|
||||
if (nextItemIndex >= _items.size() ||
|
||||
!_items[nextItemIndex]->execute(_context->getSegment(), this, loadingSave)) {
|
||||
debugC(6, kPinkDebugScripts, "Sequence %s ended", _name.c_str());
|
||||
end();
|
||||
return;
|
||||
}
|
||||
|
||||
uint i = nextItemIndex + 1;
|
||||
while (i < _items.size()) {
|
||||
if (_items[i]->isLeader()) {
|
||||
break;
|
||||
}
|
||||
_items[i++]->execute(_context->getSegment(), this, loadingSave);
|
||||
}
|
||||
|
||||
_context->execute(i, loadingSave);
|
||||
}
|
||||
|
||||
void Sequence::update() {
|
||||
if (!_context->getActor()->isPlaying()) {
|
||||
debugC(6, kPinkDebugScripts, "SubSequence of %s Sequence ended", _name.c_str());
|
||||
start(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::end() {
|
||||
_context->setActor(nullptr);
|
||||
_canBeSkipped = 1;
|
||||
_sequencer->removeContext(_context);
|
||||
}
|
||||
|
||||
void Sequence::restart() {
|
||||
_context->setNextItemIndex(0);
|
||||
_context->clearDefaultActions();
|
||||
start(0);
|
||||
}
|
||||
|
||||
void Sequence::skip() {
|
||||
if (_context->getNextItemIndex() >= _items.size())
|
||||
return;
|
||||
|
||||
for (int i = _items.size() - 1; i >= 0; --i) {
|
||||
if (_items[i]->isLeader()) {
|
||||
_context->setNextItemIndex(i);
|
||||
_context->clearDefaultActions();
|
||||
for (int j = 0; j < i; ++j) {
|
||||
_items[j]->skip(this);
|
||||
}
|
||||
start(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::skipSubSequence() {
|
||||
if (_context->getNextItemIndex() < _items.size())
|
||||
this->start(0);
|
||||
}
|
||||
|
||||
void Sequence::forceEnd() {
|
||||
skip();
|
||||
end();
|
||||
}
|
||||
|
||||
void Sequence::init(bool loadingSave) {
|
||||
start(loadingSave);
|
||||
}
|
||||
|
||||
void SequenceAudio::deserialize(Archive &archive) {
|
||||
Sequence::deserialize(archive);
|
||||
_soundName = archive.readString();
|
||||
}
|
||||
|
||||
void SequenceAudio::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\tSequenceAudio %s : _sound = %s", _name.c_str(), _soundName.c_str());
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\t\tItems:");
|
||||
for (uint i = 0; i < _items.size(); ++i) {
|
||||
_items[i]->toConsole();
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceAudio::start(bool loadingSave) {
|
||||
Sequence::start(loadingSave);
|
||||
uint index = _context->getNextItemIndex();
|
||||
if (index < _items.size()) {
|
||||
_leader = (SequenceItemLeaderAudio *)_items[index];
|
||||
} else {
|
||||
_leader = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceAudio::end() {
|
||||
_sound.stop();
|
||||
Sequence::end();
|
||||
}
|
||||
|
||||
void SequenceAudio::update() {
|
||||
if (!_sound.isPlaying())
|
||||
end();
|
||||
else if (_leader && _leader->getSample() <= _sound.getCurrentSample())
|
||||
start(0);
|
||||
}
|
||||
|
||||
void SequenceAudio::init(bool loadingSave) {
|
||||
_leader = nullptr;
|
||||
_sound.play(_sequencer->getPage()->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
|
||||
start(loadingSave);
|
||||
}
|
||||
|
||||
void SequenceAudio::restart() {
|
||||
_leader = nullptr;
|
||||
_sound.play(_sequencer->getPage()->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
|
||||
Sequence::restart();
|
||||
}
|
||||
|
||||
void SequenceAudio::skip() {
|
||||
end();
|
||||
}
|
||||
|
||||
} // End of namespace Pink
|
||||
98
engines/pink/objects/sequences/sequence.h
Normal file
98
engines/pink/objects/sequences/sequence.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PINK_SEQUENCE_H
|
||||
#define PINK_SEQUENCE_H
|
||||
|
||||
#include "pink/sound.h"
|
||||
#include "pink/objects/sequences/sequence_item.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
class Sequencer;
|
||||
class SequenceItem;
|
||||
class SequenceContext;
|
||||
|
||||
class Sequence : public NamedObject {
|
||||
public:
|
||||
Sequence();
|
||||
~Sequence() override;
|
||||
|
||||
void deserialize(Archive &archive) override ;
|
||||
void toConsole() const override;
|
||||
|
||||
public:
|
||||
virtual void init(bool loadingSave);
|
||||
|
||||
virtual void start(bool loadingSave);
|
||||
virtual void end();
|
||||
virtual void restart();
|
||||
|
||||
void forceEnd();
|
||||
|
||||
virtual void update();
|
||||
|
||||
virtual void skipSubSequence();
|
||||
virtual void skip();
|
||||
|
||||
void allowSkipping() { _canBeSkipped = true; }
|
||||
bool isSkippingAllowed() { return _canBeSkipped; }
|
||||
|
||||
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;
|
||||
bool _canBeSkipped;
|
||||
};
|
||||
|
||||
class SequenceAudio : public Sequence {
|
||||
public:
|
||||
SequenceAudio()
|
||||
: _leader(nullptr) {}
|
||||
|
||||
void deserialize(Archive &archive) override;
|
||||
void toConsole() const override;
|
||||
|
||||
void init(bool loadingSave) override;
|
||||
void start(bool loadingSave) override;
|
||||
void end() override;
|
||||
|
||||
void update() override;
|
||||
void restart() override;
|
||||
|
||||
void skipSubSequence() override {}
|
||||
void skip() override;
|
||||
|
||||
private:
|
||||
SequenceItemLeaderAudio *_leader;
|
||||
Common::String _soundName;
|
||||
Sound _sound;
|
||||
};
|
||||
|
||||
} // End of namespace Pink
|
||||
|
||||
#endif
|
||||
97
engines/pink/objects/sequences/sequence_context.cpp
Normal file
97
engines/pink/objects/sequences/sequence_context.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "pink/pink.h"
|
||||
#include "pink/objects/actors/actor.h"
|
||||
#include "pink/objects/pages/game_page.h"
|
||||
#include "pink/objects/sequences/sequence.h"
|
||||
#include "pink/objects/sequences/sequence_context.h"
|
||||
#include "pink/objects/sequences/sequencer.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
void SequenceActorState::execute(uint segment, Sequence *sequence, bool loadingSave) const {
|
||||
Actor *actor = sequence->getSequencer()->getPage()->findActor(this->actorName);
|
||||
if (actor && _segment != segment && !defaultActionName.empty()) {
|
||||
Action *action = actor->findAction(defaultActionName);
|
||||
if (action && actor->getAction() != action) {
|
||||
actor->setAction(action, loadingSave);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SequenceContext::SequenceContext(Sequence *sequence)
|
||||
: _sequence(sequence), _nextItemIndex(0),
|
||||
_segment(1), _actor(nullptr) {
|
||||
sequence->setContext(this);
|
||||
Common::Array<SequenceItem *> &items = sequence->getItems();
|
||||
debug(kPinkDebugScripts, "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].actorName) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
debug(kPinkDebugScripts, "%s", items[i]->getActor().c_str());
|
||||
_states.push_back(SequenceActorState(items[i]->getActor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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].defaultActionName.clear();
|
||||
}
|
||||
}
|
||||
|
||||
SequenceActorState *SequenceContext::findState(const Common::String &actor) {
|
||||
for (uint i = 0; i < _states.size(); ++i) {
|
||||
if (_states[i].actorName == actor)
|
||||
return &_states[i];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SequenceContext::isConflictingWith(SequenceContext *context) {
|
||||
for (uint i = 0; i < _states.size(); ++i) {
|
||||
if (context->findState(_states[i].actorName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // End of namespace Pink
|
||||
75
engines/pink/objects/sequences/sequence_context.h
Normal file
75
engines/pink/objects/sequences/sequence_context.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PINK_SEQUENCE_CONTEXT_H
|
||||
#define PINK_SEQUENCE_CONTEXT_H
|
||||
|
||||
#include "common/array.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
class Sequence;
|
||||
class Sequencer;
|
||||
|
||||
struct SequenceActorState {
|
||||
SequenceActorState(const Common::String &actor)
|
||||
: actorName(actor), _segment(0) {}
|
||||
|
||||
void execute(uint segment, Sequence *sequence, bool loadingSave) const;
|
||||
|
||||
Common::String actorName;
|
||||
Common::String defaultActionName;
|
||||
uint _segment;
|
||||
};
|
||||
|
||||
class Actor;
|
||||
|
||||
class SequenceContext {
|
||||
public:
|
||||
SequenceContext(Sequence *sequence);
|
||||
|
||||
void execute(uint nextItemIndex, bool loadingSave);
|
||||
|
||||
bool isConflictingWith(SequenceContext *context);
|
||||
|
||||
void clearDefaultActions();
|
||||
|
||||
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;
|
||||
Actor *_actor;
|
||||
Common::Array<SequenceActorState> _states;
|
||||
uint _nextItemIndex;
|
||||
uint _segment;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
99
engines/pink/objects/sequences/sequence_item.cpp
Normal file
99
engines/pink/objects/sequences/sequence_item.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "pink/archive.h"
|
||||
#include "pink/pink.h"
|
||||
#include "pink/objects/actions/action.h"
|
||||
#include "pink/objects/actors/actor.h"
|
||||
#include "pink/objects/pages/game_page.h"
|
||||
#include "pink/objects/sequences/sequence_item.h"
|
||||
#include "pink/objects/sequences/sequence.h"
|
||||
#include "pink/objects/sequences/sequencer.h"
|
||||
#include "pink/objects/sequences/sequence_context.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
void SequenceItem::deserialize(Archive &archive) {
|
||||
_actor = archive.readString();
|
||||
_action = archive.readString();
|
||||
}
|
||||
|
||||
void SequenceItem::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItem: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
|
||||
}
|
||||
|
||||
bool SequenceItem::execute(uint segment, Sequence *sequence, bool loadingSave) {
|
||||
Actor *actor = sequence->getSequencer()->getPage()->findActor(_actor);
|
||||
Action *action;
|
||||
if (!actor || !(action = actor->findAction(_action)))
|
||||
return false;
|
||||
|
||||
actor->setAction(action, loadingSave);
|
||||
|
||||
SequenceContext *context = sequence->getContext();
|
||||
SequenceActorState *state = context->findState(_actor);
|
||||
if (state)
|
||||
state->_segment = segment;
|
||||
if (isLeader())
|
||||
context->setActor(actor);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SequenceItem::isLeader() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SequenceItemLeader::isLeader() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SequenceItemLeader::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemLeader: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
|
||||
}
|
||||
|
||||
|
||||
void SequenceItemLeaderAudio::deserialize(Archive &archive) {
|
||||
SequenceItem::deserialize(archive);
|
||||
_sample = archive.readDWORD();
|
||||
}
|
||||
|
||||
void SequenceItemLeaderAudio::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemLeaderAudio: _actor=%s, _action=%s _sample=%d", _actor.c_str(), _action.c_str(), _sample);
|
||||
}
|
||||
|
||||
bool SequenceItemDefaultAction::execute(uint segment, Sequence *sequence, bool loadingSave) {
|
||||
SequenceActorState *state = sequence->getContext()->findState(_actor);
|
||||
if (state)
|
||||
state->defaultActionName = _action;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SequenceItemDefaultAction::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemDefaultAction: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
|
||||
}
|
||||
|
||||
void SequenceItemDefaultAction::skip(Sequence *sequence) {
|
||||
execute(0, sequence, 1);
|
||||
}
|
||||
|
||||
} // End of namespace Pink
|
||||
78
engines/pink/objects/sequences/sequence_item.h
Normal file
78
engines/pink/objects/sequences/sequence_item.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PINK_SEQUENCE_ITEM_H
|
||||
#define PINK_SEQUENCE_ITEM_H
|
||||
|
||||
#include "pink/objects/object.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
class Sequence;
|
||||
|
||||
class SequenceItem : public Object {
|
||||
public:
|
||||
void deserialize(Archive &archive) override;
|
||||
|
||||
void toConsole() const override;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class SequenceItemLeader : public SequenceItem {
|
||||
public:
|
||||
void toConsole() const override;
|
||||
bool isLeader() override;
|
||||
};
|
||||
|
||||
class SequenceItemLeaderAudio : public SequenceItemLeader {
|
||||
public:
|
||||
SequenceItemLeaderAudio()
|
||||
: _sample(0) {}
|
||||
|
||||
void deserialize(Archive &archive) override;
|
||||
void toConsole() const override;
|
||||
|
||||
uint32 getSample() { return _sample; }
|
||||
|
||||
private:
|
||||
uint32 _sample;
|
||||
};
|
||||
|
||||
class SequenceItemDefaultAction : public SequenceItem {
|
||||
public:
|
||||
void toConsole() const override;
|
||||
|
||||
bool execute(uint segment, Sequence *sequence, bool loadingSave) override;
|
||||
void skip(Sequence *sequence) override;
|
||||
};
|
||||
|
||||
} // End of namespace Pink
|
||||
|
||||
#endif
|
||||
215
engines/pink/objects/sequences/sequencer.cpp
Normal file
215
engines/pink/objects/sequences/sequencer.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include "pink/archive.h"
|
||||
#include "pink/pink.h"
|
||||
#include "pink/objects/actors/lead_actor.h"
|
||||
#include "pink/objects/pages/game_page.h"
|
||||
#include "pink/objects/sequences/sequencer.h"
|
||||
#include "pink/objects/sequences/sequence.h"
|
||||
#include "pink/objects/sequences/sequence_context.h"
|
||||
#include "pink/objects/sequences/seq_timer.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
Sequencer::Sequencer(GamePage *page)
|
||||
: _context(nullptr), _page(page), _time(0), _isSkipping(false) {}
|
||||
|
||||
Sequencer::~Sequencer() {
|
||||
for (uint i = 0; i < _sequences.size(); ++i) {
|
||||
delete _sequences[i];
|
||||
}
|
||||
for (uint i = 0; i < _timers.size(); ++i) {
|
||||
delete _timers[i];
|
||||
}
|
||||
delete _context;
|
||||
for (uint i = 0; i < _parallelContexts.size(); ++i) {
|
||||
delete _parallelContexts[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::deserialize(Archive &archive) {
|
||||
_sequences.deserialize(archive);
|
||||
_timers.deserialize(archive);
|
||||
}
|
||||
|
||||
Sequence *Sequencer::findSequence(const Common::String &name) {
|
||||
for (uint i = 0; i < _sequences.size(); ++i) {
|
||||
if (_sequences[i]->getName() == name)
|
||||
return _sequences[i];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Sequencer::authorSequence(Sequence *sequence, bool loadingSave) {
|
||||
if (_context)
|
||||
_context->getSequence()->forceEnd();
|
||||
|
||||
if (sequence) {
|
||||
SequenceContext *context = new SequenceContext(sequence);
|
||||
SequenceContext *conflict;
|
||||
while ((conflict = findConflictingContextWith(context)) != nullptr) {
|
||||
conflict->getSequence()->forceEnd();
|
||||
}
|
||||
_context = context;
|
||||
sequence->init(loadingSave);
|
||||
debugC(5, kPinkDebugScripts, "Main Sequence %s started", sequence->getName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::authorParallelSequence(Sequence *sequence, bool loadingSave) {
|
||||
if (_context && _context->getSequence() == sequence)
|
||||
return;
|
||||
|
||||
for (uint i = 0; i < _parallelContexts.size(); ++i) {
|
||||
if (_parallelContexts[i]->getSequence() == sequence)
|
||||
return;
|
||||
}
|
||||
|
||||
const Common::String leadName = _page->getLeadActor()->getName();
|
||||
SequenceContext *context = new SequenceContext(sequence);
|
||||
|
||||
if (!context->findState(leadName) && !findConflictingContextWith(context)) {
|
||||
_parallelContexts.push_back(context);
|
||||
sequence->init(loadingSave);
|
||||
debugC(6, kPinkDebugScripts, "Parallel Sequence %s started", sequence->getName().c_str());
|
||||
} else
|
||||
delete context;
|
||||
}
|
||||
|
||||
|
||||
void Sequencer::toConsole() const {
|
||||
debugC(6, kPinkDebugLoadingObjects, "Sequencer:");
|
||||
for (uint i = 0; i < _sequences.size(); ++i) {
|
||||
_sequences[i]->toConsole();
|
||||
}
|
||||
for (uint i = 0; i < _timers.size(); ++i) {
|
||||
_timers[i]->toConsole();
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::update() {
|
||||
if (_context)
|
||||
_context->getSequence()->update();
|
||||
|
||||
for (uint i = 0; i < _parallelContexts.size(); ++i) {
|
||||
_parallelContexts[i]->getSequence()->update();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (context == _context) {
|
||||
delete _context;
|
||||
_context = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint i = 0; i < _parallelContexts.size(); ++i) {
|
||||
if (context == _parallelContexts[i]) {
|
||||
delete _parallelContexts[i];
|
||||
_parallelContexts.remove_at(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::skipSubSequence() {
|
||||
if (_context) {
|
||||
_isSkipping = true;
|
||||
_context->getSequence()->skipSubSequence();
|
||||
_isSkipping = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::restartSequence() {
|
||||
if (_context) {
|
||||
_isSkipping = true;
|
||||
_context->getSequence()->restart();
|
||||
_isSkipping = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::skipSequence() {
|
||||
if (_context && _context->getSequence()->isSkippingAllowed()) {
|
||||
_isSkipping = true;
|
||||
_context->getSequence()->skip();
|
||||
_isSkipping = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::loadState(Archive &archive) {
|
||||
Sequence *sequence = findSequence(archive.readString());
|
||||
authorSequence(sequence, 1);
|
||||
|
||||
uint size = archive.readWORD();
|
||||
for (uint i = 0; i < size; ++i) {
|
||||
sequence = findSequence(archive.readString());
|
||||
authorParallelSequence(sequence, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Sequencer::saveState(Archive &archive) {
|
||||
Common::String sequenceName;
|
||||
if (_context)
|
||||
sequenceName = _context->getSequence()->getName();
|
||||
archive.writeString(sequenceName);
|
||||
|
||||
archive.writeWORD(_parallelContexts.size());
|
||||
for (uint i = 0; i < _parallelContexts.size(); ++i) {
|
||||
archive.writeString(_parallelContexts[i]->getSequence()->getName());
|
||||
}
|
||||
}
|
||||
|
||||
SequenceContext *Sequencer::findConflictingContextWith(SequenceContext *context) {
|
||||
if (_context && _context->isConflictingWith(context)) {
|
||||
return _context;
|
||||
}
|
||||
for (uint i = 0; i < _parallelContexts.size(); ++i) {
|
||||
if (_parallelContexts[i]->isConflictingWith(context))
|
||||
return _parallelContexts[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 < _parallelContexts.size(); ++i) {
|
||||
state = _parallelContexts[i]->findState(name);
|
||||
if (state)
|
||||
break;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
} // End of namespace Pink
|
||||
80
engines/pink/objects/sequences/sequencer.h
Normal file
80
engines/pink/objects/sequences/sequencer.h
Normal file
@@ -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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PINK_SEQUENCER_H
|
||||
#define PINK_SEQUENCER_H
|
||||
|
||||
#include "pink/objects/object.h"
|
||||
|
||||
namespace Pink {
|
||||
|
||||
class Sequence;
|
||||
class SequenceContext;
|
||||
class GamePage;
|
||||
class SeqTimer;
|
||||
|
||||
struct SequenceActorState;
|
||||
|
||||
class Sequencer : public Object {
|
||||
public:
|
||||
Sequencer(GamePage *page);
|
||||
~Sequencer() override;
|
||||
|
||||
void toConsole() const override;
|
||||
void deserialize(Archive &archive) override;
|
||||
|
||||
public:
|
||||
void loadState(Archive &archive);
|
||||
void saveState(Archive &archive);
|
||||
|
||||
bool isPlaying() { return _context != nullptr; }
|
||||
bool isSkipping() { return _isSkipping; }
|
||||
void update();
|
||||
|
||||
void authorSequence(Sequence *sequence, bool loadingSave);
|
||||
void authorParallelSequence(Sequence *sequence, bool loadingSave);
|
||||
|
||||
void skipSubSequence();
|
||||
void restartSequence();
|
||||
void skipSequence();
|
||||
|
||||
void removeContext(SequenceContext *context);
|
||||
|
||||
SequenceContext *findConflictingContextWith(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 *> _parallelContexts;
|
||||
Array<Sequence *> _sequences;
|
||||
Array<SeqTimer *> _timers;
|
||||
uint _time;
|
||||
bool _isSkipping;
|
||||
};
|
||||
|
||||
} // End of namespace Pink
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user