aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Zbróg2013-11-05 21:20:46 +0000
committerKamil Zbróg2013-11-05 21:20:46 +0000
commit4722d0e5becee530b1ca11e5a1ef0f35b23fe721 (patch)
tree2db8241a03d932433976d09294d73bc80e250739
parent91466575eb8fa7e192ce1385a4bf3bb86be5a8c5 (diff)
downloadscummvm-rg350-4722d0e5becee530b1ca11e5a1ef0f35b23fe721.tar.gz
scummvm-rg350-4722d0e5becee530b1ca11e5a1ef0f35b23fe721.tar.bz2
scummvm-rg350-4722d0e5becee530b1ca11e5a1ef0f35b23fe721.zip
PRINCE: code cleanup, mostly loading resources
-rw-r--r--engines/prince/cursor.cpp54
-rw-r--r--engines/prince/cursor.h50
-rw-r--r--engines/prince/font.cpp2
-rw-r--r--engines/prince/font.h2
-rw-r--r--engines/prince/module.mk1
-rw-r--r--engines/prince/prince.cpp203
-rw-r--r--engines/prince/prince.h20
7 files changed, 197 insertions, 135 deletions
diff --git a/engines/prince/cursor.cpp b/engines/prince/cursor.cpp
new file mode 100644
index 0000000000..9a9162fd27
--- /dev/null
+++ b/engines/prince/cursor.cpp
@@ -0,0 +1,54 @@
+/* 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 "prince/cursor.h"
+
+#include "common/debug.h"
+#include "common/stream.h"
+
+namespace Prince {
+
+Cursor::Cursor() : _surface(NULL) {
+}
+
+Cursor::~Cursor() {
+ delete _surface;
+ _surface = NULL;
+}
+
+bool Cursor::loadFromStream(Common::SeekableReadStream &stream) {
+ stream.skip(4);
+ uint16 w = stream.readUint16LE();
+ uint16 h = stream.readUint16LE();
+
+ _surface = new Graphics::Surface();
+ _surface->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+
+ for (int ih = 0; ih < h; ++ih) {
+ stream.read(_surface->getBasePtr(0, ih), w);
+ }
+ return true;
+}
+
+}
+
+/* vim: set tabstop=4 noexpandtab: */
diff --git a/engines/prince/cursor.h b/engines/prince/cursor.h
new file mode 100644
index 0000000000..05c7da9f33
--- /dev/null
+++ b/engines/prince/cursor.h
@@ -0,0 +1,50 @@
+/* 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 CURSOR_PRINCE_H
+#define CURSOR_PRINCE_H
+
+#include "graphics/surface.h"
+
+namespace Common {
+ class SeekableReadStream;
+}
+
+namespace Prince {
+
+class Cursor {
+public:
+ Cursor();
+ ~Cursor();
+
+ bool loadFromStream(Common::SeekableReadStream &stream);
+ Graphics::Surface *getSurface() const { return _surface; }
+
+private:
+ Graphics::Surface *_surface;
+};
+
+}
+
+#endif
+
+/* vim: set tabstop=4 expandtab!: */
diff --git a/engines/prince/font.cpp b/engines/prince/font.cpp
index 30e7b5aee2..33149c14e4 100644
--- a/engines/prince/font.cpp
+++ b/engines/prince/font.cpp
@@ -38,7 +38,7 @@ Font::~Font() {
delete [] _fontData;
}
-bool Font::load(Common::SeekableReadStream &stream) {
+bool Font::loadFromStream(Common::SeekableReadStream &stream) {
stream.seek(0);
_fontData = new byte[stream.size()];
stream.read(_fontData, stream.size());
diff --git a/engines/prince/font.h b/engines/prince/font.h
index 1afafa3be3..020e12bf54 100644
--- a/engines/prince/font.h
+++ b/engines/prince/font.h
@@ -39,7 +39,7 @@ public:
Font();
virtual ~Font();
- bool load(Common::SeekableReadStream &stream);
+ bool loadFromStream(Common::SeekableReadStream &stream);
virtual int getFontHeight() const override;
diff --git a/engines/prince/module.mk b/engines/prince/module.mk
index f8003f834a..593c59dcff 100644
--- a/engines/prince/module.mk
+++ b/engines/prince/module.mk
@@ -12,6 +12,7 @@ MODULE_OBJS = \
sound.o \
flags.o \
variatxt.o \
+ cursor.o \
prince.o
# This module can be built as a plugin
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index b5cb26739b..e1d35091ed 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -52,35 +52,12 @@
#include "prince/sound.h"
#include "prince/variatxt.h"
#include "prince/flags.h"
-
-#include "video/flic_decoder.h"
+#include "prince/font.h"
+#include "prince/mhwanh.h"
+#include "prince/cursor.h"
namespace Prince {
-Graphics::Surface *loadCursor(const char *curName)
-{
- Common::SeekableReadStream *curStream = SearchMan.createReadStreamForMember(curName);
- if (!curStream) {
- error("Can't load %s", curName);
- return NULL;
- }
-
- curStream->skip(4);
- uint16 w = curStream->readUint16LE();
- uint16 h = curStream->readUint16LE();
-
- debug("Loading cursor %s, w %d, h %d", curName, w, h);
-
- Graphics::Surface *curSurface = new Graphics::Surface();
- curSurface->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
- for (int ih = 0; ih < h; ++ih) {
- curStream->read(curSurface->getBasePtr(0, ih), w);
- }
-
- delete curStream;
- return curSurface;
-}
-
void PrinceEngine::debugEngine(const char *s, ...) {
char buf[STRINGBUFLEN];
va_list va;
@@ -92,11 +69,11 @@ void PrinceEngine::debugEngine(const char *s, ...) {
debug("Prince::Engine frame %08ld %s", _frameNr, buf);
}
-
PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) :
Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL),
_locationNr(0), _debugger(NULL), _objectList(NULL), _mobList(NULL), _midiPlayer(NULL),
- _cameraX(0), _newCameraX(0), _frameNr(0) {
+ _cameraX(0), _newCameraX(0), _frameNr(0), _cursor1(NULL), _cursor2(NULL), _font(NULL),
+ _walizkaBmp(NULL), _roomBmp(NULL) {
// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
@@ -105,7 +82,6 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
DebugMan.enableDebugChannel("script");
gDebugLevel = 10;
-
_rnd = new Common::RandomSource("prince");
_debugger = new Debugger(this);
@@ -118,15 +94,49 @@ PrinceEngine::~PrinceEngine() {
delete _rnd;
delete _debugger;
- delete _cur1;
- delete _cur2;
+ delete _cursor1;
+ delete _cursor2;
delete _midiPlayer;
+ delete _script;
+ delete _font;
+ delete _roomBmp;
+ delete _walizkaBmp;
}
GUI::Debugger *PrinceEngine::getDebugger() {
return _debugger;
}
+template <typename T>
+bool loadFromStream(T &resource, Common::SeekableReadStream &stream) {
+ return resource.loadFromStream(stream);
+}
+
+template <>
+bool loadFromStream<MhwanhDecoder>(MhwanhDecoder &image, Common::SeekableReadStream &stream) {
+ return image.loadStream(stream);
+}
+
+template <>
+bool loadFromStream<Graphics::BitmapDecoder>(Graphics::BitmapDecoder &image, Common::SeekableReadStream &stream) {
+ return image.loadStream(stream);
+}
+
+template<typename T>
+bool loadResource(T *resource, const char *resourceName) {
+ Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
+ if (!stream) {
+ error("Can't load %s", resourceName);
+ return NULL;
+ }
+
+ bool ret = loadFromStream(*resource, *stream);
+
+ delete stream;
+
+ return ret;
+}
+
Common::Error PrinceEngine::run() {
_graph = new GraphicsMan(this);
@@ -136,45 +146,23 @@ Common::Error PrinceEngine::run() {
SearchMan.addSubDirectoryMatching(gameDataDir, "all", 0, 2);
SearchMan.addSubDirectoryMatching(gameDataDir, "data/voices/output", 0, 2);
+
+ _font = new Font();
+ loadResource(_font, "font1.raw");
+ _walizkaBmp = new MhwanhDecoder();
+ loadResource(_walizkaBmp, "walizka");
- Common::SeekableReadStream *font1stream = SearchMan.createReadStreamForMember("font1.raw");
- if (!font1stream)
- return Common::kPathNotFile;
-
- if (_font.load(*font1stream)) {
- _font.getCharWidth(103);
- }
- delete font1stream;
-
- Common::SeekableReadStream * walizka = SearchMan.createReadStreamForMember("walizka");
- if (!walizka)
- return Common::kPathDoesNotExist;
-
- debugEngine("Loading walizka");
- if (!_walizkaBmp.loadStream(*walizka)) {
- return Common::kPathDoesNotExist;
- }
-
- Common::SeekableReadStream * skryptStream = SearchMan.createReadStreamForMember("skrypt.dat");
- if (!skryptStream)
- return Common::kPathNotFile;
-
- debugEngine("Loading skrypt");
_script = new Script(this);
- _script->loadFromStream(*skryptStream);
-
- delete skryptStream;
-
- Common::SeekableReadStream *variaTxtStream = SearchMan.createReadStreamForMember("variatxt.dat");
-
- if (!variaTxtStream) {
- error("Can't load variatxt.dat");
- return Common::kPathNotFile;
- }
+ loadResource(_script, "skrypt.dat");
_variaTxt = new VariaTxt();
- _variaTxt->loadFromStream(*variaTxtStream);
- delete variaTxtStream;
+ loadResource(_variaTxt, "variatxt.dat");
+
+ _cursor1 = new Cursor();
+ loadResource(_cursor1, "mouse1.cur");
+
+ _cursor2 = new Cursor();
+ loadResource(_cursor2, "mouse2.cur");
Common::SeekableReadStream *talkTxtStream = SearchMan.createReadStreamForMember("talktxt.dat");
if (!talkTxtStream) {
@@ -188,22 +176,17 @@ Common::Error PrinceEngine::run() {
delete talkTxtStream;
-
- _cur1 = loadCursor("mouse1.cur");
- _cur2 = loadCursor("mouse2.cur");
-#if 0
- Common::SeekableReadStream *logoStream = SearchMan.createReadStreamForMember("logo.raw");
- if (logoStream)
+ MhwanhDecoder *logo = new MhwanhDecoder();
+ loadResource(logo, "logo.raw");
+ if (logo)
{
- MhwanhDecoder logo;
- logo.loadStream(*logoStream);
- _graph->setPalette(logo.getPalette());
- _graph->draw(0, 0, logo.getSurface());
+ _graph->setPalette(logo->getPalette());
+ _graph->draw(0, 0, logo->getSurface());
_graph->update();
_system->delayMillis(700);
}
- delete logoStream;
-#endif
+ delete logo;
+
mainLoop();
return Common::kNoError;
@@ -251,47 +234,21 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {
debugEngine("loadLocation %s", locationNrStr.c_str());
SearchMan.addSubDirectoryMatching(gameDataDir, locationNrStr, 0, 2);
+ delete _roomBmp;
// load location background
- Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room");
-
- if (!room) {
- error("Can't load room bitmap");
- return false;
- }
-
- if(_roomBmp.loadStream(*room)) {
- debugEngine("Room bitmap loaded");
- _sceneWidth = _roomBmp.getSurface()->w;
+ _roomBmp = new Graphics::BitmapDecoder();
+ loadResource(_roomBmp, "room");
+ if (_roomBmp->getSurface()) {
+ _sceneWidth = _roomBmp->getSurface()->w;
}
- delete room;
-
delete _mobList;
- _mobList = NULL;
-
- Common::SeekableReadStream *mobListStream = SearchMan.createReadStreamForMember("mob.lst");
- if (!mobListStream) {
- error("Can't read mob.lst");
- return false;
- }
-
_mobList = new MobList();
- _mobList->loadFromStream(*mobListStream);
-
- delete mobListStream;
+ loadResource(_mobList, "mob.lst");
delete _objectList;
- _objectList = NULL;
-
- Common::SeekableReadStream *objListStream = SearchMan.createReadStreamForMember("obj.lst");
- if (!objListStream) {
- error("Can't read obj.lst");
- return false;
- }
-
_objectList = new ObjectList();
- _objectList->loadFromStream(*objListStream);
- delete objListStream;
+ loadResource(_objectList, "obj.lst");
const char *musName = MusicPlayer::_musTable[MusicPlayer::_musRoomTable[locationNr]];
_midiPlayer->loadMidi(musName);
@@ -311,16 +268,16 @@ void PrinceEngine::changeCursor(uint16 curId)
CursorMan.showMouse(false);
return;
case 1:
- curSurface = _cur1;
+ curSurface = _cursor1->getSurface();
break;
case 2:
- curSurface = _cur2;
+ curSurface = _cursor2->getSurface();
hotspotX = curSurface->w >> 1;
hotspotY = curSurface->h >> 1;
break;
}
- CursorMan.replaceCursorPalette(_roomBmp.getPalette(), 0, 255);
+ CursorMan.replaceCursorPalette(_roomBmp->getPalette(), 0, 255);
CursorMan.replaceCursor(
curSurface->getBasePtr(0, 0),
curSurface->w, curSurface->h,
@@ -418,7 +375,7 @@ void PrinceEngine::hotspot() {
if (it->_rect.contains(mousePosCamera)) {
uint16 textW = 0;
for (uint16 i = 0; i < it->_name.size(); ++i)
- textW += _font.getCharWidth(it->_name[i]);
+ textW += _font->getCharWidth(it->_name[i]);
uint16 x = mousepos.x - textW/2;
if (x > _graph->_frontScreen->w)
@@ -427,11 +384,11 @@ void PrinceEngine::hotspot() {
if (x + textW > _graph->_frontScreen->w)
x = _graph->_frontScreen->w - textW;
- _font.drawString(
+ _font->drawString(
_graph->_frontScreen,
it->_name,
x,
- mousepos.y - _font.getFontHeight(),
+ mousepos.y - _font->getFontHeight(),
_graph->_frontScreen->w,
216
);
@@ -454,7 +411,7 @@ void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, ui
uint32 PrinceEngine::getTextWidth(const char *s) {
uint16 textW = 0;
while (*s) {
- textW += _font.getCharWidth(*s) + _font.getKerningOffset(0, 0);
+ textW += _font->getCharWidth(*s) + _font->getKerningOffset(0, 0);
++s;
}
return textW;
@@ -467,14 +424,14 @@ void PrinceEngine::showTexts() {
continue;
Common::Array<Common::String> lines;
- _font.wordWrapText(text._str, _graph->_frontScreen->w, lines);
+ _font->wordWrapText(text._str, _graph->_frontScreen->w, lines);
for (uint8 i = 0; i < lines.size(); ++i) {
- _font.drawString(
+ _font->drawString(
_graph->_frontScreen,
lines[i],
text._x - getTextWidth(lines[i].c_str())/2,
- text._y - (lines.size() - i) * (_font.getFontHeight()),
+ text._y - (lines.size() - i) * (_font->getFontHeight()),
_graph->_frontScreen->w,
text._color
);
@@ -488,9 +445,9 @@ void PrinceEngine::showTexts() {
}
void PrinceEngine::drawScreen() {
- const Graphics::Surface *roomSurface = _roomBmp.getSurface();
+ const Graphics::Surface *roomSurface = _roomBmp->getSurface();
if (roomSurface) {
- _graph->setPalette(_roomBmp.getPalette());
+ _graph->setPalette(_roomBmp->getPalette());
const Graphics::Surface visiblePart = roomSurface->getSubArea(Common::Rect(_cameraX, 0, roomSurface->w, roomSurface->h));
_graph->draw(0, 0, &visiblePart);
}
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index 977f178b18..c97a9022a6 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -42,9 +42,6 @@
#include "video/flic_decoder.h"
-#include "prince/font.h"
-#include "prince/mhwanh.h"
-
namespace Prince {
struct PrinceGameDescription;
@@ -57,6 +54,9 @@ class ObjectList;
class MobList;
class MusicPlayer;
class VariaTxt;
+class Cursor;
+class MhwanhDecoder;
+class Font;
struct Text {
const char *_str;
@@ -124,21 +124,21 @@ private:
uint32 getTextWidth(const char *s);
void debugEngine(const char *s, ...);
- Common::RandomSource *_rnd;
- Graphics::BitmapDecoder _roomBmp;
uint16 _locationNr;
- MhwanhDecoder _walizkaBmp;
-
- Graphics::Surface *_cur1;
- Graphics::Surface *_cur2;
+ Common::RandomSource *_rnd;
+ Graphics::BitmapDecoder *_roomBmp;
+ Cursor *_cursor1;
+ Cursor *_cursor2;
+ MhwanhDecoder *_walizkaBmp;
Debugger *_debugger;
GraphicsMan *_graph;
Script *_script;
- Font _font;
+ Font *_font;
ObjectList *_objectList;
MobList *_mobList;
MusicPlayer *_midiPlayer;
+
uint16 _cameraX;
uint16 _newCameraX;
uint16 _sceneWidth;