PINK: reformat Action's code

This commit is contained in:
whiterandrek 2018-06-03 14:24:59 +03:00 committed by Eugene Sandulenko
parent 442f725a5d
commit da0adc92a2
20 changed files with 162 additions and 121 deletions

View File

@ -31,4 +31,14 @@ void Action::deserialize(Archive &archive) {
_actor = static_cast<Actor*>(archive.readObject());
}
bool Action::initPalette(Director *director) {
return false;
}
void Action::pause(bool paused) {}
Actor *Action::getActor() const {
return _actor;
}
} // End of namespace Pink

View File

@ -32,17 +32,16 @@ class Director;
class Action : public NamedObject {
public:
virtual void deserialize(Archive &archive);
virtual void start(bool unk) {};
virtual void end() {};
virtual void update() {};
virtual void toConsole() {};
virtual void deserialize(Archive &archive) override;
virtual bool initPalette(Director *director) { return 0; }
virtual bool initPalette(Director *director);
Actor *getActor() { return _actor; }
virtual void start() = 0;
virtual void end() = 0;
virtual void pause(bool paused) {};
virtual void pause(bool paused);
Actor *getActor() const;
protected:
Actor *_actor;

View File

@ -34,13 +34,29 @@ namespace Pink {
ActionCEL::ActionCEL()
: _decoder(nullptr) {}
ActionCEL::~ActionCEL() {
end();
}
void ActionCEL::deserialize(Archive &archive) {
Action::deserialize(archive);
_fileName = archive.readString();
_z = archive.readDWORD();
}
void ActionCEL::start(bool unk) {
bool ActionCEL::initPalette(Director *director) {
if (!_decoder)
_decoder = _actor->getPage()->loadCel(_fileName);
if (_decoder->getCurFrame() == -1) {
_decoder->decodeNextFrame();
_decoder->rewind();
}
debug("%u", _decoder->isPaused());
director->setPallette(_decoder->getPalette());
return true;
}
void ActionCEL::start() {
if (!_decoder)
_decoder = _actor->getPage()->loadCel(_fileName);
_actor->getPage()->getGame()->getDirector()->addSprite(this);
@ -54,6 +70,17 @@ void ActionCEL::end() {
_decoder = nullptr;
}
void ActionCEL::update() {
if (_decoder->endOfVideo()) {
_decoder->stop();
_actor->endAction();
}
}
void ActionCEL::pause(bool paused) {
_decoder->pauseVideo(paused);
}
uint32 ActionCEL::getZ() {
return _z;
}
@ -62,28 +89,4 @@ CelDecoder *ActionCEL::getDecoder() {
return _decoder;
}
bool ActionCEL::initPalette(Director *director) {
_decoder = _actor->getPage()->loadCel(_fileName);
_decoder->decodeNextFrame();
_decoder->rewind();
director->setPallette(_decoder->getPalette());
return 1;
}
void ActionCEL::update() {
if (_decoder->endOfVideo()) {
_decoder->stop();
_actor->endAction();
}
}
ActionCEL::~ActionCEL() {
end();
}
void ActionCEL::pause(bool paused) {
_decoder->pauseVideo(paused);
}
} // End of namespace Pink

View File

@ -31,23 +31,26 @@ class CelDecoder;
class ActionCEL : public Action {
public:
ActionCEL();
~ActionCEL() override;
ActionCEL();
virtual void deserialize(Archive &archive);
virtual void start(bool unk);
virtual void end();
void deserialize(Archive &archive) override;
bool initPalette(Director *director) override;
void start() override;
void end() override;
virtual void update();
void pause(bool paused) override;
uint32 getZ();
CelDecoder *getDecoder();
virtual bool initPalette(Director *director);
void pause(bool paused) override;
protected:
virtual void onStart() {};
virtual void onStart() = 0;
CelDecoder *_decoder;
Common::String _fileName;
uint32 _z;

View File

@ -26,11 +26,11 @@
namespace Pink {
void Pink::ActionHide::deserialize(Archive &archive) {
Action::deserialize(archive);
void ActionHide::toConsole() {
debug("\tActionHide: _name = %s", _name.c_str());
}
void ActionHide::start(bool unk_startNow) {
void ActionHide::start() {
debug("Actor %s has now ActionHide %s", _actor->getName().c_str(), _name.c_str());
_actor->endAction();
}
@ -39,10 +39,4 @@ void ActionHide::end() {
debug("ActionHide %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
void ActionHide::toConsole() {
debug("\tActionHide: _name = %s", _name.c_str());
}
ActionHide::~ActionHide() {}
} //End of namespace Pink

View File

@ -29,13 +29,10 @@ namespace Pink {
class ActionHide : public Action {
public:
~ActionHide() override;
void toConsole() override;
virtual void deserialize(Archive &archive);
virtual void toConsole();
virtual void start(bool unk);
virtual void end();
void start() override;
void end() override;
};
} //End of namespace Pink

View File

@ -29,11 +29,14 @@ namespace Pink {
class ActionLoop : public ActionPlay {
public:
virtual void deserialize(Archive &archive);
virtual void toConsole();
virtual void update();
void deserialize(Archive &archive) override;
void toConsole() override;
void update() override;
protected:
virtual void onStart();
void onStart() override;
enum Style {
kPingPong = 2,

View File

@ -44,6 +44,17 @@ void ActionPlay::end() {
debug("ActionPlay %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
void ActionPlay::update() {
if (_decoder->endOfVideo() || _decoder->getCurFrame() == _stopFrame) {
_decoder->stop();
_actor->endAction();
}
}
void ActionPlay::pause(bool paused) {
ActionCEL::pause(paused);
}
void ActionPlay::onStart() {
debug("Actor %s has now ActionPlay %s", _actor->getName().c_str(), _name.c_str());
_decoder->start();
@ -53,11 +64,4 @@ void ActionPlay::onStart() {
_decoder->decodeNextFrame();
}
void ActionPlay::update() {
if (_decoder->endOfVideo() || _decoder->getCurFrame() == _stopFrame) {
_decoder->stop();
_actor->endAction();
}
}
} // End of namespace Pink

View File

@ -29,15 +29,18 @@ namespace Pink {
class ActionPlay : public ActionStill {
public:
virtual void deserialize(Archive &archive);
virtual void toConsole();
void deserialize(Archive &archive) override;
virtual void end();
void toConsole() override;
void end() override;
void update() override;
void pause(bool paused) override;
protected:
virtual void onStart();
void onStart() override;
int32 _stopFrame;
};

View File

@ -28,6 +28,13 @@
namespace Pink {
ActionPlayWithSfx::~ActionPlayWithSfx() {
ActionPlay::end();
for (uint i = 0; i < _sfxArray.size(); ++i) {
delete _sfxArray[i];
}
}
void ActionPlayWithSfx::deserialize(Pink::Archive &archive) {
ActionPlay::deserialize(archive);
_isLoop = archive.readDWORD();
@ -71,11 +78,11 @@ void ActionPlayWithSfx::updateSound() {
}
}
ActionPlayWithSfx::~ActionPlayWithSfx() {
ActionPlay::end();
for (uint i = 0; i < _sfxArray.size(); ++i) {
delete _sfxArray[i];
}
ActionSfx::ActionSfx()
: _sound(nullptr) {}
ActionSfx::~ActionSfx() {
end();
}
void ActionSfx::deserialize(Pink::Archive &archive) {
@ -97,20 +104,13 @@ void ActionSfx::play(Page *page) {
_sound->play(Audio::Mixer::kSFXSoundType, _volume, 0);
}
ActionSfx::~ActionSfx() {
end();
void ActionSfx::end() {
delete _sound;
_sound = nullptr;
}
uint32 ActionSfx::getFrame() {
return _frame;
}
ActionSfx::ActionSfx()
: _sound(nullptr) {}
void ActionSfx::end() {
delete _sound;
_sound = nullptr;
}
} // End of namespace Pink

View File

@ -31,18 +31,22 @@ class ActionSfx;
class ActionPlayWithSfx : public ActionPlay {
public:
virtual ~ActionPlayWithSfx();
virtual void deserialize(Archive &archive);
virtual void toConsole();
virtual void update();
~ActionPlayWithSfx() override;
void deserialize(Archive &archive) override;
void toConsole() override;
void update() override;
protected:
virtual void onStart();
void onStart() override;
private:
void updateSound();
uint32 _isLoop;
Array<ActionSfx *> _sfxArray;
uint32 _isLoop;
};
class Sound;
@ -51,14 +55,17 @@ class Page;
class ActionSfx : public Object {
public:
ActionSfx();
virtual ~ActionSfx();
virtual void deserialize(Archive &archive);
virtual void toConsole();
~ActionSfx() override;
void deserialize(Archive &archive) override;
void toConsole() override;
void play(Page *page);
uint32 getFrame();
void end();
uint32 getFrame();
private:
Sound *_sound;
Common::String _sfxName;

View File

@ -51,7 +51,7 @@ void ActionSound::toConsole() {
" _isBackground = %u", _name.c_str(), _fileName.c_str(), _volume, _isLoop, _isBackground);
}
void ActionSound::start(bool unk) {
void ActionSound::start() {
assert(!_sound);
_sound = _actor->getPage()->loadSound(_fileName);

View File

@ -34,13 +34,14 @@ public:
ActionSound();
~ActionSound();
virtual void deserialize(Archive &archive);
void deserialize(Archive &archive) override;
virtual void toConsole();
void toConsole() override;
virtual void start(bool unk_startNow);
virtual void end();
virtual void update();
void start() override;
void end() override;
void update();
void pause(bool paused) override;

View File

@ -44,6 +44,8 @@ void ActionStill::end() {
debug("ActionStill %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
void ActionStill::pause(bool paused) {}
void ActionStill::onStart() {
debug("Actor %s has now ActionStill %s", _actor->getName().c_str(), _name.c_str());
for (uint i = 0; i < _startFrame; ++i) {

View File

@ -29,14 +29,16 @@ namespace Pink {
class ActionStill : public ActionCEL {
public:
virtual void deserialize(Archive &archive);
virtual void toConsole();
void deserialize(Archive &archive) override;
virtual void end();
virtual void pause(bool paused) {}
void toConsole() override;
void end() override;
void pause(bool paused) override;
protected:
virtual void onStart();
void onStart() override;
uint32 _startFrame;
};

View File

@ -40,12 +40,6 @@ void ActionTalk::toConsole() {
_name.c_str(), _fileName.c_str(), _z, _startFrame, _stopFrame, _intro, _style, _vox.c_str());
}
void ActionTalk::onStart() {
ActionPlay::onStart();
_sound = _actor->getPage()->loadSound(_vox);
_sound->play(Audio::Mixer::kSpeechSoundType, 100, 0);
}
void ActionTalk::update() {
ActionLoop::update();
if (!_sound->isPlaying()) {
@ -66,4 +60,10 @@ void ActionTalk::pause(bool paused) {
_sound->pause(paused);
}
void ActionTalk::onStart() {
ActionPlay::onStart();
_sound = _actor->getPage()->loadSound(_vox);
_sound->play(Audio::Mixer::kSpeechSoundType, 100, 0);
}
} // End of namespace Pink

View File

@ -31,16 +31,18 @@ class Sound;
class ActionTalk : public ActionLoop {
public:
virtual void deserialize(Archive &archive);
virtual void toConsole();
virtual void update();
void deserialize(Archive &archive) override;
virtual void end();
void toConsole() override;
void update() override;
void end() override;
void pause(bool paused) override;
protected:
virtual void onStart();
void onStart() override;
private:
Sound *_sound;

View File

@ -48,4 +48,12 @@ void ActionText::toConsole() {
_name.c_str(), _fileName.c_str(), _xLeft, _yTop, _xRight, _yBottom, _centered, _scrollBar, _textColor, _backgroundColor);
}
void ActionText::start() {
}
void ActionText::end() {
}
} // End of namespace Pink

View File

@ -33,6 +33,9 @@ public:
void toConsole() override;
void start() override;
void end() override;
private:
Common::String _fileName;

View File

@ -29,9 +29,9 @@ namespace Pink {
class WalkAction : public ActionCEL {
public:
virtual void deserialize(Archive &archive);
void deserialize(Archive &archive) override;
virtual void toConsole();
void toConsole() override;
protected:
void onStart() override;