Skip to content

Commit

Permalink
PRINCE: drawMask progress, changes in spriteCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jun 22, 2014
1 parent dab83cc commit 7874a4e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
17 changes: 15 additions & 2 deletions engines/prince/graphics.cpp
Expand Up @@ -90,15 +90,28 @@ void GraphicsMan::drawTransparent(int32 posX, int32 posY, const Graphics::Surfac
}

void GraphicsMan::drawMask(int32 posX, int32 posY, int32 width, int32 height, byte *maskData, const Graphics::Surface *originalRoomSurface) {
int maskWidth = width >> 3;
int maskPostion = 0;
int maskCounter = 128;
for (int y = 0; y < height; y++) {
int tempMaskPostion = maskPostion;
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;
if ((maskData[tempMaskPostion] & maskCounter) != 0) {
byte orgPixel = *((byte*)originalRoomSurface->getBasePtr(x + posX, y + posY));
*((byte*)_frontScreen->getBasePtr(x + posX, y + posY)) = orgPixel;
}
maskCounter >>= 1;
if (maskCounter == 0) {
maskCounter = 128;
tempMaskPostion++;
}
}
}
}
maskPostion += maskWidth;
maskCounter = 128;
}
change();
}
Expand Down
2 changes: 1 addition & 1 deletion engines/prince/hero.cpp
Expand Up @@ -203,7 +203,7 @@ void Hero::countDrawPosition() {
_scaledFrameYSize = getScaledValue(_frameYSize);

//TODO
int tempHeroHeight = _scaledFrameYSize; // not used? global?
//int tempHeroHeight = _scaledFrameYSize; // not used? global?
int width = _frameXSize / 2;
tempMiddleX = _middleX - width; //eax
int z = _middleY; //ebp
Expand Down
41 changes: 38 additions & 3 deletions engines/prince/prince.cpp
Expand Up @@ -718,6 +718,35 @@ void PrinceEngine::showTexts() {
}
}

bool PrinceEngine::spriteCheck(int sprWidth, int sprHeight, int destX, int destY) {
destX -= _picWindowX;
destY -= _picWindowY;

// if x1 is on visible part of screen
if (destX < 0) {
if (destX + sprWidth < 1) {
//x2 is negative - out of window
return false;
}
}
// if x1 is outside of screen on right side
if (destX >= kNormalWidth) {
return false;
}

if (destY < 0) {
if (destY + sprHeight < 1) {
//y2 is negative - out of window
return false;
}
}
if (destY >= kNormalHeight) {
return false;
}

return true;
}
/*
bool PrinceEngine::spriteCheck(Graphics::Surface *backAnimSurface, int destX, int destY) {
int sprWidth = backAnimSurface->w;
int sprHeight = backAnimSurface->h;
Expand Down Expand Up @@ -748,6 +777,7 @@ bool PrinceEngine::spriteCheck(Graphics::Surface *backAnimSurface, int destX, in
return true;
}
*/

// CheckNak
void PrinceEngine::checkMasks(int x1, int y1, int sprWidth, int sprHeight, int z) {
Expand All @@ -774,27 +804,32 @@ void PrinceEngine::insertMasks(const Graphics::Surface *originalRoomSurface) {
for (uint i = 0; i < _maskList.size(); i++) {
if (_maskList[i]._state == 1) {
showMask(i, originalRoomSurface);
_maskList[i]._state = 0; // here or somewhere else?
}
}
}

// ShowNak
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);
if (spriteCheck(_maskList[maskNr]._width, _maskList[maskNr]._height, _maskList[maskNr]._x1, _maskList[maskNr]._y1)) {
int destX = _maskList[maskNr]._x1 - _picWindowX;
int destY = _maskList[maskNr]._y1 - _picWindowY;
_graph->drawMask(destX, destY, _maskList[maskNr]._width, _maskList[maskNr]._height, _maskList[maskNr].getMask(), originalRoomSurface);
}
}
}

void PrinceEngine::showSprite(Graphics::Surface *backAnimSurface, int destX, int destY) {
if (spriteCheck(backAnimSurface, destX, destY)) {
if (spriteCheck(backAnimSurface->w, backAnimSurface->h, destX, destY)) {
destX -= _picWindowX;
destY -= _picWindowY;
_graph->drawTransparent(destX, destY, backAnimSurface);
}
}

void PrinceEngine::showSpriteShadow(Graphics::Surface *shadowSurface, int destX, int destY) {
if (spriteCheck(shadowSurface, destX, destY)) {
if (spriteCheck(shadowSurface->w, shadowSurface->h, destX, destY)) {
destX -= _picWindowX;
destY -= _picWindowY;
_graph->drawAsShadow(destX, destY, shadowSurface, _graph->_shadowTable70);
Expand Down
3 changes: 2 additions & 1 deletion engines/prince/prince.h
Expand Up @@ -30,6 +30,7 @@
#include "common/textconsole.h"
#include "common/rect.h"
#include "common/events.h"
#include "common/endian.h"

#include "image/bmp.h"

Expand Down Expand Up @@ -262,7 +263,7 @@ class PrinceEngine : public Engine {
void showLogo();
void showBackAnims();
void clearBackAnimList();
bool spriteCheck(Graphics::Surface *backAnimSurface, int destX, int destY);
bool spriteCheck(int sprWidth, int sprHeight, int destX, int destY);
void showSprite(Graphics::Surface *backAnimSurface, int destX, int destY);
void showSpriteShadow(Graphics::Surface *shadowSurface, int destX, int destY);
void makeShadowTable(int brightness);
Expand Down
3 changes: 2 additions & 1 deletion engines/prince/script.cpp
Expand Up @@ -332,9 +332,10 @@ bool Script::loadAllMasks(Common::Array<Mask> &maskList, int offset) {
}
delete msStream;
}
tempMask._width = tempMask.getHeight();
tempMask._width = tempMask.getWidth();
tempMask._height = tempMask.getHeight();
debug("width: %d, height: %d\n", tempMask._width, tempMask._height);
debug("dataSize: %d", dataSize);

maskList.push_back(tempMask);
offset += 16; // size of Mask (Nak) struct
Expand Down

0 comments on commit 7874a4e

Please sign in to comment.