2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-09-21 18:59:54 +00:00
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "pragmas.h"
|
|
|
|
|
|
|
|
#include "blood.h"
|
2020-11-26 16:19:42 +00:00
|
|
|
#include "interpolate.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
char flicker1[] = {
|
|
|
|
0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0,
|
|
|
|
1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,
|
|
|
|
0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 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
|
};
|
|
|
|
|
|
|
|
char strobe[] = {
|
|
|
|
64, 64, 64, 48, 36, 27, 20, 15, 11, 9, 6, 5, 4, 3, 2, 2,
|
|
|
|
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
int GetWaveValue(int a, int b, int c)
|
|
|
|
{
|
|
|
|
b &= 2047;
|
|
|
|
switch (a)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return c;
|
|
|
|
case 1:
|
|
|
|
return (b>>10)*c;
|
|
|
|
case 2:
|
|
|
|
return (klabs(128-(b>>3))*c)>>7;
|
|
|
|
case 3:
|
|
|
|
return ((b>>3)*c)>>8;
|
|
|
|
case 4:
|
|
|
|
return ((255-(b>>3))*c)>>8;
|
|
|
|
case 5:
|
|
|
|
return (c+mulscale30(c,Sin(b)))>>1;
|
|
|
|
case 6:
|
|
|
|
return flicker1[b>>5]*c;
|
|
|
|
case 7:
|
|
|
|
return (flicker2[b>>5]*c)>>2;
|
|
|
|
case 8:
|
|
|
|
return (flicker3[b>>5]*c)>>2;
|
|
|
|
case 9:
|
|
|
|
return (flicker4[b>>4]*c)>>2;
|
|
|
|
case 10:
|
|
|
|
return (strobe[b>>5]*c)>>6;
|
|
|
|
case 11:
|
|
|
|
if (b*4 > 2048)
|
|
|
|
return 0;
|
|
|
|
return (c-mulscale30(c, Cos(b*4)))>>1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-21 11:02:17 +00:00
|
|
|
int shadeCount = 0;
|
|
|
|
short shadeList[kMaxXSectors];
|
|
|
|
int panCount = 0;
|
|
|
|
short panList[kMaxXSectors];
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
void DoSectorLighting(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < shadeCount; i++)
|
|
|
|
{
|
|
|
|
int nXSector = shadeList[i];
|
|
|
|
XSECTOR *pXSector = &xsector[nXSector];
|
|
|
|
int nSector = pXSector->reference;
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(sector[nSector].extra == nXSector);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSector->shade)
|
|
|
|
{
|
|
|
|
int v4 = pXSector->shade;
|
|
|
|
if (pXSector->shadeFloor)
|
|
|
|
{
|
|
|
|
sector[nSector].floorshade -= v4;
|
|
|
|
if (pXSector->color)
|
|
|
|
{
|
|
|
|
int nTemp = pXSector->floorpal;
|
|
|
|
pXSector->floorpal = sector[nSector].floorpal;
|
|
|
|
sector[nSector].floorpal = nTemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pXSector->shadeCeiling)
|
|
|
|
{
|
|
|
|
sector[nSector].ceilingshade -= v4;
|
|
|
|
if (pXSector->color)
|
|
|
|
{
|
|
|
|
int nTemp = pXSector->ceilpal;
|
|
|
|
pXSector->ceilpal = sector[nSector].ceilingpal;
|
|
|
|
sector[nSector].ceilingpal = nTemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pXSector->shadeWalls)
|
|
|
|
{
|
|
|
|
int nStartWall = sector[nSector].wallptr;
|
|
|
|
int nEndWall = nStartWall + sector[nSector].wallnum;
|
|
|
|
for (int j = nStartWall; j < nEndWall; j++)
|
|
|
|
{
|
|
|
|
wall[j].shade -= v4;
|
|
|
|
if (pXSector->color)
|
|
|
|
{
|
|
|
|
wall[j].pal = sector[nSector].floorpal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pXSector->shade = 0;
|
|
|
|
}
|
|
|
|
if (pXSector->shadeAlways || pXSector->busy)
|
|
|
|
{
|
|
|
|
int t1 = pXSector->wave;
|
|
|
|
int t2 = pXSector->amplitude;
|
|
|
|
if (!pXSector->shadeAlways && pXSector->busy)
|
|
|
|
{
|
|
|
|
t2 = mulscale16(t2, pXSector->busy);
|
|
|
|
}
|
2020-09-01 18:12:02 +00:00
|
|
|
int v4 = GetWaveValue(t1, pXSector->phase*8+pXSector->freq*gFrameClock, t2);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSector->shadeFloor)
|
|
|
|
{
|
|
|
|
sector[nSector].floorshade = ClipRange(sector[nSector].floorshade+v4, -128, 127);
|
|
|
|
if (pXSector->color && v4 != 0)
|
|
|
|
{
|
|
|
|
int nTemp = pXSector->floorpal;
|
|
|
|
pXSector->floorpal = sector[nSector].floorpal;
|
|
|
|
sector[nSector].floorpal = nTemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pXSector->shadeCeiling)
|
|
|
|
{
|
|
|
|
sector[nSector].ceilingshade = ClipRange(sector[nSector].ceilingshade+v4, -128, 127);
|
|
|
|
if (pXSector->color && v4 != 0)
|
|
|
|
{
|
|
|
|
int nTemp = pXSector->ceilpal;
|
|
|
|
pXSector->ceilpal = sector[nSector].ceilingpal;
|
|
|
|
sector[nSector].ceilingpal = nTemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pXSector->shadeWalls)
|
|
|
|
{
|
|
|
|
int nStartWall = sector[nSector].wallptr;
|
|
|
|
int nEndWall = nStartWall + sector[nSector].wallnum;
|
|
|
|
for (int j = nStartWall; j < nEndWall; j++)
|
|
|
|
{
|
|
|
|
wall[j].shade = ClipRange(wall[j].shade+v4, -128, 127);
|
|
|
|
if (pXSector->color && v4 != 0)
|
|
|
|
{
|
|
|
|
wall[j].pal = sector[nSector].floorpal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pXSector->shade = v4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoSectorLighting(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numsectors; i++)
|
|
|
|
{
|
|
|
|
int nXSprite = sector[i].extra;
|
|
|
|
if (nXSprite > 0)
|
|
|
|
{
|
|
|
|
XSECTOR *pXSector = &xsector[i];
|
|
|
|
if (pXSector->shade)
|
|
|
|
{
|
|
|
|
int v4 = pXSector->shade;
|
|
|
|
if (pXSector->shadeFloor)
|
|
|
|
{
|
|
|
|
sector[i].floorshade -= v4;
|
|
|
|
if (pXSector->color)
|
|
|
|
{
|
|
|
|
int nTemp = pXSector->floorpal;
|
|
|
|
pXSector->floorpal = sector[i].floorpal;
|
|
|
|
sector[i].floorpal = nTemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pXSector->shadeCeiling)
|
|
|
|
{
|
|
|
|
sector[i].ceilingshade -= v4;
|
|
|
|
if (pXSector->color)
|
|
|
|
{
|
|
|
|
int nTemp = pXSector->ceilpal;
|
|
|
|
pXSector->ceilpal = sector[i].ceilingpal;
|
|
|
|
sector[i].ceilingpal = nTemp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pXSector->shadeWalls)
|
|
|
|
{
|
|
|
|
int nStartWall = sector[i].wallptr;
|
|
|
|
int nEndWall = nStartWall + sector[i].wallnum;
|
|
|
|
for (int j = nStartWall; j < nEndWall; j++)
|
|
|
|
{
|
|
|
|
wall[j].shade -= v4;
|
|
|
|
if (pXSector->color)
|
|
|
|
{
|
|
|
|
wall[j].pal = sector[i].floorpal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pXSector->shade = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
short wallPanList[kMaxXWalls];
|
|
|
|
int wallPanCount;
|
|
|
|
|
|
|
|
void DoSectorPanning(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < panCount; i++)
|
|
|
|
{
|
|
|
|
int nXSector = panList[i];
|
|
|
|
XSECTOR *pXSector = &xsector[nXSector];
|
|
|
|
int nSector = pXSector->reference;
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(nSector >= 0 && nSector < kMaxSectors);
|
2019-09-19 22:42:45 +00:00
|
|
|
sectortype *pSector = §or[nSector];
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSector->extra == nXSector);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSector->panAlways || pXSector->busy)
|
|
|
|
{
|
|
|
|
int angle = pXSector->panAngle+1024;
|
|
|
|
int speed = pXSector->panVel<<10;
|
|
|
|
if (!pXSector->panAlways && (pXSector->busy&0xffff))
|
|
|
|
speed = mulscale16(speed, pXSector->busy);
|
|
|
|
|
|
|
|
if (pXSector->panFloor) // Floor
|
|
|
|
{
|
|
|
|
int nTile = pSector->floorpicnum;
|
2020-11-09 19:50:27 +00:00
|
|
|
if (pSector->floorstat & 64)
|
2019-09-19 22:42:45 +00:00
|
|
|
angle -= 512;
|
2020-11-09 19:50:27 +00:00
|
|
|
int xBits = tileWidth(nTile) >> int((pSector->floorstat & 8) != 0);
|
2020-11-25 19:52:06 +00:00
|
|
|
int px = mulscale30(speed << 2, Cos(angle)) / xBits;
|
2020-11-09 19:50:27 +00:00
|
|
|
int yBits = tileHeight(nTile) >> int((pSector->floorstat & 8) != 0);
|
2020-11-25 19:52:06 +00:00
|
|
|
int py = mulscale30(speed << 2, Sin(angle)) / yBits;
|
|
|
|
pSector->addfloorxpan(px * (1. / 256));
|
|
|
|
pSector->addfloorypan(-py * (1. / 256));
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
if (pXSector->panCeiling) // Ceiling
|
|
|
|
{
|
|
|
|
int nTile = pSector->ceilingpicnum;
|
2020-11-09 19:50:27 +00:00
|
|
|
if (pSector->ceilingstat & 64)
|
2019-09-19 22:42:45 +00:00
|
|
|
angle -= 512;
|
2020-11-25 19:52:06 +00:00
|
|
|
int xBits = tileWidth(nTile) >> int((pSector->ceilingstat & 8) != 0);
|
|
|
|
int px = mulscale30(speed << 2, Cos(angle)) / xBits;
|
|
|
|
int yBits = tileHeight(nTile) >> int((pSector->ceilingstat & 8) != 0);
|
|
|
|
int py = mulscale30(speed << 2, Sin(angle)) / yBits;
|
|
|
|
pSector->addceilingxpan(px * (1. / 256));
|
|
|
|
pSector->addceilingypan(-py * (1. / 256));
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < wallPanCount; i++)
|
|
|
|
{
|
|
|
|
int nXWall = wallPanList[i];
|
|
|
|
XWALL *pXWall = &xwall[nXWall];
|
|
|
|
int nWall = pXWall->reference;
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(wall[nWall].extra == nXWall);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXWall->panAlways || pXWall->busy)
|
|
|
|
{
|
|
|
|
int psx = pXWall->panXVel<<10;
|
|
|
|
int psy = pXWall->panYVel<<10;
|
|
|
|
if (!pXWall->panAlways && (pXWall->busy & 0xffff))
|
|
|
|
{
|
|
|
|
psx = mulscale16(psx, pXWall->busy);
|
|
|
|
psy = mulscale16(psy, pXWall->busy);
|
|
|
|
}
|
|
|
|
int nTile = wall[nWall].picnum;
|
2020-11-26 07:38:59 +00:00
|
|
|
int px = (psx << 2) / tileWidth(nTile);
|
|
|
|
int py = (psy << 2) / tileHeight(nTile);
|
|
|
|
|
|
|
|
wall[nWall].addxpan(px * (1. / 256));
|
|
|
|
wall[nWall].addypan(py * (1. / 256));
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitSectorFX(void)
|
|
|
|
{
|
|
|
|
shadeCount = 0;
|
|
|
|
panCount = 0;
|
|
|
|
wallPanCount = 0;
|
|
|
|
for (int i = 0; i < numsectors; i++)
|
|
|
|
{
|
|
|
|
int nXSector = sector[i].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
{
|
|
|
|
XSECTOR *pXSector = &xsector[nXSector];
|
|
|
|
if (pXSector->amplitude)
|
|
|
|
shadeList[shadeCount++] = nXSector;
|
|
|
|
if (pXSector->panVel)
|
2020-11-26 16:19:42 +00:00
|
|
|
{
|
2019-09-19 22:42:45 +00:00
|
|
|
panList[panCount++] = nXSector;
|
2020-11-26 16:19:42 +00:00
|
|
|
|
|
|
|
if (pXSector->panCeiling)
|
|
|
|
{
|
|
|
|
StartInterpolation(i, Interp_Sect_CeilingPanX);
|
|
|
|
StartInterpolation(i, Interp_Sect_CeilingPanY);
|
|
|
|
}
|
|
|
|
if (pXSector->panFloor)
|
|
|
|
{
|
|
|
|
StartInterpolation(i, Interp_Sect_FloorPanX);
|
|
|
|
StartInterpolation(i, Interp_Sect_FloorPanY);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < numwalls; i++)
|
|
|
|
{
|
|
|
|
int nXWall = wall[i].extra;
|
|
|
|
if (nXWall > 0)
|
|
|
|
{
|
|
|
|
XWALL *pXWall = &xwall[nXWall];
|
|
|
|
if (pXWall->panXVel || pXWall->panYVel)
|
2020-11-26 16:19:42 +00:00
|
|
|
{
|
2019-09-19 22:42:45 +00:00
|
|
|
wallPanList[wallPanCount++] = nXWall;
|
2020-11-26 16:19:42 +00:00
|
|
|
if (pXWall->panXVel) StartInterpolation(i, Interp_Wall_PanX);
|
|
|
|
if (pXWall->panXVel) StartInterpolation(i, Interp_Wall_PanY);
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CSectorListMgr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSectorListMgr();
|
|
|
|
int CreateList(short);
|
|
|
|
void AddSector(int, short);
|
|
|
|
int GetSectorCount(int);
|
|
|
|
short *GetSectorList(int);
|
|
|
|
private:
|
|
|
|
int nLists;
|
|
|
|
int nListSize[32];
|
|
|
|
int nListStart[32];
|
|
|
|
short nSectors[kMaxSectors];
|
|
|
|
};
|
|
|
|
|
|
|
|
CSectorListMgr::CSectorListMgr()
|
|
|
|
{
|
|
|
|
nLists = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSectorListMgr::CreateList(short nSector)
|
|
|
|
{
|
|
|
|
int nStart = 0;
|
|
|
|
if (nLists)
|
|
|
|
nStart = nListStart[nLists-1]+nListStart[nLists-1];
|
|
|
|
int nList = nLists;
|
|
|
|
nListStart[nList] = nStart;
|
|
|
|
nListSize[nList] = 1;
|
|
|
|
nLists++;
|
|
|
|
short *pList = GetSectorList(nList);
|
|
|
|
pList[0] = nSector;
|
|
|
|
return nList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSectorListMgr::AddSector(int nList, short nSector)
|
|
|
|
{
|
|
|
|
for (int i = nLists; i > nList; i--)
|
|
|
|
{
|
|
|
|
short *pList = GetSectorList(i);
|
|
|
|
int nCount = GetSectorCount(i);
|
|
|
|
memmove(pList+1,pList,nCount*sizeof(short));
|
|
|
|
nListStart[i]++;
|
|
|
|
}
|
|
|
|
short *pList = GetSectorList(nList);
|
|
|
|
int nCount = GetSectorCount(nList);
|
|
|
|
pList[nCount] = nSector;
|
|
|
|
nListSize[nList]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSectorListMgr::GetSectorCount(int nList)
|
|
|
|
{
|
|
|
|
return nListSize[nList];
|
|
|
|
}
|
|
|
|
|
|
|
|
short * CSectorListMgr::GetSectorList(int nList)
|
|
|
|
{
|
|
|
|
return nSectors+nListStart[nList];
|
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|