Skip to content

Commit

Permalink
PRINCE: showMask, drawMask update
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jun 22, 2014
1 parent 4be66f5 commit dab83cc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
14 changes: 14 additions & 0 deletions engines/prince/graphics.cpp
Expand Up @@ -89,6 +89,20 @@ void GraphicsMan::drawTransparent(int32 posX, int32 posY, const Graphics::Surfac
change();
}

void GraphicsMan::drawMask(int32 posX, int32 posY, int32 width, int32 height, byte *maskData, const Graphics::Surface *originalRoomSurface) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (x + posX < _frontScreen->w && x + posX >= 0) {
if (y + posY < _frontScreen->h && y + posY >= 0) {
byte orgPixel = *((byte*)originalRoomSurface->getBasePtr(x + posX, y + posY));
*((byte*)_frontScreen->getBasePtr(x + posX, y + posY)) = orgPixel;
}
}
}
}
change();
}

void GraphicsMan::drawAsShadow(int32 posX, int32 posY, const Graphics::Surface *s, byte *shadowTable) {
for (int y = 0; y < s->h; y++) {
for (int x = 0; x < s->w; x++) {
Expand Down
1 change: 1 addition & 0 deletions engines/prince/graphics.h
Expand Up @@ -46,6 +46,7 @@ class GraphicsMan
void draw(uint16 x, uint16 y, const Graphics::Surface *s);
void drawTransparent(int32 posX, int32 poxY, const Graphics::Surface *s);
void drawAsShadow(int32 posX, int32 poxY, const Graphics::Surface *s, byte *shadowTable);
void drawMask(int32 posX, int32 posY, int32 width, int32 height, byte *maskData, const Graphics::Surface *originalRoomSurface);

Graphics::Surface *_frontScreen;
Graphics::Surface *_backScreen;
Expand Down
14 changes: 9 additions & 5 deletions engines/prince/prince.cpp
Expand Up @@ -770,18 +770,18 @@ void PrinceEngine::checkMasks(int x1, int y1, int sprWidth, int sprHeight, int z
}

// InsertNakladki
void PrinceEngine::insertMasks() {
void PrinceEngine::insertMasks(const Graphics::Surface *originalRoomSurface) {
for (uint i = 0; i < _maskList.size(); i++) {
if (_maskList[i]._state == 1) {
showMask(i);
showMask(i, originalRoomSurface);
}
}
}

// ShowNak
void PrinceEngine::showMask(int maskNr) {
void PrinceEngine::showMask(int maskNr, const Graphics::Surface *originalRoomSurface) {
if (_maskList[maskNr]._flags == 0) {

_graph->drawMask(_maskList[maskNr]._x1, _maskList[maskNr]._y1, _maskList[maskNr]._width, _maskList[maskNr]._height, _maskList[maskNr].getMask(), originalRoomSurface);
}
}

Expand Down Expand Up @@ -971,8 +971,9 @@ void PrinceEngine::clearBackAnimList() {

void PrinceEngine::drawScreen() {
const Graphics::Surface *roomSurface = _roomBmp->getSurface();
Graphics::Surface visiblePart;
if (roomSurface) {
const Graphics::Surface visiblePart = roomSurface->getSubArea(Common::Rect(_picWindowX, 0, roomSurface->w, roomSurface->h));
visiblePart = roomSurface->getSubArea(Common::Rect(_picWindowX, 0, roomSurface->w, roomSurface->h));
_graph->draw(0, 0, &visiblePart);
}

Expand Down Expand Up @@ -1002,6 +1003,9 @@ void PrinceEngine::drawScreen() {
*/

showBackAnims();
if (roomSurface) {
insertMasks(&visiblePart);
}

playNextFrame();

Expand Down
25 changes: 23 additions & 2 deletions engines/prince/prince.h
Expand Up @@ -151,7 +151,28 @@ struct Mask {
int16 _y2;
int16 _z;
int16 _number; // number of mask for background recreating
int16 _width;
int16 _height;
byte *_data;

int16 Mask::getX() const {
return READ_LE_UINT16(_data);
}

int16 Mask::getY() const {
return READ_LE_UINT16(_data + 2);
}

int16 Mask::getWidth() const {
return READ_LE_UINT16(_data + 4);
}

int16 Mask::getHeight() const {
return READ_LE_UINT16(_data + 6);
}
byte *Mask::getMask() const {
return (byte *)(_data + 8);
}
};

struct DebugChannel {
Expand Down Expand Up @@ -223,8 +244,8 @@ class PrinceEngine : public Engine {
static const int16 kNormalHeight = 480;

void checkMasks(int x1, int y1, int sprWidth, int sprHeight, int z);
void insertMasks();
void showMask(int maskNr);
void insertMasks(const Graphics::Surface *originalRoomSurface);
void showMask(int maskNr, const Graphics::Surface *originalRoomSurface);

int testAnimNr;
int testAnimFrame;
Expand Down
8 changes: 6 additions & 2 deletions engines/prince/script.cpp
Expand Up @@ -312,7 +312,7 @@ bool Script::loadAllMasks(Common::Array<Mask> &maskList, int offset) {
tempMask._z = READ_UINT32(&_data[offset + 12]);
debug("tempMask._z: %d", tempMask._z);
tempMask._number = READ_UINT32(&_data[offset + 14]);
debug("tempMask._number: %d\n", tempMask._number);
debug("tempMask._number: %d", tempMask._number);

const Common::String msStreamName = Common::String::format("MS%02d", tempMask._number);
Common::SeekableReadStream *msStream = SearchMan.createReadStreamForMember(msStreamName);
Expand All @@ -321,6 +321,7 @@ bool Script::loadAllMasks(Common::Array<Mask> &maskList, int offset) {
delete msStream;
return false;
}

uint32 dataSize = msStream->size();
if (dataSize != -1) {
tempMask._data = (byte *)malloc(dataSize);
Expand All @@ -331,9 +332,12 @@ bool Script::loadAllMasks(Common::Array<Mask> &maskList, int offset) {
}
delete msStream;
}
tempMask._width = tempMask.getHeight();
tempMask._height = tempMask.getHeight();
debug("width: %d, height: %d\n", tempMask._width, tempMask._height);

maskList.push_back(tempMask);
offset += 16; // size of tempMask (Nak) struct
offset += 16; // size of Mask (Nak) struct
}
debug("Mask size: %d", sizeof(tempMask));
debug("maskList size: %d", maskList.size());
Expand Down

0 comments on commit dab83cc

Please sign in to comment.