aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/graphics
diff options
context:
space:
mode:
authorFilippos Karapetis2011-01-22 13:01:10 +0000
committerFilippos Karapetis2011-01-22 13:01:10 +0000
commit89087b18c79885680ad1f0d17d36975ea7b06f13 (patch)
tree87e07190e5e610881db62cac72f47421f4d23850 /engines/sci/graphics
parent7c14cf2b1bddaf4ec9403f49a1fc09ec750ee6c6 (diff)
downloadscummvm-rg350-89087b18c79885680ad1f0d17d36975ea7b06f13.tar.gz
scummvm-rg350-89087b18c79885680ad1f0d17d36975ea7b06f13.tar.bz2
scummvm-rg350-89087b18c79885680ad1f0d17d36975ea7b06f13.zip
SCI21: Allow the game scripts to sync robot videos, like in SSCI. Also, references of the SciEngine class to itself via g_sci have been removed
svn-id: r55422
Diffstat (limited to 'engines/sci/graphics')
-rw-r--r--engines/sci/graphics/frameout.cpp4
-rw-r--r--engines/sci/graphics/paint32.cpp8
-rw-r--r--engines/sci/graphics/robot.cpp92
-rw-r--r--engines/sci/graphics/robot.h13
4 files changed, 73 insertions, 44 deletions
diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp
index 01b17ae4f8..ced9c00683 100644
--- a/engines/sci/graphics/frameout.cpp
+++ b/engines/sci/graphics/frameout.cpp
@@ -40,6 +40,7 @@
#include "sci/graphics/paint32.h"
#include "sci/graphics/palette.h"
#include "sci/graphics/picture.h"
+#include "sci/graphics/robot.h"
#include "sci/graphics/frameout.h"
namespace Sci {
@@ -338,6 +339,9 @@ static int16 GetLongest(const char *text, int16 maxWidth, GfxFont *font) {
}
void GfxFrameout::kernelFrameout() {
+ if (g_sci->_gfxRobot->isPlaying())
+ return;
+
_palette->palVaryUpdate();
for (PlaneList::iterator it = _planes.begin(); it != _planes.end(); it++) {
diff --git a/engines/sci/graphics/paint32.cpp b/engines/sci/graphics/paint32.cpp
index a2cf1c73ad..0167593084 100644
--- a/engines/sci/graphics/paint32.cpp
+++ b/engines/sci/graphics/paint32.cpp
@@ -25,6 +25,7 @@
#include "common/util.h"
#include "common/stack.h"
+
#include "graphics/primitives.h"
#include "sci/sci.h"
@@ -81,8 +82,11 @@ void GfxPaint32::kernelGraphDrawLine(Common::Point startPoint, Common::Point end
}
void GfxPaint32::debugDrawRobot(GuiResourceId robotId) {
- GfxRobot *test = new GfxRobot(g_sci->getResMan(), _screen, _palette, robotId);
- test->draw(0,0);
+ GfxRobot *test = new GfxRobot(g_sci->getResMan(), _screen, _palette);
+ test->init(robotId, 0, 0);
+ while (test->getCurFrame() + 1 < test->getFrameCount()) {
+ test->drawNextFrame();
+ }
delete test;
}
diff --git a/engines/sci/graphics/robot.cpp b/engines/sci/graphics/robot.cpp
index 768eba2214..853e111daa 100644
--- a/engines/sci/graphics/robot.cpp
+++ b/engines/sci/graphics/robot.cpp
@@ -57,10 +57,10 @@ namespace Sci {
// around the screen and go behind other objects. (...)
#ifdef ENABLE_SCI32
-GfxRobot::GfxRobot(ResourceManager *resMan, GfxScreen *screen, GfxPalette *palette, GuiResourceId resourceId)
- : _resMan(resMan), _screen(screen), _palette(palette), _resourceId(resourceId) {
- assert(resourceId != -1);
- initData(resourceId);
+GfxRobot::GfxRobot(ResourceManager *resMan, GfxScreen *screen, GfxPalette *palette)
+ : _resMan(resMan), _screen(screen), _palette(palette) {
+ _resourceId = -1;
+ _x = _y = 0;
}
GfxRobot::~GfxRobot() {
@@ -70,11 +70,17 @@ GfxRobot::~GfxRobot() {
delete[] _audioLen;
}
-void GfxRobot::initData(GuiResourceId resourceId) {
+void GfxRobot::init(GuiResourceId resourceId, uint16 x, uint16 y) {
char fileName[10];
uint32 fileSize;
- sprintf(fileName, "%d.rbt", resourceId);
+ // resourceId = 1305; // debug
+
+ _resourceId = resourceId;
+ _x = x;
+ _y = y;
+ _curFrame = 0;
+ sprintf(fileName, "%d.rbt", _resourceId);
Common::File robotFile;
if (robotFile.open(fileName)) {
@@ -98,28 +104,22 @@ void GfxRobot::initData(GuiResourceId resourceId) {
_hasSound = (_resourceData[25] != 0);
_palOffset = 60;
- if (_hasSound)
+
+ // Some robot files have sound, which doesn't start from frame 0
+ // (e.g. Phantasmagoria, robot 1305)
+ if (_hasSound && _audioSize > 14)
_palOffset += READ_LE_UINT32(_resourceData + 60) + 14;
getFrameOffsets();
assert(_imageStart[_frameCount] == fileSize);
+ setPalette();
+
debug("Robot %d, %d frames, sound: %s\n", resourceId, _frameCount, _hasSound ? "yes" : "no");
}
-void GfxRobot::draw(int x, int y) {
-
- return; // TODO: Remove once done
- // Play the audio of the robot file (for debugging)
-#if 0
- if (_hasSound) {
- Audio::SoundHandle _audioHandle;
- Audio::AudioStream *audioStream = g_sci->_audio->getRobotAudioStream(_resourceData);
- g_system->getMixer()->playStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream);
- }
-#endif
-
- byte *paletteData = _hasSound ?
+void GfxRobot::setPalette() {
+ byte *paletteData = (_hasSound && _audioSize > 14) ?
_resourceData + 60 + 14 + _audioSize :
_resourceData + 60;
uint16 paletteSize = READ_LE_UINT16(_resourceData + 16);
@@ -127,7 +127,6 @@ void GfxRobot::draw(int x, int y) {
Palette resourcePal;
byte robotPal[256 * 4];
- byte savePal[256 * 4];
int startIndex = READ_LE_UINT16(paletteData + 25);
int colorCount = READ_LE_UINT16(paletteData + 29);
@@ -136,13 +135,13 @@ void GfxRobot::draw(int x, int y) {
_palette->createFromData(paletteData, paletteSize, &resourcePal);
for (int i = 0; i < 256; ++i) {
- savePal[i * 4 + 0] = _palette->_sysPalette.colors[i].r;
- savePal[i * 4 + 1] = _palette->_sysPalette.colors[i].g;
- savePal[i * 4 + 2] = _palette->_sysPalette.colors[i].b;
- savePal[i * 4 + 3] = 0;
+ _savedPal[i * 4 + 0] = _palette->_sysPalette.colors[i].r;
+ _savedPal[i * 4 + 1] = _palette->_sysPalette.colors[i].g;
+ _savedPal[i * 4 + 2] = _palette->_sysPalette.colors[i].b;
+ _savedPal[i * 4 + 3] = 0;
}
- memcpy(robotPal, savePal, sizeof(savePal));
+ memcpy(robotPal, _savedPal, sizeof(_savedPal));
for (int i = 0; i < colorCount; ++i) {
int index = i + startIndex;
@@ -153,19 +152,34 @@ void GfxRobot::draw(int x, int y) {
}
g_system->setPalette(robotPal, 0, 256);
+}
- for (int i = 0; i < _frameCount; ++i) {
- int width, height;
-
- byte *pixels = assembleVideoFrame(i);
- getFrameDimensions(i, width, height);
- g_system->copyRectToScreen(pixels, width, x, y, width, height * getFrameScale(i) / 100);
- g_system->updateScreen();
- g_system->delayMillis(100);
- delete[] pixels;
+void GfxRobot::drawNextFrame() {
+ // Play the audio of the robot file (for debugging)
+#if 0
+ if (_hasSound) {
+ Audio::SoundHandle _audioHandle;
+ Audio::AudioStream *audioStream = g_sci->_audio->getRobotAudioStream(_resourceData);
+ g_system->getMixer()->playStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream);
}
+#endif
+
+ int width, height;
+
+ byte *pixels = assembleVideoFrame(_curFrame);
+ getFrameDimensions(_curFrame, width, height);
+ g_system->copyRectToScreen(pixels, width, _x, _y, width, height * getFrameScale(_curFrame) / 100);
+ g_system->updateScreen();
+ g_system->delayMillis(100);
+ delete[] pixels;
- g_system->setPalette(savePal, 0, 256);
+ _curFrame++;
+
+ if (_curFrame == _frameCount) {
+ // End of robot video, restore palette
+ g_system->setPalette(_savedPal, 0, 256);
+ _resourceId = -1;
+ }
}
void GfxRobot::getFrameOffsets() {
@@ -183,7 +197,7 @@ void GfxRobot::getFrameOffsets() {
if (frameDataOffset & 0x7ff)
frameDataOffset = (frameDataOffset & ~0x7ff)+0x800;
- _imageStart = new uint32[_frameCount+1];
+ _imageStart = new uint32[_frameCount + 1];
_audioStart = new uint32[_frameCount];
_audioLen = new uint32[_frameCount];
@@ -276,9 +290,7 @@ void GfxRobot::getFrameRect(int frame, Common::Rect &rect) {
int GfxRobot::getFrameScale(int frame) {
byte *videoData = _resourceData + _imageStart[frame];
- byte percentage = videoData[3];
-
- return percentage;
+ return videoData[3];
}
#endif
diff --git a/engines/sci/graphics/robot.h b/engines/sci/graphics/robot.h
index fc5f498862..d794c4ba60 100644
--- a/engines/sci/graphics/robot.h
+++ b/engines/sci/graphics/robot.h
@@ -33,10 +33,14 @@ namespace Sci {
#ifdef ENABLE_SCI32
class GfxRobot {
public:
- GfxRobot(ResourceManager *resMan, GfxScreen *screen, GfxPalette *palette, GuiResourceId resourceId);
+ GfxRobot(ResourceManager *resMan, GfxScreen *screen, GfxPalette *palette);
~GfxRobot();
- void draw(int x, int y);
+ void init(GuiResourceId resourceId, uint16 x, uint16 y);
+ void drawNextFrame();
+ uint16 getCurFrame() { return _curFrame; }
+ uint16 getFrameCount() { return _frameCount; }
+ bool isPlaying() { return _resourceId != -1; }
private:
void initData(GuiResourceId resourceId);
@@ -45,6 +49,7 @@ private:
void getFrameDimensions(int frame, int &width, int &height);
void getFrameRect(int frame, Common::Rect &rect); // Not sure what to use this for yet
int getFrameScale(int frame); // Scale factor (multiplied by 100). More like custom height, but why use a percentage for it?
+ void setPalette();
ResourceManager *_resMan;
GfxScreen *_screen;
@@ -52,7 +57,10 @@ private:
GuiResourceId _resourceId;
byte *_resourceData;
+ byte _savedPal[256 * 4];
+ uint16 _x;
+ uint16 _y;
//uint16 _width;
//uint16 _height;
uint16 _frameCount;
@@ -63,6 +71,7 @@ private:
uint32 *_imageStart;
uint32 *_audioStart;
uint32 *_audioLen;
+ uint16 _curFrame;
};
#endif