diff options
-rw-r--r-- | engines/tsage/core.cpp | 93 | ||||
-rw-r--r-- | engines/tsage/core.h | 32 | ||||
-rw-r--r-- | engines/tsage/ringworld_scenes10.cpp | 14 |
3 files changed, 79 insertions, 60 deletions
diff --git a/engines/tsage/core.cpp b/engines/tsage/core.cpp index 7fff9603e1..4043c42fed 100644 --- a/engines/tsage/core.cpp +++ b/engines/tsage/core.cpp @@ -1036,18 +1036,35 @@ PaletteModifier::PaletteModifier() { /*--------------------------------------------------------------------------*/ -PaletteRotation::PaletteRotation() : PaletteModifier() { - _disabled = false; - _delayFrames = 0; +PaletteModifierCached::PaletteModifierCached(): PaletteModifier() { + _step = 0; + _percent = 0; +} + +void PaletteModifierCached::setPalette(ScenePalette *palette, int step) { + _scenePalette = palette; + _step = step; + _percent = 100; +} + +void PaletteModifierCached::synchronise(Serialiser &s) { + PaletteModifier::synchronise(s); + + s.syncAsByte(_step); + s.syncAsSint32LE(_percent); +} + +/*--------------------------------------------------------------------------*/ + +PaletteRotation::PaletteRotation() : PaletteModifierCached() { + _percent = 0; _delayCtr = 0; _frameNumber = _globals->_events.getFrameNumber(); } void PaletteRotation::synchronise(Serialiser &s) { - PaletteModifier::synchronise(s); + PaletteModifierCached::synchronise(s); - s.syncAsByte(_disabled); - s.syncAsSint32LE(_delayFrames); s.syncAsSint32LE(_delayCtr); s.syncAsUint32LE(_frameNumber); s.syncAsSint32LE(_currIndex); @@ -1077,8 +1094,8 @@ void PaletteRotation::signal() { if (_delayCtr) return; - _delayCtr = _delayFrames; - if (_disabled) + _delayCtr = _percent; + if (_step) return; bool flag = true; @@ -1141,7 +1158,7 @@ void PaletteRotation::remove() { void PaletteRotation::set(ScenePalette *palette, int start, int end, int rotationMode, int duration, Action *action) { _duration = duration; - _disabled = false; + _step = false; _action = action; _scenePalette = palette; @@ -1162,12 +1179,6 @@ void PaletteRotation::set(ScenePalette *palette, int start, int end, int rotatio } } -void PaletteRotation::setPalette(ScenePalette *palette, bool disabled) { - _scenePalette = palette; - _disabled = disabled; - _delayFrames = 100; -} - bool PaletteRotation::decDuration() { if (_duration) { if (--_duration == 0) { @@ -1179,18 +1190,16 @@ bool PaletteRotation::decDuration() { } void PaletteRotation::setDelay(int amount) { - _delayFrames = _delayCtr = amount; + _percent = _delayCtr = amount; } /*--------------------------------------------------------------------------*/ -void PaletteUnknown::synchronise(Serialiser &s) { - PaletteModifier::synchronise(s); +void PaletteFader::synchronise(Serialiser &s) { + PaletteModifierCached::synchronise(s); s.syncAsSint16LE(_step); s.syncAsSint16LE(_percent); - s.syncAsSint16LE(_field12); - s.syncAsSint16LE(_field14); for (int i = 0; i < 256; ++i) { s.syncAsByte(_palette[i].r); s.syncAsByte(_palette[i].g); @@ -1198,7 +1207,7 @@ void PaletteUnknown::synchronise(Serialiser &s) { } } -void PaletteUnknown::signal() { +void PaletteFader::signal() { _percent -= _step; if (_percent > 0) { _scenePalette->fade((byte *)_palette, true /* 256 */, _percent); @@ -1207,17 +1216,18 @@ void PaletteUnknown::signal() { } } -void PaletteUnknown::remove() { - if (_scenePalette) { - for (int i = 0; i < 256; i++) - _scenePalette->_palette[i] = _palette[i]; - _scenePalette->refresh(); - _scenePalette->_listeners.remove(this); - delete this; - } +void PaletteFader::remove() { + // Save of a copy of the object's action, since it will be used after the object is destroyed + Action *action = _action; - if (_action) - _action->signal(); + for (int i = 0; i < 256; i++) + _scenePalette->_palette[i] = _palette[i]; + _scenePalette->refresh(); + _scenePalette->_listeners.remove(this); + delete this; + + if (action) + action->signal(); } /*--------------------------------------------------------------------------*/ @@ -1358,18 +1368,19 @@ PaletteRotation *ScenePalette::addRotation(int start, int end, int rotationMode, return obj; } -PaletteUnknown *ScenePalette::addUnkPal(RGB8 *arrBufferRGB, int unkNumb, bool disabled, Action *action) { - PaletteUnknown *paletteUnk = new PaletteUnknown(); - paletteUnk->_action = action; +PaletteFader *ScenePalette::addFader(RGB8 *arrBufferRGB, int palSize, int percent, Action *action) { + PaletteFader *fader = new PaletteFader(); + fader->_action = action; for (int i = 0; i < 256; i++) { - if (unkNumb <= 1) - paletteUnk->_palette[i] = arrBufferRGB[i]; - else - paletteUnk->_palette[i] = arrBufferRGB[0]; + fader->_palette[i] = *arrBufferRGB; + + if (palSize > 1) + ++arrBufferRGB; } -// PaletteRotation::setPalette(this, disabled); - _globals->_scenePalette._listeners.push_back(paletteUnk); - return paletteUnk; + + fader->setPalette(this, percent); + _globals->_scenePalette._listeners.push_back(fader); + return fader; } diff --git a/engines/tsage/core.h b/engines/tsage/core.h index 77923606d1..2e3e5365a9 100644 --- a/engines/tsage/core.h +++ b/engines/tsage/core.h @@ -317,10 +317,21 @@ public: virtual void remove() = 0; }; -class PaletteRotation : public PaletteModifier { +class PaletteModifierCached: public PaletteModifier { +public: + RGB8 _palette[256]; + int _step; + int _percent; + + PaletteModifierCached(); + + void setPalette(ScenePalette *palette, int step); + virtual Common::String getClassName() { return "PaletteModifierCached"; } + virtual void synchronise(Serialiser &s); +}; + +class PaletteRotation: public PaletteModifierCached { public: - bool _disabled; - int _delayFrames; int _delayCtr; uint32 _frameNumber; int _currIndex; @@ -328,7 +339,6 @@ public: int _end; int _rotationMode; int _duration; - RGB8 _palette[256]; public: PaletteRotation(); @@ -337,26 +347,24 @@ public: virtual void signal(); virtual void remove(); - void setDisabled(bool v) { _disabled = v; } + void setStep(int step) { _step = step; } void set(ScenePalette *palette, int start, int end, int rotationMode, int duration, Action *action); - void setPalette(ScenePalette *palette, bool disabled); bool decDuration(); void setDelay(int amount); }; -/*--------------------------------------------------------------------------*/ - -class PaletteUnknown : public PaletteModifier { +class PaletteFader: public PaletteModifierCached { public: - int _step, _percent, _field12, _field14; RGB8 _palette[256]; public: - virtual Common::String getClassName() { return "PaletteUnknown"; } + virtual Common::String getClassName() { return "PaletteFader"; } virtual void synchronise(Serialiser &s); virtual void signal(); virtual void remove(); }; +/*--------------------------------------------------------------------------*/ + enum FadeMode {FADEMODE_NONE = 0, FADEMODE_GRADUAL = 1, FADEMODE_IMMEDIATE = 2}; class ScenePalette : public SavedObject { @@ -385,7 +393,7 @@ public: void clearListeners(); void fade(const byte *adjustData, bool fullAdjust, int percent); PaletteRotation *addRotation(int start, int end, int rotationMode, int duration = 0, Action *action = NULL); - PaletteUnknown *addUnkPal(RGB8 *arrBufferRGB, int unkNumb, bool disabled, Action *action); + PaletteFader *addFader(RGB8 *arrBufferRGB, int palSize, int percent, Action *action); static void changeBackground(const Rect &bounds, FadeMode fadeMode); diff --git a/engines/tsage/ringworld_scenes10.cpp b/engines/tsage/ringworld_scenes10.cpp index 7b3d00d637..9930f047dc 100644 --- a/engines/tsage/ringworld_scenes10.cpp +++ b/engines/tsage/ringworld_scenes10.cpp @@ -1652,18 +1652,18 @@ void Scene9900::strAction1::signal() { break; case 1: _palette1.getPalette(); - _globals->_scenePalette.addUnkPal(&mask1, 1, true /*10*/, this); + _globals->_scenePalette.addFader(&mask1, 1, 10, this); break; case 2: _object9.remove(); - _globals->_scenePalette.addUnkPal(&mask2, 1, true /*5*/, this); + _globals->_scenePalette.addFader(&mask2, 1, 5, this); break; case 3: _globals->_soundHandler.startSound(377, 0, 127); setDelay(120); break; case 4: - _globals->_scenePalette.addUnkPal(_palette1._palette, 256, 1, this); + _globals->_scenePalette.addFader(_palette1._palette, 256, 1, this); break; case 5: remove(); @@ -1777,18 +1777,18 @@ void Scene9900::strAction3::signal() { case 0: _palette2.getPalette(); _palette3.loadPalette(2003); - _globals->_scenePalette.addUnkPal(_palette3._palette, 256, true /*5*/, this); + _globals->_scenePalette.addFader(_palette3._palette, 256, 5, this); break; case 1: - _globals->_scenePalette.addUnkPal(&mask3, 1, true /*10*/, this); + _globals->_scenePalette.addFader(&mask3, 1, 10, this); break; case 2: - _globals->_scenePalette.addUnkPal(&mask4, 1, true /*1*/, this); + _globals->_scenePalette.addFader(&mask4, 1, 1, this); break; case 3: _palette2.loadPalette(17); _globals->_sceneManager._scene->loadScene(17); - _globals->_scenePalette.addUnkPal(_palette2._palette, 256, true /*5*/, this); + _globals->_scenePalette.addFader(_palette2._palette, 256, 5, this); break; case 4: _globals->_game.endGame(9900, 61); |