From f3db412d6f3dd90893eb90a084491b90acdddc9e Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sat, 25 Feb 2017 18:13:55 -0600 Subject: SCI32: Serialize Robots in SCI3 This is necessary for at least Lighthouse, which maintains the state of Robots across save games. --- engines/sci/video/robot_decoder.cpp | 17 ++++++++++---- engines/sci/video/robot_decoder.h | 46 ++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 13 deletions(-) (limited to 'engines/sci/video') diff --git a/engines/sci/video/robot_decoder.cpp b/engines/sci/video/robot_decoder.cpp index ba8a4683dd..6a4e912218 100644 --- a/engines/sci/video/robot_decoder.cpp +++ b/engines/sci/video/robot_decoder.cpp @@ -371,6 +371,8 @@ void RobotDecoder::initStream(const GuiResourceId robotId) { error("Unable to open robot file %s", fileName.c_str()); } + _robotId = robotId; + const uint16 id = stream->readUint16LE(); if (id != 0x16) { error("Invalid robot file %s", fileName.c_str()); @@ -437,17 +439,16 @@ void RobotDecoder::initAudio() { void RobotDecoder::initVideo(const int16 x, const int16 y, const int16 scale, const reg_t plane, const bool hasPalette, const uint16 paletteSize) { _position = Common::Point(x, y); - if (scale != 128) { - _scaleInfo.x = scale; - _scaleInfo.y = scale; - _scaleInfo.signal = kScaleSignalManual; - } + _scaleInfo.x = scale; + _scaleInfo.y = scale; + _scaleInfo.signal = scale == 128 ? kScaleSignalNone : kScaleSignalManual; _plane = g_sci->_gfxFrameout->getPlanes().findByObject(plane); if (_plane == nullptr) { error("Invalid plane %04x:%04x passed to RobotDecoder::open", PRINT_REG(plane)); } + _planeId = plane; _minFrameRate = _frameRate - kMaxFrameRateDrift; _maxFrameRate = _frameRate + kMaxFrameRateDrift; @@ -585,6 +586,8 @@ void RobotDecoder::close() { debugC(kDebugLevelVideo, "Closing robot"); + _robotId = -1; + _planeId = NULL_REG; _status = kRobotStatusUninitialized; _videoSizes.clear(); _recordPositions.clear(); @@ -1343,6 +1346,10 @@ void RobotDecoder::expandCel(byte* target, const byte* source, const int16 celWi } } +int16 RobotDecoder::getPriority() const { + return _priority; +} + void RobotDecoder::setPriority(const int16 newPriority) { _priority = newPriority; } diff --git a/engines/sci/video/robot_decoder.h b/engines/sci/video/robot_decoder.h index 9d8c720968..aa1d9da75c 100644 --- a/engines/sci/video/robot_decoder.h +++ b/engines/sci/video/robot_decoder.h @@ -469,23 +469,25 @@ public: #pragma mark RobotDecoder /** - * RobotDecoder implements the logic required - * for Robot animations. - * - * @note A paused or finished RobotDecoder was - * classified as serializable in SCI3, but the - * save/load code would attempt to use uninitialised - * values, so it seems that robots were not ever - * actually able to be saved. + * RobotDecoder implements the logic required for Robot animations. */ class RobotDecoder { public: RobotDecoder(SegManager *segMan); ~RobotDecoder(); + GuiResourceId getResourceId() const { + return _robotId; + } + private: SegManager *_segMan; + /** + * The ID of the currently loaded robot. + */ + GuiResourceId _robotId; + #pragma mark Constants public: /** @@ -1174,6 +1176,27 @@ private: #pragma mark - #pragma mark Rendering public: + /** + * Gets the plane used to render the robot. + */ + const reg_t getPlaneId() const { + return _planeId; + } + + /** + * Gets the origin of the robot. + */ + Common::Point getPosition() const { + return _position; + } + + /** + * Gets the scale of the robot. + */ + int16 getScale() const { + return _scaleInfo.x; + } + /** * Puts the current dimensions of the robot, in game script * coordinates, into the given rect, and returns the total @@ -1207,6 +1230,8 @@ public: */ void expandCel(byte *target, const byte* source, const int16 celWidth, const int16 celHeight) const; + int16 getPriority() const; + /** * Sets the visual priority of the robot. * @see Plane::_priority @@ -1291,6 +1316,11 @@ private: */ DecompressorLZS _decompressor; + /** + * The ID of the robot plane. + */ + reg_t _planeId; + /** * The origin of the robot animation, in screen * coordinates. -- cgit v1.2.3