Skip to content

Commit

Permalink
PRINCE: loadTrans(), drawTransparentWithTransDrawNode() - implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Aug 10, 2014
1 parent 075ea1a commit 7026f68
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 17 deletions.
65 changes: 56 additions & 9 deletions engines/prince/graphics.cpp
Expand Up @@ -164,15 +164,62 @@ void GraphicsMan::drawTransparentDrawNode(Graphics::Surface *screen, DrawNode *d
byte *dst1 = (byte *)screen->getBasePtr(drawNode->posX, drawNode->posY);

for (int y = 0; y < drawNode->s->h; y++) {
byte *src2 = src1;
byte *dst2 = dst1;
for (int x = 0; x < drawNode->s->w; x++, src2++, dst2++) {
if (*src2 != 255) {
if (x + drawNode->posX < screen->w && x + drawNode->posX >= 0) {
if (y + drawNode->posY < screen->h && y + drawNode->posY >= 0) {
*dst2 = *src2;
}
}
if (y + drawNode->posY < screen->h && y + drawNode->posY >= 0) {
byte *src2 = src1;
byte *dst2 = dst1;
for (int x = 0; x < drawNode->s->w; x++, src2++, dst2++) {
if (*src2 != 255) {
if (x + drawNode->posX < screen->w && x + drawNode->posX >= 0) {
*dst2 = *src2;
}
}
}
}
src1 += drawNode->s->pitch;
dst1 += screen->pitch;
}
}

void GraphicsMan::drawTransparentWithTransDrawNode(Graphics::Surface *screen, DrawNode *drawNode) {
byte *src1 = (byte *)drawNode->s->getBasePtr(0, 0);
byte *dst1 = (byte *)screen->getBasePtr(drawNode->posX, drawNode->posY);
byte *transTableData = (byte *)drawNode->data;

for (int y = 0; y < drawNode->s->h; y++) {
if (y + drawNode->posY < screen->h && y + drawNode->posY >= 0) {
byte *src2 = src1;
byte *dst2 = dst1;
for (int x = 0; x < drawNode->s->w; x++, src2++, dst2++) {
if (x + drawNode->posX < screen->w && x + drawNode->posX >= 0) {
if (*src2 != 255) {
*dst2 = *src2;
} else if (x) {
if (*(src2 - 1) == 255) {
if (x != drawNode->s->w - 1) {
if (*(src2 + 1) == 255) {
continue;
}
}
}
} else if (*(src2 + 1) == 255) {
continue;
}
byte value = 0;
if (y != drawNode->s->h - 1) {
value = *(src1 + drawNode->s->pitch + x);
if (value == 255) {
if (y) {
value = *(src1 + x);
if (value == 255) {
continue;
}
} else {
continue;
}
}
*dst2 = transTableData[*dst2 * 256 + value];
}
}
}
}
src1 += drawNode->s->pitch;
Expand Down
1 change: 1 addition & 0 deletions engines/prince/graphics.h
Expand Up @@ -49,6 +49,7 @@ class GraphicsMan {
void drawTransparentWithBlendSurface(Graphics::Surface *screen, int32 posX, int32 posY, const Graphics::Surface *s, int transColor);

static void drawTransparentDrawNode(Graphics::Surface *screen, DrawNode *drawNode);
static void drawTransparentWithTransDrawNode(Graphics::Surface *screen, DrawNode *drawNode);
static void drawAsShadowDrawNode(Graphics::Surface *screen, DrawNode *drawNode);
static void drawMaskDrawNode(Graphics::Surface *screen, DrawNode *drawNode);
static void drawBackSpriteDrawNode(Graphics::Surface *screen, DrawNode *drawNode);
Expand Down
4 changes: 2 additions & 2 deletions engines/prince/hero.cpp
Expand Up @@ -892,8 +892,8 @@ void Hero::drawHero() {
newDrawNode.width = 0;
newDrawNode.height = 0;
newDrawNode.originalRoomSurface = nullptr;
newDrawNode.data = nullptr;
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;
newDrawNode.data = _vm->_transTable;
newDrawNode.drawFunction = &_graph->drawTransparentWithTransDrawNode;

if (_zoomFactor) {
_zoomedHeroSurface = zoomSprite(mainHeroSurface);
Expand Down
38 changes: 32 additions & 6 deletions engines/prince/prince.cpp
Expand Up @@ -94,7 +94,7 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
_checkBitmapTemp(nullptr), _checkBitmap(nullptr), _checkMask(0), _checkX(0), _checkY(0), _traceLineFirstPointFlag(false),
_tracePointFirstPointFlag(false), _coordsBuf2(nullptr), _coords2(nullptr), _coordsBuf3(nullptr), _coords3(nullptr),
_shanLen(0), _directionTable(nullptr), _currentMidi(0), _lightX(0), _lightY(0), _curveData(nullptr), _curvPos(0),
_creditsData(nullptr), _creditsDataSize(0), _currentTime(0) {
_creditsData(nullptr), _creditsDataSize(0), _currentTime(0), _zoomBitmap(nullptr), _shadowBitmap(nullptr), _transTable(nullptr) {

// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
Expand Down Expand Up @@ -191,6 +191,7 @@ PrinceEngine::~PrinceEngine() {

free(_zoomBitmap);
free(_shadowBitmap);
free(_transTable);

free(_curveData);

Expand Down Expand Up @@ -339,6 +340,7 @@ void PrinceEngine::init() {

_zoomBitmap = (byte *)malloc(kZoomBitmapLen);
_shadowBitmap = (byte *)malloc(2 * kShadowBitmapSize);
_transTable = (byte *)malloc(kTransTableSize);

_curveData = (int16 *)malloc(2 * kCurveLen * sizeof(int16));

Expand Down Expand Up @@ -444,6 +446,7 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {

loadZoom(_zoomBitmap, kZoomBitmapLen, "zoom");
loadShadow(_shadowBitmap, kShadowBitmapSize, "shadow", "shadow2");
loadTrans(_transTable, "trans");
loadPath("path");

for (uint32 i = 0; i < _pscrList.size(); i++) {
Expand Down Expand Up @@ -832,6 +835,25 @@ bool PrinceEngine::loadShadow(byte *shadowBitmap, uint32 dataSize, const char *r
return true;
}

bool PrinceEngine::loadTrans(byte *transTable, const char *resourceName) {
Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
if (!stream) {
delete stream;
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
transTable[i * 256 + j] = j;
}
}
return true;
}
if (stream->read(transTable, kTransTableSize) != kTransTableSize) {
delete stream;
return false;
}
delete stream;
return true;
}

bool PrinceEngine::loadPath(const char *resourceName) {
Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
if (!stream) {
Expand Down Expand Up @@ -1305,8 +1327,8 @@ void PrinceEngine::showSprite(Graphics::Surface *spriteSurface, int destX, int d
newDrawNode.height = 0;
newDrawNode.s = spriteSurface;
newDrawNode.originalRoomSurface = nullptr;
newDrawNode.data = nullptr;
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;
newDrawNode.data = _transTable;
newDrawNode.drawFunction = &_graph->drawTransparentWithTransDrawNode;
_drawNodeList.push_back(newDrawNode);
}
}
Expand Down Expand Up @@ -1690,12 +1712,16 @@ void PrinceEngine::showObjects() {
newDrawNode.height = 0;
newDrawNode.s = objSurface;
newDrawNode.originalRoomSurface = nullptr;
newDrawNode.data = nullptr;

if ((_objList[nr]->_flags & 0x2000)) {
newDrawNode.data = nullptr;
newDrawNode.drawFunction = &_graph->drawBackSpriteDrawNode;
} else {
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;
newDrawNode.data = _transTable;
if (_flags->getFlagValue(Flags::NOANTIALIAS)) {
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;
} else {
newDrawNode.drawFunction = &_graph->drawTransparentWithTransDrawNode;
}
}
_drawNodeList.push_back(newDrawNode);
}
Expand Down
3 changes: 3 additions & 0 deletions engines/prince/prince.h
Expand Up @@ -285,6 +285,7 @@ class PrinceEngine : public Engine {
bool loadSample(uint32 sampleSlot, const Common::String &name);
bool loadZoom(byte *zoomBitmap, uint32 dataSize, const char *resourceName);
bool loadShadow(byte *shadowBitmap, uint32 dataSize, const char *resourceName1, const char *resourceName2);
bool loadTrans(byte *transTable, const char *resourceName);
bool loadMobPriority(const char *resourceName);

bool loadMusic(int musNumber);
Expand Down Expand Up @@ -334,6 +335,7 @@ class PrinceEngine : public Engine {
uint8 _currentMidi;
byte *_zoomBitmap;
byte *_shadowBitmap;
byte *_transTable;

static const int16 kFPS = 15;

Expand All @@ -346,6 +348,7 @@ class PrinceEngine : public Engine {
static const int16 kZoomBitmapHeight = kMaxPicHeight / kZoomStep;
static const int16 kNormalWidth = 640;
static const int16 kNormalHeight = 480;
static const int32 kTransTableSize = 256 * 256;

static const int kMaxNormAnims = 64;
static const int kMaxBackAnims = 64;
Expand Down

0 comments on commit 7026f68

Please sign in to comment.