Browse Source

Clean up rendering

pull/1021/head
Anders Jenbo 5 years ago
parent
commit
60d3e9ceb1
  1. 2
      Source/debug.cpp
  2. 2
      Source/inv.cpp
  3. 4
      Source/items.cpp
  4. 6
      Source/missiles.cpp
  5. 4
      Source/monster.cpp
  6. 18
      Source/objects.cpp
  7. 12
      Source/player.cpp
  8. 213
      Source/scrollrt.cpp
  9. 1
      Source/town.cpp

2
Source/debug.cpp

@ -203,7 +203,7 @@ void GetDebugMonster()
if (mi2 != 0) {
mi1 = mi2 - 1;
if (mi2 <= 0)
mi1 = -1 - mi2;
mi1 = -(mi2 + 1);
} else {
mi1 = dbgmon;
}

2
Source/inv.cpp

@ -1930,7 +1930,7 @@ BOOL CanPut(int x, int y)
return FALSE;
if (dObject[x][y] != 0) {
if (object[dObject[x][y] > 0 ? dObject[x][y] - 1 : -1 - dObject[x][y]]._oSolidFlag)
if (object[dObject[x][y] > 0 ? dObject[x][y] - 1 : -(dObject[x][y] + 1)]._oSolidFlag)
return FALSE;
}

4
Source/items.cpp

@ -2485,7 +2485,7 @@ int RndItem(int m)
int ril[512];
if ((monster[m].MData->mTreasure & 0x8000) != 0)
return -1 - (monster[m].MData->mTreasure & 0xFFF);
return -((monster[m].MData->mTreasure & 0xFFF) + 1);
if (monster[m].MData->mTreasure & 0x4000)
return 0;
@ -2528,7 +2528,7 @@ int RndUItem(int m)
BOOL okflag;
if (m != -1 && (monster[m].MData->mTreasure & 0x8000) != 0 && !gbIsMultiplayer)
return -1 - (monster[m].MData->mTreasure & 0xFFF);
return -((monster[m].MData->mTreasure & 0xFFF) + 1);
int curlv = items_get_currlevel();
ri = 0;

6
Source/missiles.cpp

