From 01eb329be2df445f3374f8183bec5d9031450062 Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Mon, 4 Jan 2010 16:44:58 +0000 Subject: SCI: kPalette / animate adjustments to behave more like sierra sci, also doesnt crash in island of brain anymore svn-id: r46975 --- engines/sci/engine/kgraphics.cpp | 7 ++++-- engines/sci/gui/gui.cpp | 10 +++++--- engines/sci/gui/gui.h | 3 ++- engines/sci/gui/gui_palette.cpp | 54 ++++++++++++++++++++++++++++------------ engines/sci/gui/gui_palette.h | 2 +- engines/sci/gui32/gui32.cpp | 6 ++++- engines/sci/gui32/gui32.h | 3 ++- 7 files changed, 60 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 9835aa6687..f909ab5f13 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -569,12 +569,16 @@ reg_t kPalette(EngineState *s, int argc, reg_t *argv) { } case 6: { // Animate int16 argNr; + bool paletteChanged = false; for (argNr = 1; argNr < argc; argNr += 3) { uint16 fromColor = argv[argNr].toUint16(); uint16 toColor = argv[argNr + 1].toUint16(); int16 speed = argv[argNr + 2].toSint16(); - s->_gui->paletteAnimate(fromColor, toColor, speed); + if (s->_gui->paletteAnimate(fromColor, toColor, speed)) + paletteChanged = true; } + if (paletteChanged) + s->_gui->paletteAnimateSet(); break; } case 7: { // Save palette to heap @@ -963,7 +967,6 @@ reg_t kAnimate(EngineState *s, int argc, reg_t *argv) { // Take care of incoming events (kAnimate is called semi-regularly) process_sound_events(s); #endif - s->_gui->animate(castListReference, cycle, argc, argv); return s->r_acc; diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp index 4451dfa940..47d32e27c5 100644 --- a/engines/sci/gui/gui.cpp +++ b/engines/sci/gui/gui.cpp @@ -573,12 +573,16 @@ void SciGui::paletteSetIntensity(uint16 fromColor, uint16 toColor, uint16 intens _palette->setIntensity(fromColor, toColor, intensity, setPalette); } -void SciGui::paletteAnimate(uint16 fromColor, uint16 toColor, int16 speed) { +bool SciGui::paletteAnimate(uint16 fromColor, uint16 toColor, int16 speed) { // we are also called on Amiga as well, but for colors above 32, so it doesnt make sense if (!_s->resMan->isVGA()) - return; + return false; + + return _palette->animate(fromColor, toColor, speed); +} - _palette->animate(fromColor, toColor, speed); +void SciGui::paletteAnimateSet() { + _palette->setOnScreen(); } void SciGui::shakeScreen(uint16 shakeCount, uint16 directions) { diff --git a/engines/sci/gui/gui.h b/engines/sci/gui/gui.h index ee1604d25b..59f9b8b36e 100644 --- a/engines/sci/gui/gui.h +++ b/engines/sci/gui/gui.h @@ -116,7 +116,8 @@ public: virtual void paletteUnsetFlag(uint16 fromColor, uint16 toColor, uint16 flag); virtual int16 paletteFind(uint16 r, uint16 g, uint16 b); virtual void paletteSetIntensity(uint16 fromColor, uint16 toColor, uint16 intensity, bool setPalette); - virtual void paletteAnimate(uint16 fromColor, uint16 toColor, int16 speed); + virtual bool paletteAnimate(uint16 fromColor, uint16 toColor, int16 speed); + virtual void paletteAnimateSet(); virtual void shakeScreen(uint16 shakeCount, uint16 directions); diff --git a/engines/sci/gui/gui_palette.cpp b/engines/sci/gui/gui_palette.cpp index 68b9777286..320221b1aa 100644 --- a/engines/sci/gui/gui_palette.cpp +++ b/engines/sci/gui/gui_palette.cpp @@ -296,37 +296,59 @@ void SciGuiPalette::setIntensity(uint16 fromColor, uint16 toColor, uint16 intens setOnScreen(); } -void SciGuiPalette::animate(byte fromColor, byte toColor, int speed) { +// Returns true, if palette got changed +bool SciGuiPalette::animate(byte fromColor, byte toColor, int speed) { GuiColor col; - int len = toColor - fromColor - 1; + byte colorNr; + int16 colorCount; uint32 now = g_system->getMillis() * 60 / 1000; // search for sheduled animations with the same 'from' value - int sz = _schedules.size(); - for (int i = 0; i < sz; i++) { - if (_schedules[i].from == fromColor) { - if (_schedules[i].schedule < now) { + // schedule animation... + int scheduleCount = _schedules.size(); + int scheduleNr; + for (scheduleNr = 0; scheduleNr < scheduleCount; scheduleNr++) { + if (_schedules[scheduleNr].from == fromColor) + break; + } + if (scheduleNr == scheduleCount) { + // adding a new schedule + GuiPalSchedule newSchedule; + newSchedule.from = fromColor; + newSchedule.schedule = now + ABS(speed); + _schedules.push_back(newSchedule); + scheduleCount++; + } + + for (scheduleNr = 0; scheduleNr < scheduleCount; scheduleNr++) { + if (_schedules[scheduleNr].from == fromColor) { + if (_schedules[scheduleNr].schedule <= now) { if (speed > 0) { + // TODO: Not really sure about this, sierra sci seems to do exactly this here col = _sysPalette.colors[fromColor]; - memmove(&_sysPalette.colors[fromColor], &_sysPalette.colors[fromColor + 1], len * sizeof(GuiColor)); + if (fromColor < toColor) { + colorCount = toColor - fromColor - 1; + memmove(&_sysPalette.colors[fromColor], &_sysPalette.colors[fromColor + 1], colorCount * sizeof(GuiColor)); + } _sysPalette.colors[toColor - 1] = col; } else { col = _sysPalette.colors[toColor - 1]; - memmove(&_sysPalette.colors[fromColor + 1], &_sysPalette.colors[fromColor], len * sizeof(GuiColor)); + if (fromColor < toColor) { + colorCount = toColor - fromColor - 1; + memmove(&_sysPalette.colors[fromColor + 1], &_sysPalette.colors[fromColor], colorCount * sizeof(GuiColor)); + } _sysPalette.colors[fromColor] = col; } // removing schedule - _schedules.remove_at(i); + _schedules[scheduleNr].schedule = now + ABS(speed); + // TODO: Not sure when sierra actually removes a schedule + //_schedules.remove_at(scheduleNr); + return true; } - setOnScreen(); - return; + return false; } } - // adding a new schedule - GuiPalSchedule newSchedule; - newSchedule.from = fromColor; - newSchedule.schedule = now + ABS(speed); - _schedules.push_back(newSchedule); + return false; } // palVary diff --git a/engines/sci/gui/gui_palette.h b/engines/sci/gui/gui_palette.h index ea63f7fe0f..f3eca7448d 100644 --- a/engines/sci/gui/gui_palette.h +++ b/engines/sci/gui/gui_palette.h @@ -50,7 +50,7 @@ public: void setFlag(uint16 fromColor, uint16 toColor, uint16 flag); void unsetFlag(uint16 fromColor, uint16 toColor, uint16 flag); void setIntensity(uint16 fromColor, uint16 toColor, uint16 intensity, bool setPalette); - void animate(byte fromColor, byte toColor, int speed); + bool animate(byte fromColor, byte toColor, int speed); GuiPalette _sysPalette; diff --git a/engines/sci/gui32/gui32.cpp b/engines/sci/gui32/gui32.cpp index fab3cb1d6c..bcda0e3611 100644 --- a/engines/sci/gui32/gui32.cpp +++ b/engines/sci/gui32/gui32.cpp @@ -1588,8 +1588,12 @@ void SciGui32::paletteSetIntensity(uint16 fromColor, uint16 toColor, uint16 inte #endif } -void SciGui32::paletteAnimate(uint16 fromColor, uint16 toColor, uint16 speed) { +bool SciGui32::paletteAnimate(uint16 fromColor, uint16 toColor, uint16 speed) { //warning("STUB"); + return false; +} + +void SciGui32::paletteAnimateSet() { } #define SHAKE_DOWN 1 diff --git a/engines/sci/gui32/gui32.h b/engines/sci/gui32/gui32.h index 2bd13ae850..3221242dd0 100644 --- a/engines/sci/gui32/gui32.h +++ b/engines/sci/gui32/gui32.h @@ -94,7 +94,8 @@ public: void paletteUnsetFlag(uint16 fromColor, uint16 toColor, uint16 flag); int16 paletteFind(uint16 r, uint16 g, uint16 b); void paletteSetIntensity(uint16 fromColor, uint16 toColor, uint16 intensity); - void paletteAnimate(uint16 fromColor, uint16 toColor, uint16 speed); + bool paletteAnimate(uint16 fromColor, uint16 toColor, uint16 speed); + void paletteAnimateSet(); void shakeScreen(uint16 shakeCount, uint16 directions); -- cgit v1.2.3