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.cpp38
-rw-r--r--engines/sword25/detection_tables.h129
-rw-r--r--engines/sword25/fmv/movieplayer.cpp31
-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.cpp327
-rw-r--r--engines/sword25/fmv/theora_decoder.h56
-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.cpp3
-rw-r--r--engines/sword25/gfx/graphicengine.h5
-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/imgloader.cpp85
-rw-r--r--engines/sword25/gfx/image/imgloader.h (renamed from engines/sword25/gfx/image/pngloader.h)42
-rw-r--r--engines/sword25/gfx/image/pngloader.cpp295
-rw-r--r--engines/sword25/gfx/image/renderedimage.cpp88
-rw-r--r--engines/sword25/gfx/image/renderedimage.h3
-rw-r--r--engines/sword25/gfx/image/swimage.cpp15
-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.cpp7
-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.cpp82
-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.h5
-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.cpp8
-rw-r--r--engines/sword25/kernel/kernel.h5
-rw-r--r--engines/sword25/kernel/kernel_script.cpp3
-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.cpp59
-rw-r--r--engines/sword25/kernel/persistenceservice.h3
-rw-r--r--engines/sword25/kernel/resmanager.cpp3
-rw-r--r--engines/sword25/kernel/resmanager.h3
-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.cpp5
-rw-r--r--engines/sword25/math/polygon.h9
-rw-r--r--engines/sword25/math/region.cpp5
-rw-r--r--engines/sword25/math/region.h7
-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.h6
-rw-r--r--engines/sword25/math/walkregion.cpp9
-rw-r--r--engines/sword25/math/walkregion.h3
-rw-r--r--engines/sword25/module.mk6
-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.cpp7
-rw-r--r--engines/sword25/script/luascript.h8
-rw-r--r--engines/sword25/script/script.h5
-rw-r--r--engines/sword25/sfx/soundengine.cpp7
-rw-r--r--engines/sword25/sfx/soundengine.h5
-rw-r--r--engines/sword25/sfx/soundengine_script.cpp3
-rw-r--r--engines/sword25/sword25.cpp7
-rw-r--r--engines/sword25/sword25.h3
-rw-r--r--engines/sword25/util/lua/lapi.cpp16
-rw-r--r--engines/sword25/util/lua/lauxlib.cpp50
-rw-r--r--engines/sword25/util/lua/ldo.cpp30
-rw-r--r--engines/sword25/util/lua/ldump.cpp164
-rw-r--r--engines/sword25/util/lua/liolib.cpp222
-rw-r--r--engines/sword25/util/lua/llex.cpp20
-rw-r--r--engines/sword25/util/lua/lmathlib.cpp4
-rw-r--r--engines/sword25/util/lua/loadlib.cpp197
-rw-r--r--engines/sword25/util/lua/loslib.cpp77
-rw-r--r--engines/sword25/util/lua/lua.h2
-rw-r--r--engines/sword25/util/lua/luaconf.h35
-rw-r--r--engines/sword25/util/lua/lundump.cpp225
-rw-r--r--engines/sword25/util/lua/lundump.h36
-rw-r--r--engines/sword25/util/lua/lvm.cpp2
-rw-r--r--engines/sword25/util/lua/print.cpp227
-rw-r--r--engines/sword25/util/lua/scummvm_file.cpp205
-rw-r--r--engines/sword25/util/lua/scummvm_file.h56
130 files changed, 1084 insertions, 2096 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..edb8c30545 100644
--- a/engines/sword25/detection.cpp
+++ b/engines/sword25/detection.cpp
@@ -18,15 +18,13 @@
* 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"
#include "engines/advancedDetector.h"
#include "sword25/sword25.h"
+#include "sword25/detection_tables.h"
#include "sword25/kernel/persistenceservice.h"
namespace Sword25 {
@@ -38,38 +36,6 @@ static const PlainGameDescriptor Sword25Game[] = {
{0, 0}
};
-namespace Sword25 {
-
-// TODO: Need to decide whether we're going to implement code to detect all the various languages allowed,
-// both by the core data package, as well as the extra languages added by the patch file; also, I don't
-// think that all the languages supported by the game currently have constants in ScummVM
-static const ADGameDescription gameDescriptions[] = {
- {
- "sword25",
- "",
- AD_ENTRY1s("data.b25c", "f8b6e03ada2d2f6cf27fbc11ad1572e9", 654310588),
- Common::EN_ANY,
- Common::kPlatformUnknown,
- ADGF_NO_FLAGS,
- Common::GUIO_NONE
- },
- {
- "sword25",
- "Extracted",
- {{"_includes.lua", 0, 0, -1},
- {"boot.lua", 0, 0, -1},
- {"kernel.lua", 0, 0, -1},
- AD_LISTEND},
- Common::EN_ANY,
- Common::kPlatformUnknown,
- GF_EXTRACTED,
- Common::GUIO_NONE
- },
- AD_TABLE_END_MARKER
-};
-
-} // End of namespace Sword25
-
static const char *directoryGlobs[] = {
"system", // Used by extracted dats
0
@@ -105,7 +71,7 @@ public:
Sword25MetaEngine() : AdvancedMetaEngine(detectionParams) {}
virtual const char *getName() const {
- return "The Broken Sword 2.5 Engine";
+ return "Sword25";
}
virtual const char *getOriginalCopyright() const {
diff --git a/engines/sword25/detection_tables.h b/engines/sword25/detection_tables.h
new file mode 100644
index 0000000000..ca586b4f01
--- /dev/null
+++ b/engines/sword25/detection_tables.h
@@ -0,0 +1,129 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+namespace Sword25 {
+
+using Common::GUIO_NONE;
+using Common::GUIO_NOSPEECH;
+using Common::GUIO_NOSFX;
+using Common::GUIO_NOMUSIC;
+
+static const ADGameDescription gameDescriptions[] = {
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("data.b25c", "f8b6e03ada2d2f6cf27fbc11ad1572e9", 654310588),
+ Common::EN_ANY,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_fr.b25c", "690caf157387e06d2c3d1ca53c43f428", 1006043),
+ Common::FR_FRA,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("data.b25c", "f8b6e03ada2d2f6cf27fbc11ad1572e9", 654310588),
+ Common::DE_DEU,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_hr.b25c", "e881054d1f8ec1e527422fc521c25405", 1273217),
+ Common::HU_HUN,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_it.b25c", "f3325666da0515cc2b42062e953c0889", 996197),
+ Common::IT_ITA,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_pl.b25c", "49dc1a20f95391a808e475c49be2bac0", 1281799),
+ Common::PL_POL,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_pt.b25c", "1df701432f9e13dcefe1adeb890b9c69", 993812),
+ Common::PT_BRA,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_ru.b25c", "deb33dd2f90a71ff60181918a8ce5063", 1235378),
+ Common::RU_RUS,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+ {
+ "sword25",
+ "",
+ AD_ENTRY1s("lang_es.b25c", "384c19072d83725f351bb9ecb4d3f02b", 987965),
+ Common::ES_ESP,
+ Common::kPlatformUnknown,
+ ADGF_NO_FLAGS,
+ Common::GUIO_NONE
+ },
+
+ // Extracted version
+ {
+ "sword25",
+ "Extracted",
+ {{"_includes.lua", 0, 0, -1},
+ {"boot.lua", 0, 0, -1},
+ {"kernel.lua", 0, 0, -1},
+ AD_LISTEND},
+ Common::EN_ANY,
+ Common::kPlatformUnknown,
+ GF_EXTRACTED,
+ Common::GUIO_NONE
+ },
+ AD_TABLE_END_MARKER
+};
+
+} // End of namespace Sword25
diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp
index 975f08be22..d0ad41de22 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();
+ }
}
}
}
@@ -146,7 +145,7 @@ bool MoviePlayer::isMovieLoaded() {
}
bool MoviePlayer::isPaused() {
- return _decoder.isPaused();
+ return _decoder.isPaused() || _decoder.endOfVideo();
}
float MoviePlayer::getScaleFactor() {
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..be6d940d23 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,15 +52,14 @@ 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;
_theoraPacket = 0;
_vorbisPacket = 0;
_theoraDecode = 0;
_theoraSetup = 0;
- _stateFlag = false;
+ _nextFrameStartTime = 0.0;
_soundType = soundType;
_audStream = 0;
@@ -70,7 +67,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 +100,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 +117,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 +131,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,22 +275,39 @@ 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);
+ _endOfAudio = true;
}
- // open audio
- if (_vorbisPacket) {
- _audStream = createAudioStream();
- if (_audStream && _mixer)
- _mixer->playStream(_soundType, _audHandle, _audStream);
- }
+ _surface.create(_theoraInfo.frame_width, _theoraInfo.frame_height, g_system->getScreenFormat());
- _surface = new Graphics::Surface();
+ // Set up a display surface
+ _displaySurface.pixels = _surface.getBasePtr(_theoraInfo.pic_x, _theoraInfo.pic_y);
+ _displaySurface.w = _theoraInfo.pic_width;
+ _displaySurface.h = _theoraInfo.pic_height;
+ _displaySurface.format = _surface.format;
+ _displaySurface.pitch = _surface.pitch;
- _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 +320,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;
}
@@ -325,57 +342,16 @@ void TheoraDecoder::close() {
delete _fileStream;
_fileStream = 0;
- _surface->free();
- delete _surface;
- _surface = 0;
+ _surface.free();
+ _displaySurface.pixels = 0;
+ _displaySurface.free();
reset();
}
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 +361,124 @@ 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 &_displaySurface;
+}
- // 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) {
+ byte flags = Audio::FLAG_16BITS | Audio::FLAG_STEREO;
+#ifdef SCUMM_LITTLE_ENDIAN
+ flags |= Audio::FLAG_LITTLE_ENDIAN;
+#endif
+ _audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::NO, flags);
- 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 +488,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 +529,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 +542,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..e8cc5ab8b9 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,40 @@ 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 _displaySurface.w; }
+ uint16 getHeight() const { return _displaySurface.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 _displaySurface.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;
+ Graphics::Surface _surface;
+ Graphics::Surface _displaySurface;
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 +123,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 fbaa69d09c..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$
- *
*/
/*
diff --git a/engines/sword25/gfx/graphicengine.h b/engines/sword25/gfx/graphicengine.h
index 8d12168b62..3309763966 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$
- *
*/
/*
@@ -109,7 +106,7 @@ public:
// ---------
/**
- * Initialises the graphics engine and sets the screen mode. Returns
+ * Initializes the graphics engine and sets the screen mode. Returns
* true if initialisation failed.
* @note This method should be called immediately after the
* initialisation of all services.
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/imgloader.cpp b/engines/sword25/gfx/image/imgloader.cpp
new file mode 100644
index 0000000000..1df0fba70c
--- /dev/null
+++ b/engines/sword25/gfx/image/imgloader.cpp
@@ -0,0 +1,85 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This code is based on Broken Sword 2.5 engine
+ *
+ * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
+ *
+ * Licensed under GNU GPL v2
+ *
+ */
+
+#include "common/memstream.h"
+#include "sword25/gfx/image/image.h"
+#include "sword25/gfx/image/imgloader.h"
+#include "graphics/pixelformat.h"
+#include "graphics/png.h"
+
+namespace Sword25 {
+
+bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) {
+ Common::MemoryReadStream *fileStr = new Common::MemoryReadStream(fileDataPtr, fileSize, DisposeAfterUse::NO);
+ Graphics::PNG *png = new Graphics::PNG();
+ if (!png->read(fileStr)) // the fileStr pointer, and thus pFileData will be deleted after this is done
+ error("Error while reading PNG image");
+
+ Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
+ Graphics::Surface *pngSurface = png->getSurface(format);
+
+ width = pngSurface->w;
+ height = pngSurface->h;
+ uncompressedDataPtr = new byte[pngSurface->pitch * pngSurface->h];
+ memcpy(uncompressedDataPtr, (byte *)pngSurface->pixels, pngSurface->pitch * pngSurface->h);
+ pngSurface->free();
+
+ delete pngSurface;
+ delete png;
+
+ // Signal success
+ return true;
+}
+
+bool ImgLoader::decodeThumbnailImage(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;
+}
+
+} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/imgloader.h
index fea6ece0e9..735ab9203c 100644
--- a/engines/sword25/gfx/image/pngloader.h
+++ b/engines/sword25/gfx/image/imgloader.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$
- *
*/
/*
@@ -32,30 +29,22 @@
*
*/
-#ifndef SWORD25_PNGLOADER2_H
-#define SWORD25_PNGLOADER2_H
+#ifndef SWORD25_IMGLOADER_H
+#define SWORD25_IMGLOADER_H
#include "sword25/kernel/common.h"
#include "sword25/gfx/graphicengine.h"
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.
*
* Originally written by Malte Thiesen.
*/
-class PNGLoader {
+class ImgLoader {
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
+ ImgLoader() {} // Protected constructor to prevent instances
public:
@@ -73,28 +62,15 @@ public:
* @remark This function does not free the image buffer passed to it,
* it is the callers responsibility to do so.
*/
- static bool decodeImage(const byte *pFileData, uint fileSize,
+ static bool decodePNGImage(const byte *pFileData, uint fileSize,
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
- * @param[in] fileSize size of the image data in bytes
- * @param[out] width if successful, this is set to the width of the image
- * @param[out] height if successful, this is set to the height of the image
- * @return returns true if extraction of the properties was successful, false in case of an error
- *
- * @remark This function does not free the image buffer passed to it,
- * it is the callers responsibility to do so.
- */
- static bool imageProperties(const byte *fileDatePtr, uint fileSize,
- int &width,
- int &height);
-#endif
-
+ static bool decodeThumbnailImage(const byte *pFileData, uint fileSize,
+ byte *&pUncompressedData,
+ int &width, int &height,
+ int &pitch);
};
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp
deleted file mode 100644
index d3c119b1a0..0000000000
--- a/engines/sword25/gfx/image/pngloader.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * 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$
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-#ifndef USE_INTERNAL_PNG_DECODER
-// Disable symbol overrides so that we can use png.h
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-#endif
-
-#include "common/memstream.h"
-#include "sword25/gfx/image/image.h"
-#include "sword25/gfx/image/pngloader.h"
-#ifndef USE_INTERNAL_PNG_DECODER
-#include <png.h>
-#else
-#include "graphics/pixelformat.h"
-#include "graphics/png.h"
-#endif
-
-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);
- memcpy(data, *ref, length);
- *ref += length;
-}
-
-static bool doIsCorrectImageFormat(const byte *fileDataPtr, uint fileSize) {
- return (fileSize > 8) && png_check_sig(const_cast<byte *>(fileDataPtr), 8);
-}
-#endif
-
-bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) {
-#ifndef USE_INTERNAL_PNG_DECODER
- png_structp png_ptr = NULL;
- png_infop info_ptr = NULL;
-
- int bitDepth;
- int colorType;
- int interlaceType;
- int i;
-
- // Check for valid PNG signature
- if (!doIsCorrectImageFormat(fileDataPtr, fileSize)) {
- error("png_check_sig failed");
- }
-
- // Create both PNG structures
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- error("Could not create libpng read struct.");
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- error("Could not create libpng info struct.");
- }
-
- // Use alternative reading function
- const byte **ref = &fileDataPtr;
- png_set_read_fn(png_ptr, (void *)ref, png_user_read_data);
-
- // Read PNG header
- png_read_info(png_ptr, info_ptr);
-
- // Read out PNG informations
-
- png_uint_32 w, h;
- png_get_IHDR(png_ptr, info_ptr, &w, &h, &bitDepth, &colorType, &interlaceType, NULL, NULL);
- width = w;
- height = h;
-
- // Calculate pitch of output image
- pitch = GraphicEngine::calcPitch(GraphicEngine::CF_ARGB32, width);
-
- // Allocate memory for the final image data.
- // To keep memory framentation low this happens before allocating memory for temporary image data.
- uncompressedDataPtr = new byte[pitch * height];
- if (!uncompressedDataPtr) {
- error("Could not allocate memory for output image.");
- }
-
- // Images of all color formates will be transformed into ARGB images
- if (bitDepth == 16)
- png_set_strip_16(png_ptr);
- if (colorType == PNG_COLOR_TYPE_PALETTE)
- png_set_expand(png_ptr);
- if (bitDepth < 8)
- png_set_expand(png_ptr);
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
- png_set_expand(png_ptr);
- if (colorType == PNG_COLOR_TYPE_GRAY ||
- colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
- png_set_gray_to_rgb(png_ptr);
-
- png_set_bgr(png_ptr);
-
- if (colorType != PNG_COLOR_TYPE_RGB_ALPHA)
- png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
-
- // After the transformations have been registered, the image data is read again.
- png_read_update_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &w, &h, &bitDepth, &colorType, NULL, NULL, NULL);
- width = w;
- height = h;
-
- if (interlaceType == PNG_INTERLACE_NONE) {
- // PNGs without interlacing can simply be read row by row.
- for (i = 0; i < height; i++) {
- png_read_row(png_ptr, uncompressedDataPtr + i * pitch, NULL);
- }
- } else {
- // PNGs with interlacing require us to allocate an auxillary
- // buffer with pointers to all row starts.
-
- // Allocate row pointer buffer
- png_bytep *pRowPtr = new png_bytep[height];
- if (!pRowPtr) {
- error("Could not allocate memory for row pointers.");
- }
-
- // Initialize row pointers
- for (i = 0; i < height; i++)
- pRowPtr[i] = uncompressedDataPtr + i * pitch;
-
- // Read image data
- png_read_image(png_ptr, pRowPtr);
-
- // Free row pointer buffer
- delete[] pRowPtr;
- }
-
- // Read additional data at the end.
- png_read_end(png_ptr, NULL);
-
- // Destroy libpng structures
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-#else
- Common::MemoryReadStream *fileStr = new Common::MemoryReadStream(fileDataPtr, fileSize, DisposeAfterUse::NO);
- Graphics::PNG *png = new Graphics::PNG();
- if (!png->read(fileStr)) // the fileStr pointer, and thus pFileData will be deleted after this is done
- error("Error while reading PNG image");
-
- Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
- Graphics::Surface *pngSurface = png->getSurface(format);
-
- width = pngSurface->w;
- height = pngSurface->h;
- uncompressedDataPtr = new byte[pngSurface->pitch * pngSurface->h];
- memcpy(uncompressedDataPtr, (byte *)pngSurface->pixels, pngSurface->pitch * pngSurface->h);
- pngSurface->free();
-
- delete pngSurface;
- delete png;
-
-#endif
- // Signal success
- return true;
-}
-
-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);
-}
-
-#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;
-
- png_structp png_ptr = NULL;
- png_infop info_ptr = NULL;
-
- // Create both PNG structures
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- error("Could not create libpng read struct.");
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- error("Could not create libpng info struct.");
- }
-
- // Use alternative reading function
- const byte **ref = &fileDataPtr;
- png_set_read_fn(png_ptr, (void *)ref, png_user_read_data);
-
- // Read PNG Header
- png_read_info(png_ptr, info_ptr);
-
- // Read out PNG informations
- int bitDepth;
- int colorType;
- png_uint_32 w, h;
- png_get_IHDR(png_ptr, info_ptr, &w, &h, &bitDepth, &colorType, NULL, NULL, NULL);
-
- width = w;
- height = h;
-
- // Destroy libpng structures
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-
- 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);
-}
-
-#else
- // We don't need to read the image properties here...
-#endif
-
-
-} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp
index 132c516c12..a9c9de4f0c 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$
- *
*/
/*
@@ -38,25 +35,64 @@
#include "common/savefile.h"
#include "sword25/package/packagemanager.h"
-#include "sword25/gfx/image/pngloader.h"
+#include "sword25/gfx/image/imgloader.h"
#include "sword25/gfx/image/renderedimage.h"
#include "common/system.h"
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();
+ Common::InSaveFile *file = sfm->openForLoading(lastPathComponent(filename, '/'));
+ if (!file)
+ error("Save file \"%s\" could not be loaded.", filename.c_str());
+
+ // 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;
+}
+
RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
_data(0),
_width(0),
@@ -72,15 +108,10 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
byte *pFileData;
uint fileSize;
+ bool isPNG = true;
+
if (filename.hasPrefix("/saves")) {
- // A savegame thumbnail
- Common::SaveFileManager *sfm = g_system->getSavefileManager();
- int slotNum = atoi(filename.c_str() + filename.size() - 3);
- Common::InSaveFile *file = sfm->openForLoading(generateSavegameFilename(slotNum));
- fileSize = file->size();
- pFileData = new byte[fileSize];
- file->read(pFileData, fileSize);
- delete file;
+ pFileData = readSavegameThumbnail(filename, fileSize, isPNG);
} else {
pFileData = pPackage->getFile(filename, &fileSize);
}
@@ -90,18 +121,14 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
return;
}
-#ifndef USE_INTERNAL_PNG_DECODER
- // Determine image properties
- if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) {
- error("Could not read image properties.");
- delete[] pFileData;
- return;
- }
-#endif
-
// Uncompress the image
int pitch;
- if (!PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch)) {
+ if (isPNG)
+ result = ImgLoader::decodePNGImage(pFileData, fileSize, _data, _width, _height, pitch);
+ else
+ result = ImgLoader::decodeThumbnailImage(pFileData, fileSize, _data, _width, _height, pitch);
+
+ if (!result) {
error("Could not decode image.");
delete[] pFileData;
return;
@@ -112,7 +139,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 0f3814eb54..0b9cc11df2 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$
- *
*/
/*
@@ -33,7 +30,7 @@
*/
#include "sword25/package/packagemanager.h"
-#include "sword25/gfx/image/pngloader.h"
+#include "sword25/gfx/image/imgloader.h"
#include "sword25/gfx/image/swimage.h"
namespace Sword25 {
@@ -56,18 +53,10 @@ SWImage::SWImage(const Common::String &filename, bool &result) :
return;
}
-#ifndef USE_INTERNAL_PNG_DECODER
- // Determine image properties
- 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)) {
+ if (!ImgLoader::decodePNGImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) {
error("Could not decode image.");
return;
}
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..6d5b2a623d 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$
- *
*/
/*
@@ -50,12 +47,12 @@ Panel::Panel(RenderObjectPtr<RenderObject> parentPtr, int width, int height, uin
_height = height;
if (_width < 0) {
- error("Tried to initialise a panel with an invalid width (%d).", _width);
+ error("Tried to initialize a panel with an invalid width (%d).", _width);
return;
}
if (_height < 0) {
- error("Tried to initialise a panel with an invalid height (%d).", _height);
+ error("Tried to initialize a panel with an invalid height (%d).", _height);
return;
}
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..4f9ba1d3c5 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$
- *
*/
/*
@@ -32,90 +29,37 @@
*
*/
-// Disable symbol overrides so that we can use png.h
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-
#include "common/memstream.h"
#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++) {
+ // This is only called by createThumbnail below, which
+ // provides a fake 'surface' with LE data in it.
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;
}
@@ -148,7 +92,7 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data)
for (int j = 0; j < 4; ++j) {
const uint32 *srcP = (const uint32 *)data->getBasePtr(x * 4, y * 4 + j + 50);
for (int i = 0; i < 4; ++i) {
- uint32 pixel = READ_LE_UINT32(srcP + i);
+ uint32 pixel = READ_UINT32(srcP + i);
alpha += (pixel >> 24);
red += (pixel >> 16) & 0xff;
green += (pixel >> 8) & 0xff;
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..f79890a9fd 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$
- *
*/
/*
@@ -175,7 +172,7 @@ public:
/// --------------------------------------------------------------
/**
- * Initialises the input engine
+ * Initializes the input engine
* @return Returns a true on success, otherwise false.
*/
bool init();
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..d6388eee2b 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;
@@ -65,7 +63,7 @@ Kernel::Kernel() :
// Create the resource manager
_resourceManager = new ResourceManager(this);
- // Initialise the script engine
+ // Initialize the script engine
_script = new LuaScriptEngine(this);
if (!_script || !_script->init()) {
_initSuccess = false;
diff --git a/engines/sword25/kernel/kernel.h b/engines/sword25/kernel/kernel.h
index 3abf43d239..adf69f92d6 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$
- *
*/
/*
@@ -82,7 +79,7 @@ public:
uint getMilliTicks();
/**
- * Specifies whether the kernel was successfully initialised
+ * Specifies whether the kernel was successfully initialized
*/
bool getInitSuccess() const {
return _initSuccess;
diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp
index 43a144b2c6..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$
- *
*/
/*
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 6bb2b1b102..17e9199b5c 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$
- *
*/
/*
@@ -32,11 +29,9 @@
*
*/
-// Disable symbol overrides so that we can use zlib.h
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-
#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 +42,6 @@
#include "sword25/input/inputengine.h"
#include "sword25/math/regionregistry.h"
#include "sword25/script/script.h"
-#include <zlib.h>
namespace Sword25 {
@@ -291,34 +285,23 @@ 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];
+ thumbnail->seek(0, SEEK_SET);
while (!thumbnail->eos()) {
int bytesRead = thumbnail->read(&buffer[0], FILE_COPY_BUFFER_SIZE);
file->write(&buffer[0], bytesRead);
@@ -331,7 +314,6 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF
file->finalize();
delete file;
- delete[] compressionBuffer;
// Savegameinformationen für diesen Slot aktualisieren.
_impl->readSlotSavegameInformation(slotID);
@@ -372,7 +354,7 @@ bool PersistenceService::loadGame(uint slotID) {
#endif
byte *compressedDataBuffer = new byte[curSavegameInfo.gamedataLength];
- byte *uncompressedDataBuffer = new Bytef[curSavegameInfo.gamedataUncompressedLength];
+ byte *uncompressedDataBuffer = new byte[curSavegameInfo.gamedataUncompressedLength];
Common::String filename = generateSavegameFilename(slotID);
file = sfm->openForLoading(filename);
@@ -385,15 +367,22 @@ bool PersistenceService::loadGame(uint slotID) {
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\".", 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);
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 b77d79e8ea..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$
- *
*/
/*
diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h
index f8006bd62d..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$
- *
*/
/*
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..2e7836ff77 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$
- *
*/
/*
@@ -62,7 +59,7 @@ Polygon::~Polygon() {
}
bool Polygon::init(int vertexCount_, const Vertex *vertices_) {
- // Rember the old obstate to restore it if an error occurs whilst initialising it with the new data
+ // Rember the old obstate to restore it if an error occurs whilst initializing it with the new data
int oldvertexCount = this->vertexCount;
Vertex *oldvertices = this->vertices;
diff --git a/engines/sword25/math/polygon.h b/engines/sword25/math/polygon.h
index 4bb28f827a..ffdbf14f6b 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$
- *
*/
/*
@@ -81,15 +78,15 @@ public:
virtual ~Polygon();
/**
- * Initialises the BS_Polygon with a list of Vertecies.
+ * Initializes the BS_Polygon with a list of Vertecies.
*
* The Vertices need to define a polygon must not have self-intersections.
- * If a polygon already has verticies, this will re-initialise it with the new list.
+ * If a polygon already has verticies, this will re-initialize it with the new list.
*
* @param VertexCount The number of vertices being passed
* @param Vertecies An array of BS_Vertex objects representing the vertices in the polygon.
* @return Returns false if the Vertecies have self-intersections. In this case,
- * the object is not initialised.
+ * the object is not initialized.
*/
bool init(int vertexCount_, const Vertex *vertices_);
diff --git a/engines/sword25/math/region.cpp b/engines/sword25/math/region.cpp
index 5d08b0c14e..7681ef6d9f 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$
- *
*/
/*
@@ -118,7 +115,7 @@ bool Region::init(const Polygon &contour, const Common::Array<Polygon> *pHoles)
}
- // Initialise bounding box
+ // Initialize bounding box
updateBoundingBox();
_valid = true;
diff --git a/engines/sword25/math/region.h b/engines/sword25/math/region.h
index fa65b4b7ad..0fd7223631 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$
- *
*/
/*
@@ -76,12 +73,12 @@ public:
virtual ~Region();
/**
- * Initialises a BS_Region object
+ * Initializes a BS_Region object
* @param Contour A polygon indicating the outline of the region
* @param pHoles A pointer to an array of polygons representing the hole state in the region.
* If the region has no holes, it must be passed as NULL. The default value is NULL.
* @return Returns true if the initialisation was successful, otherwise false.
- * @remark If the region was already initialised, the old state will be deleted.
+ * @remark If the region was already initialized, the old state will be deleted.
*/
virtual bool init(const Polygon &contour, const Common::Array<Polygon> *pHoles = NULL);
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..4cb0eaca30 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$
- *
*/
/*
@@ -46,7 +43,8 @@
#include <math.h>
#include "common/rect.h"
#include "sword25/kernel/common.h"
-#include "sword25/util/lua/lua.h"
+
+struct lua_State;
#if defined(MACOSX) || defined(SOLARIS) || defined(__MINGW32__)
#define sqrtf(x) ((float)sqrt(x))
diff --git a/engines/sword25/math/walkregion.cpp b/engines/sword25/math/walkregion.cpp
index 8306553f7b..bace4d54bc 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$
- *
*/
/*
@@ -104,7 +101,7 @@ static void initDijkstraNodes(DijkstraNode::Container &dijkstraNodes, const Regi
// Allocate sufficient space in the array
dijkstraNodes.resize(nodes.size());
- // Initialise all the nodes which are visible from the starting node
+ // Initialize all the nodes which are visible from the starting node
DijkstraNode::Iter dijkstraIter = dijkstraNodes.begin();
for (Common::Array<Vertex>::const_iterator nodesIter = nodes.begin();
nodesIter != nodes.end(); nodesIter++, dijkstraIter++) {
@@ -176,7 +173,7 @@ void reverseArray(Common::Array<T> &arr) {
bool WalkRegion::findPath(const Vertex &start, const Vertex &end, BS_Path &path) const {
// This is an implementation of Dijkstra's algorithm
- // Initialise edge node list
+ // Initialize edge node list
DijkstraNode::Container dijkstraNodes;
initDijkstraNodes(dijkstraNodes, *this, start, _nodes);
@@ -250,7 +247,7 @@ void WalkRegion::initNodeVector() {
}
void WalkRegion::computeVisibilityMatrix() {
- // Initialise visibility matrix
+ // Initialize visibility matrix
_visibilityMatrix = Common::Array< Common::Array <int> >();
for (uint idx = 0; idx < _nodes.size(); ++idx) {
Common::Array<int> arr;
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/module.mk b/engines/sword25/module.mk
index da91c848b5..302120c500 100644
--- a/engines/sword25/module.mk
+++ b/engines/sword25/module.mk
@@ -24,7 +24,7 @@ MODULE_OBJS := \
gfx/text.o \
gfx/timedrenderobject.o \
gfx/image/art.o \
- gfx/image/pngloader.o \
+ gfx/image/imgloader.o \
gfx/image/renderedimage.o \
gfx/image/swimage.o \
gfx/image/vectorimage.o \
@@ -60,7 +60,6 @@ MODULE_OBJS := \
util/lua/ldblib.o \
util/lua/ldebug.o \
util/lua/ldo.o \
- util/lua/ldump.o \
util/lua/lfunc.o \
util/lua/lgc.o \
util/lua/linit.o \
@@ -79,10 +78,9 @@ MODULE_OBJS := \
util/lua/ltable.o \
util/lua/ltablib.o \
util/lua/ltm.o \
- util/lua/lundump.o \
util/lua/lvm.o \
util/lua/lzio.o \
- util/lua/print.o \
+ util/lua/scummvm_file.o \
util/pluto/pdep.o \
util/pluto/pluto.o \
util/pluto/plzio.o
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..9d394309e6 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$
- *
*/
/*
@@ -115,7 +112,7 @@ bool LuaScriptEngine::init() {
// Place the error handler function in the Lua registry, and remember the index
_pcallErrorhandlerRegistryIndex = luaL_ref(_state, LUA_REGISTRYINDEX);
- // Initialise the Pluto-Persistence library
+ // Initialize the Pluto-Persistence library
luaopen_pluto(_state);
lua_pop(_state, 1);
@@ -180,7 +177,7 @@ bool LuaScriptEngine::executeFile(const Common::String &fileName) {
}
bool LuaScriptEngine::executeString(const Common::String &code) {
- return executeBuffer((byte *)code.c_str(), code.size(), "???");
+ return executeBuffer((const byte *)code.c_str(), code.size(), "???");
}
namespace {
diff --git a/engines/sword25/script/luascript.h b/engines/sword25/script/luascript.h
index b66c32176a..1a4a38c3be 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$
- *
*/
/*
@@ -39,7 +36,8 @@
#include "common/str-array.h"
#include "sword25/kernel/common.h"
#include "sword25/script/script.h"
-#include "sword25/util/lua/lua.h"
+
+struct lua_State;
namespace Sword25 {
@@ -51,7 +49,7 @@ public:
virtual ~LuaScriptEngine();
/**
- * Initialises the scripting engine
+ * Initializes the scripting engine
* @return Returns true if successful, otherwise false.
*/
virtual bool init();
diff --git a/engines/sword25/script/script.h b/engines/sword25/script/script.h
index 9ca146026e..04f248fe7e 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$
- *
*/
/*
@@ -57,7 +54,7 @@ public:
// -----------------------------------------------------------------------------
/**
- * Initialises the scrip tengine. Returns true if successful, false otherwise.
+ * Initializes the scrip tengine. Returns true if successful, false otherwise.
*/
virtual bool init() = 0;
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..4dbd475846 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$
- *
*/
/*
@@ -91,7 +88,7 @@ public:
~SoundEngine() {}
/**
- * Initialises the sound engine
+ * Initializes the sound engine
* @param SampleRate Specifies the sample rate to use.
* @param Channels The maximum number of channels. The default is 32.
* @return Returns true on success, otherwise false.
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..b111746c32 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$
- *
*/
/*
@@ -97,7 +94,7 @@ Common::Error Sword25Engine::run() {
}
Common::Error Sword25Engine::appStart() {
- // Initialise the graphics mode to ARGB8888
+ // Initialize the graphics mode to ARGB8888
Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
initGraphics(800, 600, true, &format);
if (format != g_system->getScreenFormat())
@@ -145,7 +142,7 @@ bool Sword25Engine::appMain() {
}
bool Sword25Engine::appEnd() {
- // The kernel is shutdown, and un-initialises all subsystems
+ // The kernel is shutdown, and un-initializes all subsystems
Kernel::deleteInstance();
AnimationTemplateRegistry::destroy();
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/lapi.cpp b/engines/sword25/util/lua/lapi.cpp
index b1118db368..16f8460e39 100644
--- a/engines/sword25/util/lua/lapi.cpp
+++ b/engines/sword25/util/lua/lapi.cpp
@@ -26,9 +26,8 @@
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
-#include "lundump.h"
#include "lvm.h"
-
+#include "common/textconsole.h"
const char lua_ident[] =
@@ -876,17 +875,8 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
- int status;
- TValue *o;
- lua_lock(L);
- api_checknelems(L, 1);
- o = L->top - 1;
- if (isLfunction(o))
- status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
- else
- status = 1;
- lua_unlock(L);
- return status;
+ error("lua_dump not supported: Handling of precompiled LUA scripts has been removed in ScummVM");
+ return 1; // error
}
diff --git a/engines/sword25/util/lua/lauxlib.cpp b/engines/sword25/util/lua/lauxlib.cpp
index 53c0556625..8978cd5613 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>
@@ -23,7 +22,8 @@
#include "lua.h"
#include "lauxlib.h"
-
+#include "scummvm_file.h"
+#include "common/textconsole.h"
#define FREELIST_REF 0 /* free list of references */
@@ -521,7 +521,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
typedef struct LoadF {
int extraline;
- FILE *f;
+ Sword25::Sword25FileProxy *f;
char buff[LUAL_BUFFERSIZE];
} LoadF;
@@ -534,27 +534,31 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
*size = 1;
return "\n";
}
- if (feof(lf->f)) return NULL;
- *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
+ if (lf->f->eof()) return NULL;
+ *size = lf->f->read(lf->buff, 1, sizeof(lf->buff));
return (*size > 0) ? lf->buff : NULL;
}
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;
+ const char *serr = "General error";
+ 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;
}
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
LoadF lf;
int status, readstatus;
- int c;
+// int c;
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
lf.extraline = 0;
+
+ lua_pushfstring(L, "@%s", filename);
+ lf.f = new Sword25::Sword25FileProxy(filename, "r");
+/*
if (filename == NULL) {
lua_pushliteral(L, "=stdin");
lf.f = stdin;
@@ -564,23 +568,25 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
lf.f = fopen(filename, "r");
if (lf.f == NULL) return errfile(L, "open", fnameindex);
}
- c = getc(lf.f);
- if (c == '#') { /* Unix exec. file? */
+
+ c = lf.f->getc();
+ if (c == '#') { // Unix exec. file?
lf.extraline = 1;
- while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
- if (c == '\n') c = getc(lf.f);
+ while ((c = lf.f->getc()) != EOF && c != '\n') ; // skip first line
+ if (c == '\n') c = lf.f->getc();
}
- if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
- lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
+ if (c == LUA_SIGNATURE[0] && filename) { // binary file?
+ lf.f = freopen(filename, "rb", lf.f); // reopen in binary mode
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
- /* skip eventual `#!...' */
- while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
+ // skip eventual `#!...'
+ while ((c = lf.f->getc()) != EOF && c != LUA_SIGNATURE[0]) ;
lf.extraline = 0;
}
ungetc(c, lf.f);
+*/
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
- readstatus = ferror(lf.f);
- if (filename) fclose(lf.f); /* close file (even in case of errors) */
+ readstatus = 0; //ferror(lf.f);
+ if (filename) delete lf.f; // close file (even in case of errors)
if (readstatus) {
lua_settop(L, fnameindex); /* ignore results from `lua_load' */
return errfile(L, "read", fnameindex);
@@ -638,7 +644,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
static int panic (lua_State *L) {
(void)L; /* to avoid warnings */
- fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
+ warning("PANIC: unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
return 0;
}
diff --git a/engines/sword25/util/lua/ldo.cpp b/engines/sword25/util/lua/ldo.cpp
index 07508fbb14..bbcdf98b3d 100644
--- a/engines/sword25/util/lua/ldo.cpp
+++ b/engines/sword25/util/lua/ldo.cpp
@@ -5,6 +5,16 @@
*/
+// FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp.
+// Neither of these is supported in ScummVM. So we need to come up
+// with a replacement. The most simple, direct and crude approach:
+// Replace "throw" with an "error()" call. Of course we only
+// would want to do that if this actually never happens...
+#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
+#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+
+#include "common/textconsole.h"
+
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
@@ -26,10 +36,9 @@
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
-#include "lundump.h"
#include "lvm.h"
#include "lzio.h"
-
+#include "common/textconsole.h"
@@ -94,6 +103,11 @@ static void resetstack (lua_State *L, int status) {
void luaD_throw (lua_State *L, int errcode) {
if (L->errorJmp) {
L->errorJmp->status = errcode;
+ // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp.
+ // Neither of these is supported in ScummVM. So we need to come up
+ // with a replacement. The most simple, direct and crude approach:
+ // Replace "throw" with an "error()" call. Of course we only
+ // would want to do that if this actually never happens...
LUAI_THROW(L, L->errorJmp);
}
else {
@@ -103,7 +117,7 @@ void luaD_throw (lua_State *L, int errcode) {
lua_unlock(L);
G(L)->panic(L);
}
- exit(EXIT_FAILURE);
+ error("luaD_throw failure");
}
}
@@ -113,6 +127,11 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
lj.status = 0;
lj.previous = L->errorJmp; /* chain new error handler */
L->errorJmp = &lj;
+ // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp.
+ // Neither of these is supported in ScummVM. So we need to come up
+ // with a replacement. The most simple, direct and crude approach:
+ // Replace "throw" with an "error()" call. Of course we only
+ // would want to do that if this actually never happens...
LUAI_TRY(L, &lj,
(*f)(L, ud);
);
@@ -494,8 +513,9 @@ static void f_parser (lua_State *L, void *ud) {
struct SParser *p = cast(struct SParser *, ud);
int c = luaZ_lookahead(p->z);
luaC_checkGC(L);
- tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,
- &p->buff, p->name);
+ if (c == LUA_SIGNATURE[0])
+ error("Handling of precompiled LUA scripts has been removed in ScummVM");
+ tf = luaY_parser(L, p->z, &p->buff, p->name);
cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));
cl->l.p = tf;
for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */
diff --git a/engines/sword25/util/lua/ldump.cpp b/engines/sword25/util/lua/ldump.cpp
deleted file mode 100644
index 3ce16542d6..0000000000
--- a/engines/sword25/util/lua/ldump.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
-** $Id$
-** save precompiled Lua chunks
-** See Copyright Notice in lua.h
-*/
-
-#include <stddef.h>
-
-#define ldump_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "lobject.h"
-#include "lstate.h"
-#include "lundump.h"
-
-typedef struct {
- lua_State* L;
- lua_Writer writer;
- void* data;
- int strip;
- int status;
-} DumpState;
-
-#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
-#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
-
-static void DumpBlock(const void* b, size_t size, DumpState* D)
-{
- if (D->status==0)
- {
- lua_unlock(D->L);
- D->status=(*D->writer)(D->L,b,size,D->data);
- lua_lock(D->L);
- }
-}
-
-static void DumpChar(int y, DumpState* D)
-{
- char x=(char)y;
- DumpVar(x,D);
-}
-
-static void DumpInt(int x, DumpState* D)
-{
- DumpVar(x,D);
-}
-
-static void DumpNumber(lua_Number x, DumpState* D)
-{
- DumpVar(x,D);
-}
-
-static void DumpVector(const void* b, int n, size_t size, DumpState* D)
-{
- DumpInt(n,D);
- DumpMem(b,n,size,D);
-}
-
-static void DumpString(const TString* s, DumpState* D)
-{
- if (s==NULL || getstr(s)==NULL)
- {
- size_t size=0;
- DumpVar(size,D);
- }
- else
- {
- size_t size=s->tsv.len+1; /* include trailing '\0' */
- DumpVar(size,D);
- DumpBlock(getstr(s),size,D);
- }
-}
-
-#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
-
-static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
-
-static void DumpConstants(const Proto* f, DumpState* D)
-{
- int i,n=f->sizek;
- DumpInt(n,D);
- for (i=0; i<n; i++)
- {
- const TValue* o=&f->k[i];
- DumpChar(ttype(o),D);
- switch (ttype(o))
- {
- case LUA_TNIL:
- break;
- case LUA_TBOOLEAN:
- DumpChar(bvalue(o),D);
- break;
- case LUA_TNUMBER:
- DumpNumber(nvalue(o),D);
- break;
- case LUA_TSTRING:
- DumpString(rawtsvalue(o),D);
- break;
- default:
- lua_assert(0); /* cannot happen */
- break;
- }
- }
- n=f->sizep;
- DumpInt(n,D);
- for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
-}
-
-static void DumpDebug(const Proto* f, DumpState* D)
-{
- int i,n;
- n= (D->strip) ? 0 : f->sizelineinfo;
- DumpVector(f->lineinfo,n,sizeof(int),D);
- n= (D->strip) ? 0 : f->sizelocvars;
- DumpInt(n,D);
- for (i=0; i<n; i++)
- {
- DumpString(f->locvars[i].varname,D);
- DumpInt(f->locvars[i].startpc,D);
- DumpInt(f->locvars[i].endpc,D);
- }
- n= (D->strip) ? 0 : f->sizeupvalues;
- DumpInt(n,D);
- for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
-}
-
-static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
-{
- DumpString((f->source==p || D->strip) ? NULL : f->source,D);
- DumpInt(f->linedefined,D);
- DumpInt(f->lastlinedefined,D);
- DumpChar(f->nups,D);
- DumpChar(f->numparams,D);
- DumpChar(f->is_vararg,D);
- DumpChar(f->maxstacksize,D);
- DumpCode(f,D);
- DumpConstants(f,D);
- DumpDebug(f,D);
-}
-
-static void DumpHeader(DumpState* D)
-{
- char h[LUAC_HEADERSIZE];
- luaU_header(h);
- DumpBlock(h,LUAC_HEADERSIZE,D);
-}
-
-/*
-** dump Lua function as precompiled chunk
-*/
-int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
-{
- DumpState D;
- D.L=L;
- D.writer=w;
- D.data=data;
- D.strip=strip;
- D.status=0;
- DumpHeader(&D);
- DumpFunction(f,NULL,&D);
- return D.status;
-}
diff --git a/engines/sword25/util/lua/liolib.cpp b/engines/sword25/util/lua/liolib.cpp
index aa44dcafa3..b505d1e4df 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>
@@ -17,7 +16,8 @@
#include "lauxlib.h"
#include "lualib.h"
-
+#include "common/textconsole.h"
+#include "scummvm_file.h"
#define IO_INPUT 1
@@ -28,7 +28,7 @@ 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 */
+ int en = 0; /*errno;*/ // Currently hardcoded for ScumMVM, this may need to be changed
if (i) {
lua_pushboolean(L, 1);
return 1;
@@ -36,55 +36,56 @@ static int pushresult (lua_State *L, int i, const char *filename) {
else {
lua_pushnil(L);
if (filename)
- lua_pushfstring(L, "%s: %s", filename, strerror(en));
+ lua_pushfstring(L, "%s: %s", filename, "General error" /*strerror(en)*/);
else
- lua_pushfstring(L, "%s", strerror(en));
+ lua_pushfstring(L, "%s", "General error" /*strerror(en)*/);
lua_pushinteger(L, en);
return 3;
}
}
-
+/*
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));
}
-
+*/
#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
-
+#define tofileProxy(L) ((Sword25::Sword25FileProxy **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
static int io_type (lua_State *L) {
+ return luaL_error(L, "%s", "LUA I/O has been removed in ScummVM");
+/*
void *ud;
luaL_checkany(L, 1);
ud = lua_touserdata(L, 1);
lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))
- lua_pushnil(L); /* not a file */
+ lua_pushnil(L); // not a file
else if (*((FILE **)ud) == NULL)
lua_pushliteral(L, "closed file");
else
lua_pushliteral(L, "file");
return 1;
+*/
}
-
-static FILE *tofile (lua_State *L) {
- FILE **f = tofilep(L);
+static Sword25::Sword25FileProxy *tofile (lua_State *L) {
+ Sword25::Sword25FileProxy **f = tofileProxy(L);
if (*f == NULL)
luaL_error(L, "attempt to use a closed file");
return *f;
}
-
/*
** When creating file handles, always creates a `closed' file handle
** before opening the actual file; so, if there is a memory error, the
** file is not left opened.
*/
-static FILE **newfile (lua_State *L) {
- FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
+static Sword25::Sword25FileProxy **newfile (lua_State *L) {
+ Sword25::Sword25FileProxy **pf = (Sword25::Sword25FileProxy **)lua_newuserdata(L, sizeof(Sword25::Sword25FileProxy *));
*pf = NULL; /* file handle is currently `closed' */
luaL_getmetatable(L, LUA_FILEHANDLE);
lua_setmetatable(L, -2);
@@ -106,10 +107,13 @@ static int io_noclose (lua_State *L) {
** function to close 'popen' files
*/
static int io_pclose (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+/*
FILE **p = tofilep(L);
int ok = lua_pclose(L, *p);
*p = NULL;
return pushresult(L, ok, NULL);
+ */
}
@@ -117,52 +121,63 @@ static int io_pclose (lua_State *L) {
** function to close regular files
*/
static int io_fclose (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+ /*
FILE **p = tofilep(L);
int ok = (fclose(*p) == 0);
*p = NULL;
return pushresult(L, ok, NULL);
+ */
}
-
+/*
static int aux_close (lua_State *L) {
lua_getfenv(L, 1);
lua_getfield(L, -1, "__close");
return (lua_tocfunction(L, -1))(L);
}
-
+*/
static int io_close (lua_State *L) {
if (lua_isnone(L, 1))
lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
- tofile(L); /* make sure argument is a file */
- return aux_close(L);
+
+ Sword25::Sword25FileProxy **f = tofileProxy(L);
+ delete *f;
+ *f = NULL;
+
+ return 0;
}
static int io_gc (lua_State *L) {
- FILE *f = *tofilep(L);
- /* ignore closed files */
- if (f != NULL)
- aux_close(L);
+ Sword25::Sword25FileProxy **f = tofileProxy(L);
+ // ignore closed files
+ if (*f != NULL)
+ delete *f;
+
return 0;
}
static int io_tostring (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+ /*
FILE *f = *tofilep(L);
if (f == NULL)
lua_pushliteral(L, "file (closed)");
else
lua_pushfstring(L, "file (%p)", f);
return 1;
+ */
}
static int io_open (lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
- FILE **pf = newfile(L);
- *pf = fopen(filename, mode);
+ Sword25::Sword25FileProxy **pf = newfile(L);
+ *pf = new Sword25::Sword25FileProxy(filename, mode);
return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}
@@ -172,21 +187,22 @@ static int io_open (lua_State *L) {
** correct __close for 'popen' files
*/
static int io_popen (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+/*
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
FILE **pf = newfile(L);
*pf = lua_popen(L, filename, mode);
return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
+ */
}
static int io_tmpfile (lua_State *L) {
- FILE **pf = newfile(L);
- *pf = tmpfile();
- return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
+ return luaL_error(L, "%s", "LUA I/O error descriptions have been removed in ScummVM");
}
-
+/*
static FILE *getiofile (lua_State *L, int findex) {
FILE *f;
lua_rawgeti(L, LUA_ENVIRONINDEX, findex);
@@ -195,8 +211,8 @@ static FILE *getiofile (lua_State *L, int findex) {
luaL_error(L, "standard %s file is closed", fnames[findex - 1]);
return f;
}
-
-
+*/
+/*
static int g_iofile (lua_State *L, int f, const char *mode) {
if (!lua_isnoneornil(L, 1)) {
const char *filename = lua_tostring(L, 1);
@@ -207,24 +223,26 @@ static int g_iofile (lua_State *L, int f, const char *mode) {
fileerror(L, 1, filename);
}
else {
- tofile(L); /* check that it's a valid file handle */
+ tofile(L); // check that it's a valid file handle
lua_pushvalue(L, 1);
}
lua_rawseti(L, LUA_ENVIRONINDEX, f);
}
- /* return current value */
+ // return current value
lua_rawgeti(L, LUA_ENVIRONINDEX, f);
return 1;
}
-
+*/
static int io_input (lua_State *L) {
- return g_iofile(L, IO_INPUT, "r");
+ error("LUA I/O has been removed in ScummVM");
+// return g_iofile(L, IO_INPUT, "r");
}
static int io_output (lua_State *L) {
- return g_iofile(L, IO_OUTPUT, "w");
+ error("LUA I/O has been removed in ScummVM");
+// return g_iofile(L, IO_OUTPUT, "w");
}
@@ -246,8 +264,10 @@ static int f_lines (lua_State *L) {
static int io_lines (lua_State *L) {
- if (lua_isnoneornil(L, 1)) { /* no arguments? */
- /* will iterate over default input */
+ error("LUA I/O has been removed in ScummVM");
+/*
+ if (lua_isnoneornil(L, 1)) { // no arguments?
+ // will iterate over default input
lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);
return f_lines(L);
}
@@ -260,6 +280,7 @@ static int io_lines (lua_State *L) {
aux_lines(L, lua_gettop(L), 1);
return 1;
}
+ */
}
@@ -269,18 +290,18 @@ static int io_lines (lua_State *L) {
** =======================================================
*/
-
-static int read_number (lua_State *L, FILE *f) {
+/*
+static int read_number (lua_State *L, Sword25::Sword25FileProxy *f) {
lua_Number d;
if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
lua_pushnumber(L, d);
return 1;
}
- else return 0; /* read fails */
+ else return 0; // read fails
}
-static int test_eof (lua_State *L, FILE *f) {
+static int test_eof (lua_State *L, Sword25::Sword25FileProxy *f) {
int c = getc(f);
ungetc(c, f);
lua_pushlstring(L, NULL, 0);
@@ -288,56 +309,56 @@ static int test_eof (lua_State *L, FILE *f) {
}
-static int read_line (lua_State *L, FILE *f) {
+static int read_line (lua_State *L, Sword25::Sword25FileProxy *f) {
luaL_Buffer b;
luaL_buffinit(L, &b);
for (;;) {
size_t l;
char *p = luaL_prepbuffer(&b);
- if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
- luaL_pushresult(&b); /* close buffer */
- return (lua_objlen(L, -1) > 0); /* check whether read something */
+ if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { // eof?
+ luaL_pushresult(&b); // close buffer
+ return (lua_objlen(L, -1) > 0); // check whether read something
}
l = strlen(p);
if (l == 0 || p[l-1] != '\n')
luaL_addsize(&b, l);
else {
- luaL_addsize(&b, l - 1); /* do not include `eol' */
- luaL_pushresult(&b); /* close buffer */
- return 1; /* read at least an `eol' */
+ luaL_addsize(&b, l - 1); // do not include `eol'
+ luaL_pushresult(&b); // close buffer
+ return 1; // read at least an `eol'
}
}
}
-static int read_chars (lua_State *L, FILE *f, size_t n) {
- size_t rlen; /* how much to read */
- size_t nr; /* number of chars actually read */
+static int read_chars (lua_State *L, Sword25::Sword25FileProxy *f, size_t n) {
+ size_t rlen; // how much to read
+ size_t nr; // number of chars actually read
luaL_Buffer b;
luaL_buffinit(L, &b);
- rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
+ rlen = LUAL_BUFFERSIZE; // try to read that much each time
do {
char *p = luaL_prepbuffer(&b);
- if (rlen > n) rlen = n; /* cannot read more than asked */
+ if (rlen > n) rlen = n; // cannot read more than asked
nr = fread(p, sizeof(char), rlen, f);
luaL_addsize(&b, nr);
- n -= nr; /* still have to read `n' chars */
- } while (n > 0 && nr == rlen); /* until end of count or eof */
- luaL_pushresult(&b); /* close buffer */
+ n -= nr; // still have to read `n' chars
+ } while (n > 0 && nr == rlen); // until end of count or eof
+ luaL_pushresult(&b); // close buffer
return (n == 0 || lua_objlen(L, -1) > 0);
}
-static int g_read (lua_State *L, FILE *f, int first) {
+static int g_read (lua_State *L, Sword25::Sword25FileProxy *f, int first) {
int nargs = lua_gettop(L) - 1;
int success;
int n;
clearerr(f);
- if (nargs == 0) { /* no arguments? */
+ if (nargs == 0) { // no arguments?
success = read_line(L, f);
- n = first+1; /* to return 1 result */
+ n = first+1; // to return 1 result
}
- else { /* ensure stack space for all results and for auxlib's buffer */
+ else { // ensure stack space for all results and for auxlib's buffer
luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
success = 1;
for (n = first; nargs-- && success; n++) {
@@ -349,15 +370,15 @@ static int g_read (lua_State *L, FILE *f, int first) {
const char *p = lua_tostring(L, n);
luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
switch (p[1]) {
- case 'n': /* number */
+ case 'n': // number
success = read_number(L, f);
break;
- case 'l': /* line */
+ case 'l': // line
success = read_line(L, f);
break;
- case 'a': /* file */
- read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
- success = 1; /* always success */
+ case 'a': // file
+ read_chars(L, f, ~((size_t)0)); // read MAX_SIZE_T chars
+ success = 1; // always success
break;
default:
return luaL_argerror(L, n, "invalid format");
@@ -368,58 +389,66 @@ static int g_read (lua_State *L, FILE *f, int first) {
if (ferror(f))
return pushresult(L, 0, NULL);
if (!success) {
- lua_pop(L, 1); /* remove last result */
- lua_pushnil(L); /* push nil instead */
+ lua_pop(L, 1); // remove last result
+ lua_pushnil(L); // push nil instead
}
return n - first;
}
-
+*/
static int io_read (lua_State *L) {
- return g_read(L, getiofile(L, IO_INPUT), 1);
+ error("LUA I/O has been removed in ScummVM");
+// return g_read(L, getiofile(L, IO_INPUT), 1);
}
static int f_read (lua_State *L) {
- return g_read(L, tofile(L), 2);
+ error("LUA I/O has been removed in ScummVM");
+// return g_read(L, tofile(L), 2);
}
static int io_readline (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+/*
FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
int sucess;
- if (f == NULL) /* file is already closed? */
+ if (f == NULL) // file is already closed?
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? */
+ else { // EOF
+ if (lua_toboolean(L, lua_upvalueindex(2))) { // generator created file?
lua_settop(L, 0);
lua_pushvalue(L, lua_upvalueindex(1));
- aux_close(L); /* close it */
+ aux_close(L); // close it
}
return 0;
}
+*/
}
/* }====================================================== */
-static int g_write (lua_State *L, FILE *f, int arg) {
+static int g_write (lua_State *L, Sword25::Sword25FileProxy *f, int arg) {
int nargs = lua_gettop(L) - 1;
int status = 1;
for (; nargs--; arg++) {
if (lua_type(L, arg) == LUA_TNUMBER) {
- /* optimization: could be done exactly as for strings */
- status = status &&
- fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
- }
+ // optimization: could be done exactly as for strings
+ if (status) {
+ char buffer[20];
+ sprintf(buffer, LUA_NUMBER_FMT, lua_tonumber(L, arg));
+ status = f->write(buffer, strlen(buffer)) == strlen(buffer);
+ }
+ }
else {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
- status = status && (fwrite(s, sizeof(char), l, f) == l);
+ status = status && (f->write(s, l) == l);
}
}
return pushresult(L, status, NULL);
@@ -427,7 +456,8 @@ static int g_write (lua_State *L, FILE *f, int arg) {
static int io_write (lua_State *L) {
- return g_write(L, getiofile(L, IO_OUTPUT), 1);
+ error("LUA I/O has been removed in ScummVM");
+// return g_write(L, getiofile(L, IO_OUTPUT), 1);
}
@@ -437,6 +467,8 @@ static int f_write (lua_State *L) {
static int f_seek (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+ /*
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL};
FILE *f = tofile(L);
@@ -444,15 +476,18 @@ static int f_seek (lua_State *L) {
long offset = luaL_optlong(L, 3, 0);
op = fseek(f, offset, mode[op]);
if (op)
- return pushresult(L, 0, NULL); /* error */
+ return pushresult(L, 0, NULL); // error
else {
lua_pushinteger(L, ftell(f));
return 1;
}
+*/
}
static int f_setvbuf (lua_State *L) {
+ error("LUA I/O has been removed in ScummVM");
+ /*
static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
static const char *const modenames[] = {"no", "full", "line", NULL};
FILE *f = tofile(L);
@@ -460,17 +495,20 @@ static int f_setvbuf (lua_State *L) {
lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
int res = setvbuf(f, NULL, mode[op], sz);
return pushresult(L, res == 0, NULL);
+ */
}
static int io_flush (lua_State *L) {
- return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
+ error("LUA I/O has been removed in ScummVM");
+// return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
}
static int f_flush (lua_State *L) {
- return pushresult(L, fflush(tofile(L)) == 0, NULL);
+ error("LUA I/O has been removed in ScummVM");
+// return pushresult(L, fflush(tofile(L)) == 0, NULL);
}
@@ -511,18 +549,18 @@ static void createmeta (lua_State *L) {
luaL_register(L, NULL, flib); /* file methods */
}
-
+/*
static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
*newfile(L) = f;
if (k > 0) {
lua_pushvalue(L, -1);
lua_rawseti(L, LUA_ENVIRONINDEX, k);
}
- lua_pushvalue(L, -2); /* copy environment */
- lua_setfenv(L, -2); /* set it */
+ lua_pushvalue(L, -2); // copy environment
+ lua_setfenv(L, -2); // set it
lua_setfield(L, -3, fname);
}
-
+*/
static void newfenv (lua_State *L, lua_CFunction cls) {
lua_createtable(L, 0, 1);
@@ -540,9 +578,11 @@ LUALIB_API int luaopen_io (lua_State *L) {
luaL_register(L, LUA_IOLIBNAME, iolib);
/* create (and set) default files */
newfenv(L, io_noclose); /* close function for default files */
+/*
createstdfile(L, stdin, IO_INPUT, "stdin");
createstdfile(L, stdout, IO_OUTPUT, "stdout");
createstdfile(L, stderr, 0, "stderr");
+*/
lua_pop(L, 1); /* pop environment for default files */
lua_getfield(L, -1, "popen");
newfenv(L, io_pclose); /* create environment for 'popen' */
diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp
index fdde2b8e5f..4d73a6a600 100644
--- a/engines/sword25/util/lua/llex.cpp
+++ b/engines/sword25/util/lua/llex.cpp
@@ -6,7 +6,7 @@
#include <ctype.h>
-#include <locale.h>
+#include <stdio.h>
#include <string.h>
#define llex_c
@@ -176,9 +176,23 @@ 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();
+ // Normally we'd use localeconv() to get the decimal point separator, but
+ // annoyingly that is not available on some platforms, e.g. Android. Figure
+ // it out by formatting a known value and extract the separator from that
+ // instead. The result could be cached, but considering the game I doubt
+ // this will ever be a bottleneck. Note that the separator is assumed to fit
+ // in a char, but that was a limitation in the original code as well.
char old = ls->decpoint;
- ls->decpoint = (cv ? cv->decimal_point[0] : '.');
+ char buf[5];
+ int i;
+ sprintf(buf, "%.1f", 1.0);
+ ls->decpoint = '.';
+ for (i = 0; buf[i]; i++) {
+ if (!isspace(buf[i]) && !isdigit(buf[i])) {
+ ls->decpoint = buf[i];
+ break;
+ }
+ }
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/lmathlib.cpp b/engines/sword25/util/lua/lmathlib.cpp
index 7e64d75789..6c36bbcf4e 100644
--- a/engines/sword25/util/lua/lmathlib.cpp
+++ b/engines/sword25/util/lua/lmathlib.cpp
@@ -5,6 +5,10 @@
*/
+// FIXME: rand and srand should be replaced by a RandomSource
+#define FORBIDDEN_SYMBOL_EXCEPTION_rand
+#define FORBIDDEN_SYMBOL_EXCEPTION_srand
+
#include <stdlib.h>
// MSVC does not define M_PI, M_SQRT2 and other math defines by default.
// _USE_MATH_DEFINES must be defined in order to have these defined, thus
diff --git a/engines/sword25/util/lua/loadlib.cpp b/engines/sword25/util/lua/loadlib.cpp
index 2549e2bdb1..9795a575f5 100644
--- a/engines/sword25/util/lua/loadlib.cpp
+++ b/engines/sword25/util/lua/loadlib.cpp
@@ -9,10 +9,6 @@
*/
-#include <stdlib.h>
-#include <string.h>
-
-
#define loadlib_c
#define LUA_LIB
@@ -35,18 +31,6 @@
#define LIB_FAIL "open"
-/* error codes for ll_loadfunc */
-#define ERRLIB 1
-#define ERRFUNC 2
-
-#define setprogdir(L) ((void)0)
-
-
-static void ll_unloadlib (void *lib);
-static void *ll_load (lua_State *L, const char *path);
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
-
-
/*
** {======================================================
** Fallback for other systems
@@ -60,24 +44,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
#define DLMSG "dynamic libraries not enabled; check your Lua installation"
-static void ll_unloadlib (void *lib) {
- (void)lib; /* to avoid warnings */
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- (void)path; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- (void)lib; (void)sym; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
/* }====================================================== */
@@ -108,39 +74,33 @@ static void **ll_register (lua_State *L, const char *path) {
*/
static int gctm (lua_State *L) {
void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
- if (*lib) ll_unloadlib(*lib);
*lib = NULL; /* mark library as closed */
return 0;
}
-static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
- void **reg = ll_register(L, path);
- if (*reg == NULL) *reg = ll_load(L, path);
- if (*reg == NULL)
- return ERRLIB; /* unable to load library */
- else {
- lua_CFunction f = ll_sym(L, *reg, sym);
- if (f == NULL)
- return ERRFUNC; /* unable to find function */
- lua_pushcfunction(L, f);
- return 0; /* return function */
- }
-}
+/* error codes for ll_loadfunc */
+#define ERRLIB 1
+#define ERRFUNC 2
static int ll_loadlib (lua_State *L) {
const char *path = luaL_checkstring(L, 1);
- const char *init = luaL_checkstring(L, 2);
- int stat = ll_loadfunc(L, path, init);
- if (stat == 0) /* no errors? */
- return 1; /* return the loaded function */
- else { /* error; error message is on stack top */
- lua_pushnil(L);
- lua_insert(L, -2);
- lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init");
- return 3; /* return nil, error message, and where */
+// const char *init = luaL_checkstring(L, 2);
+ int stat;
+ void **reg = ll_register(L, path);
+ if (*reg == NULL) {
+ stat = ERRLIB; /* unable to load library */
+ } else {
+ stat = ERRFUNC; /* unable to find function */
}
+ lua_pushliteral(L, DLMSG);
+
+ /* error; error message is on stack top */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init");
+ return 3; /* return nil, error message, and where */
}
@@ -152,109 +112,6 @@ static int ll_loadlib (lua_State *L) {
*/
-static int readable (const char *filename) {
- FILE *f = fopen(filename, "r"); /* try to open file */
- if (f == NULL) return 0; /* open failed */
- fclose(f);
- return 1;
-}
-
-
-static const char *pushnexttemplate (lua_State *L, const char *path) {
- const char *l;
- while (*path == *LUA_PATHSEP) path++; /* skip separators */
- if (*path == '\0') return NULL; /* no more templates */
- l = strchr(path, *LUA_PATHSEP); /* find next separator */
- if (l == NULL) l = path + strlen(path);
- lua_pushlstring(L, path, l - path); /* template */
- return l;
-}
-
-
-static const char *findfile (lua_State *L, const char *name,
- const char *pname) {
- const char *path;
- name = luaL_gsub(L, name, ".", LUA_DIRSEP);
- lua_getfield(L, LUA_ENVIRONINDEX, pname);
- path = lua_tostring(L, -1);
- if (path == NULL)
- luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
- lua_pushliteral(L, ""); /* error accumulator */
- while ((path = pushnexttemplate(L, path)) != NULL) {
- const char *filename;
- filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
- lua_remove(L, -2); /* remove path template */
- if (readable(filename)) /* does file exist and is readable? */
- return filename; /* return that file name */
- lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
- lua_remove(L, -2); /* remove file name */
- lua_concat(L, 2); /* add entry to possible error message */
- }
- return NULL; /* not found */
-}
-
-
-static void loaderror (lua_State *L, const char *filename) {
- luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
- lua_tostring(L, 1), filename, lua_tostring(L, -1));
-}
-
-
-static int loader_Lua (lua_State *L) {
- const char *filename;
- const char *name = luaL_checkstring(L, 1);
- filename = findfile(L, name, "path");
- if (filename == NULL) return 1; /* library not found in this path */
- if (luaL_loadfile(L, filename) != 0)
- loaderror(L, filename);
- return 1; /* library loaded successfully */
-}
-
-
-static const char *mkfuncname (lua_State *L, const char *modname) {
- const char *funcname;
- const char *mark = strchr(modname, *LUA_IGMARK);
- if (mark) modname = mark + 1;
- funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
- funcname = lua_pushfstring(L, POF"%s", funcname);
- lua_remove(L, -2); /* remove 'gsub' result */
- return funcname;
-}
-
-
-static int loader_C (lua_State *L) {
- const char *funcname;
- const char *name = luaL_checkstring(L, 1);
- const char *filename = findfile(L, name, "cpath");
- if (filename == NULL) return 1; /* library not found in this path */
- funcname = mkfuncname(L, name);
- if (ll_loadfunc(L, filename, funcname) != 0)
- loaderror(L, filename);
- return 1; /* library loaded successfully */
-}
-
-
-static int loader_Croot (lua_State *L) {
- const char *funcname;
- const char *filename;
- const char *name = luaL_checkstring(L, 1);
- const char *p = strchr(name, '.');
- int stat;
- if (p == NULL) return 0; /* is root */
- lua_pushlstring(L, name, p - name);
- filename = findfile(L, lua_tostring(L, -1), "cpath");
- if (filename == NULL) return 1; /* root not found */
- funcname = mkfuncname(L, name);
- if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
- if (stat != ERRFUNC) loaderror(L, filename); /* real error */
- lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
- name, filename);
- return 1; /* function not found */
- }
- return 1;
-}
-
-
static int loader_preload (lua_State *L) {
const char *name = luaL_checkstring(L, 1);
lua_getfield(L, LUA_ENVIRONINDEX, "preload");
@@ -407,23 +264,11 @@ static int ll_seeall (lua_State *L) {
-/* auxiliary mark (for internal use) */
-#define AUXMARK "\1"
-
static void setpath (lua_State *L, const char *fieldname, const char *envname,
const char *def) {
- const char *path = getenv(envname);
- if (path == NULL) /* no environment variable? */
- lua_pushstring(L, def); /* use default */
- else {
- /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
- path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
- LUA_PATHSEP AUXMARK LUA_PATHSEP);
- luaL_gsub(L, path, AUXMARK, def);
- lua_remove(L, -2);
- }
- setprogdir(L);
- lua_setfield(L, -2, fieldname);
+ // no environment variable -> use default
+ lua_pushstring(L, def);
+ lua_setfield(L, -2, fieldname);
}
@@ -442,7 +287,7 @@ static const luaL_Reg ll_funcs[] = {
static const lua_CFunction loaders[] =
- {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
+ {loader_preload, NULL};
LUALIB_API int luaopen_package (lua_State *L) {
diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp
index 035925ceb5..b61f8c65e1 100644
--- a/engines/sword25/util/lua/loslib.cpp
+++ b/engines/sword25/util/lua/loslib.cpp
@@ -4,11 +4,9 @@
** See Copyright Notice in lua.h
*/
+// FIXME: Get rid of all time.h stuff
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
-#include <errno.h>
-#include <locale.h>
-#include <stdlib.h>
-#include <string.h>
#include <time.h>
#define loslib_c
@@ -19,54 +17,53 @@
#include "lauxlib.h"
#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;
- }
-}
+#include "common/system.h"
+#include "common/textconsole.h"
static int os_execute (lua_State *L) {
- lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
+ // Non-portable call, removed in ScummVM.
+ // FIXME: Is this ever invoked? If so, investigate that code further.
+ lua_pushinteger(L, -1); // signal that an error occurred
return 1;
}
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);
+ // Non-portable call, removed in ScummVM.
+ return 1;
}
static int os_tmpname (lua_State *L) {
+ // Non-portable call, removed in ScummVM.
+ // FIXME: Why do we return an error in tmpname, but for other
+ // removed methods we just do nothing?
return luaL_error(L, "unable to generate a unique filename");
}
static int os_getenv (lua_State *L) {
- lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
+ // Non-portable call, removed in ScummVM.
+ // FIXME: Is this ever invoked? If so, investigate that code further.
+ lua_pushstring(L, NULL);
return 1;
}
static int os_clock (lua_State *L) {
- lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
+ // Non-portable call to clock() replaced by invocation of OSystem::getMillis.
+ lua_pushnumber(L, ((lua_Number)g_system->getMillis())/(lua_Number)1000);
return 1;
}
@@ -117,6 +114,12 @@ static int getfield (lua_State *L, const char *key, int d) {
static int os_date (lua_State *L) {
const char *s = luaL_optstring(L, 1, "%c");
+ // FIXME: Rewrite the code below to use OSystem::getTimeAndDate
+ // Alternatively, remove it, if sword25 does not use it.
+ //
+ // The former would mean sacrificing the ability to choose the timezone, *or*
+ // we would have to drive an effort to add time zone support to OSystem (is it
+ // worth that, though???)
time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
struct tm *stm;
if (*s == '!') { /* UTC? */
@@ -162,6 +165,8 @@ static int os_date (lua_State *L) {
static int os_time (lua_State *L) {
+ // FIXME: Rewrite the code below to use OSystem::getTimeAndDate.
+ // Alternatively, remove it, if sword25 does not use it.
time_t t;
if (lua_isnoneornil(L, 1)) /* called without args? */
t = time(NULL); /* get current time */
@@ -187,6 +192,9 @@ static int os_time (lua_State *L) {
static int os_difftime (lua_State *L) {
+ // FIXME: difftime is not portable, unfortunately.
+ // So we either have to replace this code, or just remove it,
+ // depending on whether sword25 actually uses it.
lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
(time_t)(luaL_optnumber(L, 2, 0))));
return 1;
@@ -196,19 +204,20 @@ 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;
}
static int os_exit (lua_State *L) {
- exit(luaL_optint(L, 1, EXIT_SUCCESS));
+ // FIXME: Using exit is not portable!
+ // Using OSystem::quit() isn't really a great idea, either.
+ // We really would prefer to let the main run loop exit, so that
+ // our main() can perform cleanup.
+ if (0 == luaL_optint(L, 1, EXIT_SUCCESS))
+ g_system->quit();
+ error("LUA os_exit invokes with non-zero exit value");
}
static const luaL_Reg syslib[] = {
diff --git a/engines/sword25/util/lua/lua.h b/engines/sword25/util/lua/lua.h
index 088a511cf9..417cdadf8b 100644
--- a/engines/sword25/util/lua/lua.h
+++ b/engines/sword25/util/lua/lua.h
@@ -9,6 +9,8 @@
#ifndef lua_h
#define lua_h
+#include "common/scummsys.h"
+
#include <stdarg.h>
#include <stddef.h>
diff --git a/engines/sword25/util/lua/luaconf.h b/engines/sword25/util/lua/luaconf.h
index 669b0e7a49..f3509e969b 100644
--- a/engines/sword25/util/lua/luaconf.h
+++ b/engines/sword25/util/lua/luaconf.h
@@ -183,7 +183,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
@@ -345,7 +349,7 @@
/*
@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
@* facility.
-** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
+** CHANGE it to 2 if you want the old behavior, or undefine it to turn
** off the advisory error when nesting [[...]].
*/
#define LUA_COMPAT_LSTR 1
@@ -634,33 +638,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.
diff --git a/engines/sword25/util/lua/lundump.cpp b/engines/sword25/util/lua/lundump.cpp
deleted file mode 100644
index 4ffc623575..0000000000
--- a/engines/sword25/util/lua/lundump.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
-** $Id$
-** load precompiled Lua chunks
-** See Copyright Notice in lua.h
-*/
-
-#include <string.h>
-
-#define lundump_c
-#define LUA_CORE
-
-#include "lua.h"
-
-#include "ldebug.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstring.h"
-#include "lundump.h"
-#include "lzio.h"
-
-typedef struct {
- lua_State* L;
- ZIO* Z;
- Mbuffer* b;
- const char* name;
-} LoadState;
-
-#ifdef LUAC_TRUST_BINARIES
-#define IF(c,s)
-#define error(S,s)
-#else
-#define IF(c,s) if (c) error(S,s)
-
-static void error(LoadState* S, const char* why)
-{
- luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
- luaD_throw(S->L,LUA_ERRSYNTAX);
-}
-#endif
-
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
-#define LoadByte(S) (lu_byte)LoadChar(S)
-#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
-#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
-
-static void LoadBlock(LoadState* S, void* b, size_t size)
-{
- size_t r=luaZ_read(S->Z,b,size);
- UNUSED(r);
- IF (r!=0, "unexpected end");
-}
-
-static int LoadChar(LoadState* S)
-{
- char x;
- LoadVar(S,x);
- return x;
-}
-
-static int LoadInt(LoadState* S)
-{
- int x;
- LoadVar(S,x);
- IF (x<0, "bad integer");
- return x;
-}
-
-static lua_Number LoadNumber(LoadState* S)
-{
- lua_Number x;
- LoadVar(S,x);
- return x;
-}
-
-static TString* LoadString(LoadState* S)
-{
- size_t size;
- LoadVar(S,size);
- if (size==0)
- return NULL;
- else
- {
- char* s=luaZ_openspace(S->L,S->b,size);
- LoadBlock(S,s,size);
- return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
- }
-}
-
-static void LoadCode(LoadState* S, Proto* f)
-{
- int n=LoadInt(S);
- f->code=luaM_newvector(S->L,n,Instruction);
- f->sizecode=n;
- LoadVector(S,f->code,n,sizeof(Instruction));
-}
-
-static Proto* LoadFunction(LoadState* S, TString* p);
-
-static void LoadConstants(LoadState* S, Proto* f)
-{
- int i,n;
- n=LoadInt(S);
- f->k=luaM_newvector(S->L,n,TValue);
- f->sizek=n;
- for (i=0; i<n; i++) setnilvalue(&f->k[i]);
- for (i=0; i<n; i++)
- {
- TValue* o=&f->k[i];
- int t=LoadChar(S);
- switch (t)
- {
- case LUA_TNIL:
- setnilvalue(o);
- break;
- case LUA_TBOOLEAN:
- setbvalue(o,LoadChar(S));
- break;
- case LUA_TNUMBER:
- setnvalue(o,LoadNumber(S));
- break;
- case LUA_TSTRING:
- setsvalue2n(S->L,o,LoadString(S));
- break;
- default:
- error(S,"bad constant");
- break;
- }
- }
- n=LoadInt(S);
- f->p=luaM_newvector(S->L,n,Proto*);
- f->sizep=n;
- for (i=0; i<n; i++) f->p[i]=NULL;
- for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
-}
-
-static void LoadDebug(LoadState* S, Proto* f)
-{
- int i,n;
- n=LoadInt(S);
- f->lineinfo=luaM_newvector(S->L,n,int);
- f->sizelineinfo=n;
- LoadVector(S,f->lineinfo,n,sizeof(int));
- n=LoadInt(S);
- f->locvars=luaM_newvector(S->L,n,LocVar);
- f->sizelocvars=n;
- for (i=0; i<n; i++) f->locvars[i].varname=NULL;
- for (i=0; i<n; i++)
- {
- f->locvars[i].varname=LoadString(S);
- f->locvars[i].startpc=LoadInt(S);
- f->locvars[i].endpc=LoadInt(S);
- }
- n=LoadInt(S);
- f->upvalues=luaM_newvector(S->L,n,TString*);
- f->sizeupvalues=n;
- for (i=0; i<n; i++) f->upvalues[i]=NULL;
- for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
-}
-
-static Proto* LoadFunction(LoadState* S, TString* p)
-{
- Proto* f=luaF_newproto(S->L);
- setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
- f->source=LoadString(S); if (f->source==NULL) f->source=p;
- f->linedefined=LoadInt(S);
- f->lastlinedefined=LoadInt(S);
- f->nups=LoadByte(S);
- f->numparams=LoadByte(S);
- f->is_vararg=LoadByte(S);
- f->maxstacksize=LoadByte(S);
- LoadCode(S,f);
- LoadConstants(S,f);
- LoadDebug(S,f);
- IF (!luaG_checkcode(f), "bad code");
- S->L->top--;
- return f;
-}
-
-static void LoadHeader(LoadState* S)
-{
- char h[LUAC_HEADERSIZE];
- char s[LUAC_HEADERSIZE];
- luaU_header(h);
- LoadBlock(S,s,LUAC_HEADERSIZE);
- IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
-}
-
-/*
-** load precompiled chunk
-*/
-Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
-{
- LoadState S;
- if (*name=='@' || *name=='=')
- S.name=name+1;
- else if (*name==LUA_SIGNATURE[0])
- S.name="binary string";
- else
- S.name=name;
- S.L=L;
- S.Z=Z;
- S.b=buff;
- LoadHeader(&S);
- return LoadFunction(&S,luaS_newliteral(L,"=?"));
-}
-
-/*
-* make header
-*/
-void luaU_header (char* h)
-{
- int x=1;
- memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
- h+=sizeof(LUA_SIGNATURE)-1;
- *h++=(char)LUAC_VERSION;
- *h++=(char)LUAC_FORMAT;
- *h++=(char)*(char*)&x; /* endianness */
- *h++=(char)sizeof(int);
- *h++=(char)sizeof(size_t);
- *h++=(char)sizeof(Instruction);
- *h++=(char)sizeof(lua_Number);
- *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
-}
diff --git a/engines/sword25/util/lua/lundump.h b/engines/sword25/util/lua/lundump.h
deleted file mode 100644
index f791a4f173..0000000000
--- a/engines/sword25/util/lua/lundump.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-** $Id$
-** load precompiled Lua chunks
-** See Copyright Notice in lua.h
-*/
-
-#ifndef lundump_h
-#define lundump_h
-
-#include "lobject.h"
-#include "lzio.h"
-
-/* load one chunk; from lundump.c */
-LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
-
-/* make header; from lundump.c */
-LUAI_FUNC void luaU_header (char* h);
-
-/* dump one chunk; from ldump.c */
-LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
-
-#ifdef luac_c
-/* print one chunk; from print.c */
-LUAI_FUNC void luaU_print (const Proto* f, int full);
-#endif
-
-/* for header of binary files -- this is Lua 5.1 */
-#define LUAC_VERSION 0x51
-
-/* for header of binary files -- this is the official format */
-#define LUAC_FORMAT 0
-
-/* size of header of binary files */
-#define LUAC_HEADERSIZE 12
-
-#endif
diff --git a/engines/sword25/util/lua/lvm.cpp b/engines/sword25/util/lua/lvm.cpp
index ae70fe2645..fb700c20a2 100644
--- a/engines/sword25/util/lua/lvm.cpp
+++ b/engines/sword25/util/lua/lvm.cpp
@@ -202,7 +202,7 @@ static int l_strcmp (const TString *ls, const TString *rs) {
const char *r = getstr(rs);
size_t lr = rs->tsv.len;
for (;;) {
- int temp = strcoll(l, r);
+ int temp = strcmp(l, r);
if (temp != 0) return temp;
else { /* strings are equal up to a `\0' */
size_t len = strlen(l); /* index of first `\0' in both strings */
diff --git a/engines/sword25/util/lua/print.cpp b/engines/sword25/util/lua/print.cpp
deleted file mode 100644
index 22039c9861..0000000000
--- a/engines/sword25/util/lua/print.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
-** $Id$
-** print bytecodes
-** See Copyright Notice in lua.h
-*/
-
-#include <ctype.h>
-#include <stdio.h>
-
-#define luac_c
-#define LUA_CORE
-
-#include "ldebug.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lundump.h"
-
-#define PrintFunction luaU_print
-
-#define Sizeof(x) ((int)sizeof(x))
-#define VOID(p) ((const void*)(p))
-
-static void PrintString(const TString* ts)
-{
- const char* s=getstr(ts);
- size_t i,n=ts->tsv.len;
- putchar('"');
- for (i=0; i<n; i++)
- {
- int c=s[i];
- switch (c)
- {
- case '"': printf("\\\""); break;
- case '\\': printf("\\\\"); break;
- case '\a': printf("\\a"); break;
- case '\b': printf("\\b"); break;
- case '\f': printf("\\f"); break;
- case '\n': printf("\\n"); break;
- case '\r': printf("\\r"); break;
- case '\t': printf("\\t"); break;
- case '\v': printf("\\v"); break;
- default: if (isprint((unsigned char)c))
- putchar(c);
- else
- printf("\\%03u",(unsigned char)c);
- }
- }
- putchar('"');
-}
-
-static void PrintConstant(const Proto* f, int i)
-{
- const TValue* o=&f->k[i];
- switch (ttype(o))
- {
- case LUA_TNIL:
- printf("nil");
- break;
- case LUA_TBOOLEAN:
- printf(bvalue(o) ? "true" : "false");
- break;
- case LUA_TNUMBER:
- printf(LUA_NUMBER_FMT,nvalue(o));
- break;
- case LUA_TSTRING:
- PrintString(rawtsvalue(o));
- break;
- default: /* cannot happen */
- printf("? type=%d",ttype(o));
- break;
- }
-}
-
-static void PrintCode(const Proto* f)
-{
- const Instruction* code=f->code;
- int pc,n=f->sizecode;
- for (pc=0; pc<n; pc++)
- {
- Instruction i=code[pc];
- OpCode o=GET_OPCODE(i);
- int a=GETARG_A(i);
- int b=GETARG_B(i);
- int c=GETARG_C(i);
- int bx=GETARG_Bx(i);
- int sbx=GETARG_sBx(i);
- int line=getline(f,pc);
- printf("\t%d\t",pc+1);
- if (line>0) printf("[%d]\t",line); else printf("[-]\t");
- printf("%-9s\t",luaP_opnames[o]);
- switch (getOpMode(o))
- {
- case iABC:
- printf("%d",a);
- if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
- if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
- break;
- case iABx:
- if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
- break;
- case iAsBx:
- if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
- break;
- }
- switch (o)
- {
- case OP_LOADK:
- printf("\t; "); PrintConstant(f,bx);
- break;
- case OP_GETUPVAL:
- case OP_SETUPVAL:
- printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
- break;
- case OP_GETGLOBAL:
- case OP_SETGLOBAL:
- printf("\t; %s",svalue(&f->k[bx]));
- break;
- case OP_GETTABLE:
- case OP_SELF:
- if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
- break;
- case OP_SETTABLE:
- case OP_ADD:
- case OP_SUB:
- case OP_MUL:
- case OP_DIV:
- case OP_POW:
- case OP_EQ:
- case OP_LT:
- case OP_LE:
- if (ISK(b) || ISK(c))
- {
- printf("\t; ");
- if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
- printf(" ");
- if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
- }
- break;
- case OP_JMP:
- case OP_FORLOOP:
- case OP_FORPREP:
- printf("\t; to %d",sbx+pc+2);
- break;
- case OP_CLOSURE:
- printf("\t; %p",VOID(f->p[bx]));
- break;
- case OP_SETLIST:
- if (c==0) printf("\t; %d",(int)code[++pc]);
- else printf("\t; %d",c);
- break;
- default:
- break;
- }
- printf("\n");
- }
-}
-
-#define SS(x) (x==1)?"":"s"
-#define S(x) x,SS(x)
-
-static void PrintHeader(const Proto* f)
-{
- const char* s=getstr(f->source);
- if (*s=='@' || *s=='=')
- s++;
- else if (*s==LUA_SIGNATURE[0])
- s="(bstring)";
- else
- s="(string)";
- printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
- (f->linedefined==0)?"main":"function",s,
- f->linedefined,f->lastlinedefined,
- S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
- printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
- f->numparams,f->is_vararg?"+":"",SS(f->numparams),
- S(f->maxstacksize),S(f->nups));
- printf("%d local%s, %d constant%s, %d function%s\n",
- S(f->sizelocvars),S(f->sizek),S(f->sizep));
-}
-
-static void PrintConstants(const Proto* f)
-{
- int i,n=f->sizek;
- printf("constants (%d) for %p:\n",n,VOID(f));
- for (i=0; i<n; i++)
- {
- printf("\t%d\t",i+1);
- PrintConstant(f,i);
- printf("\n");
- }
-}
-
-static void PrintLocals(const Proto* f)
-{
- int i,n=f->sizelocvars;
- printf("locals (%d) for %p:\n",n,VOID(f));
- for (i=0; i<n; i++)
- {
- printf("\t%d\t%s\t%d\t%d\n",
- i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
- }
-}
-
-static void PrintUpvalues(const Proto* f)
-{
- int i,n=f->sizeupvalues;
- printf("upvalues (%d) for %p:\n",n,VOID(f));
- if (f->upvalues==NULL) return;
- for (i=0; i<n; i++)
- {
- printf("\t%d\t%s\n",i,getstr(f->upvalues[i]));
- }
-}
-
-void PrintFunction(const Proto* f, int full)
-{
- int i,n=f->sizep;
- PrintHeader(f);
- PrintCode(f);
- if (full)
- {
- PrintConstants(f);
- PrintLocals(f);
- PrintUpvalues(f);
- }
- for (i=0; i<n; i++) PrintFunction(f->p[i],full);
-}
diff --git a/engines/sword25/util/lua/scummvm_file.cpp b/engines/sword25/util/lua/scummvm_file.cpp
new file mode 100644
index 0000000000..3c0377d0ee
--- /dev/null
+++ b/engines/sword25/util/lua/scummvm_file.cpp
@@ -0,0 +1,205 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "sword25/util/lua/scummvm_file.h"
+#include "common/config-manager.h"
+#include "common/util.h"
+
+namespace Sword25 {
+
+Sword25FileProxy::Sword25FileProxy(const Common::String &filename, const Common::String &mode) {
+ assert(filename.contains("config.lua"));
+ if (mode == "r")
+ setupConfigFile();
+}
+
+void Sword25FileProxy::setupConfigFile() {
+ double sfxVolume = ConfMan.hasKey("sfx_volume") ? 1.0 : 1.0 * ConfMan.getInt("sfx_volume") / 255.0;
+ double musicVolume = ConfMan.hasKey("music_volume") ? 0.5 : 1.0 * ConfMan.getInt("music_volume") / 255.0;
+ double speechVolume = ConfMan.hasKey("speech_volume") ? 1.0 : 1.0 * ConfMan.getInt("speech_volume") / 255.0;
+ bool subtitles = ConfMan.hasKey("subtitles") ? true : ConfMan.getBool("subtitles");
+
+ _readData = Common::String::format(
+"GAME_LANGUAGE = \"%s\"\r\n\
+GAME_SUBTITLES = %s\r\n\
+MAX_MEMORY_USAGE = 256000000\r\n\
+GFX_VSYNC_ACTIVE = true\r\n\
+SFX_SAMPLING_RATE = 44100\r\n\
+SFX_CHANNEL_COUNT = 32\r\n\
+SFX_SOUND_VOLUME = %f\r\n\
+SFX_MUSIC_VOLUME = %f\r\n\
+SFX_SPEECH_VOLUME = %f\r\n",
+ getLanguage().c_str(), subtitles ? "true" : "false", sfxVolume, musicVolume, speechVolume);
+
+ _readPos = 0;
+}
+
+Sword25FileProxy::~Sword25FileProxy() {
+ if (!_settings.empty())
+ writeSettings();
+}
+
+size_t Sword25FileProxy::read(void *ptr, size_t size, size_t count) {
+ size_t bytesRead = MIN<size_t>(_readData.size() - _readPos, size * count);
+ memmove(ptr, &_readData.c_str()[_readPos], bytesRead);
+ _readPos += bytesRead;
+ return bytesRead / size;
+}
+
+size_t Sword25FileProxy::write(const char *ptr, size_t count) {
+ // Loop through the provided line(s)
+ while (*ptr) {
+ if ((*ptr == '-') && (*(ptr + 1) == '-')) {
+ // Comment line to skip over
+ while ((*ptr != '\r') && (*ptr != '\n'))
+ ++ptr;
+ } else {
+ // Legitimate data
+ const char *p = strchr(ptr, '\n');
+ if (!p) p = ptr + strlen(ptr);
+ while ((*p == '\r') || (*p == '\n'))
+ ++p;
+
+ _settings += Common::String(ptr, p - ptr);
+ ptr = p;
+ }
+
+ while ((*ptr == '\r') || (*ptr == '\n'))
+ ++ptr;
+ }
+
+ return count;
+}
+
+void Sword25FileProxy::writeSettings() {
+ // Loop through the setting lines
+ const char *pSrc = _settings.c_str();
+ while (*pSrc) {
+ if ((*pSrc != '\r') && (*pSrc != '\n')) {
+ const char *p = strchr(pSrc, '=');
+ assert(p);
+
+ // Get the setting name
+ const char *pEnd = p - 1;
+ while (*pEnd == ' ')
+ --pEnd;
+ Common::String settingName(pSrc, pEnd - pSrc + 1);
+
+ // Get the setting value
+ const char *pStart = p + 1;
+ while (*pStart == ' ')
+ ++pStart;
+
+ pEnd = pStart + 1;
+ while ((*pEnd != '\r') && (*pEnd != '\n') && (*pEnd != '\0'))
+ ++pEnd;
+ Common::String value(pStart + (*pStart == '"' ? 1 : 0), pEnd - pStart - (*pStart == '"' ? 2 : 0));
+
+ // Update the setting
+ updateSetting(settingName, value);
+ pSrc = pEnd;
+ }
+
+ // Move to next line
+ while ((*pSrc == '\r') || (*pSrc == '\n'))
+ ++pSrc;
+ }
+
+ ConfMan.flushToDisk();
+}
+
+void Sword25FileProxy::updateSetting(const Common::String &setting, const Common::String &value) {
+ if (setting == "GAME_LANGUAGE")
+ setLanguage(value);
+ else if (setting == "GAME_SUBTITLES")
+ ConfMan.setBool("subtitles", value == "true");
+ else if (setting == "SFX_SOUND_VOLUME") {
+ double v = strtod(value.c_str(), NULL);
+ ConfMan.setInt("sfx_volume", (int)(v * 255));
+ } else if (setting == "SFX_MUSIC_VOLUME") {
+ double v = strtod(value.c_str(), NULL);
+ ConfMan.setInt("music_volume", (int)(v * 255));
+ } else if (setting == "SFX_SPEECH_VOLUME") {
+ double v = strtod(value.c_str(), NULL);
+ ConfMan.setInt("speech_volume", (int)(v * 255));
+ } else {
+ // All other settings are ignored
+ }
+}
+
+/**
+ * Get the language code used by the game for each language it supports
+ */
+Common::String Sword25FileProxy::getLanguage() {
+ Common::Language lang = Common::parseLanguage(ConfMan.get("language"));
+ switch (lang) {
+ case Common::EN_ANY:
+ return "en";
+ case Common::DE_DEU:
+ return "de";
+ case Common::ES_ESP:
+ return "es";
+ case Common::FR_FRA:
+ return "fr";
+ case Common::HU_HUN:
+ return "hr";
+ case Common::IT_ITA:
+ return "it";
+ case Common::PL_POL:
+ return "pl";
+ case Common::PT_BRA:
+ return "pt";
+ case Common::RU_RUS:
+ return "ru";
+ default:
+ error("Unknown language '%s' encountered", ConfMan.get("language").c_str());
+ break;
+ }
+}
+
+/**
+ * Set the language code fro the game
+ */
+void Sword25FileProxy::setLanguage(const Common::String &lang) {
+ if (lang == "en")
+ ConfMan.set("language", Common::getLanguageCode(Common::EN_ANY));
+ else if (lang == "de")
+ ConfMan.set("language", Common::getLanguageCode(Common::DE_DEU));
+ else if (lang == "es")
+ ConfMan.set("language", Common::getLanguageCode(Common::ES_ESP));
+ else if (lang == "fr")
+ ConfMan.set("language", Common::getLanguageCode(Common::FR_FRA));
+ else if (lang == "hr")
+ ConfMan.set("language", Common::getLanguageCode(Common::HU_HUN));
+ else if (lang == "it")
+ ConfMan.set("language", Common::getLanguageCode(Common::IT_ITA));
+ else if (lang == "pl")
+ ConfMan.set("language", Common::getLanguageCode(Common::PL_POL));
+ else if (lang == "pt")
+ ConfMan.set("language", Common::getLanguageCode(Common::PT_BRA));
+ else if (lang == "ru")
+ ConfMan.set("language", Common::getLanguageCode(Common::RU_RUS));
+ else
+ error("Unknown language encountered");
+}
+
+} // End of namespace Sword25
diff --git a/engines/sword25/util/lua/scummvm_file.h b/engines/sword25/util/lua/scummvm_file.h
new file mode 100644
index 0000000000..a4cbd2a6cf
--- /dev/null
+++ b/engines/sword25/util/lua/scummvm_file.h
@@ -0,0 +1,56 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SWORD25_SCUMMVM_FILE_H
+#define SWORD25_SCUMMVM_FILE_H
+
+#include "common/str.h"
+
+namespace Sword25 {
+
+/**
+ * The following class acts as a proxy interface to the I/O code, pretending that the ScummVM
+ * settings are a properly formatted 'config.lua' file
+ */
+class Sword25FileProxy {
+private:
+ Common::String _readData;
+ uint _readPos;
+ Common::String _settings;
+
+ void setupConfigFile();
+ Common::String getLanguage();
+ void setLanguage(const Common::String &lang);
+ void writeSettings();
+ void updateSetting(const Common::String &setting, const Common::String &value);
+public:
+ Sword25FileProxy(const Common::String &filename, const Common::String &mode);
+ ~Sword25FileProxy();
+
+ bool eof() const { return _readPos >= _readData.size(); }
+ size_t read(void *ptr, size_t size, size_t count);
+ size_t write(const char *ptr, size_t count);
+};
+
+} // End of namespace Sword25
+
+#endif