@ -2770,7 +2770,7 @@ void AddStone(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i
ty = dy + CrawlTable[l];
if (tx > 0 && tx < MAXDUNX && ty > 0 && ty < MAXDUNY) {
mid = dMonster[tx][ty];
mid = mid > 0 ? mid - 1 : -1 - mid;
mid = mid > 0 ? mid - 1 : -(mid + 1);
if (mid > MAX_PLRS - 1 && monster[mid]._mAi != AI_DIABLO && monster[mid].MType->mtype != MT_NAKRUL) {
if (monster[mid]._mmode != MM_FADEIN && monster[mid]._mmode != MM_FADEOUT && monster[mid]._mmode != MM_CHARGE) {
j = -99;
@ -3685,7 +3685,7 @@ void MI_Lightball(int i)
if (obj > 0) {
oi = obj - 1;
} else {
oi = -1 - obj;
oi = -(obj + 1);
}
if (object[oi]._otype == OBJ_SHRINEL || object[oi]._otype == OBJ_SHRINER)
missile[i]._mirange = j;
@ -5003,7 +5003,7 @@ void MI_Rhino(int i)
}
monster[monst]._mfutx = omx;
monster[monst]._moldx = omx;
dMonster[omx][omy] = -1 - monst;
dMonster[omx][omy] = -(monst + 1);
monster[monst]._mx = omx;
monster[monst]._mfuty = omy;
monster[monst]._moldy = omy;

4
Source/monster.cpp

@ -1595,7 +1595,7 @@ void M_ClearSquares(int i)
mx = monster[i]._moldx;
my = monster[i]._moldy;
m1 = -1 - i;
m1 = -(i + 1);
m2 = i + 1;
for (y = my - 1; y <= my + 1; y++) {
@ -4197,7 +4197,7 @@ void MAI_Rhino(int i)
if (AddMissile(Monst->_mx, Monst->_my, fx, fy, md, MIS_RHINO, Monst->_menemy, i, 0, 0) != -1) {
if (Monst->MData->snd_special)
PlayEffect(i, 3);
dMonster[Monst->_mx][Monst->_my] = -1 - i;
dMonster[Monst->_mx][Monst->_my] = -(i + 1);
Monst->_mmode = MM_CHARGE;
}
} else {

18
Source/objects.cpp

@ -1420,9 +1420,9 @@ void AddPurifyingFountain(int i)
ox = object[i]._ox;
oy = object[i]._oy;
dObject[ox][oy - 1] = -1 - i;
dObject[ox - 1][oy] = -1 - i;
dObject[ox - 1][oy - 1] = -1 - i;
dObject[ox][oy - 1] = -(i + 1);
dObject[ox - 1][oy] = -(i + 1);
dObject[ox - 1][oy - 1] = -(i + 1);
object[i]._oRndSeed = AdvanceRndSeed();
}
@ -1452,9 +1452,9 @@ void AddMurkyFountain(int i)
ox = object[i]._ox;
oy = object[i]._oy;
dObject[ox][oy - 1] = -1 - i;
dObject[ox - 1][oy] = -1 - i;
dObject[ox - 1][oy - 1] = -1 - i;
dObject[ox][oy - 1] = -(i + 1);
dObject[ox - 1][oy] = -(i + 1);
dObject[ox - 1][oy - 1] = -(i + 1);
object[i]._oRndSeed = AdvanceRndSeed();
}
@ -1565,9 +1565,9 @@ void AddMushPatch()
if (nobjects < MAXOBJECTS) {
i = objectavail[0];
GetRndObjLoc(5, &x, &y);
dObject[x + 1][y + 1] = -1 - i;
dObject[x + 2][y + 1] = -1 - i;
dObject[x + 1][y + 2] = -1 - i;
dObject[x + 1][y + 1] = -(i + 1);
dObject[x + 2][y + 1] = -(i + 1);
dObject[x + 1][y + 2] = -(i + 1);
AddObject(OBJ_MUSHPATCH, x + 2, y + 2);
}
}

12
Source/player.cpp

@ -1397,7 +1397,7 @@ void StartWalk(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int y
plr[pnum]._pVar7 = 0;
break;
case PM_WALK2:
dPlayer[plr[pnum]._px][plr[pnum]._py] = -1 - pnum;
dPlayer[plr[pnum]._px][plr[pnum]._py] = -(pnum + 1);
plr[pnum]._pVar1 = plr[pnum]._px;
plr[pnum]._pVar2 = plr[pnum]._py;
plr[pnum]._px = px; // Move player to the next tile to maintain correct render order
@ -1420,8 +1420,8 @@ void StartWalk(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int y
int x = mapx + plr[pnum]._px;
int y = mapy + plr[pnum]._py;
dPlayer[plr[pnum]._px][plr[pnum]._py] = -1 - pnum;
dPlayer[px][py] = -1 - pnum;
dPlayer[plr[pnum]._px][plr[pnum]._py] = -(pnum + 1);
dPlayer[px][py] = -(pnum + 1);
plr[pnum]._pVar4 = x;
plr[pnum]._pVar5 = y;
dFlags[x][y] |= BFLAG_PLAYERLR;
@ -3266,7 +3266,7 @@ void CheckNewPath(int pnum)
i = plr[pnum].destParam1;
x = abs(plr[pnum]._px - object[i]._ox);
y = abs(plr[pnum]._py - object[i]._oy);
if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i) {
if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -(i + 1)) {
y = abs(plr[pnum]._py - object[i]._oy + 1);
}
if (x <= 1 && y <= 1) {
@ -3282,7 +3282,7 @@ void CheckNewPath(int pnum)
i = plr[pnum].destParam1;
x = abs(plr[pnum]._px - object[i]._ox);
y = abs(plr[pnum]._py - object[i]._oy);
if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i) {
if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -(i + 1)) {
y = abs(plr[pnum]._py - object[i]._oy + 1);
}
if (x <= 1 && y <= 1) {
@ -3362,7 +3362,7 @@ void CheckNewPath(int pnum)
i = plr[pnum].destParam1;
x = abs(plr[pnum]._px - object[i]._ox);
y = abs(plr[pnum]._py - object[i]._oy);
if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i) {
if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -(i + 1)) {
y = abs(plr[pnum]._py - object[i]._oy + 1);
}
if (x <= 1 && y <= 1) {

213
Source/scrollrt.cpp

@ -243,16 +243,12 @@ void DrawMissilePrivate(MissileStruct *m, int sx, int sy, BOOL pre)
return;
pCelBuff = m->_miAnimData;
if (!pCelBuff) {
// app_fatal("Draw Missile 2 type %d: NULL Cel Buffer", m->_mitype);
return;
}
assurance(pCelBuff != NULL, m->_mitype);
nCel = m->_miAnimFrame;
frames = SDL_SwapLE32(*(DWORD *)pCelBuff);
if (nCel < 1 || frames > 50 || nCel > frames) {
// app_fatal("Draw Missile 2: frame %d of %d, missile type==%d", nCel, frames, m->_mitype);
return;
}
assurance(nCel >= 1 && frames <= 50 && nCel <= frames, nCel);
mx = sx + m->_mixoff - m->_miAnimWidth2;
my = sy + m->_miyoff;
if (m->_miUniqTrans)
@ -308,34 +304,14 @@ static void DrawMonster(int x, int y, int mx, int my, int m)
char trans;
BYTE *pCelBuff;
if ((DWORD)m >= MAXMONSTERS) {
// app_fatal("Draw Monster: tried to draw illegal monster %d", m);
return;
}
assurance(m >= 0 && m < MAXMONSTERS, m);
pCelBuff = monster[m]._mAnimData;
if (!pCelBuff) {
// app_fatal("Draw Monster \"%s\": NULL Cel Buffer", monster[m].mName);
return;
}
assurance(pCelBuff != NULL, m);
nCel = monster[m]._mAnimFrame;
frames = SDL_SwapLE32(*(DWORD *)pCelBuff);
if (nCel < 1 || frames > 50 || nCel > frames) {
/*
const char *szMode = "unknown action";
if(monster[m]._mmode <= 17)
szMode = szMonModeAssert[monster[m]._mmode];
app_fatal(
"Draw Monster \"%s\" %s: facing %d, frame %d of %d",
monster[m].mName,
szMode,
monster[m]._mdir,
nCel,
frames);
*/
return;
}
assurance(nCel >= 1 && frames <= 50 && nCel <= frames, nCel);
if (!(dFlags[x][y] & BFLAG_LIT)) {
Cl2DrawLightTbl(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, 1);
@ -354,6 +330,36 @@ static void DrawMonster(int x, int y, int mx, int my, int m)
}
}
/**
* @brief Helper for rendering player a Mana Shild
* @param pnum Player id
* @param sx Back buffer coordinate
* @param sy Back buffer coordinate
* @param lighting Should lighting be applied
*/
static void DrawManaShild(int pnum, int x, int y, bool lighting)
{
if (!plr[pnum].pManaShield)
return;
x += plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0];
int width = misfiledata[MFILE_MANASHLD].mAnimWidth[0];
BYTE *pCelBuff = misfiledata[MFILE_MANASHLD].mAnimData[0];
if (pnum == myplr) {
Cl2Draw(x, y, pCelBuff, 1, width);
return;
}
if (lighting) {
Cl2DrawLightTbl(x, y, pCelBuff, 1, width, 1);
return;
}
Cl2DrawLight(x, y, pCelBuff, 1, width);
}
/**
* @brief Render a player sprite
* @param pnum Player id
@ -369,66 +375,40 @@ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, i
{
int l, frames;
if (dFlags[x][y] & BFLAG_LIT || plr[myplr]._pInfraFlag || !setlevel && currlevel == 0) {
if (!pCelBuff) {
// app_fatal("Drawing player %d \"%s\": NULL Cel Buffer", pnum, plr[pnum]._pName);
return;
}
frames = SDL_SwapLE32(*(DWORD *)pCelBuff);
if (nCel < 1 || frames > 50 || nCel > frames) {
/*
const char *szMode = "unknown action";
if(plr[pnum]._pmode <= PM_QUIT)
szMode = szPlrModeAssert[plr[pnum]._pmode];
app_fatal(
"Drawing player %d \"%s\" %s: facing %d, frame %d of %d",
pnum,
plr[pnum]._pName,
szMode,
plr[pnum]._pdir,
nCel,
frames);
*/
return;
}
if (pnum == pcursplr)
Cl2DrawOutline(165, px, py, pCelBuff, nCel, nWidth);
if (pnum == myplr) {
Cl2Draw(px, py, pCelBuff, nCel, nWidth);
if (plr[pnum].pManaShield)
Cl2Draw(
px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0],
py,
misfiledata[MFILE_MANASHLD].mAnimData[0],
1,
misfiledata[MFILE_MANASHLD].mAnimWidth[0]);
} else if (!(dFlags[x][y] & BFLAG_LIT) || plr[myplr]._pInfraFlag && light_table_index > 8) {
Cl2DrawLightTbl(px, py, pCelBuff, nCel, nWidth, 1);
if (plr[pnum].pManaShield)
Cl2DrawLightTbl(
px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0],
py,
misfiledata[MFILE_MANASHLD].mAnimData[0],
1,
misfiledata[MFILE_MANASHLD].mAnimWidth[0],
1);
} else {
l = light_table_index;
if (light_table_index < 5)
light_table_index = 0;
else
light_table_index -= 5;
Cl2DrawLight(px, py, pCelBuff, nCel, nWidth);
if (plr[pnum].pManaShield)
Cl2DrawLight(
px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0],
py,
misfiledata[MFILE_MANASHLD].mAnimData[0],
1,
misfiledata[MFILE_MANASHLD].mAnimWidth[0]);
light_table_index = l;
}
if ((dFlags[x][y] & BFLAG_LIT) == 0 && !plr[myplr]._pInfraFlag && leveltype != DTYPE_TOWN) {
return;
}
assurance(pCelBuff != NULL, pnum);
frames = SDL_SwapLE32(*(DWORD *)pCelBuff);
assurance(nCel >= 1 && frames <= 50 && nCel <= frames, nCel);
if (pnum == pcursplr)
Cl2DrawOutline(165, px, py, pCelBuff, nCel, nWidth);
if (pnum == myplr) {
Cl2Draw(px, py, pCelBuff, nCel, nWidth);
DrawManaShild(pnum, px, py, true);
return;
}
if (!(dFlags[x][y] & BFLAG_LIT) || plr[myplr]._pInfraFlag && light_table_index > 8) {
Cl2DrawLightTbl(px, py, pCelBuff, nCel, nWidth, 1);
DrawManaShild(pnum, px, py, true);
return;
}
l = light_table_index;
if (light_table_index < 5)
light_table_index = 0;
else
light_table_index -= 5;
Cl2DrawLight(px, py, pCelBuff, nCel, nWidth);
DrawManaShild(pnum, px, py, false);
light_table_index = l;
}
/**
@ -492,17 +472,11 @@ static void DrawObject(int x, int y, int ox, int oy, BOOL pre)
assert((unsigned char)bv < MAXOBJECTS);
pCelBuff = object[bv]._oAnimData;
if (!pCelBuff) {
// app_fatal("Draw Object type %d: NULL Cel Buffer", object[bv]._otype);
return;
}
assurance(pCelBuff != NULL, object[bv]._otype);
nCel = object[bv]._oAnimFrame;
frames = SDL_SwapLE32(*(DWORD *)pCelBuff);
if (nCel < 1 || frames > 50 || nCel > (int)frames) {
// app_fatal("Draw Object: frame %d of %d, object type==%d", nCel, frames, object[bv]._otype);
return;
}
assurance(nCel >= 1 && frames <= 50 && nCel <= frames, nCel);
if (bv == pcursobj)
CelBlitOutline(194, sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth);
@ -599,16 +573,12 @@ static void DrawItem(int x, int y, int sx, int sy, BOOL pre)
return;
pCelBuff = pItem->_iAnimData;
if (pCelBuff == NULL) {
// app_fatal("Draw Item \"%s\" 1: NULL Cel Buffer", pItem->_iIName);
return;
}
pFrameTable = (DWORD *)pCelBuff;
assurance(pCelBuff != NULL, bItem);
nCel = pItem->_iAnimFrame;
if (nCel < 1 || pFrameTable[0] > 50 || nCel > (int)pFrameTable[0]) {
// app_fatal("Draw \"%s\" Item 1: frame %d of %d, item type==%d", pItem->_iIName, nCel, pFrameTable[0], pItem->_itype);
return;
}
pFrameTable = (DWORD *)pCelBuff;
assurance(nCel >= 1 && pFrameTable[0] <= 50 && nCel <= pFrameTable[0], nCel);
int px = sx - pItem->_iAnimWidth2;
if (bItem - 1 == pcursitem || AutoMapShowItems) {
CelBlitOutline(181, px, sy, pCelBuff, nCel, pItem->_iAnimWidth);
@ -645,20 +615,14 @@ static void DrawMonsterHelper(int x, int y, int oy, int sx, int sy)
if (!(dFlags[x][y] & BFLAG_LIT) && !plr[myplr]._pInfraFlag)
return;
if ((DWORD)mi >= MAXMONSTERS) {
// app_fatal("Draw Monster: tried to draw illegal monster %d", mi);
return;
}
assurance(mi >= 0 && mi < MAXMONSTERS, mi);
pMonster = &monster[mi];
if (pMonster->_mFlags & MFLAG_HIDDEN) {
return;
}
if (pMonster->MType == NULL) {
// app_fatal("Draw Monster \"%s\": uninitialized monster", pMonster->mName);
return;
}
assurance(pMonster->MType != NULL, mi);
px = sx + pMonster->_mxoff - pMonster->MType->width2;
py = sy + pMonster->_myoff;
@ -672,25 +636,21 @@ static void DrawMonsterHelper(int x, int y, int oy, int sx, int sy)
* @brief Check if and how a player should be rendered
* @param y dPiece coordinate
* @param x dPiece coordinate
* @param oy dPiece Y offset
* @param sx Back buffer coordinate
* @param sy Back buffer coordinate
*/
static void DrawPlayerHelper(int x, int y, int oy, int sx, int sy)
static void DrawPlayerHelper(int x, int y, int sx, int sy)
{
int p = dPlayer[x][y + oy];
int p = dPlayer[x][y];
p = p > 0 ? p - 1 : -(p + 1);
if ((DWORD)p >= MAX_PLRS) {
// app_fatal("draw player: tried to draw illegal player %d", p);
return;
}
assurance(p >= 0 && p < MAX_PLRS, p);
PlayerStruct *pPlayer = &plr[p];
int px = sx + pPlayer->_pxoff - pPlayer->_pAnimWidth2;
int py = sy + pPlayer->_pyoff;
DrawPlayer(p, x, y + oy, px, py, pPlayer->_pAnimData, pPlayer->_pAnimFrame, pPlayer->_pAnimWidth);
DrawPlayer(p, x, y, px, py, pPlayer->_pAnimData, pPlayer->_pAnimFrame, pPlayer->_pAnimWidth);
}
/**
@ -747,8 +707,7 @@ static void scrollrt_draw_dungeon(int sx, int sy, int dx, int dy)
pFrameTable = (DWORD *)pCelBuff;
nCel = pDeadGuy->_deadFrame;
if (nCel < 1 || pFrameTable[0] > 50 || nCel > (int)pFrameTable[0]) {
// app_fatal("Unclipped dead: frame %d of %d, deadnum==%d", nCel, pFrameTable[0], (bDead & 0x1F) - 1);
break;
app_fatal("Unclipped dead: frame %d of %d, deadnum==%d", nCel, pFrameTable[0], (bDead & 0x1F) - 1);
}
if (pDeadGuy->_deadtrans != 0) {
Cl2DrawLightTbl(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, pDeadGuy->_deadtrans);
@ -761,7 +720,7 @@ static void scrollrt_draw_dungeon(int sx, int sy, int dx, int dy)
DrawItem(sx, sy, dx, dy, 1);
if (bFlag & BFLAG_PLAYERLR) {
assert((DWORD)(sy - 1) < MAXDUNY);
DrawPlayerHelper(sx, sy, -1, dx, dy);
DrawPlayerHelper(sx, sy - 1, dx, dy);
}
if (bFlag & BFLAG_MONSTLR && negMon < 0) {
DrawMonsterHelper(sx, sy, -1, dx, dy);
@ -770,7 +729,7 @@ static void scrollrt_draw_dungeon(int sx, int sy, int dx, int dy)
DrawDeadPlayer(sx, sy, dx, dy);
}
if (dPlayer[sx][sy] > 0) {
DrawPlayerHelper(sx, sy, 0, dx, dy);
DrawPlayerHelper(sx, sy, dx, dy);
}
if (dMonster[sx][sy] > 0) {
DrawMonsterHelper(sx, sy, 0, dx, dy);

1
Source/town.cpp

@ -339,6 +339,7 @@ void CreateTown(int entry)
}
T_Pass3();
memset(dFlags, 0, sizeof(dFlags));
memset(dLight, 0, sizeof(dLight));
memset(dFlags, 0, sizeof(dFlags));
memset(dPlayer, 0, sizeof(dPlayer));

Loading…
Cancel
Save