Skip to content

Commit

Permalink
PRINCE: graphic routines moved to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Zbróg committed Oct 13, 2013
1 parent fb26275 commit dce5c87
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 31 deletions.
34 changes: 34 additions & 0 deletions engines/prince/graphics.cpp
@@ -0,0 +1,34 @@
#include "prince/graphics.h"

#include "prince/prince.h"

#include "graphics/palette.h"

namespace Prince {

GraphicsMan::GraphicsMan(PrinceEngine *vm) : _vm(vm), _changed(false)
{
initGraphics(640, 480, true);
}

void GraphicsMan::update()
{
if (_changed)
{
_vm->_system->copyRectToScreen((byte*)_roomBackground->getBasePtr(0,0), 640, 0, 0, 640, 480);

_vm->_system->updateScreen();
}
}

void GraphicsMan::setPalette(const byte *palette)
{
_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
}

void GraphicsMan::change()
{
_changed = true;
}

}
58 changes: 58 additions & 0 deletions engines/prince/graphics.h
@@ -0,0 +1,58 @@
/* 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_GRAPHICS_H
#define PRINCE_GRAPHICS_H

#include "graphics/surface.h"


namespace Prince {

class PrinceEngine;

class GraphicsMan
{
public:
GraphicsMan(PrinceEngine *vm);

void update();

void change();

void setPalette(const byte *palette);

Graphics::Surface *_backScreen;
const Graphics::Surface *_roomBackground;

private:

PrinceEngine *_vm;

bool _changed;
byte _palette[3 * 256];
Graphics::Surface *_frontScreen;
};

}

#endif
2 changes: 1 addition & 1 deletion engines/prince/mhwanh.cpp
Expand Up @@ -42,7 +42,7 @@ void MhwanhDecoder::destroy()
if (_surface)
{
_surface->free();
delete _surface; _surface = 0;
_surface = 0;
}

delete [] _palette; _palette = 0;
Expand Down
1 change: 1 addition & 0 deletions engines/prince/module.mk
@@ -1,6 +1,7 @@
MODULE := engines/prince

MODULE_OBJS = \
graphics.o \
mhwanh.o \
detection.o \
font.o \
Expand Down
35 changes: 17 additions & 18 deletions engines/prince/prince.cpp
Expand Up @@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "common/scummsys.h"

#include "common/config-manager.h"
Expand All @@ -45,6 +46,7 @@
#include "prince/prince.h"
#include "prince/font.h"
#include "prince/mhwanh.h"
#include "prince/graphics.h"

namespace Prince {

Expand All @@ -61,7 +63,7 @@ PrinceEngine::~PrinceEngine() {

Common::Error PrinceEngine::run() {

initGraphics(640, 480, true);
_graph = new GraphicsMan(this);

const Common::FSNode gameDataDir(ConfMan.get("path"));

Expand All @@ -81,44 +83,45 @@ Common::Error PrinceEngine::run() {
{
font1.getCharWidth(103);
}
delete font1stream;

Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room");

_frontScreen = new Graphics::Surface();
_frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
//_frontScreen = new Graphics::Surface();
//_frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());

if (room)
{
Graphics::BitmapDecoder roomBmp;
roomBmp.loadStream(*room);
_roomBackground = roomBmp.getSurface();
//_roomBackground = roomBmp.getSurface();
_system->getPaletteManager()->setPalette(roomBmp.getPalette(), 0, 256);

font1.drawString(_frontScreen, "Hello World", 10, 10, 640, 1);
//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);
_graph->_roomBackground = walizkaBmp.getSurface();
_graph->setPalette(walizkaBmp.getPalette());
}
}

_graph->change();


mainLoop();
}
delete room;



return Common::kNoError;
}

void PrinceEngine::mainLoop() {
uint32 nextFrameTime = 0;
//uint32 nextFrameTime = 0;
while (!shouldQuit()) {
Common::Event event;
Common::EventManager *eventMan = _system->getEventManager();
Expand All @@ -137,24 +140,20 @@ void PrinceEngine::mainLoop() {
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();
if (shouldQuit())
return;

_graph->update();

_system->delayMillis(40);

}
}

void PrinceEngine::setFullPalette() {
_system->getPaletteManager()->setPalette(_palette, 0, 256);
}


} // End of namespace Prince
15 changes: 3 additions & 12 deletions engines/prince/prince.h
Expand Up @@ -33,15 +33,14 @@
#include "engines/engine.h"
#include "engines/util.h"

#include "graphics/surface.h"

#include "audio/mixer.h"

namespace Prince {

struct PrinceGameDescription;

class PrinceEngine;
class GraphicsMan;

class PrinceEngine : public Engine {
protected:
Expand All @@ -62,17 +61,9 @@ class PrinceEngine : public Engine {

private:
Common::RandomSource *_rnd;

byte _palette[768];
Graphics::Surface *_frontScreen;
const Graphics::Surface *_roomBackground;

void mainLoop();

void loadBackground(Common::SeekableReadStream *stream);
void setFullPalette();
GraphicsMan *_graph;

void drawSprite(Graphics::Surface *sprite, int32 x, int32 y, int32 mod);
void mainLoop();

};

Expand Down

0 comments on commit dce5c87

Please sign in to comment.