aboutsummaryrefslogtreecommitdiff
path: root/engines/prince
diff options
context:
space:
mode:
authorKamil Zbróg2013-10-13 02:42:09 +0100
committerKamil Zbróg2013-10-13 02:42:09 +0100
commitfb2627569e03f3a1f51d7619db381253b30b9a0b (patch)
tree70fd753fd802f38e5eb1e1bae2a2e1595e482a3e /engines/prince
parentb49707d9485c4d1eaf05fc079e15625b4e2672da (diff)
downloadscummvm-rg350-fb2627569e03f3a1f51d7619db381253b30b9a0b.tar.gz
scummvm-rg350-fb2627569e03f3a1f51d7619db381253b30b9a0b.tar.bz2
scummvm-rg350-fb2627569e03f3a1f51d7619db381253b30b9a0b.zip
PRINCE: mhwanh decoder added. simple game loop works
Diffstat (limited to 'engines/prince')
-rw-r--r--engines/prince/font.cpp94
-rw-r--r--engines/prince/font.h66
-rw-r--r--engines/prince/mhwanh.cpp77
-rw-r--r--engines/prince/mhwanh.h52
-rw-r--r--engines/prince/module.mk2
-rw-r--r--engines/prince/prince.cpp90
-rw-r--r--engines/prince/prince.h4
7 files changed, 384 insertions, 1 deletions
diff --git a/engines/prince/font.cpp b/engines/prince/font.cpp
new file mode 100644
index 0000000000..d3ae4d6b83
--- /dev/null
+++ b/engines/prince/font.cpp
@@ -0,0 +1,94 @@
+/* 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 "common/archive.h"
+#include "common/debug.h"
+#include "common/stream.h"
+#include "common/str.h"
+
+#include "graphics/surface.h"
+
+#include "prince/font.h"
+
+namespace Prince {
+
+Font::Font()
+{
+}
+
+Font::~Font()
+{
+ delete _fontData;
+}
+
+bool Font::load(Common::SeekableReadStream &stream)
+{
+ stream.seek(0);
+ _fontData = new byte[stream.size()];
+ stream.read(_fontData, stream.size());
+ return true;
+}
+
+int Font::getFontHeight() const
+{
+ debug("Font::getFontHeight %d", _fontData[5]);
+ return _fontData[5];
+}
+
+int Font::getMaxCharWidth() const
+{
+ return 0;
+}
+
+Font::ChrData Font::getChrData(byte chr) const
+{
+ chr -= 32;
+ uint16 chrOffset = 4*chr+6;
+
+ ChrData chrData;
+ chrData._width = _fontData[chrOffset+2];
+ chrData._height = _fontData[chrOffset+3];
+ chrData._pixels = _fontData + READ_LE_UINT16(_fontData + chrOffset);
+
+ return chrData;
+}
+
+int Font::getCharWidth(byte chr) const
+{
+ return getChrData(chr)._width;
+}
+
+void Font::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const
+{
+ const ChrData chrData = getChrData(chr);
+ const byte *src = chrData._pixels;
+ byte *target = (byte *)dst->getBasePtr(x, y);
+
+ for (int i = 0; i < chrData._height; i++) {
+ memcpy(target, src, chrData._width);
+ src += chrData._width;
+ target += dst->pitch;
+ }
+
+}
+
+}
diff --git a/engines/prince/font.h b/engines/prince/font.h
new file mode 100644
index 0000000000..0bffcf601b
--- /dev/null
+++ b/engines/prince/font.h
@@ -0,0 +1,66 @@
+/* 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 PRINCE_FONT_H
+#define PRINCE_FONT_H
+
+#include "graphics/font.h"
+
+namespace Graphics {
+ class Surface;
+}
+
+namespace Common {
+ class String;
+}
+
+namespace Prince {
+
+class Font : public Graphics::Font {
+public:
+ Font();
+ virtual ~Font();
+
+ bool load(Common::SeekableReadStream &stream);
+
+ virtual int getFontHeight() const override;
+
+ virtual int getMaxCharWidth() const override;
+
+ virtual int getCharWidth(byte chr) const override;
+
+ virtual void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const override;
+
+private:
+ struct ChrData {
+ byte * _pixels;
+ byte _width;
+ byte _height;
+ };
+
+ ChrData getChrData(byte chr) const;
+
+ byte * _fontData;
+};
+
+}
+
+#endif
diff --git a/engines/prince/mhwanh.cpp b/engines/prince/mhwanh.cpp
new file mode 100644
index 0000000000..4ce7beded9
--- /dev/null
+++ b/engines/prince/mhwanh.cpp
@@ -0,0 +1,77 @@
+/* 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 "common/stream.h"
+
+#include "graphics/surface.h"
+
+#include "prince/mhwanh.h"
+
+namespace Prince {
+
+MhwanhDecoder::MhwanhDecoder() : _surface(0), _palette(0), _paletteColorCount(0)
+{
+}
+
+MhwanhDecoder::~MhwanhDecoder()
+{
+ destroy();
+}
+
+void MhwanhDecoder::destroy()
+{
+ if (_surface)
+ {
+ _surface->free();
+ delete _surface; _surface = 0;
+ }
+
+ delete [] _palette; _palette = 0;
+ _paletteColorCount = 0;
+}
+
+bool MhwanhDecoder::loadStream(Common::SeekableReadStream &stream)
+{
+ _paletteColorCount = 256;
+ stream.seek(0);
+ stream.skip(0x20);
+ // Read the palette
+ _palette = new byte[_paletteColorCount * 3];
+ for (uint16 i = 0; i < _paletteColorCount; i++) {
+ _palette[i * 3 + 0] = stream.readByte();
+ _palette[i * 3 + 1] = stream.readByte();
+ _palette[i * 3 + 2] = stream.readByte();
+ }
+
+ _surface = new Graphics::Surface();
+ _surface->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
+ for (int h = 0; h < 480; ++h)
+ {
+ stream.read(_surface->getBasePtr(0, h - 1), 640);
+ }
+
+ return true;
+}
+
+}
+
+
diff --git a/engines/prince/mhwanh.h b/engines/prince/mhwanh.h
new file mode 100644
index 0000000000..44f957372e
--- /dev/null
+++ b/engines/prince/mhwanh.h
@@ -0,0 +1,52 @@
+/* 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 PRINCE_MHWANH_H
+#define PRINCE_MHWANH_H
+
+#include "graphics/decoders/image_decoder.h"
+
+namespace Prince {
+
+class MhwanhDecoder : public Graphics::ImageDecoder
+{
+public:
+ MhwanhDecoder();
+ virtual ~MhwanhDecoder();
+
+ // ImageDecoder API
+ void destroy();
+ virtual bool loadStream(Common::SeekableReadStream &stream);
+ virtual Graphics::Surface *getSurface() const { return _surface; }
+ const byte *getPalette() const { return _palette; }
+ uint16 getPaletteCount() const { return _paletteColorCount; }
+
+private:
+ Graphics::Surface *_surface;
+ byte *_palette;
+ uint16 _paletteColorCount;
+};
+
+}
+
+
+#endif
diff --git a/engines/prince/module.mk b/engines/prince/module.mk
index 1621e48ce7..e4a792f84d 100644
--- a/engines/prince/module.mk
+++ b/engines/prince/module.mk
@@ -1,7 +1,9 @@
MODULE := engines/prince
MODULE_OBJS = \
+ mhwanh.o \
detection.o \
+ font.o \
prince.o
# This module can be built as a plugin
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index e2149e9919..2791bda86c 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -35,6 +35,7 @@
#include "graphics/surface.h"
#include "graphics/palette.h"
#include "graphics/pixelformat.h"
+#include "graphics/decoders/bmp.h"
#include "engines/util.h"
#include "engines/advancedDetector.h"
@@ -42,11 +43,14 @@
#include "audio/audiostream.h"
#include "prince/prince.h"
+#include "prince/font.h"
+#include "prince/mhwanh.h"
namespace Prince {
PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
_rnd = new Common::RandomSource("prince");
+
}
PrinceEngine::~PrinceEngine() {
@@ -59,9 +63,95 @@ Common::Error PrinceEngine::run() {
initGraphics(640, 480, true);
+ const Common::FSNode gameDataDir(ConfMan.get("path"));
+
+ debug("Adding all path: %s", gameDataDir.getPath().c_str());
+
+ SearchMan.addSubDirectoryMatching(gameDataDir, "all", 0, 2);
+ SearchMan.addSubDirectoryMatching(gameDataDir, "01", 0, 2);
+
+ Common::SeekableReadStream * walizka = SearchMan.createReadStreamForMember("walizka");
+
+ Common::SeekableReadStream *font1stream = SearchMan.createReadStreamForMember("font1.raw");
+ if (!font1stream)
+ return Common::kPathNotFile;
+
+ Font font1 = Font();
+ if (font1.load(*font1stream))
+ {
+ font1.getCharWidth(103);
+ }
+
+ Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room");
+
+ _frontScreen = new Graphics::Surface();
+ _frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
+
+ if (room)
+ {
+ Graphics::BitmapDecoder roomBmp;
+ roomBmp.loadStream(*room);
+ _roomBackground = roomBmp.getSurface();
+ _system->getPaletteManager()->setPalette(roomBmp.getPalette(), 0, 256);
+
+ font1.drawString(_frontScreen, "Hello World", 10, 10, 640, 1);
+
+ MhwanhDecoder walizkaBmp;
+ if (walizka)
+ {
+ debug("Loading walizka");
+ if (walizkaBmp.loadStream(*walizka))
+ {
+ _roomBackground = walizkaBmp.getSurface();
+ _system->getPaletteManager()->setPalette(walizkaBmp.getPalette(), 0, 256);
+ }
+ }
+
+
+ mainLoop();
+ }
+ delete room;
+
+
+
return Common::kNoError;
}
+void PrinceEngine::mainLoop() {
+ uint32 nextFrameTime = 0;
+ while (!shouldQuit()) {
+ Common::Event event;
+ Common::EventManager *eventMan = _system->getEventManager();
+ while (eventMan->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_KEYDOWN:
+ break;
+ case Common::EVENT_KEYUP:
+ break;
+ case Common::EVENT_MOUSEMOVE:
+ break;
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_RBUTTONDOWN:
+ break;
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONUP:
+ break;
+ case Common::EVENT_QUIT:
+ _system->quit();
+ break;
+ default:
+ break;
+ }
+ }
+ _system->copyRectToScreen((byte*)_roomBackground->getBasePtr(0,0), 640, 0, 0, 640, 480);
+
+ _system->updateScreen();
+
+ _system->delayMillis(40);
+
+ }
+}
+
void PrinceEngine::setFullPalette() {
_system->getPaletteManager()->setPalette(_palette, 0, 256);
}
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index e73deb63e3..3ae6c6a221 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -65,7 +65,9 @@ private:
byte _palette[768];
Graphics::Surface *_frontScreen;
- Graphics::Surface *_roomBackground;
+ const Graphics::Surface *_roomBackground;
+
+ void mainLoop();
void loadBackground(Common::SeekableReadStream *stream);
void setFullPalette();