aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2015-03-16 08:07:24 -0400
committerPaul Gilbert2015-03-16 08:07:24 -0400
commitb762bebf27ce7c231dd17fc05bc32f72911e6ed5 (patch)
tree7152067e080d1257a65c0750a6d923ad7f05f82b
parent02657f5a91bba15c7d494f71d0c975ece7178861 (diff)
downloadscummvm-rg350-b762bebf27ce7c231dd17fc05bc32f72911e6ed5.tar.gz
scummvm-rg350-b762bebf27ce7c231dd17fc05bc32f72911e6ed5.tar.bz2
scummvm-rg350-b762bebf27ce7c231dd17fc05bc32f72911e6ed5.zip
SHERLOCK: Implement sprite palette loading and fade out
-rw-r--r--engines/sherlock/animation.cpp12
-rw-r--r--engines/sherlock/events.cpp11
-rw-r--r--engines/sherlock/events.h4
-rw-r--r--engines/sherlock/graphics.cpp32
-rw-r--r--engines/sherlock/graphics.h7
-rw-r--r--engines/sherlock/sprite.cpp17
-rw-r--r--engines/sherlock/sprite.h3
7 files changed, 84 insertions, 2 deletions
diff --git a/engines/sherlock/animation.cpp b/engines/sherlock/animation.cpp
index 4111f6f88f..2e9eb294d3 100644
--- a/engines/sherlock/animation.cpp
+++ b/engines/sherlock/animation.cpp
@@ -67,6 +67,9 @@ Animation::Animation(SherlockEngine *vm): _vm(vm) {
void Animation::playPrologue(const Common::String &filename, int minDelay, int fade,
bool setPalette, int speed) {
+ EventsManager &events = *_vm->_events;
+ Screen &screen = *_vm->_screen;
+
// Check for any any sound frames for the given animation
const int *soundFrames = checkForSoundFrames(filename);
@@ -93,6 +96,15 @@ void Animation::playPrologue(const Common::String &filename, int minDelay, int f
Common::SeekableReadStream *vdaStream = _vm->_res->load(vdaName);
Sprite sprite(*vdaStream, true);
+ events.delay(minDelay);
+ if (fade != 0 && fade != 255)
+ screen.fadeToBlack();
+
+ if (setPalette) {
+ if (fade != 255)
+ screen.setPalette(sprite._palette);
+ }
+
// TODO
diff --git a/engines/sherlock/events.cpp b/engines/sherlock/events.cpp
index fdcf61e46f..4a51c4a5fb 100644
--- a/engines/sherlock/events.cpp
+++ b/engines/sherlock/events.cpp
@@ -116,6 +116,15 @@ void EventsManager::pollEvents() {
}
/**
+ * Poll for events and introduce a small delay, to allow the system to
+ * yield to other running programs
+ */
+void EventsManager::pollEventsAndWait() {
+ pollEvents();
+ g_system->delayMillis(10);
+}
+
+/**
* Check whether it's time to display the next screen frame
*/
bool EventsManager::checkForNextFrameCounter() {
@@ -149,7 +158,7 @@ void EventsManager::clearEvents() {
}
/**
- * Delay for a given number of frames/cycles
+ * Delay for a given number of cycles, where each cycle is 1/60th of a second
*/
void EventsManager::delay(int cycles) {
uint32 totalMilli = cycles * 1000 / GAME_FRAME_RATE;
diff --git a/engines/sherlock/events.h b/engines/sherlock/events.h
index 26f4ddb2d5..f4e6964ef5 100644
--- a/engines/sherlock/events.h
+++ b/engines/sherlock/events.h
@@ -31,7 +31,7 @@ namespace Sherlock {
enum CursorType { CURSOR_NONE = 0 };
-#define GAME_FRAME_RATE 50
+#define GAME_FRAME_RATE 60
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
class SherlockEngine;
@@ -63,6 +63,8 @@ public:
void pollEvents();
+ void pollEventsAndWait();
+
Common::Point mousePos() const { return _mousePos; }
uint32 getFrameCounter() const { return _frameCounter; }
diff --git a/engines/sherlock/graphics.cpp b/engines/sherlock/graphics.cpp
index 5c6c94606e..583389e060 100644
--- a/engines/sherlock/graphics.cpp
+++ b/engines/sherlock/graphics.cpp
@@ -23,6 +23,7 @@
#include "sherlock/graphics.h"
#include "sherlock/sherlock.h"
#include "common/system.h"
+#include "graphics/palette.h"
namespace Sherlock {
@@ -65,4 +66,35 @@ void Screen::update() {
g_system->updateScreen();
}
+void Screen::getPalette(byte palette[PALETTE_SIZE]) {
+ g_system->getPaletteManager()->grabPalette(palette, 0, PALETTE_COUNT);
+}
+
+void Screen::setPalette(const byte palette[PALETTE_SIZE]) {
+ g_system->getPaletteManager()->setPalette(palette, 0, PALETTE_COUNT);
+}
+
+void Screen::fadeToBlack() {
+ const int FADE_AMOUNT = 2;
+ bool repeatFlag;
+ byte *srcP;
+ int count;
+ byte tempPalette[PALETTE_SIZE];
+
+ getPalette(tempPalette);
+ do {
+ repeatFlag = false;
+ for (srcP = &tempPalette[0], count = 0; count < PALETTE_SIZE; ++count, ++srcP) {
+ int v = *srcP;
+ if (v) {
+ repeatFlag = true;
+ *srcP = MAX(*srcP - FADE_AMOUNT, 0);
+ }
+ }
+
+ setPalette(tempPalette);
+ _vm->_events->pollEventsAndWait();
+ } while (repeatFlag && !_vm->shouldQuit());
+}
+
} // End of namespace Sherlock
diff --git a/engines/sherlock/graphics.h b/engines/sherlock/graphics.h
index 97daaef6e3..0385deebde 100644
--- a/engines/sherlock/graphics.h
+++ b/engines/sherlock/graphics.h
@@ -31,6 +31,7 @@
namespace Sherlock {
#define PALETTE_SIZE 768
+#define PALETTE_COUNT 256
class SherlockEngine;
@@ -53,6 +54,12 @@ public:
void setFont(int fontNumber);
void update();
+
+ void getPalette(byte palette[PALETTE_SIZE]);
+
+ void setPalette(const byte palette[PALETTE_SIZE]);
+
+ void fadeToBlack();
};
} // End of namespace Sherlock
diff --git a/engines/sherlock/sprite.cpp b/engines/sherlock/sprite.cpp
index ee7c8e5019..c8d9ab55e3 100644
--- a/engines/sherlock/sprite.cpp
+++ b/engines/sherlock/sprite.cpp
@@ -21,11 +21,13 @@
*/
#include "sherlock/sprite.h"
+#include "sherlock/graphics.h"
#include "common/debug.h"
namespace Sherlock {
Sprite::Sprite(Common::SeekableReadStream &stream, bool skipPal) {
+ Common::fill(&_palette[0], &_palette[PALETTE_SIZE], 0);
load(stream, skipPal);
}
@@ -38,6 +40,8 @@ Sprite::~Sprite() {
* Load the data of the sprite
*/
void Sprite::load(Common::SeekableReadStream &stream, bool skipPal) {
+ loadPalette(stream);
+
while (stream.pos() < stream.size()) {
SpriteFrame frame;
frame._width = stream.readUint16LE() + 1;
@@ -71,6 +75,19 @@ void Sprite::load(Common::SeekableReadStream &stream, bool skipPal) {
}
/**
+ * Gets the palette at the start of the sprite file
+ */
+void Sprite::loadPalette(Common::SeekableReadStream &stream) {
+ int v1 = stream.readUint16LE() + 1;
+ int v2 = stream.readUint16LE() + 1;
+ int size = v1 * v2;
+ assert((size - 12) == PALETTE_SIZE);
+
+ stream.seek(4 + 12, SEEK_CUR);
+ stream.read(&_palette[0], PALETTE_SIZE);
+}
+
+/**
* Decompress a single frame for the sprite
*/
void Sprite::decompressFrame(SpriteFrame &frame, const byte *src) {
diff --git a/engines/sherlock/sprite.h b/engines/sherlock/sprite.h
index 17566c81bd..5a510b2548 100644
--- a/engines/sherlock/sprite.h
+++ b/engines/sherlock/sprite.h
@@ -44,8 +44,11 @@ struct SpriteFrame {
class Sprite: public Common::Array<SpriteFrame> {
private:
void load(Common::SeekableReadStream &stream, bool skipPal);
+ void loadPalette(Common::SeekableReadStream &stream);
void decompressFrame(SpriteFrame &frame, const byte *src);
public:
+ byte _palette[256 * 3];
+public:
Sprite(Common::SeekableReadStream &stream, bool skipPal = false);
~Sprite();
};