aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25')
-rw-r--r--engines/sword25/console.cpp3
-rw-r--r--engines/sword25/console.h3
-rw-r--r--engines/sword25/detection.cpp5
-rw-r--r--engines/sword25/fmv/movieplayer.cpp29
-rw-r--r--engines/sword25/fmv/movieplayer.h3
-rw-r--r--engines/sword25/fmv/movieplayer_script.cpp3
-rw-r--r--engines/sword25/fmv/theora_decoder.cpp310
-rw-r--r--engines/sword25/fmv/theora_decoder.h53
-rw-r--r--engines/sword25/gfx/animation.cpp3
-rw-r--r--engines/sword25/gfx/animation.h3
-rw-r--r--engines/sword25/gfx/animationdescription.cpp3
-rw-r--r--engines/sword25/gfx/animationdescription.h3
-rw-r--r--engines/sword25/gfx/animationresource.cpp3
-rw-r--r--engines/sword25/gfx/animationresource.h3
-rw-r--r--engines/sword25/gfx/animationtemplate.cpp3
-rw-r--r--engines/sword25/gfx/animationtemplate.h3
-rw-r--r--engines/sword25/gfx/animationtemplateregistry.cpp3
-rw-r--r--engines/sword25/gfx/animationtemplateregistry.h3
-rw-r--r--engines/sword25/gfx/bitmap.cpp3
-rw-r--r--engines/sword25/gfx/bitmap.h3
-rw-r--r--engines/sword25/gfx/bitmapresource.h3
-rw-r--r--engines/sword25/gfx/dynamicbitmap.cpp3
-rw-r--r--engines/sword25/gfx/dynamicbitmap.h3
-rw-r--r--engines/sword25/gfx/fontresource.cpp3
-rw-r--r--engines/sword25/gfx/fontresource.h3
-rw-r--r--engines/sword25/gfx/graphicengine.cpp33
-rw-r--r--engines/sword25/gfx/graphicengine.h17
-rw-r--r--engines/sword25/gfx/graphicengine_script.cpp3
-rw-r--r--engines/sword25/gfx/image/art.cpp3
-rw-r--r--engines/sword25/gfx/image/art.h3
-rw-r--r--engines/sword25/gfx/image/image.h3
-rw-r--r--engines/sword25/gfx/image/pngloader.cpp67
-rw-r--r--engines/sword25/gfx/image/pngloader.h12
-rw-r--r--engines/sword25/gfx/image/renderedimage.cpp104
-rw-r--r--engines/sword25/gfx/image/renderedimage.h3
-rw-r--r--engines/sword25/gfx/image/swimage.cpp7
-rw-r--r--engines/sword25/gfx/image/swimage.h3
-rw-r--r--engines/sword25/gfx/image/vectorimage.cpp3
-rw-r--r--engines/sword25/gfx/image/vectorimage.h3
-rw-r--r--engines/sword25/gfx/image/vectorimagerenderer.cpp3
-rw-r--r--engines/sword25/gfx/panel.cpp3
-rw-r--r--engines/sword25/gfx/panel.h3
-rw-r--r--engines/sword25/gfx/renderobject.cpp3
-rw-r--r--engines/sword25/gfx/renderobject.h3
-rw-r--r--engines/sword25/gfx/renderobjectmanager.cpp3
-rw-r--r--engines/sword25/gfx/renderobjectmanager.h3
-rw-r--r--engines/sword25/gfx/renderobjectptr.h3
-rw-r--r--engines/sword25/gfx/renderobjectregistry.h3
-rw-r--r--engines/sword25/gfx/rootrenderobject.h3
-rw-r--r--engines/sword25/gfx/screenshot.cpp75
-rw-r--r--engines/sword25/gfx/screenshot.h3
-rw-r--r--engines/sword25/gfx/staticbitmap.cpp3
-rw-r--r--engines/sword25/gfx/staticbitmap.h3
-rw-r--r--engines/sword25/gfx/text.cpp3
-rw-r--r--engines/sword25/gfx/text.h3
-rw-r--r--engines/sword25/gfx/timedrenderobject.cpp3
-rw-r--r--engines/sword25/gfx/timedrenderobject.h3
-rw-r--r--engines/sword25/input/inputengine.cpp3
-rw-r--r--engines/sword25/input/inputengine.h3
-rw-r--r--engines/sword25/input/inputengine_script.cpp3
-rw-r--r--engines/sword25/kernel/common.h3
-rw-r--r--engines/sword25/kernel/filesystemutil.cpp3
-rw-r--r--engines/sword25/kernel/filesystemutil.h3
-rw-r--r--engines/sword25/kernel/inputpersistenceblock.cpp3
-rw-r--r--engines/sword25/kernel/inputpersistenceblock.h3
-rw-r--r--engines/sword25/kernel/kernel.cpp6
-rw-r--r--engines/sword25/kernel/kernel.h3
-rw-r--r--engines/sword25/kernel/kernel_script.cpp120
-rw-r--r--engines/sword25/kernel/objectregistry.h3
-rw-r--r--engines/sword25/kernel/outputpersistenceblock.cpp3
-rw-r--r--engines/sword25/kernel/outputpersistenceblock.h3
-rw-r--r--engines/sword25/kernel/persistable.h3
-rw-r--r--engines/sword25/kernel/persistenceblock.h3
-rw-r--r--engines/sword25/kernel/persistenceservice.cpp94
-rw-r--r--engines/sword25/kernel/persistenceservice.h3
-rw-r--r--engines/sword25/kernel/resmanager.cpp18
-rw-r--r--engines/sword25/kernel/resmanager.h8
-rw-r--r--engines/sword25/kernel/resource.cpp3
-rw-r--r--engines/sword25/kernel/resource.h3
-rw-r--r--engines/sword25/kernel/resservice.h3
-rw-r--r--engines/sword25/kernel/service.h3
-rw-r--r--engines/sword25/math/geometry.h3
-rw-r--r--engines/sword25/math/geometry_script.cpp3
-rw-r--r--engines/sword25/math/line.h3
-rw-r--r--engines/sword25/math/polygon.cpp3
-rw-r--r--engines/sword25/math/polygon.h3
-rw-r--r--engines/sword25/math/region.cpp3
-rw-r--r--engines/sword25/math/region.h3
-rw-r--r--engines/sword25/math/regionregistry.cpp3
-rw-r--r--engines/sword25/math/regionregistry.h3
-rw-r--r--engines/sword25/math/vertex.cpp3
-rw-r--r--engines/sword25/math/vertex.h3
-rw-r--r--engines/sword25/math/walkregion.cpp3
-rw-r--r--engines/sword25/math/walkregion.h3
-rw-r--r--engines/sword25/package/packagemanager.cpp3
-rw-r--r--engines/sword25/package/packagemanager.h3
-rw-r--r--engines/sword25/package/packagemanager_script.cpp3
-rw-r--r--engines/sword25/script/lua_extensions.cpp3
-rw-r--r--engines/sword25/script/luabindhelper.cpp3
-rw-r--r--engines/sword25/script/luabindhelper.h3
-rw-r--r--engines/sword25/script/luacallback.cpp3
-rw-r--r--engines/sword25/script/luacallback.h3
-rw-r--r--engines/sword25/script/luascript.cpp3
-rw-r--r--engines/sword25/script/luascript.h3
-rw-r--r--engines/sword25/script/script.h3
-rw-r--r--engines/sword25/sfx/soundengine.cpp7
-rw-r--r--engines/sword25/sfx/soundengine.h3
-rw-r--r--engines/sword25/sfx/soundengine_script.cpp3
-rw-r--r--engines/sword25/sword25.cpp3
-rw-r--r--engines/sword25/sword25.h3
-rw-r--r--engines/sword25/util/lua/lauxlib.cpp7
-rw-r--r--engines/sword25/util/lua/liolib.cpp20
-rw-r--r--engines/sword25/util/lua/llex.cpp7
-rw-r--r--engines/sword25/util/lua/loslib.cpp39
-rw-r--r--engines/sword25/util/lua/luaconf.h41
115 files changed, 421 insertions, 937 deletions
diff --git a/engines/sword25/console.cpp b/engines/sword25/console.cpp
index 902d9a5b72..5d15f189ab 100644
--- a/engines/sword25/console.cpp
+++ b/engines/sword25/console.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#include "sword25/console.h"
diff --git a/engines/sword25/console.h b/engines/sword25/console.h
index dcf8082d3c..9e2516ccf0 100644
--- a/engines/sword25/console.h
+++ b/engines/sword25/console.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#ifndef SWORD25_CONSOLE_H
diff --git a/engines/sword25/detection.cpp b/engines/sword25/detection.cpp
index fe24675f8a..caa1cf51ac 100644
--- a/engines/sword25/detection.cpp
+++ b/engines/sword25/detection.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#include "base/plugins.h"
@@ -105,7 +102,7 @@ public:
Sword25MetaEngine() : AdvancedMetaEngine(detectionParams) {}
virtual const char *getName() const {
- return "The Broken Sword 2.5 Engine";
+ return "Broken Sword 2.5";
}
virtual const char *getOriginalCopyright() const {
diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp
index 975f08be22..d267506ae2 100644
--- a/engines/sword25/fmv/movieplayer.cpp
+++ b/engines/sword25/fmv/movieplayer.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -49,7 +46,7 @@ namespace Sword25 {
#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */
#ifdef USE_THEORADEC
-MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), _decoder(g_system->getMixer()) {
+MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), _decoder() {
if (!registerScriptBindings())
error("Script bindings could not be registered.");
else
@@ -122,21 +119,23 @@ bool MoviePlayer::pause() {
void MoviePlayer::update() {
if (_decoder.isVideoLoaded()) {
- const Graphics::Surface *s = _decoder.decodeNextFrame();
- if (s) {
- // Transfer the next frame
- assert(s->format.bytesPerPixel == 4);
+ if (_decoder.endOfVideo()) {
+ // Movie complete, so unload the movie
+ unloadMovie();
+ } else {
+ const Graphics::Surface *s = _decoder.decodeNextFrame();
+ if (s) {
+ // Transfer the next frame
+ assert(s->format.bytesPerPixel == 4);
#ifdef THEORA_INDIRECT_RENDERING
- byte *frameData = (byte *)s->getBasePtr(0, 0);
- _outputBitmap->setContent(frameData, s->pitch * s->h, 0, s->pitch);
+ byte *frameData = (byte *)s->getBasePtr(0, 0);
+ _outputBitmap->setContent(frameData, s->pitch * s->h, 0, s->pitch);
#else
- g_system->copyRectToScreen((byte *)s->getBasePtr(0, 0), s->pitch, _outX, _outY, MIN(s->w, _backSurface->w), MIN(s->h, _backSurface->h));
- g_system->updateScreen();
+ g_system->copyRectToScreen((byte *)s->getBasePtr(0, 0), s->pitch, _outX, _outY, MIN(s->w, _backSurface->w), MIN(s->h, _backSurface->h));
+ g_system->updateScreen();
#endif
- } else {
- // Movie complete, so unload the movie
- unloadMovie();
+ }
}
}
}
diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h
index df0792c8a8..1d256e56ba 100644
--- a/engines/sword25/fmv/movieplayer.h
+++ b/engines/sword25/fmv/movieplayer.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp
index dce9048438..8359059b85 100644
--- a/engines/sword25/fmv/movieplayer_script.cpp
+++ b/engines/sword25/fmv/movieplayer_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp
index 86236fbd21..07cb56356d 100644
--- a/engines/sword25/fmv/theora_decoder.cpp
+++ b/engines/sword25/fmv/theora_decoder.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -42,7 +39,8 @@
#ifdef USE_THEORADEC
#include "common/system.h"
#include "common/textconsole.h"
-#include "graphics/conversion.h"
+#include "common/util.h"
+#include "graphics/yuv_to_rgb.h"
#include "audio/decoders/raw.h"
#include "sword25/kernel/common.h"
@@ -54,7 +52,7 @@ static double rint(double v) {
return floor(v + 0.5);
}
-TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : _mixer(mixer) {
+TheoraDecoder::TheoraDecoder(Audio::Mixer::SoundType soundType) {
_fileStream = 0;
_surface = 0;
@@ -62,7 +60,7 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT
_vorbisPacket = 0;
_theoraDecode = 0;
_theoraSetup = 0;
- _stateFlag = false;
+ _nextFrameStartTime = 0.0;
_soundType = soundType;
_audStream = 0;
@@ -70,7 +68,7 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT
ogg_sync_init(&_oggSync);
- _curFrame = 0;
+ _curFrame = -1;
_audiobuf = (ogg_int16_t *)malloc(AUDIOFD_FRAGSIZE * sizeof(ogg_int16_t));
reset();
@@ -103,6 +101,8 @@ int TheoraDecoder::bufferData() {
bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) {
close();
+ _endOfAudio = false;
+ _endOfVideo = false;
_fileStream = stream;
// start up Ogg stream synchronization layer
@@ -118,7 +118,8 @@ bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) {
// Ogg file open; parse the headers
// Only interested in Vorbis/Theora streams
- while (!_stateFlag) {
+ bool foundHeader = false;
+ while (!foundHeader) {
int ret = bufferData();
if (ret == 0)
@@ -131,7 +132,7 @@ bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) {
if (!ogg_page_bos(&_oggPage)) {
// don't leak the page; get it into the appropriate stream
queuePage(&_oggPage);
- _stateFlag = true;
+ foundHeader = true;
break;
}
@@ -275,23 +276,34 @@ bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) {
vorbis_block_init(&_vorbisDSP, &_vorbisBlock);
debug(3, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.",
_vorbisOut.serialno, _vorbisInfo.channels, _vorbisInfo.rate);
+
+ _audStream = Audio::makeQueuingAudioStream(_vorbisInfo.rate, _vorbisInfo.channels);
+
+ // Get enough audio data to start us off
+ while (_audStream->numQueuedStreams() == 0) {
+ // Queue more data
+ bufferData();
+ while (ogg_sync_pageout(&_oggSync, &_oggPage) > 0)
+ queuePage(&_oggPage);
+
+ queueAudio();
+ }
+
+ if (_audStream)
+ g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _audHandle, _audStream);
} else {
// tear down the partial vorbis setup
vorbis_info_clear(&_vorbisInfo);
vorbis_comment_clear(&_vorbisComment);
- }
-
- // open audio
- if (_vorbisPacket) {
- _audStream = createAudioStream();
- if (_audStream && _mixer)
- _mixer->playStream(_soundType, _audHandle, _audStream);
+ _endOfAudio = true;
}
_surface = new Graphics::Surface();
-
_surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, g_system->getScreenFormat());
+ // Set the frame rate
+ _frameRate = Common::Rational(_theoraInfo.fps_numerator, _theoraInfo.fps_denominator);
+
return true;
}
@@ -303,8 +315,8 @@ void TheoraDecoder::close() {
vorbis_comment_clear(&_vorbisComment);
vorbis_info_clear(&_vorbisInfo);
- if (_mixer)
- _mixer->stopHandle(*_audHandle);
+ g_system->getMixer()->stopHandle(*_audHandle);
+
_audStream = 0;
_vorbisPacket = false;
}
@@ -333,49 +345,8 @@ void TheoraDecoder::close() {
}
const Graphics::Surface *TheoraDecoder::decodeNextFrame() {
- int i, j;
-
- // we want a video and audio frame ready to go at all times. If
- // we have to buffer incoming, buffer the compressed data (ie, let
- // ogg do the buffering)
- while (_vorbisPacket && !_audiobufReady) {
- int ret;
- float **pcm;
-
- // if there's pending, decoded audio, grab it
- if ((ret = vorbis_synthesis_pcmout(&_vorbisDSP, &pcm)) > 0) {
- int count = _audiobufFill / 2;
- int maxsamples = ((AUDIOFD_FRAGSIZE - _audiobufFill) / _vorbisInfo.channels) >> 1;
- for (i = 0; i < ret && i < maxsamples; i++)
- for (j = 0; j < _vorbisInfo.channels; j++) {
- int val = CLIP((int)rint(pcm[j][i] * 32767.f), -32768, 32767);
- _audiobuf[count++] = val;
- }
-
- vorbis_synthesis_read(&_vorbisDSP, i);
- _audiobufFill += (i * _vorbisInfo.channels) << 1;
-
- if (_audiobufFill == AUDIOFD_FRAGSIZE)
- _audiobufReady = true;
-
-#if ENABLE_THEORA_SEEKING
- if (_vorbisDSP.granulepos >= 0)
- _audiobufGranulePos = _vorbisDSP.granulepos - ret + i;
- else
- _audiobufGranulePos += i;
-#endif
- } else {
-
- // no pending audio; is there a pending packet to decode?
- if (ogg_stream_packetout(&_vorbisOut, &_oggPacket) > 0) {
- if (vorbis_synthesis(&_vorbisBlock, &_oggPacket) == 0) // test for success!
- vorbis_synthesis_blockin(&_vorbisDSP, &_vorbisBlock);
- } else // we need more data; break out to suck in another page
- break;
- }
- }
-
- while (_theoraPacket && !_videobufReady) {
+ // First, let's get our frame
+ while (_theoraPacket) {
// theora is one in, one out...
if (ogg_stream_packetout(&_theoraOut, &_oggPacket) > 0) {
@@ -385,85 +356,120 @@ const Graphics::Surface *TheoraDecoder::decodeNextFrame() {
_ppInc = 0;
}
-#if ENABLE_THEORA_SEEKING
- // HACK: This should be set after a seek or a gap, but we might not have
- // a granulepos for the first packet (we only have them for the last
- // packet on a page), so we just set it as often as we get it.
- // To do this right, we should back-track from the last packet on the
- // page and compute the correct granulepos for the first packet after
- // a seek or a gap.
- if (_oggPacket.granulepos >= 0) {
- th_decode_ctl(_theoraDecode, TH_DECCTL_SET_GRANPOS, &_oggPacket.granulepos, sizeof(_oggPacket.granulepos));
- }
-
- if (th_decode_packetin(_theoraDecode, &_oggPacket, &_videobufGranulePos) == 0) {
- _videobufTime = th_granule_time(_theoraDecode, _videobufGranulePos);
-#else
if (th_decode_packetin(_theoraDecode, &_oggPacket, NULL) == 0) {
-#endif
_curFrame++;
- _videobufReady = true;
+
+ // Convert YUV data to RGB data
+ th_ycbcr_buffer yuv;
+ th_decode_ycbcr_out(_theoraDecode, yuv);
+ translateYUVtoRGBA(yuv);
+
+ if (_curFrame == 0)
+ _startTime = g_system->getMillis();
+
+ double time = th_granule_time(_theoraDecode, _oggPacket.granulepos);
+
+ // We need to calculate when the next frame should be shown
+ // This is all in floating point because that's what the Ogg code gives us
+ // Ogg is a lossy container format, so it doesn't always list the time to the
+ // next frame. In such cases, we need to calculate it ourselves.
+ if (time == -1.0)
+ _nextFrameStartTime += _frameRate.getInverse().toDouble();
+ else
+ _nextFrameStartTime = time;
+
+ // break out
+ break;
}
- } else
- break;
- }
+ } else {
+ // If we can't get any more frames, we're done.
+ if (_theoraOut.e_o_s || _fileStream->eos()) {
+ _endOfVideo = true;
+ break;
+ }
+
+ // Queue more data
+ bufferData();
+ while (ogg_sync_pageout(&_oggSync, &_oggPage) > 0)
+ queuePage(&_oggPage);
+ }
- if (!_videobufReady && !_audiobufReady && _fileStream->eos()) {
- return NULL;
+ // Update audio if we can
+ queueAudio();
}
- if (!_videobufReady || !_audiobufReady) {
- // no data yet for somebody. Grab another page
+ // Force at least some audio to be buffered
+ // TODO: 5 is very arbitrary. We probably should do something like QuickTime does.
+ while (!_endOfAudio && _audStream->numQueuedStreams() < 5) {
bufferData();
- while (ogg_sync_pageout(&_oggSync, &_oggPage) > 0) {
+ while (ogg_sync_pageout(&_oggSync, &_oggPage) > 0)
queuePage(&_oggPage);
+
+ bool queuedAudio = queueAudio();
+ if ((_vorbisOut.e_o_s || _fileStream->eos()) && !queuedAudio) {
+ _endOfAudio = true;
+ break;
}
}
- // If playback has begun, top audio buffer off immediately.
- if (_stateFlag && _audiobufReady) {
- _audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::NO, Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_STEREO);
+ return _surface;
+}
- // The audio mixer is now responsible for the old audio buffer.
- // We need to create a new one.
- _audiobuf = (ogg_int16_t *)malloc(AUDIOFD_FRAGSIZE * sizeof(ogg_int16_t));
- _audiobufFill = 0;
- _audiobufReady = false;
- }
+bool TheoraDecoder::queueAudio() {
+ if (!_audStream)
+ return false;
- // are we at or past time for this video frame?
- if (_stateFlag && _videobufReady) {
- th_ycbcr_buffer yuv;
+ bool queuedAudio = false;
- th_decode_ycbcr_out(_theoraDecode, yuv);
+ for (;;) {
+ float **pcm;
- // Convert YUV data to RGB data
- translateYUVtoRGBA(yuv, (byte *)_surface->getBasePtr(0, 0));
-
- _videobufReady = false;
- }
+ // if there's pending, decoded audio, grab it
+ int ret = vorbis_synthesis_pcmout(&_vorbisDSP, &pcm);
+ if (ret > 0) {
+ int count = _audiobufFill / 2;
+ int maxsamples = ((AUDIOFD_FRAGSIZE - _audiobufFill) / _vorbisInfo.channels) >> 1;
+ int i;
+ for (i = 0; i < ret && i < maxsamples; i++)
+ for (int j = 0; j < _vorbisInfo.channels; j++) {
+ int val = CLIP((int)rint(pcm[j][i] * 32767.f), -32768, 32767);
+ _audiobuf[count++] = val;
+ }
- // if our buffers either don't exist or are ready to go,
- // we can begin playback
- if ((!_theoraPacket || _videobufReady) &&
- (!_vorbisPacket || _audiobufReady))
- _stateFlag = true;
+ vorbis_synthesis_read(&_vorbisDSP, i);
+ _audiobufFill += (i * _vorbisInfo.channels) << 1;
- // same if we've run out of input
- if (_fileStream->eos())
- _stateFlag = true;
+ if (_audiobufFill == AUDIOFD_FRAGSIZE) {
+ _audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::NO, Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_STEREO);
- return _surface;
+ // The audio mixer is now responsible for the old audio buffer.
+ // We need to create a new one.
+ _audiobuf = (ogg_int16_t *)malloc(AUDIOFD_FRAGSIZE * sizeof(ogg_int16_t));
+ _audiobufFill = 0;
+ queuedAudio = true;
+ }
+ } else {
+ // no pending audio; is there a pending packet to decode?
+ if (ogg_stream_packetout(&_vorbisOut, &_oggPacket) > 0) {
+ if (vorbis_synthesis(&_vorbisBlock, &_oggPacket) == 0) // test for success!
+ vorbis_synthesis_blockin(&_vorbisDSP, &_vorbisBlock);
+ } else // we've buffered all we have, break out for now
+ return queuedAudio;
+ }
+ }
+
+ // Unreachable
+ return false;
}
void TheoraDecoder::reset() {
- FixedRateVideoDecoder::reset();
+ VideoDecoder::reset();
+
+ // FIXME: This does a rewind() instead of a reset()!
if (_fileStream)
_fileStream->seek(0);
- _videobufReady = false;
-
#if ENABLE_THEORA_SEEKING
_videobufGranulePos = -1;
_audiobufGranulePos = 0;
@@ -473,36 +479,39 @@ void TheoraDecoder::reset() {
_audiobufFill = 0;
_audiobufReady = false;
- _curFrame = 0;
+ _curFrame = -1;
_theoraPacket = 0;
_vorbisPacket = 0;
- _stateFlag = false;
}
bool TheoraDecoder::endOfVideo() const {
- return !isVideoLoaded();
+ return !isVideoLoaded() || (_endOfVideo && (!_audStream || (_audStream->endOfData() && _endOfAudio)));
}
+uint32 TheoraDecoder::getTimeToNextFrame() const {
+ if (endOfVideo() || _curFrame < 0)
+ return 0;
-uint32 TheoraDecoder::getElapsedTime() const {
- if (_audStream && _mixer)
- return _mixer->getSoundElapsedTime(*_audHandle);
+ uint32 elapsedTime = getElapsedTime();
+ uint32 nextFrameStartTime = (uint32)(_nextFrameStartTime * 1000);
+
+ if (nextFrameStartTime <= elapsedTime)
+ return 0;
- return FixedRateVideoDecoder::getElapsedTime();
+ return nextFrameStartTime - elapsedTime;
}
-Audio::QueuingAudioStream *TheoraDecoder::createAudioStream() {
- return Audio::makeQueuingAudioStream(_vorbisInfo.rate, _vorbisInfo.channels);
+uint32 TheoraDecoder::getElapsedTime() const {
+ if (_audStream)
+ return g_system->getMixer()->getSoundElapsedTime(*_audHandle);
+
+ return VideoDecoder::getElapsedTime();
}
-static void convertYUVtoBGRA(int y, int u, int v, byte *dst) {
- byte r, g, b;
- Graphics::YUV2RGB(y, u, v, r, g, b);
- *(dst + 0) = b;
- *(dst + 1) = g;
- *(dst + 2) = r;
- *(dst + 3) = 0xFF;
+void TheoraDecoder::pauseVideoIntern(bool pause) {
+ if (_audStream)
+ g_system->getMixer()->pauseHandle(*_audHandle, pause);
}
enum TheoraYUVBuffers {
@@ -511,7 +520,7 @@ enum TheoraYUVBuffers {
kBufferV = 2
};
-void TheoraDecoder::translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer, byte *pixelData) {
+void TheoraDecoder::translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer) {
// Width and height of all buffers have to be divisible by 2.
assert((YUVBuffer[kBufferY].width & 1) == 0);
assert((YUVBuffer[kBufferY].height & 1) == 0);
@@ -524,40 +533,7 @@ void TheoraDecoder::translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer, byte *pixelDa
assert(YUVBuffer[kBufferU].height == YUVBuffer[kBufferY].height >> 1);
assert(YUVBuffer[kBufferV].height == YUVBuffer[kBufferY].height >> 1);
- const byte *ySrc = YUVBuffer[kBufferY].data;
- const byte *uSrc = YUVBuffer[kBufferU].data;
- const byte *vSrc = YUVBuffer[kBufferV].data;
- byte *dst = pixelData;
- int u = 0, v = 0;
-
- const int blockSize = YUVBuffer[kBufferY].width << 2;
- const int halfHeight = YUVBuffer[kBufferY].height >> 1;
- const int halfWidth = YUVBuffer[kBufferY].width >> 1;
- const int yStep = (YUVBuffer[kBufferY].stride << 1) - YUVBuffer[kBufferY].width;
- // The UV step is usually 0, since in most cases stride == width.
- // The asserts at the top ensure that the U and V steps are equal
- // (and they must always be equal)
- const int uvStep = YUVBuffer[kBufferU].stride - YUVBuffer[kBufferU].width;
- const int stride = YUVBuffer[kBufferY].stride;
-
- for (int h = 0; h < halfHeight; ++h) {
- for (int w = 0; w < halfWidth; ++w) {
- u = *uSrc++;
- v = *vSrc++;
-
- for (int i = 0; i <= 1; i++) {
- convertYUVtoBGRA(*ySrc, u, v, dst);
- convertYUVtoBGRA(*(ySrc + stride), u, v, dst + blockSize);
- ySrc++;
- dst += 4; // BGRA
- }
- }
-
- dst += blockSize;
- ySrc += yStep;
- uSrc += uvStep;
- vSrc += uvStep;
- }
+ Graphics::convertYUV420ToRGB(_surface, YUVBuffer[kBufferY].data, YUVBuffer[kBufferU].data, YUVBuffer[kBufferV].data, YUVBuffer[kBufferY].width, YUVBuffer[kBufferY].height, YUVBuffer[kBufferY].stride, YUVBuffer[kBufferU].stride);
}
} // End of namespace Sword25
diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h
index 4ed2af5f98..10a05647c3 100644
--- a/engines/sword25/fmv/theora_decoder.h
+++ b/engines/sword25/fmv/theora_decoder.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#ifndef SWORD25_THEORADECODER_H
@@ -44,8 +41,6 @@ namespace Common {
class SeekableReadStream;
}
-//#define ENABLE_THEORA_SEEKING // enables the extra calculations used for video seeking
-
namespace Sword25 {
/**
@@ -54,9 +49,9 @@ namespace Sword25 {
* Video decoder used in engines:
* - sword25
*/
-class TheoraDecoder : public Video::FixedRateVideoDecoder {
+class TheoraDecoder : public Video::VideoDecoder {
public:
- TheoraDecoder(Audio::Mixer *mixer = 0, Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
+ TheoraDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
virtual ~TheoraDecoder();
/**
@@ -74,51 +69,39 @@ public:
*/
const Graphics::Surface *decodeNextFrame();
- bool isVideoLoaded() const {
- return _fileStream != 0;
- }
- bool isPaused() const {
- return (FixedRateVideoDecoder::isPaused() || !isVideoLoaded());
- }
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return _surface->w; }
+ uint16 getHeight() const { return _surface->h; }
- uint16 getWidth() const {
- return _surface->w;
- }
- uint16 getHeight() const {
- return _surface->h;
- }
uint32 getFrameCount() const {
// It is not possible to get frame count easily
// I.e. seeking is required
assert(0);
return 0;
}
- Graphics::PixelFormat getPixelFormat() const {
- return Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
- }
+ Graphics::PixelFormat getPixelFormat() const { return _surface->format; }
uint32 getElapsedTime() const;
+ uint32 getTimeToNextFrame() const;
bool endOfVideo() const;
protected:
- Common::Rational getFrameRate() const {
- return _frameRate;
- }
+ void pauseVideoIntern(bool pause);
private:
void queuePage(ogg_page *page);
+ bool queueAudio();
int bufferData();
- Audio::QueuingAudioStream *createAudioStream();
- void translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer, byte *pixelData);
+ void translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer);
-private:
Common::SeekableReadStream *_fileStream;
Graphics::Surface *_surface;
Common::Rational _frameRate;
- uint32 _frameCount;
+ double _nextFrameStartTime;
+ bool _endOfVideo;
+ bool _endOfAudio;
- Audio::Mixer *_mixer;
Audio::Mixer::SoundType _soundType;
Audio::SoundHandle *_audHandle;
Audio::QueuingAudioStream *_audStream;
@@ -139,25 +122,15 @@ private:
int _theoraPacket;
int _vorbisPacket;
- bool _stateFlag;
int _ppLevelMax;
int _ppLevel;
int _ppInc;
- // single frame video buffering
- bool _videobufReady;
-
// single audio fragment audio buffering
int _audiobufFill;
bool _audiobufReady;
ogg_int16_t *_audiobuf;
-
-#if ENABLE_THEORA_SEEKING
- double _videobufTime;
- ogg_int64_t _videobufGranulePos;
- ogg_int64_t _audiobufGranulePos; // time position of last sample
-#endif
};
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/animation.cpp b/engines/sword25/gfx/animation.cpp
index 5b56d708cb..22a4dfb71b 100644
--- a/engines/sword25/gfx/animation.cpp
+++ b/engines/sword25/gfx/animation.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animation.h b/engines/sword25/gfx/animation.h
index a530c02b12..55deacd333 100644
--- a/engines/sword25/gfx/animation.h
+++ b/engines/sword25/gfx/animation.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationdescription.cpp b/engines/sword25/gfx/animationdescription.cpp
index 68ba7b63a6..da0a660df9 100644
--- a/engines/sword25/gfx/animationdescription.cpp
+++ b/engines/sword25/gfx/animationdescription.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationdescription.h b/engines/sword25/gfx/animationdescription.h
index 88cbb23503..3b11686bb9 100644
--- a/engines/sword25/gfx/animationdescription.h
+++ b/engines/sword25/gfx/animationdescription.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationresource.cpp b/engines/sword25/gfx/animationresource.cpp
index f9347e3dad..a9c9cf9c29 100644
--- a/engines/sword25/gfx/animationresource.cpp
+++ b/engines/sword25/gfx/animationresource.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationresource.h b/engines/sword25/gfx/animationresource.h
index 0cbaf0a507..2a1e3ce882 100644
--- a/engines/sword25/gfx/animationresource.h
+++ b/engines/sword25/gfx/animationresource.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationtemplate.cpp b/engines/sword25/gfx/animationtemplate.cpp
index 835ae09fe8..19924302b9 100644
--- a/engines/sword25/gfx/animationtemplate.cpp
+++ b/engines/sword25/gfx/animationtemplate.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationtemplate.h b/engines/sword25/gfx/animationtemplate.h
index 06be94719d..b61ecfcf54 100644
--- a/engines/sword25/gfx/animationtemplate.h
+++ b/engines/sword25/gfx/animationtemplate.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationtemplateregistry.cpp b/engines/sword25/gfx/animationtemplateregistry.cpp
index c41a7cde55..43c099c89d 100644
--- a/engines/sword25/gfx/animationtemplateregistry.cpp
+++ b/engines/sword25/gfx/animationtemplateregistry.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/animationtemplateregistry.h b/engines/sword25/gfx/animationtemplateregistry.h
index 574ccce136..d3d02b2ac8 100644
--- a/engines/sword25/gfx/animationtemplateregistry.h
+++ b/engines/sword25/gfx/animationtemplateregistry.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/bitmap.cpp b/engines/sword25/gfx/bitmap.cpp
index 9010a9c981..593a426975 100644
--- a/engines/sword25/gfx/bitmap.cpp
+++ b/engines/sword25/gfx/bitmap.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/bitmap.h b/engines/sword25/gfx/bitmap.h
index 741269c423..caa1238558 100644
--- a/engines/sword25/gfx/bitmap.h
+++ b/engines/sword25/gfx/bitmap.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/bitmapresource.h b/engines/sword25/gfx/bitmapresource.h
index 9feca82184..f1278f3885 100644
--- a/engines/sword25/gfx/bitmapresource.h
+++ b/engines/sword25/gfx/bitmapresource.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/dynamicbitmap.cpp b/engines/sword25/gfx/dynamicbitmap.cpp
index 46c2af55d7..137d943575 100644
--- a/engines/sword25/gfx/dynamicbitmap.cpp
+++ b/engines/sword25/gfx/dynamicbitmap.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/dynamicbitmap.h b/engines/sword25/gfx/dynamicbitmap.h
index 1737bdf5fc..35ed9a9341 100644
--- a/engines/sword25/gfx/dynamicbitmap.h
+++ b/engines/sword25/gfx/dynamicbitmap.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/fontresource.cpp b/engines/sword25/gfx/fontresource.cpp
index 0f0496e9ab..f99987fc91 100644
--- a/engines/sword25/gfx/fontresource.cpp
+++ b/engines/sword25/gfx/fontresource.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/fontresource.h b/engines/sword25/gfx/fontresource.h
index 47aa581a9e..511f485658 100644
--- a/engines/sword25/gfx/fontresource.h
+++ b/engines/sword25/gfx/fontresource.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp
index 8bdf2a4a6e..6b1c2bc514 100644
--- a/engines/sword25/gfx/graphicengine.cpp
+++ b/engines/sword25/gfx/graphicengine.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -86,7 +83,6 @@ GraphicEngine::GraphicEngine(Kernel *pKernel) :
GraphicEngine::~GraphicEngine() {
unregisterScriptBindings();
_backSurface.free();
- _frameBuffer.free();
delete _thumbnail;
}
@@ -115,7 +111,6 @@ bool GraphicEngine::init(int width, int height, int bitDepth, int backbufferCoun
const Graphics::PixelFormat format = g_system->getScreenFormat();
_backSurface.create(width, height, format);
- _frameBuffer.create(width, height, format);
// Standardmäßig ist Vsync an.
setVsync(true);
@@ -151,18 +146,6 @@ bool GraphicEngine::endFrame() {
_renderObjectManagerPtr->render();
- // FIXME: The following hack doesn't really work (all the thumbnails are empty)
-#if 0
- // HACK: The frame buffer surface is only used as the base for creating thumbnails when saving the
- // game, since the _backSurface is blanked. Currently I'm doing a slightly hacky check and only
- // copying the back surface if line 50 (the first line after the interface area) is non-blank
- if (READ_LE_UINT32((byte *)_backSurface.pixels + (_backSurface.pitch * 50)) & 0xffffff) {
- // Make a copy of the current frame into the frame buffer
- Common::copy((byte *)_backSurface.pixels, (byte *)_backSurface.pixels +
- (_backSurface.pitch * _backSurface.h), (byte *)_frameBuffer.pixels);
- }
-#endif
-
g_system->updateScreen();
return true;
@@ -239,10 +222,6 @@ bool GraphicEngine::fill(const Common::Rect *fillRectPtr, uint color) {
return true;
}
-Graphics::Surface *GraphicEngine::getScreenshot() {
- return &_frameBuffer;
-}
-
// -----------------------------------------------------------------------------
// RESOURCE MANAGING
// -----------------------------------------------------------------------------
@@ -270,8 +249,9 @@ Resource *GraphicEngine::loadResource(const Common::String &filename) {
return pResource;
}
- // Load sprite image
- if (filename.hasSuffix(".png") || filename.hasSuffix(".b25s")) {
+ // Load sprite image. Savegame thumbnails are also loaded here.
+ if (filename.hasSuffix(".png") || filename.hasSuffix(".b25s") ||
+ filename.hasPrefix("/saves")) {
bool result = false;
RenderedImage *pImage = new RenderedImage(filename, result);
if (!result) {
@@ -358,7 +338,8 @@ bool GraphicEngine::canLoadResource(const Common::String &filename) {
filename.hasSuffix("_ani.xml") ||
filename.hasSuffix("_fnt.xml") ||
filename.hasSuffix(".swf") ||
- filename.hasSuffix(".b25s");
+ filename.hasSuffix(".b25s") ||
+ filename.hasPrefix("/saves");
}
void GraphicEngine::updateLastFrameDuration() {
@@ -387,7 +368,9 @@ bool GraphicEngine::saveThumbnailScreenshot(const Common::String &filename) {
// Note: In ScumMVM, rather than saivng the thumbnail to a file, we store it in memory
// until needed when creating savegame files
delete _thumbnail;
- _thumbnail = Screenshot::createThumbnail(&_frameBuffer);
+
+ _thumbnail = Screenshot::createThumbnail(&_backSurface);
+
return true;
}
diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h
index 38eecaa60f..04826c2e5a 100644
--- a/engines/sword25/gfx/graphicengine.h
+++ b/engines/sword25/gfx/graphicengine.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -146,17 +143,6 @@ public:
*/
bool saveThumbnailScreenshot(const Common::String &filename);
- /**
- * Reads the current contents of the frame buffer
- * Notes: This method is for creating screenshots. It is not very optimised. It should only be called
- * after a call to EndFrame(), and before the next call to StartFrame().
- * @param Width Returns the width of the frame buffer
- * @param Height Returns the height of the frame buffer
- * @param Data Returns the raw data of the frame buffer as an array of 32-bit color values.
- */
- Graphics::Surface *getScreenshot();
-
-
RenderObjectPtr<Panel> getMainPanel();
/**
@@ -246,9 +232,6 @@ public:
Graphics::Surface _backSurface;
Graphics::Surface *getSurface() { return &_backSurface; }
- Graphics::Surface _frameBuffer;
- Graphics::Surface *getFrameBuffer() { return &_frameBuffer; }
-
Common::SeekableReadStream *_thumbnail;
Common::SeekableReadStream *getThumbnail() { return _thumbnail; }
diff --git a/engines/sword25/gfx/graphicengine_script.cpp b/engines/sword25/gfx/graphicengine_script.cpp
index d8daaab32c..b4334195a1 100644
--- a/engines/sword25/gfx/graphicengine_script.cpp
+++ b/engines/sword25/gfx/graphicengine_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp
index 69f9425a53..cd7cfb6b69 100644
--- a/engines/sword25/gfx/image/art.cpp
+++ b/engines/sword25/gfx/image/art.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/art.h b/engines/sword25/gfx/image/art.h
index fe3bbd4982..bfeb31cc30 100644
--- a/engines/sword25/gfx/image/art.h
+++ b/engines/sword25/gfx/image/art.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/image.h b/engines/sword25/gfx/image/image.h
index 7029402c4a..f1934656da 100644
--- a/engines/sword25/gfx/image/image.h
+++ b/engines/sword25/gfx/image/image.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp
index f6c00b6968..6f370d8861 100644
--- a/engines/sword25/gfx/image/pngloader.cpp
+++ b/engines/sword25/gfx/image/pngloader.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -32,9 +29,6 @@
*
*/
-// Define to use ScummVM's PNG decoder, instead of libpng
-#define USE_INTERNAL_PNG_DECODER
-
#ifndef USE_INTERNAL_PNG_DECODER
// Disable symbol overrides so that we can use png.h
#define FORBIDDEN_SYMBOL_ALLOW_ALL
@@ -52,51 +46,6 @@
namespace Sword25 {
-/**
- * Load a NULL-terminated string from the given stream.
- */
-static Common::String loadString(Common::ReadStream &in, uint maxSize = 999) {
- Common::String result;
-
- while (!in.eos() && (result.size() < maxSize)) {
- char ch = (char)in.readByte();
- if (ch == '\0')
- break;
-
- result += ch;
- }
-
- return result;
-}
-
-/**
- * Check if the given data is a savegame, and if so, locate the
- * offset to the image data.
- * @return offset to image data if fileDataPtr contains a savegame; 0 otherwise
- */
-static uint findEmbeddedPNG(const byte *fileDataPtr, uint fileSize) {
- if (fileSize < 100)
- return 0;
- if (memcmp(fileDataPtr, "BS25SAVEGAME", 12))
- return 0;
-
- // Read in the header
- Common::MemoryReadStream stream(fileDataPtr, fileSize);
- stream.seek(0, SEEK_SET);
-
- // Read header information of savegame
- uint compressedGamedataSize;
- loadString(stream); // Marker
- loadString(stream); // Version
- loadString(stream); // Description
- Common::String gameSize = loadString(stream);
- compressedGamedataSize = atoi(gameSize.c_str());
- loadString(stream);
-
- // Return the offset of where the thumbnail starts
- return static_cast<uint>(stream.pos() + compressedGamedataSize);
-}
-
#ifndef USE_INTERNAL_PNG_DECODER
static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
const byte **ref = (const byte **)png_get_io_ptr(png_ptr);
@@ -238,12 +187,11 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&unc
}
bool PNGLoader::decodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) {
- uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize);
- return doDecodeImage(fileDataPtr + pngOffset, fileSize - pngOffset, uncompressedDataPtr, width, height, pitch);
+ return doDecodeImage(fileDataPtr, fileSize, uncompressedDataPtr, width, height, pitch);
}
-bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height) {
#ifndef USE_INTERNAL_PNG_DECODER
+bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height) {
// Check for valid PNG signature
if (!doIsCorrectImageFormat(fileDataPtr, fileSize))
return false;
@@ -280,17 +228,18 @@ bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &w
// Destroy libpng structures
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-#else
- // We don't need to read the image properties here...
-#endif
+
return true;
}
bool PNGLoader::imageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height) {
- uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize);
- return doImageProperties(fileDataPtr + pngOffset, fileSize - pngOffset, width, height);
+ return doImageProperties(fileDataPtr, fileSize, width, height);
}
+#else
+ // We don't need to read the image properties here...
+#endif
+
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/pngloader.h
index e0d68ff8b9..6b5f65ff57 100644
--- a/engines/sword25/gfx/image/pngloader.h
+++ b/engines/sword25/gfx/image/pngloader.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -40,6 +37,9 @@
namespace Sword25 {
+// Define to use ScummVM's PNG decoder, instead of libpng
+#define USE_INTERNAL_PNG_DECODER
+
/**
* Class for loading PNG files, and PNG data embedded into savegames.
*
@@ -50,7 +50,9 @@ protected:
PNGLoader() {} // Protected constructor to prevent instances
static bool doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch);
+#ifndef USE_INTERNAL_PNG_DECODER
static bool doImageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height);
+#endif
public:
@@ -72,6 +74,8 @@ public:
byte *&pUncompressedData,
int &width, int &height,
int &pitch);
+
+#ifndef USE_INTERNAL_PNG_DECODER
/**
* Extract the properties of an image.
* @param[in] fileDatePtr pointer to the image data
@@ -86,6 +90,8 @@ public:
static bool imageProperties(const byte *fileDatePtr, uint fileSize,
int &width,
int &height);
+#endif
+
};
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp
index 806d9b27ad..23bf2623ad 100644
--- a/engines/sword25/gfx/image/renderedimage.cpp
+++ b/engines/sword25/gfx/image/renderedimage.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -36,6 +33,7 @@
// INCLUDES
// -----------------------------------------------------------------------------
+#include "common/savefile.h"
#include "sword25/package/packagemanager.h"
#include "sword25/gfx/image/pngloader.h"
#include "sword25/gfx/image/renderedimage.h"
@@ -44,10 +42,88 @@
namespace Sword25 {
+// Duplicated from kernel/persistenceservice.cpp
+static Common::String generateSavegameFilename(uint slotID) {
+ char buffer[100];
+ // NOTE: This is hardcoded to sword25
+ snprintf(buffer, 100, "%s.%.3d", "sword25", slotID);
+ return Common::String(buffer);
+}
+
// -----------------------------------------------------------------------------
// CONSTRUCTION / DESTRUCTION
// -----------------------------------------------------------------------------
+/**
+ * Load a NULL-terminated string from the given stream.
+ */
+static Common::String loadString(Common::SeekableReadStream &in, uint maxSize = 999) {
+ Common::String result;
+
+ while (!in.eos() && (result.size() < maxSize)) {
+ char ch = (char)in.readByte();
+ if (ch == '\0')
+ break;
+
+ result += ch;
+ }
+
+ return result;
+}
+
+static byte *readSavegameThumbnail(const Common::String &filename, uint &fileSize, bool &isPNG) {
+ byte *pFileData;
+ Common::SaveFileManager *sfm = g_system->getSavefileManager();
+ int slotNum = atoi(filename.c_str() + filename.size() - 3);
+ Common::InSaveFile *file = sfm->openForLoading(generateSavegameFilename(slotNum));
+
+ // Seek to the actual PNG image
+ loadString(*file); // Marker (BS25SAVEGAME)
+ loadString(*file); // Version
+ loadString(*file); // Description
+ uint32 compressedGamedataSize = atoi(loadString(*file).c_str());
+ loadString(*file); // Uncompressed game data size
+ file->skip(compressedGamedataSize); // Skip the game data and move to the thumbnail itself
+ uint32 thumbnailStart = file->pos();
+
+ fileSize = file->size() - thumbnailStart;
+
+ // Check if the thumbnail is in our own format, or a PNG file.
+ uint32 header = file->readUint32BE();
+ isPNG = (header != MKTAG('S','C','R','N'));
+ file->seek(-4, SEEK_CUR);
+
+ pFileData = new byte[fileSize];
+ file->read(pFileData, fileSize);
+ delete file;
+
+ return pFileData;
+}
+
+// TODO: Move this method into a more generic image loading class, together with the PNG reading code
+static bool decodeThumbnail(const byte *pFileData, uint fileSize, byte *&pUncompressedData, int &width, int &height, int &pitch) {
+ const byte *src = pFileData + 4; // skip header
+ width = READ_LE_UINT16(src); src += 2;
+ height = READ_LE_UINT16(src); src += 2;
+ src++; // version, ignored for now
+ pitch = width * 4;
+
+ uint32 totalSize = pitch * height;
+ pUncompressedData = new byte[totalSize];
+ uint32 *dst = (uint32 *)pUncompressedData; // treat as uint32, for pixelformat output
+ const Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
+ byte r, g, b;
+
+ for (uint32 i = 0; i < totalSize / 4; i++) {
+ r = *src++;
+ g = *src++;
+ b = *src++;
+ *dst++ = format.RGBToColor(r, g, b);
+ }
+
+ return true;
+}
+
RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
_data(0),
_width(0),
@@ -62,22 +138,37 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
// Load file
byte *pFileData;
uint fileSize;
- pFileData = pPackage->getFile(filename, &fileSize);
+
+ bool isPNG = true;
+
+ if (filename.hasPrefix("/saves")) {
+ pFileData = readSavegameThumbnail(filename, fileSize, isPNG);
+ } else {
+ pFileData = pPackage->getFile(filename, &fileSize);
+ }
+
if (!pFileData) {
error("File \"%s\" could not be loaded.", filename.c_str());
return;
}
+#ifndef USE_INTERNAL_PNG_DECODER
// Determine image properties
- int pitch;
if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) {
error("Could not read image properties.");
delete[] pFileData;
return;
}
+#endif
// Uncompress the image
- if (!PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch)) {
+ int pitch;
+ if (isPNG)
+ result = PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch);
+ else
+ result = decodeThumbnail(pFileData, fileSize, _data, _width, _height, pitch);
+
+ if (!result) {
error("Could not decode image.");
delete[] pFileData;
return;
@@ -88,7 +179,6 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
_doCleanup = true;
- result = true;
return;
}
diff --git a/engines/sword25/gfx/image/renderedimage.h b/engines/sword25/gfx/image/renderedimage.h
index e3f23747da..f92a5b39b4 100644
--- a/engines/sword25/gfx/image/renderedimage.h
+++ b/engines/sword25/gfx/image/renderedimage.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/swimage.cpp b/engines/sword25/gfx/image/swimage.cpp
index 3b9b939eb3..92d47368b2 100644
--- a/engines/sword25/gfx/image/swimage.cpp
+++ b/engines/sword25/gfx/image/swimage.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -56,14 +53,16 @@ SWImage::SWImage(const Common::String &filename, bool &result) :
return;
}
+#ifndef USE_INTERNAL_PNG_DECODER
// Determine image properties
- int pitch;
if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) {
error("Could not read image properties.");
return;
}
+#endif
// Uncompress the image
+ int pitch;
byte *pUncompressedData;
if (!PNGLoader::decodeImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) {
error("Could not decode image.");
diff --git a/engines/sword25/gfx/image/swimage.h b/engines/sword25/gfx/image/swimage.h
index a914c4f41f..5f348958b2 100644
--- a/engines/sword25/gfx/image/swimage.h
+++ b/engines/sword25/gfx/image/swimage.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/vectorimage.cpp b/engines/sword25/gfx/image/vectorimage.cpp
index 241e80bad3..9235ec2fcf 100644
--- a/engines/sword25/gfx/image/vectorimage.cpp
+++ b/engines/sword25/gfx/image/vectorimage.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/vectorimage.h b/engines/sword25/gfx/image/vectorimage.h
index 79a7519dda..959f251c14 100644
--- a/engines/sword25/gfx/image/vectorimage.h
+++ b/engines/sword25/gfx/image/vectorimage.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/vectorimagerenderer.cpp b/engines/sword25/gfx/image/vectorimagerenderer.cpp
index 99a47015fb..97dad3346d 100644
--- a/engines/sword25/gfx/image/vectorimagerenderer.cpp
+++ b/engines/sword25/gfx/image/vectorimagerenderer.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/panel.cpp b/engines/sword25/gfx/panel.cpp
index 955c317399..34ab4876ea 100644
--- a/engines/sword25/gfx/panel.cpp
+++ b/engines/sword25/gfx/panel.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/panel.h b/engines/sword25/gfx/panel.h
index 6fe96369a6..cbf04ce40f 100644
--- a/engines/sword25/gfx/panel.h
+++ b/engines/sword25/gfx/panel.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/renderobject.cpp b/engines/sword25/gfx/renderobject.cpp
index b044d906f3..a977eb80ba 100644
--- a/engines/sword25/gfx/renderobject.cpp
+++ b/engines/sword25/gfx/renderobject.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/renderobject.h b/engines/sword25/gfx/renderobject.h
index 7b7b9047f7..0b54ccc24b 100644
--- a/engines/sword25/gfx/renderobject.h
+++ b/engines/sword25/gfx/renderobject.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/renderobjectmanager.cpp b/engines/sword25/gfx/renderobjectmanager.cpp
index 1f7938f41f..38289991eb 100644
--- a/engines/sword25/gfx/renderobjectmanager.cpp
+++ b/engines/sword25/gfx/renderobjectmanager.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/renderobjectmanager.h b/engines/sword25/gfx/renderobjectmanager.h
index 8511382d6e..9e7efd8e60 100644
--- a/engines/sword25/gfx/renderobjectmanager.h
+++ b/engines/sword25/gfx/renderobjectmanager.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/renderobjectptr.h b/engines/sword25/gfx/renderobjectptr.h
index c22c6e83e7..7b7f190a01 100644
--- a/engines/sword25/gfx/renderobjectptr.h
+++ b/engines/sword25/gfx/renderobjectptr.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/renderobjectregistry.h b/engines/sword25/gfx/renderobjectregistry.h
index 988b676aa8..92d8c9b830 100644
--- a/engines/sword25/gfx/renderobjectregistry.h
+++ b/engines/sword25/gfx/renderobjectregistry.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/rootrenderobject.h b/engines/sword25/gfx/rootrenderobject.h
index e4e3fba3c8..4782fad175 100644
--- a/engines/sword25/gfx/rootrenderobject.h
+++ b/engines/sword25/gfx/rootrenderobject.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp
index 6ea2b574d6..8306d9ce6f 100644
--- a/engines/sword25/gfx/screenshot.cpp
+++ b/engines/sword25/gfx/screenshot.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -39,83 +36,31 @@
#include "common/textconsole.h"
#include "sword25/gfx/screenshot.h"
#include "sword25/kernel/filesystemutil.h"
-#include <png.h>
namespace Sword25 {
-#include "common/pack-start.h"
-struct RGB_PIXEL {
- byte red;
- byte green;
- byte blue;
-} PACKED_STRUCT;
-#include "common/pack-end.h"
-
-void userWriteFn(png_structp png_ptr, png_bytep data, png_size_t length) {
- static_cast<Common::WriteStream *>(png_get_io_ptr(png_ptr))->write(data, length);
-}
-
-void userFlushFn(png_structp png_ptr) {
-}
+#define THUMBNAIL_VERSION 1
bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream) {
- // Reserve buffer space
- RGB_PIXEL *pixelBuffer = new RGB_PIXEL[data->w * data->h];
-
// Convert the RGBA data to RGB
const byte *pSrc = (const byte *)data->getBasePtr(0, 0);
- RGB_PIXEL *pDest = pixelBuffer;
+
+ // Write our own custom header
+ stream->writeUint32BE(MKTAG('S','C','R','N')); // SCRN, short for "Screenshot"
+ stream->writeUint16LE(data->w);
+ stream->writeUint16LE(data->h);
+ stream->writeByte(THUMBNAIL_VERSION);
for (uint y = 0; y < data->h; y++) {
for (uint x = 0; x < data->w; x++) {
uint32 srcPixel = READ_LE_UINT32(pSrc);
pSrc += sizeof(uint32);
- pDest->red = (srcPixel >> 16) & 0xff;
- pDest->green = (srcPixel >> 8) & 0xff;
- pDest->blue = srcPixel & 0xff;
- ++pDest;
+ stream->writeByte((srcPixel >> 16) & 0xff); // R
+ stream->writeByte((srcPixel >> 8) & 0xff); // G
+ stream->writeByte(srcPixel & 0xff); // B
}
}
- png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr)
- error("Could not create PNG write-struct.");
-
- png_infop info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr)
- error("Could not create PNG info-struct.");
-
- // The compression buffer must be large enough to the entire image.
- // This ensures that only an IDAT chunk is created.
- // When buffer size is used 110% of the raw data size to be sure.
- png_set_compression_buffer_size(png_ptr, (data->w * data->h * 3 * 110) / 100);
-
- // Initialise PNG-Info structure
- png_set_IHDR(png_ptr, info_ptr,
- data->w, // Width
- data->h, // Height
- 8, // Bits depth
- PNG_COLOR_TYPE_RGB, // Color type
- PNG_INTERLACE_NONE, // No interlacing
- PNG_COMPRESSION_TYPE_DEFAULT, // Compression type
- PNG_FILTER_TYPE_DEFAULT); // Filter Type
-
- // Rowpointer erstellen
- png_bytep *rowPointers = new png_bytep[data->h];
- for (uint i = 0; i < data->h; i++) {
- rowPointers[i] = (png_bytep)&pixelBuffer[data->w * i];
- }
- png_set_rows(png_ptr, info_ptr, &rowPointers[0]);
-
- // Write out the png data to the file
- png_set_write_fn(png_ptr, (void *)stream, userWriteFn, userFlushFn);
- png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
-
- png_destroy_write_struct(&png_ptr, &info_ptr);
-
- delete[] pixelBuffer;
- delete[] rowPointers;
-
return true;
}
diff --git a/engines/sword25/gfx/screenshot.h b/engines/sword25/gfx/screenshot.h
index a0f615f9e6..e2e2dfc7f5 100644
--- a/engines/sword25/gfx/screenshot.h
+++ b/engines/sword25/gfx/screenshot.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/staticbitmap.cpp b/engines/sword25/gfx/staticbitmap.cpp
index 2e8d1ba071..60ad94e20f 100644
--- a/engines/sword25/gfx/staticbitmap.cpp
+++ b/engines/sword25/gfx/staticbitmap.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/staticbitmap.h b/engines/sword25/gfx/staticbitmap.h
index b5b4c4f5a2..e66ede02b4 100644
--- a/engines/sword25/gfx/staticbitmap.h
+++ b/engines/sword25/gfx/staticbitmap.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/text.cpp b/engines/sword25/gfx/text.cpp
index b1c1708565..8e18d2936d 100644
--- a/engines/sword25/gfx/text.cpp
+++ b/engines/sword25/gfx/text.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/text.h b/engines/sword25/gfx/text.h
index 42c1cd7c5d..a0d668014f 100644
--- a/engines/sword25/gfx/text.h
+++ b/engines/sword25/gfx/text.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/timedrenderobject.cpp b/engines/sword25/gfx/timedrenderobject.cpp
index e3b4d1990c..e35b0ae95b 100644
--- a/engines/sword25/gfx/timedrenderobject.cpp
+++ b/engines/sword25/gfx/timedrenderobject.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/timedrenderobject.h b/engines/sword25/gfx/timedrenderobject.h
index 6fee19882a..44c3b40528 100644
--- a/engines/sword25/gfx/timedrenderobject.h
+++ b/engines/sword25/gfx/timedrenderobject.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/input/inputengine.cpp b/engines/sword25/input/inputengine.cpp
index 769baafeed..bb9c2c8b40 100644
--- a/engines/sword25/input/inputengine.cpp
+++ b/engines/sword25/input/inputengine.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/input/inputengine.h b/engines/sword25/input/inputengine.h
index 40f801dde2..a84c215076 100644
--- a/engines/sword25/input/inputengine.h
+++ b/engines/sword25/input/inputengine.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/input/inputengine_script.cpp b/engines/sword25/input/inputengine_script.cpp
index d4f2719b62..db2619294c 100644
--- a/engines/sword25/input/inputengine_script.cpp
+++ b/engines/sword25/input/inputengine_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/common.h b/engines/sword25/kernel/common.h
index 487bfc5c78..8cfc81e981 100644
--- a/engines/sword25/kernel/common.h
+++ b/engines/sword25/kernel/common.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/filesystemutil.cpp b/engines/sword25/kernel/filesystemutil.cpp
index e5ec6c15db..281e7986df 100644
--- a/engines/sword25/kernel/filesystemutil.cpp
+++ b/engines/sword25/kernel/filesystemutil.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/filesystemutil.h b/engines/sword25/kernel/filesystemutil.h
index b75454c1c8..bb100123d9 100644
--- a/engines/sword25/kernel/filesystemutil.h
+++ b/engines/sword25/kernel/filesystemutil.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/inputpersistenceblock.cpp b/engines/sword25/kernel/inputpersistenceblock.cpp
index 26c924dc82..c1cd771e39 100644
--- a/engines/sword25/kernel/inputpersistenceblock.cpp
+++ b/engines/sword25/kernel/inputpersistenceblock.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/inputpersistenceblock.h b/engines/sword25/kernel/inputpersistenceblock.h
index f6ab256460..f643b06bc1 100644
--- a/engines/sword25/kernel/inputpersistenceblock.h
+++ b/engines/sword25/kernel/inputpersistenceblock.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp
index 99fec52040..f45137ce02 100644
--- a/engines/sword25/kernel/kernel.cpp
+++ b/engines/sword25/kernel/kernel.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -57,7 +54,8 @@ Kernel::Kernel() :
_input(0),
_package(0),
_script(0),
- _fmv(0)
+ _fmv(0),
+ _rnd("sword25")
{
_instance = this;
diff --git a/engines/sword25/kernel/kernel.h b/engines/sword25/kernel/kernel.h
index 3abf43d239..a0c2927fdc 100644
--- a/engines/sword25/kernel/kernel.h
+++ b/engines/sword25/kernel/kernel.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp
index 458f6b2deb..27a221d45f 100644
--- a/engines/sword25/kernel/kernel_script.cpp
+++ b/engines/sword25/kernel/kernel_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -42,45 +39,9 @@
namespace Sword25 {
-static int disconnectService(lua_State *L) {
- // This function apparently is not used by the game scripts
- lua_pushboolean(L, true);
-
- return 1;
-}
-
-static int getActiveServiceIdentifier(lua_State *L) {
- // This function apparently is not used by the game scripts
- lua_pushstring(L, "QUUX");
-
- return 1;
-}
-
-static int getSuperclassCount(lua_State *L) {
- // This function is only used by a single function in system/kernel.lua which is never called.
- lua_pushnumber(L, 0);
-
- return 1;
-}
-
-static int getSuperclassIdentifier(lua_State *L) {
- // This function is only used by a single function in system/kernel.lua which is never called.
- lua_pushstring(L, "FOO");
-
- return 1;
-}
-
-static int getServiceCount(lua_State *L) {
- // This function is only used by a single function in system/kernel.lua which is never called.
- lua_pushnumber(L, 0);
-
- return 1;
-}
-
-static int getServiceIdentifier(lua_State *L) {
- // This function is only used by a single function in system/kernel.lua which is never called.
- lua_pushstring(L, "BAR");
-
+// Marks a function that should never be used
+static int dummyFuncError(lua_State *L) {
+ error("Dummy function invoked by LUA");
return 1;
}
@@ -177,12 +138,12 @@ static int getUsedMemory(lua_State *L) {
static const char *KERNEL_LIBRARY_NAME = "Kernel";
static const luaL_reg KERNEL_FUNCTIONS[] = {
- {"DisconnectService", disconnectService},
- {"GetActiveServiceIdentifier", getActiveServiceIdentifier},
- {"GetSuperclassCount", getSuperclassCount},
- {"GetSuperclassIdentifier", getSuperclassIdentifier},
- {"GetServiceCount", getServiceCount},
- {"GetServiceIdentifier", getServiceIdentifier},
+ {"DisconnectService", dummyFuncError},
+ {"GetActiveServiceIdentifier", dummyFuncError},
+ {"GetSuperclassCount", dummyFuncError},
+ {"GetSuperclassIdentifier", dummyFuncError},
+ {"GetServiceCount", dummyFuncError},
+ {"GetServiceIdentifier", dummyFuncError},
{"GetMilliTicks", getMilliTicks},
{"GetTimer", getTimer},
{"StartService", startService},
@@ -241,20 +202,6 @@ static int setY(lua_State *L) {
return 0;
}
-static int getClientX(lua_State *L) {
- // This function apparently is not used by the game scripts
- lua_pushnumber(L, 0);
-
- return 1;
-}
-
-static int getClientY(lua_State *L) {
- // This function apparently is not used by the game scripts
- lua_pushnumber(L, 0);
-
- return 1;
-}
-
static int getWidth(lua_State *L) {
// This function apparently is not used by the game scripts
lua_pushnumber(L, 800);
@@ -332,20 +279,6 @@ static int closeWanted(lua_State *L) {
return 1;
}
-static int waitForFocus(lua_State *L) {
- // This function apparently is not used by the game scripts
- lua_pushbooleancpp(L, true);
-
- return 1;
-}
-
-static int hasFocus(lua_State *L) {
- // This function apparently is not used by the game scripts
- lua_pushbooleancpp(L, true);
-
- return 1;
-}
-
static const char *WINDOW_LIBRARY_NAME = "Window";
static const luaL_reg WINDOW_FUNCTIONS[] = {
@@ -355,8 +288,8 @@ static const luaL_reg WINDOW_FUNCTIONS[] = {
{"SetX", setX},
{"GetY", getY},
{"SetY", setY},
- {"GetClientX", getClientX},
- {"GetClientY", getClientY},
+ {"GetClientX", dummyFuncError},
+ {"GetClientY", dummyFuncError},
{"GetWidth", getWidth},
{"GetHeight", getHeight},
{"SetWidth", setWidth},
@@ -365,8 +298,8 @@ static const luaL_reg WINDOW_FUNCTIONS[] = {
{"SetTitle", setTitle},
{"ProcessMessages", processMessages},
{"CloseWanted", closeWanted},
- {"WaitForFocus", waitForFocus},
- {"HasFocus", hasFocus},
+ {"WaitForFocus", dummyFuncError},
+ {"HasFocus", dummyFuncError},
{0, 0}
};
@@ -436,29 +369,6 @@ static int emptyCache(lua_State *L) {
return 0;
}
-static int isLogCacheMiss(lua_State *L) {
- Kernel *pKernel = Kernel::getInstance();
- assert(pKernel);
- ResourceManager *pResource = pKernel->getResourceManager();
- assert(pResource);
-
- // This isn't used in any script
- lua_pushbooleancpp(L, false);
-
- return 1;
-}
-
-static int setLogCacheMiss(lua_State *L) {
- Kernel *pKernel = Kernel::getInstance();
- assert(pKernel);
- ResourceManager *pResource = pKernel->getResourceManager();
- assert(pResource);
-
- // This isn't used in any script
-
- return 0;
-}
-
static int dumpLockedResources(lua_State *L) {
Kernel *pKernel = Kernel::getInstance();
assert(pKernel);
@@ -478,8 +388,8 @@ static const luaL_reg RESOURCE_FUNCTIONS[] = {
{"GetMaxMemoryUsage", getMaxMemoryUsage},
{"SetMaxMemoryUsage", setMaxMemoryUsage},
{"EmptyCache", emptyCache},
- {"IsLogCacheMiss", isLogCacheMiss},
- {"SetLogCacheMiss", setLogCacheMiss},
+ {"IsLogCacheMiss", dummyFuncError},
+ {"SetLogCacheMiss", dummyFuncError},
{"DumpLockedResources", dumpLockedResources},
{0, 0}
};
diff --git a/engines/sword25/kernel/objectregistry.h b/engines/sword25/kernel/objectregistry.h
index 69d961ae91..d9a7c353f7 100644
--- a/engines/sword25/kernel/objectregistry.h
+++ b/engines/sword25/kernel/objectregistry.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/outputpersistenceblock.cpp b/engines/sword25/kernel/outputpersistenceblock.cpp
index a8a39cb822..cf28ea401f 100644
--- a/engines/sword25/kernel/outputpersistenceblock.cpp
+++ b/engines/sword25/kernel/outputpersistenceblock.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/outputpersistenceblock.h b/engines/sword25/kernel/outputpersistenceblock.h
index 71dbe68a52..12351d22e2 100644
--- a/engines/sword25/kernel/outputpersistenceblock.h
+++ b/engines/sword25/kernel/outputpersistenceblock.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/persistable.h b/engines/sword25/kernel/persistable.h
index 25cf70fda0..1807211847 100644
--- a/engines/sword25/kernel/persistable.h
+++ b/engines/sword25/kernel/persistable.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/persistenceblock.h b/engines/sword25/kernel/persistenceblock.h
index 4a64eff11b..d8440faa50 100644
--- a/engines/sword25/kernel/persistenceblock.h
+++ b/engines/sword25/kernel/persistenceblock.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp
index 506eef3c57..a6c71433a7 100644
--- a/engines/sword25/kernel/persistenceservice.cpp
+++ b/engines/sword25/kernel/persistenceservice.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -37,6 +34,7 @@
#include "common/fs.h"
#include "common/savefile.h"
+#include "common/zlib.h"
#include "sword25/kernel/kernel.h"
#include "sword25/kernel/persistenceservice.h"
#include "sword25/kernel/inputpersistenceblock.h"
@@ -47,7 +45,6 @@
#include "sword25/input/inputengine.h"
#include "sword25/math/regionregistry.h"
#include "sword25/script/script.h"
-#include <zlib.h>
namespace Sword25 {
@@ -105,7 +102,6 @@ struct SavegameInformation {
bool isOccupied;
bool isCompatible;
Common::String description;
- Common::String filename;
uint gamedataLength;
uint gamedataOffset;
uint gamedataUncompressedLength;
@@ -118,7 +114,6 @@ struct SavegameInformation {
isOccupied = false;
isCompatible = false;
description = "";
- filename = "";
gamedataLength = 0;
gamedataOffset = 0;
gamedataUncompressedLength = 0;
@@ -133,18 +128,18 @@ struct PersistenceService::Impl {
}
void reloadSlots() {
- // Über alle Spielstanddateien iterieren und deren Infos einlesen.
+ // Iterate through all the saved games, and read their thumbnails.
for (uint i = 0; i < SLOT_COUNT; ++i) {
readSlotSavegameInformation(i);
}
}
void readSlotSavegameInformation(uint slotID) {
- // Aktuelle Slotinformationen in den Ausgangszustand versetzen, er wird im Folgenden neu gefüllt.
+ // Get the information corresponding to the requested save slot.
SavegameInformation &curSavegameInfo = _savegameInformations[slotID];
curSavegameInfo.clear();
- // Den Dateinamen für den Spielstand des Slots generieren.
+ // Generate the save slot file name.
Common::String filename = generateSavegameFilename(slotID);
// Try to open the savegame for loading
@@ -163,16 +158,15 @@ struct PersistenceService::Impl {
// If the header can be read in and is detected to be valid, we will have a valid file
if (storedMarker == FILE_MARKER) {
- // Der Slot wird als belegt markiert.
+ // The slot is marked as occupied.
curSavegameInfo.isOccupied = true;
- // Speichern, ob der Spielstand kompatibel mit der aktuellen Engine-Version ist.
+ // Check if the saved game is compatible with the current engine version.
curSavegameInfo.isCompatible = (storedVersionID == Common::String(VERSIONID));
- // Dateinamen des Spielstandes speichern.
- curSavegameInfo.filename = generateSavegameFilename(slotID);
- // Die Beschreibung des Spielstandes besteht aus einer textuellen Darstellung des Änderungsdatums der Spielstanddatei.
+ // Load the save game description.
curSavegameInfo.description = gameDescription;
- // Den Offset zu den gespeicherten Spieldaten innerhalb der Datei speichern.
- // Dieses entspricht der aktuellen Position, da nach der letzten Headerinformation noch ein Leerzeichen als trenner folgt.
+ // The offset to the stored save game data within the file.
+ // This reflects the current position, as the header information
+ // is still followed by a space as separator.
curSavegameInfo.gamedataOffset = static_cast<uint>(file->pos());
}
@@ -244,10 +238,11 @@ Common::String &PersistenceService::getSavegameDescription(uint slotID) {
}
Common::String &PersistenceService::getSavegameFilename(uint slotID) {
- static Common::String emptyString;
+ static Common::String result;
if (!checkslotID(slotID))
- return emptyString;
- return _impl->_savegameInformations[slotID].filename;
+ return result;
+ result = generateSavegameFilename(slotID);
+ return result;
}
bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotFilename) {
@@ -293,34 +288,22 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF
error("Unable to persist modules for savegame file \"%s\".", filename.c_str());
}
- // Daten komprimieren.
- uLongf compressedLength = writer.getDataSize() + (writer.getDataSize() + 500) / 1000 + 12;
- Bytef *compressionBuffer = new Bytef[compressedLength];
-
- if (compress2(&compressionBuffer[0], &compressedLength, reinterpret_cast<const Bytef *>(writer.getData()), writer.getDataSize(), 6) != Z_OK) {
- error("Unable to compress savegame data in savegame file \"%s\".", filename.c_str());
- }
-
- // Länge der komprimierten Daten und der unkomprimierten Daten in die Datei schreiben.
+ // Write the save game data uncompressed, since the final saved game will be
+ // compressed anyway.
char sBuffer[10];
- snprintf(sBuffer, 10, "%ld", compressedLength);
+ snprintf(sBuffer, 10, "%u", writer.getDataSize());
file->writeString(sBuffer);
file->writeByte(0);
snprintf(sBuffer, 10, "%u", writer.getDataSize());
file->writeString(sBuffer);
file->writeByte(0);
-
- // Komprimierte Daten in die Datei schreiben.
- file->write(reinterpret_cast<char *>(&compressionBuffer[0]), compressedLength);
- if (file->err()) {
- error("Unable to write game data to savegame file \"%s\".", filename.c_str());
- }
+ file->write(writer.getData(), writer.getDataSize());
// Get the screenshot
Common::SeekableReadStream *thumbnail = Kernel::getInstance()->getGfx()->getThumbnail();
if (thumbnail) {
- byte *buffer = new Byte[FILE_COPY_BUFFER_SIZE];
+ byte *buffer = new byte[FILE_COPY_BUFFER_SIZE];
while (!thumbnail->eos()) {
int bytesRead = thumbnail->read(&buffer[0], FILE_COPY_BUFFER_SIZE);
file->write(&buffer[0], bytesRead);
@@ -333,11 +316,13 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF
file->finalize();
delete file;
- delete[] compressionBuffer;
// Savegameinformationen für diesen Slot aktualisieren.
_impl->readSlotSavegameInformation(slotID);
+ // Empty the cache, to remove old thumbnails
+ Kernel::getInstance()->getResourceManager()->emptyThumbnailCache();
+
// Erfolg signalisieren.
return true;
}
@@ -371,28 +356,35 @@ bool PersistenceService::loadGame(uint slotID) {
#endif
byte *compressedDataBuffer = new byte[curSavegameInfo.gamedataLength];
- byte *uncompressedDataBuffer = new Bytef[curSavegameInfo.gamedataUncompressedLength];
-
- file = sfm->openForLoading(generateSavegameFilename(slotID));
+ byte *uncompressedDataBuffer = new byte[curSavegameInfo.gamedataUncompressedLength];
+ Common::String filename = generateSavegameFilename(slotID);
+ file = sfm->openForLoading(filename);
file->seek(curSavegameInfo.gamedataOffset);
file->read(reinterpret_cast<char *>(&compressedDataBuffer[0]), curSavegameInfo.gamedataLength);
if (file->err()) {
- error("Unable to load the gamedata from the savegame file \"%s\".", curSavegameInfo.filename.c_str());
+ error("Unable to load the gamedata from the savegame file \"%s\".", filename.c_str());
delete[] compressedDataBuffer;
delete[] uncompressedDataBuffer;
return false;
}
- // Spieldaten dekomprimieren.
- uLongf uncompressedBufferSize = curSavegameInfo.gamedataUncompressedLength;
- if (uncompress(reinterpret_cast<Bytef *>(&uncompressedDataBuffer[0]), &uncompressedBufferSize,
- reinterpret_cast<Bytef *>(&compressedDataBuffer[0]), curSavegameInfo.gamedataLength) != Z_OK) {
- error("Unable to decompress the gamedata from savegame file \"%s\".", curSavegameInfo.filename.c_str());
- delete[] uncompressedDataBuffer;
- delete[] compressedDataBuffer;
- delete file;
- return false;
+ // Uncompress game data, if needed.
+ unsigned long uncompressedBufferSize = curSavegameInfo.gamedataUncompressedLength;
+
+ if (uncompressedBufferSize > curSavegameInfo.gamedataLength) {
+ // Older saved game, where the game data was compressed again.
+ if (!Common::uncompress(reinterpret_cast<byte *>(&uncompressedDataBuffer[0]), &uncompressedBufferSize,
+ reinterpret_cast<byte *>(&compressedDataBuffer[0]), curSavegameInfo.gamedataLength)) {
+ error("Unable to decompress the gamedata from savegame file \"%s\".", filename.c_str());
+ delete[] uncompressedDataBuffer;
+ delete[] compressedDataBuffer;
+ delete file;
+ return false;
+ }
+ } else {
+ // Newer saved game with uncompressed game data, copy it as-is.
+ memcpy(uncompressedDataBuffer, compressedDataBuffer, uncompressedBufferSize);
}
InputPersistenceBlock reader(&uncompressedDataBuffer[0], curSavegameInfo.gamedataUncompressedLength);
@@ -411,7 +403,7 @@ bool PersistenceService::loadGame(uint slotID) {
delete file;
if (!success) {
- error("Unable to unpersist the gamedata from savegame file \"%s\".", curSavegameInfo.filename.c_str());
+ error("Unable to unpersist the gamedata from savegame file \"%s\".", filename.c_str());
return false;
}
diff --git a/engines/sword25/kernel/persistenceservice.h b/engines/sword25/kernel/persistenceservice.h
index 0db109d1b0..f73962892c 100644
--- a/engines/sword25/kernel/persistenceservice.h
+++ b/engines/sword25/kernel/persistenceservice.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp
index 8b446e69d1..cc3316250a 100644
--- a/engines/sword25/kernel/resmanager.cpp
+++ b/engines/sword25/kernel/resmanager.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -147,6 +144,21 @@ void ResourceManager::emptyCache() {
}
}
+void ResourceManager::emptyThumbnailCache() {
+ // Scan through the resource list
+ Common::List<Resource *>::iterator iter = _resources.begin();
+ while (iter != _resources.end()) {
+ if ((*iter)->getFileName().hasPrefix("/saves")) {
+ // Unlock the thumbnail
+ while ((*iter)->getLockCount() > 0)
+ (*iter)->release();
+ // Delete the thumbnail
+ iter = deleteResource(*iter);
+ } else
+ ++iter;
+ }
+}
+
/**
* Returns a requested resource. If any error occurs, returns NULL
* @param FileName Filename of resource
diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h
index 5b2bfd395f..6b95a45b6e 100644
--- a/engines/sword25/kernel/resmanager.h
+++ b/engines/sword25/kernel/resmanager.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -82,6 +79,11 @@ public:
void emptyCache();
/**
+ * Removes all the savegame thumbnails from the cache
+ **/
+ void emptyThumbnailCache();
+
+ /**
* Writes the names of all currently locked resources to the log file
*/
void dumpLockedResources();
diff --git a/engines/sword25/kernel/resource.cpp b/engines/sword25/kernel/resource.cpp
index f16cb3aaf2..656355cc17 100644
--- a/engines/sword25/kernel/resource.cpp
+++ b/engines/sword25/kernel/resource.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/resource.h b/engines/sword25/kernel/resource.h
index 5c6108a281..7c8175c9c9 100644
--- a/engines/sword25/kernel/resource.h
+++ b/engines/sword25/kernel/resource.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/resservice.h b/engines/sword25/kernel/resservice.h
index 65b2dc4b36..69b0688e32 100644
--- a/engines/sword25/kernel/resservice.h
+++ b/engines/sword25/kernel/resservice.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/kernel/service.h b/engines/sword25/kernel/service.h
index ef8858bb7d..576776bb5f 100644
--- a/engines/sword25/kernel/service.h
+++ b/engines/sword25/kernel/service.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/geometry.h b/engines/sword25/math/geometry.h
index 60898df635..bdbd5b2052 100644
--- a/engines/sword25/math/geometry.h
+++ b/engines/sword25/math/geometry.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/geometry_script.cpp b/engines/sword25/math/geometry_script.cpp
index 4b5e0550fe..70798f7692 100644
--- a/engines/sword25/math/geometry_script.cpp
+++ b/engines/sword25/math/geometry_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h
index d57fce68f7..9eaa2d3c8c 100644
--- a/engines/sword25/math/line.h
+++ b/engines/sword25/math/line.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/polygon.cpp b/engines/sword25/math/polygon.cpp
index e8385c60c8..fe2fc84cad 100644
--- a/engines/sword25/math/polygon.cpp
+++ b/engines/sword25/math/polygon.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/polygon.h b/engines/sword25/math/polygon.h
index 4bb28f827a..eac19d7900 100644
--- a/engines/sword25/math/polygon.h
+++ b/engines/sword25/math/polygon.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/region.cpp b/engines/sword25/math/region.cpp
index 5d08b0c14e..8790860a55 100644
--- a/engines/sword25/math/region.cpp
+++ b/engines/sword25/math/region.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/region.h b/engines/sword25/math/region.h
index fa65b4b7ad..f9a3f50b3f 100644
--- a/engines/sword25/math/region.h
+++ b/engines/sword25/math/region.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/regionregistry.cpp b/engines/sword25/math/regionregistry.cpp
index 978a1807f7..dff8560205 100644
--- a/engines/sword25/math/regionregistry.cpp
+++ b/engines/sword25/math/regionregistry.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/regionregistry.h b/engines/sword25/math/regionregistry.h
index db3e021e25..9e0a28bea7 100644
--- a/engines/sword25/math/regionregistry.h
+++ b/engines/sword25/math/regionregistry.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/vertex.cpp b/engines/sword25/math/vertex.cpp
index 3746ec9410..b486d35e7e 100644
--- a/engines/sword25/math/vertex.cpp
+++ b/engines/sword25/math/vertex.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/vertex.h b/engines/sword25/math/vertex.h
index 0e6d14502c..817f48e760 100644
--- a/engines/sword25/math/vertex.h
+++ b/engines/sword25/math/vertex.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/walkregion.cpp b/engines/sword25/math/walkregion.cpp
index 8306553f7b..3eea689877 100644
--- a/engines/sword25/math/walkregion.cpp
+++ b/engines/sword25/math/walkregion.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/math/walkregion.h b/engines/sword25/math/walkregion.h
index e8bf40becc..7dded1980b 100644
--- a/engines/sword25/math/walkregion.h
+++ b/engines/sword25/math/walkregion.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/package/packagemanager.cpp b/engines/sword25/package/packagemanager.cpp
index 7a64fe2e29..5c869203c6 100644
--- a/engines/sword25/package/packagemanager.cpp
+++ b/engines/sword25/package/packagemanager.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/package/packagemanager.h b/engines/sword25/package/packagemanager.h
index 3a976b32fa..3c4c4e89c5 100644
--- a/engines/sword25/package/packagemanager.h
+++ b/engines/sword25/package/packagemanager.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/package/packagemanager_script.cpp b/engines/sword25/package/packagemanager_script.cpp
index eab66f7531..229ec37459 100644
--- a/engines/sword25/package/packagemanager_script.cpp
+++ b/engines/sword25/package/packagemanager_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/lua_extensions.cpp b/engines/sword25/script/lua_extensions.cpp
index 5ba38afc36..bf502d719e 100644
--- a/engines/sword25/script/lua_extensions.cpp
+++ b/engines/sword25/script/lua_extensions.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/luabindhelper.cpp b/engines/sword25/script/luabindhelper.cpp
index 03a1802a04..8fbbe7e272 100644
--- a/engines/sword25/script/luabindhelper.cpp
+++ b/engines/sword25/script/luabindhelper.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/luabindhelper.h b/engines/sword25/script/luabindhelper.h
index 94f52743f3..0cb6d37bdc 100644
--- a/engines/sword25/script/luabindhelper.h
+++ b/engines/sword25/script/luabindhelper.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/luacallback.cpp b/engines/sword25/script/luacallback.cpp
index 809676796e..cee0531b8a 100644
--- a/engines/sword25/script/luacallback.cpp
+++ b/engines/sword25/script/luacallback.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/luacallback.h b/engines/sword25/script/luacallback.h
index e097f5b499..796af8598b 100644
--- a/engines/sword25/script/luacallback.h
+++ b/engines/sword25/script/luacallback.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp
index cce01d58c7..7fd3d1b658 100644
--- a/engines/sword25/script/luascript.cpp
+++ b/engines/sword25/script/luascript.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/luascript.h b/engines/sword25/script/luascript.h
index b66c32176a..f3530d68ed 100644
--- a/engines/sword25/script/luascript.h
+++ b/engines/sword25/script/luascript.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/script/script.h b/engines/sword25/script/script.h
index 9ca146026e..e4ce846b66 100644
--- a/engines/sword25/script/script.h
+++ b/engines/sword25/script/script.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp
index 08f0f5b4ae..20622b2098 100644
--- a/engines/sword25/sfx/soundengine.cpp
+++ b/engines/sword25/sfx/soundengine.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -154,13 +151,17 @@ bool SoundEngine::playSound(const Common::String &fileName, SOUND_TYPES type, fl
uint SoundEngine::playSoundEx(const Common::String &fileName, SOUND_TYPES type, float volume, float pan, bool loop, int loopStart, int loopEnd, uint layer) {
Common::SeekableReadStream *in = Kernel::getInstance()->getPackage()->getStream(fileName);
+#ifdef USE_VORBIS
Audio::SeekableAudioStream *stream = Audio::makeVorbisStream(in, DisposeAfterUse::YES);
+#endif
uint id;
SndHandle *handle = getHandle(&id);
debugC(1, kDebugSound, "SoundEngine::playSoundEx(%s, %d, %f, %f, %d, %d, %d, %d)", fileName.c_str(), type, volume, pan, loop, loopStart, loopEnd, layer);
+#ifdef USE_VORBIS
_mixer->playStream(getType(type), &(handle->handle), stream, -1, (byte)(volume * 255), (int8)(pan * 127));
+#endif
return id;
}
diff --git a/engines/sword25/sfx/soundengine.h b/engines/sword25/sfx/soundengine.h
index 576582b478..c087392570 100644
--- a/engines/sword25/sfx/soundengine.h
+++ b/engines/sword25/sfx/soundengine.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/sfx/soundengine_script.cpp b/engines/sword25/sfx/soundengine_script.cpp
index d347cf5eb4..d7771967a3 100644
--- a/engines/sword25/sfx/soundengine_script.cpp
+++ b/engines/sword25/sfx/soundengine_script.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp
index 38c1c89109..93666fed39 100644
--- a/engines/sword25/sword25.cpp
+++ b/engines/sword25/sword25.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/sword25.h b/engines/sword25/sword25.h
index 5bd27b311f..5d11aa69e5 100644
--- a/engines/sword25/sword25.h
+++ b/engines/sword25/sword25.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#ifndef SWORD25_H
diff --git a/engines/sword25/util/lua/lauxlib.cpp b/engines/sword25/util/lua/lauxlib.cpp
index 53c0556625..526b1c84ab 100644
--- a/engines/sword25/util/lua/lauxlib.cpp
+++ b/engines/sword25/util/lua/lauxlib.cpp
@@ -6,7 +6,6 @@
#include <ctype.h>
-#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -541,11 +540,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
static int errfile (lua_State *L, const char *what, int fnameindex) {
- const char *serr = strerror(errno);
- const char *filename = lua_tostring(L, fnameindex) + 1;
- lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
- lua_remove(L, fnameindex);
- return LUA_ERRFILE;
+ return luaL_error(L, "LUA function errfile has been removed in ScummVM");
}
diff --git a/engines/sword25/util/lua/liolib.cpp b/engines/sword25/util/lua/liolib.cpp
index aa44dcafa3..f9bad30aed 100644
--- a/engines/sword25/util/lua/liolib.cpp
+++ b/engines/sword25/util/lua/liolib.cpp
@@ -5,7 +5,6 @@
*/
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -28,25 +27,12 @@ static const char *const fnames[] = {"input", "output"};
static int pushresult (lua_State *L, int i, const char *filename) {
- int en = errno; /* calls to Lua API may change this value */
- if (i) {
- lua_pushboolean(L, 1);
- return 1;
- }
- else {
- lua_pushnil(L);
- if (filename)
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
- else
- lua_pushfstring(L, "%s", strerror(en));
- lua_pushinteger(L, en);
- return 3;
- }
+ return luaL_error(L, "LUA file I/O functions have been removed in ScummVM");
}
static void fileerror (lua_State *L, int arg, const char *filename) {
- lua_pushfstring(L, "%s: %s", filename, strerror(errno));
+ lua_pushfstring(L, "%s: %s", filename, "LUA I/O error descriptions have been removed in ScummVM");
luaL_argerror(L, arg, lua_tostring(L, -1));
}
@@ -392,7 +378,7 @@ static int io_readline (lua_State *L) {
luaL_error(L, "file is already closed");
sucess = read_line(L, f);
if (ferror(f))
- return luaL_error(L, "%s", strerror(errno));
+ return luaL_error(L, "%s", "LUA I/O error descriptions have been removed in ScummVM");
if (sucess) return 1;
else { /* EOF */
if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */
diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp
index fdde2b8e5f..87eafea45a 100644
--- a/engines/sword25/util/lua/llex.cpp
+++ b/engines/sword25/util/lua/llex.cpp
@@ -6,7 +6,6 @@
#include <ctype.h>
-#include <locale.h>
#include <string.h>
#define llex_c
@@ -176,9 +175,11 @@ static void buffreplace (LexState *ls, char from, char to) {
static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* format error: try to update decimal point separator */
- struct lconv *cv = localeconv();
+ // Non-portable call to update the decimal point separator.
+ // It has been simplified in ScummVM to not use any system locale
+ // information, as it's not used in sword25.
char old = ls->decpoint;
- ls->decpoint = (cv ? cv->decimal_point[0] : '.');
+ ls->decpoint = '.';
buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
/* format error with correct decimal point: no more options */
diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp
index 035925ceb5..578a7cb09a 100644
--- a/engines/sword25/util/lua/loslib.cpp
+++ b/engines/sword25/util/lua/loslib.cpp
@@ -5,8 +5,6 @@
*/
-#include <errno.h>
-#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -20,21 +18,6 @@
#include "lualib.h"
-static int os_pushresult (lua_State *L, int i, const char *filename) {
- int en = errno; /* calls to Lua API may change this value */
- if (i) {
- lua_pushboolean(L, 1);
- return 1;
- }
- else {
- lua_pushnil(L);
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
- lua_pushinteger(L, en);
- return 3;
- }
-}
-
-
static int os_execute (lua_State *L) {
lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
return 1;
@@ -42,15 +25,18 @@ static int os_execute (lua_State *L) {
static int os_remove (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- return os_pushresult(L, remove(filename) == 0, filename);
+ // Non-portable call that deletes a file. Removed in ScummVM.
+ // This call is invoked in sword25 when loading games in order to remove the
+ // temporary savegame thumbnail that the original engine code created. We
+ // embed the thumbnail in the savegame instead, so this call is not needed at
+ // all.
+ return 1;
}
static int os_rename (lua_State *L) {
- const char *fromname = luaL_checkstring(L, 1);
- const char *toname = luaL_checkstring(L, 2);
- return os_pushresult(L, rename(fromname, toname) == 0, fromname);
+ // Removed in ScummVM, does nothing.
+ return 1;
}
@@ -196,13 +182,8 @@ static int os_difftime (lua_State *L) {
static int os_setlocale (lua_State *L) {
- static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
- LC_NUMERIC, LC_TIME};
- static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
- "numeric", "time", NULL};
- const char *l = luaL_optstring(L, 1, NULL);
- int op = luaL_checkoption(L, 2, "all", catnames);
- lua_pushstring(L, setlocale(cat[op], l));
+ // Non-portable call to set the numeric locale. Removed in ScummVM, as it's
+ // not used in sword25.
return 1;
}
diff --git a/engines/sword25/util/lua/luaconf.h b/engines/sword25/util/lua/luaconf.h
index 669b0e7a49..29411d5af1 100644
--- a/engines/sword25/util/lua/luaconf.h
+++ b/engines/sword25/util/lua/luaconf.h
@@ -18,6 +18,14 @@
** ===================================================================
*/
+#if defined(__ANDROID__)
+/* Android is missing strcoll().
+** For more information, refer to:
+** http://www.damonkohler.com/2008/12/lua-on-android.html
+*/
+#define strcoll strcmp
+#endif
+
/*
@@ LUA_ANSI controls the use of non-ansi features.
@@ -183,7 +191,11 @@
#define LUAI_DATA /* empty */
#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
- defined(__ELF__)
+ defined(__ELF__) && !defined(__PLAYSTATION2__)
+/*
+** The PS2 gcc compiler doesn't like the visibility attribute, so
+** we use the normal "extern" definitions in the block below
+*/
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#define LUAI_DATA LUAI_FUNC
@@ -634,33 +646,6 @@ union luai_Cast { double l_d; long l_l; };
/*
-@@ lua_tmpnam is the function that the OS library uses to create a
-@* temporary name.
-@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
-** CHANGE them if you have an alternative to tmpnam (which is considered
-** insecure) or if you want the original tmpnam anyway. By default, Lua
-** uses tmpnam except when POSIX is available, where it uses mkstemp.
-*/
-#if defined(loslib_c) || defined(luaall_c)
-
-#if defined(LUA_USE_MKSTEMP)
-#include <unistd.h>
-#define LUA_TMPNAMBUFSIZE 32
-#define lua_tmpnam(b,e) { \
- strcpy(b, "/tmp/lua_XXXXXX"); \
- e = mkstemp(b); \
- if (e != -1) close(e); \
- e = (e == -1); }
-
-#else
-#define LUA_TMPNAMBUFSIZE L_tmpnam
-#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
-#endif
-
-#endif
-
-
-/*
@@ lua_popen spawns a new process connected to the current one through
@* the file streams.
** CHANGE it if you have a way to implement it in your system.