PINK: removed usage of global variable

This commit is contained in:
Andrei Prykhodko 2019-05-08 12:01:22 +03:00
parent 711b7399a0
commit 3c67ce0eed
4 changed files with 11 additions and 13 deletions

View file

@ -26,11 +26,10 @@
#include "pink/objects/actors/actor.h" #include "pink/objects/actors/actor.h"
#include "pink/objects/actions/action_play_with_sfx.h" #include "pink/objects/actions/action_play_with_sfx.h"
#include "pink/objects/pages/game_page.h" #include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequencer.h"
namespace Pink { namespace Pink {
bool g_skipping = false; // FIXME: non-const global var
ActionPlayWithSfx::~ActionPlayWithSfx() { ActionPlayWithSfx::~ActionPlayWithSfx() {
ActionPlay::end(); ActionPlay::end();
for (uint i = 0; i < _sfxArray.size(); ++i) { for (uint i = 0; i < _sfxArray.size(); ++i) {
@ -77,7 +76,7 @@ void ActionPlayWithSfx::end() {
ActionCEL::end(); ActionCEL::end();
debugC(6, kPinkDebugActions, "ActionPlayWithSfx %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str()); debugC(6, kPinkDebugActions, "ActionPlayWithSfx %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
// original bug fix // original bug fix
if (g_skipping) { if (_actor->getPage()->getSequencer()->isSkipping()) {
for (uint i = 0; i < _sfxArray.size(); ++i) { for (uint i = 0; i < _sfxArray.size(); ++i) {
_sfxArray[i]->end(); _sfxArray[i]->end();
} }

View file

@ -28,8 +28,6 @@
namespace Pink { namespace Pink {
extern bool g_skipping;
class ActionSfx; class ActionSfx;
class ActionPlayWithSfx : public ActionPlay { class ActionPlayWithSfx : public ActionPlay {

View file

@ -24,7 +24,6 @@
#include "pink/archive.h" #include "pink/archive.h"
#include "pink/pink.h" #include "pink/pink.h"
#include "pink/objects/actions/action_play_with_sfx.h"
#include "pink/objects/actors/lead_actor.h" #include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h" #include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequencer.h" #include "pink/objects/sequences/sequencer.h"
@ -35,7 +34,7 @@
namespace Pink { namespace Pink {
Sequencer::Sequencer(GamePage *page) Sequencer::Sequencer(GamePage *page)
: _context(nullptr), _page(page), _time(0) {} : _context(nullptr), _page(page), _time(0), _isSkipping(false) {}
Sequencer::~Sequencer() { Sequencer::~Sequencer() {
for (uint i = 0; i < _sequences.size(); ++i) { for (uint i = 0; i < _sequences.size(); ++i) {
@ -145,25 +144,25 @@ void Sequencer::removeContext(SequenceContext *context) {
void Sequencer::skipSubSequence() { void Sequencer::skipSubSequence() {
if (_context) { if (_context) {
g_skipping = true; _isSkipping = true;
_context->getSequence()->skipSubSequence(); _context->getSequence()->skipSubSequence();
g_skipping = false; _isSkipping = false;
} }
} }
void Sequencer::restartSequence() { void Sequencer::restartSequence() {
if (_context) { if (_context) {
g_skipping = true; _isSkipping = true;
_context->getSequence()->restart(); _context->getSequence()->restart();
g_skipping = false; _isSkipping = false;
} }
} }
void Sequencer::skipSequence() { void Sequencer::skipSequence() {
if (_context && _context->getSequence()->isSkippingAllowed()) { if (_context && _context->getSequence()->isSkippingAllowed()) {
g_skipping = true; _isSkipping = true;
_context->getSequence()->skip(); _context->getSequence()->skip();
g_skipping = false; _isSkipping = false;
} }
} }

View file

@ -47,6 +47,7 @@ public:
void saveState(Archive &archive); void saveState(Archive &archive);
bool isPlaying() { return _context != nullptr; } bool isPlaying() { return _context != nullptr; }
bool isSkipping() { return _isSkipping; }
void update(); void update();
void authorSequence(Sequence *sequence, bool loadingSave); void authorSequence(Sequence *sequence, bool loadingSave);
@ -72,6 +73,7 @@ private:
Array<Sequence *> _sequences; Array<Sequence *> _sequences;
Array<SeqTimer *> _timers; Array<SeqTimer *> _timers;
uint _time; uint _time;
bool _isSkipping;
}; };
} // End of namespace Pink } // End of namespace Pink