SAGA2: Import drawTile from SAGA

This commit is contained in:
a/ 2021-06-01 23:54:25 +09:00 committed by Eugene Sandulenko
parent 5708989481
commit d7ea7c0541
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
3 changed files with 209 additions and 3 deletions

View File

@ -88,10 +88,215 @@ void unpackSprite(gPixelMap *map, uint8 *sprData) {
warning("STUB: unpackSprite()");
}
//void drawTile(gPixelMap *map, int32 x, int32 y, int32 height, uint8 *srcData) {
// warning("STUB: drawTile()");
//}
void drawTile(gPixelMap *map, int32 x, int32 y, int32 height, uint8 *srcData) {
warning("STUB: drawTile()");
const byte *tilePointer;
const byte *readPointer;
byte *drawPointer;
Point32 drawPoint;
int widthCount = 0;
int row, col, count, lowBound;
int bgRunCount;
int fgRunCount;
const int32 SAGA_ISOTILE_WIDTH = 32;
Point16 point(x, y);
// if (tileIndex >= _tilesTable.size()) {
// error("IsoMap::drawTile wrong tileIndex");
// }
if (point.x + SAGA_ISOTILE_WIDTH < 0) {
return;
}
if (point.x - SAGA_ISOTILE_WIDTH >= map->size.x) {
return;
}
if ((height <= 8) || (height > 64)) {
return;
}
tilePointer = srcData;
drawPoint = point;
drawPoint.y -= height;
if (drawPoint.y >= map->size.y) {
return;
}
#if 0
if (location != NULL) {
if (location->z <= -16) {
if (location->z <= -48) {
if (location->u() < -THRESH8 || location->v() < -THRESH8) {
return;
}
} else {
if (location->u() < THRESH0 || location->v() < THRESH0) {
return;
}
}
} else {
if (location->z >= 16) {
return;
} else {
switch (_tilesTable[tileIndex].getMaskRule()) {
case kMaskRuleNever:
return;
case kMaskRuleAlways:
default:
break;
case kMaskRuleUMIN:
if (location->u() < THRESH0) {
return;
}
break;
case kMaskRuleUMID:
if (location->u() < THRESH8) {
return;
}
break;
case kMaskRuleUMAX:
if (location->u() < THRESH16) {
return;
}
break;
case kMaskRuleVMIN:
if (location->v() < THRESH0) {
return;
}
break;
case kMaskRuleVMID:
if (location->v() < THRESH8) {
return;
}
break;
case kMaskRuleVMAX:
if (location->v() < THRESH16) {
return;
}
break;
case kMaskRuleYMIN:
if (location->uv() < THRESH0 * 2) {
return;
}
break;
case kMaskRuleYMID:
if (location->uv() < THRESH8 * 2) {
return;
}
break;
case kMaskRuleYMAX:
if (location->uv() < THRESH16 * 2) {
return;
}
break;
case kMaskRuleUVMAX:
if (location->u() < THRESH16 && location->v() < THRESH16) {
return;
}
break;
case kMaskRuleUVMIN:
if (location->u() < THRESH0 || location->v() < THRESH0) {
return;
}
break;
case kMaskRuleUorV:
if (location->u() < THRESH8 && location->v() < THRESH8) {
return;
}
break;
case kMaskRuleUandV:
if (location->u() < THRESH8 || location->v() < THRESH8) {
return;
}
break;
}
}
}
}
#endif
readPointer = tilePointer;
lowBound = MIN((int)(drawPoint.y + height), (int)map->size.y);
for (row = drawPoint.y; row < lowBound; row++) {
widthCount = 0;
if (row >= 0) {
drawPointer = map->data + drawPoint.x + (row * map->size.x);
col = drawPoint.x;
for (;;) {
bgRunCount = *readPointer++;
widthCount += bgRunCount;
if (widthCount >= SAGA_ISOTILE_WIDTH) {
break;
}
drawPointer += bgRunCount;
col += bgRunCount;
fgRunCount = *readPointer++;
widthCount += fgRunCount;
count = 0;
int colDiff = - col;
if (colDiff > 0) {
if (colDiff > fgRunCount) {
colDiff = fgRunCount;
}
count = colDiff;
col += colDiff;
}
colDiff = map->size.x - col;
if (colDiff > 0) {
int countDiff = fgRunCount - count;
if (colDiff > countDiff) {
colDiff = countDiff;
}
if (colDiff > 0) {
byte *dst = (byte *)(drawPointer + count);
memcpy(dst, (readPointer + count), colDiff);
col += colDiff;
}
}
readPointer += fgRunCount;
drawPointer += fgRunCount;
}
} else {
for (;;) {
bgRunCount = *readPointer++;
widthCount += bgRunCount;
if (widthCount >= SAGA_ISOTILE_WIDTH) {
break;
}
fgRunCount = *readPointer++;
widthCount += fgRunCount;
readPointer += fgRunCount;
}
}
}
// Compute dirty rect
int rectX = MAX<int>(drawPoint.x, 0);
int rectY = MAX<int>(drawPoint.y, 0);
int rectX2 = MIN<int>(drawPoint.x + SAGA_ISOTILE_WIDTH, map->size.x);
int rectY2 = lowBound;
debugC(3, kDebugTiles, "Rect = (%d,%d,%d,%d)", rectX, rectY, rectX2, rectY2);
//g_vm->_render->addDirtyRect(Common::Rect(rectX, rectY, rectX2, rectY2));
}
void maskTile(gPixelMap *map, int32 x, int32 y, int32 height, uint8 *srcData) {
warning("STUB: maskTile()");
}

View File

@ -42,7 +42,8 @@ private:
byte*(*_loader)(hResID, bool);
public:
HandleArray(uint16 size, byte*(*loadfunction)(hResID, bool), uint32 newID) {
_handles.resize(size);
for (int i = 0; i < size; ++i)
_handles.push_back(nullptr);
_loader = loadfunction;
_tileID = newID;
}

View File

@ -105,7 +105,7 @@ void setAreaSound(const TilePoint &baseCoords);
* ===================================================================== */
TileBankPtr tileBanks[maxBanks];
extern byte* tileImageBanks[];
extern HandleArray tileImageBanks;
void tileFault(int bank, int num);
void updateHandleRefs(const TilePoint &pt); //, StandingTileInfo *stiResult )
@ -4642,7 +4642,7 @@ void testTiles() {
sur.create(size.x, size.y, Graphics::PixelFormat::createFormatCLUT8());
sur.setPixels(img);
sur.debugPrint();
//g_system->copyRectToScreen(sur.getPixels(), sur.pitch, 0, 112, sur.w, sur.h);
g_system->copyRectToScreen(sur.getPixels(), sur.pitch, 0, 0, sur.w, sur.h);
// Draw sprites onto back buffer
//drawDisplayList();