PRINCE: mhwanh decoder added. simple game loop works

This commit is contained in:
Kamil Zbróg 2013-10-13 02:42:09 +01:00
parent b49707d948
commit fb2627569e
7 changed files with 384 additions and 1 deletions

94
engines/prince/font.cpp Normal file
View File

@ -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;
}
}
}

66
engines/prince/font.h Normal file
View File

@ -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

77
engines/prince/mhwanh.cpp Normal file
View File

@ -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;
}
}

52
engines/prince/mhwanh.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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();