2021-02-16 10:36:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "binaryangle.h"
|
2021-03-22 22:40:25 +00:00
|
|
|
#include "build.h"
|
2021-02-16 10:36:08 +00:00
|
|
|
|
2021-11-15 22:34:40 +00:00
|
|
|
// breadth first search, this gets used multiple times throughout the engine, mainly for iterating over sectors.
|
|
|
|
// Only works on indices, this has no knowledge of the actual objects being looked at.
|
|
|
|
// All objects of this type operate on the same shared store. Interleaved use is not allowed, nested use is fine.
|
|
|
|
class BFSSearch
|
|
|
|
{
|
|
|
|
static inline TArray<unsigned> store;
|
|
|
|
|
|
|
|
unsigned bitpos;
|
|
|
|
unsigned startpos;
|
|
|
|
unsigned curpos;
|
|
|
|
|
|
|
|
public:
|
2021-11-15 23:19:34 +00:00
|
|
|
enum { EOL = ~0u };
|
2021-11-15 22:34:40 +00:00
|
|
|
BFSSearch(unsigned datasize, unsigned startnode)
|
|
|
|
{
|
|
|
|
bitpos = store.Size();
|
|
|
|
unsigned bitsize = (datasize + 31) >> 5;
|
|
|
|
store.Reserve(bitsize);
|
|
|
|
memset(&store[bitpos], 0, bitsize*4);
|
|
|
|
|
|
|
|
startpos = store.Size();
|
|
|
|
curpos = startpos;
|
2021-11-16 22:37:31 +00:00
|
|
|
Set(startnode);
|
2021-11-15 22:34:40 +00:00
|
|
|
store.Push(startnode);
|
|
|
|
}
|
2021-11-18 00:15:18 +00:00
|
|
|
|
|
|
|
// This allows this object to just work as a bit array
|
|
|
|
// which is useful for using its shared storage.
|
|
|
|
BFSSearch(unsigned datasize)
|
|
|
|
{
|
|
|
|
bitpos = store.Size();
|
|
|
|
unsigned bitsize = (datasize + 31) >> 5;
|
|
|
|
store.Reserve(bitsize);
|
|
|
|
memset(&store[bitpos], 0, bitsize * 4);
|
|
|
|
}
|
2021-11-15 22:34:40 +00:00
|
|
|
|
|
|
|
~BFSSearch()
|
|
|
|
{
|
|
|
|
store.Clamp(bitpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Check(unsigned index) const
|
|
|
|
{
|
|
|
|
return !!(store[bitpos + (index >> 5)] & (1 << (index & 31)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(unsigned index)
|
|
|
|
{
|
|
|
|
store[bitpos + (index >> 5)] |= (1 << (index & 31));
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:15:18 +00:00
|
|
|
|
|
|
|
private:
|
2021-11-15 22:34:40 +00:00
|
|
|
public:
|
|
|
|
unsigned GetNext()
|
|
|
|
{
|
|
|
|
curpos++;
|
|
|
|
if (curpos <= store.Size())
|
|
|
|
return store[curpos-1];
|
|
|
|
else
|
|
|
|
return ~0;
|
|
|
|
}
|
2021-11-16 21:51:55 +00:00
|
|
|
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
curpos = startpos;
|
|
|
|
}
|
2021-11-15 22:34:40 +00:00
|
|
|
|
|
|
|
void Add(unsigned elem)
|
|
|
|
{
|
|
|
|
if (!Check(elem))
|
|
|
|
{
|
|
|
|
Set(elem);
|
|
|
|
store.Push(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-21 07:42:36 +00:00
|
|
|
class BFSSectorSearch : public BFSSearch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-12-21 09:51:41 +00:00
|
|
|
BFSSectorSearch(const sectortype* startnode) : BFSSearch(sector.Size(), sector.IndexOf(startnode))
|
2021-11-21 07:42:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-12-03 23:47:08 +00:00
|
|
|
bool Check(const sectortype* index) const
|
2021-11-21 07:42:36 +00:00
|
|
|
{
|
|
|
|
return BFSSearch::Check(sector.IndexOf(index));
|
|
|
|
}
|
|
|
|
|
2021-12-03 23:47:08 +00:00
|
|
|
void Set(const sectortype* index)
|
2021-11-21 07:42:36 +00:00
|
|
|
{
|
|
|
|
BFSSearch::Set(sector.IndexOf(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
sectortype* GetNext()
|
|
|
|
{
|
|
|
|
unsigned ret = BFSSearch::GetNext();
|
|
|
|
return ret == EOL? nullptr : §or[ret];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(sectortype* elem)
|
|
|
|
{
|
|
|
|
BFSSearch::Add(sector.IndexOf(elem));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-16 10:36:08 +00:00
|
|
|
extern int cameradist, cameraclock;
|
|
|
|
|
2021-06-09 06:38:40 +00:00
|
|
|
void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false);
|
2021-04-20 22:46:32 +00:00
|
|
|
|
2021-11-22 23:28:07 +00:00
|
|
|
bool calcChaseCamPos(int* px, int* py, int* pz, spritetype* pspr, sectortype** psectnum, binangle ang, fixedhoriz horiz, double const smoothratio);
|
2021-11-06 18:27:51 +00:00
|
|
|
|
2021-12-17 22:33:16 +00:00
|
|
|
void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz);
|
|
|
|
|
|
|
|
int getslopeval(sectortype* sect, int x, int y, int z, int planez);
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-19 19:40:44 +00:00
|
|
|
void setWallSectors();
|
2021-12-04 18:08:50 +00:00
|
|
|
void GetWallSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
|
|
|
void GetFlatSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
2021-03-26 19:28:44 +00:00
|
|
|
void GetFlatSpritePosition(const spritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
2021-03-20 22:01:16 +00:00
|
|
|
void checkRotatedWalls();
|
2021-12-06 17:17:45 +00:00
|
|
|
bool sectorsConnected(int sect1, int sect2);
|
2021-03-18 20:50:02 +00:00
|
|
|
|
2021-03-18 11:49:33 +00:00
|
|
|
// y is negated so that the orientation is the same as in GZDoom, in order to use its utilities.
|
|
|
|
// The render code should NOT use Build coordinates for anything!
|
|
|
|
|
2021-12-11 22:00:38 +00:00
|
|
|
inline double RenderX(int x)
|
|
|
|
{
|
|
|
|
return x * (1 / 16.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double RenderY(int y)
|
|
|
|
{
|
|
|
|
return y * (1 / -16.);
|
|
|
|
}
|
|
|
|
|
2021-03-18 11:49:33 +00:00
|
|
|
inline double WallStartX(int wallnum)
|
|
|
|
{
|
|
|
|
return wall[wallnum].x * (1 / 16.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double WallStartY(int wallnum)
|
|
|
|
{
|
|
|
|
return wall[wallnum].y * (1 / -16.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double WallEndX(int wallnum)
|
|
|
|
{
|
2021-12-01 23:54:11 +00:00
|
|
|
return wall[wallnum].point2Wall()->x * (1 / 16.);
|
2021-03-18 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline double WallEndY(int wallnum)
|
|
|
|
{
|
2021-12-01 23:54:11 +00:00
|
|
|
return wall[wallnum].point2Wall()->y * (1 / -16.);
|
2021-03-18 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline double WallStartX(const walltype* wallnum)
|
|
|
|
{
|
|
|
|
return wallnum->x * (1 / 16.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double WallStartY(const walltype* wallnum)
|
|
|
|
{
|
|
|
|
return wallnum->y * (1 / -16.);
|
|
|
|
}
|
|
|
|
|
2021-03-21 17:41:23 +00:00
|
|
|
inline DVector2 WallStart(const walltype* wallnum)
|
|
|
|
{
|
|
|
|
return { WallStartX(wallnum), WallStartY(wallnum) };
|
|
|
|
}
|
|
|
|
|
2021-03-18 11:49:33 +00:00
|
|
|
inline double WallEndX(const walltype* wallnum)
|
|
|
|
{
|
2021-12-01 23:54:11 +00:00
|
|
|
return wallnum->point2Wall()->x * (1 / 16.);
|
2021-03-18 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline double WallEndY(const walltype* wallnum)
|
|
|
|
{
|
2021-12-01 23:54:11 +00:00
|
|
|
return wallnum->point2Wall()->y * (1 / -16.);
|
2021-03-18 11:49:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-21 17:41:23 +00:00
|
|
|
inline DVector2 WallEnd(const walltype* wallnum)
|
|
|
|
{
|
|
|
|
return { WallEndX(wallnum), WallEndY(wallnum) };
|
|
|
|
}
|
|
|
|
|
|
|
|
inline DVector2 WallDelta(const walltype* wallnum)
|
|
|
|
{
|
|
|
|
return WallEnd(wallnum) - WallStart(wallnum);
|
|
|
|
}
|
|
|
|
|
2021-06-13 07:32:30 +00:00
|
|
|
inline double SpriteX(spritetype* spr)
|
|
|
|
{
|
|
|
|
return spr->x * (1 / 16.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double SpriteY(spritetype* spr)
|
|
|
|
{
|
|
|
|
return spr->y * (1 / -16.);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline DVector2 SpritePos(spritetype* spr)
|
|
|
|
{
|
|
|
|
return { SpriteX(spr), SpriteY(spr) };
|
|
|
|
}
|
|
|
|
|
2021-03-18 11:49:33 +00:00
|
|
|
inline double PointOnLineSide(double x, double y, double linex, double liney, double deltax, double deltay)
|
|
|
|
{
|
|
|
|
return (x - linex) * deltay - (y - liney) * deltax;
|
|
|
|
}
|
|
|
|
|
2021-03-21 17:41:23 +00:00
|
|
|
inline double PointOnLineSide(const DVector2 &pos, const walltype *line)
|
|
|
|
{
|
|
|
|
return (pos.X - WallStartX(line)) * WallDelta(line).Y - (pos.Y - WallStartY(line)) * WallDelta(line).X;
|
|
|
|
}
|
|
|
|
|
2021-04-19 22:28:52 +00:00
|
|
|
template<class T>
|
|
|
|
inline double PointOnLineSide(const TVector2<T>& pos, const TVector2<T>& linestart, const TVector2<T>& lineend)
|
|
|
|
{
|
|
|
|
return (pos.X - linestart.X) * (lineend.Y - linestart.Y) - (pos.Y - linestart.Y) * (lineend.X - linestart.X);
|
|
|
|
}
|
|
|
|
|
2021-03-25 08:13:16 +00:00
|
|
|
extern int numshades;
|
|
|
|
|
|
|
|
// Return type is int because this gets passed to variadic functions where structs may produce undefined behavior.
|
|
|
|
inline int shadeToLight(int shade)
|
|
|
|
{
|
|
|
|
shade = clamp(shade, 0, numshades - 1);
|
|
|
|
int light = Scale(numshades - 1 - shade, 255, numshades - 1);
|
|
|
|
return PalEntry(255, light, light, light);
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:33:21 +00:00
|
|
|
inline void copyfloorpal(spritetype* spr, const sectortype* sect)
|
|
|
|
{
|
|
|
|
if (!lookups.noFloorPal(sect->floorpal)) spr->pal = sect->floorpal;
|
|
|
|
}
|
2021-06-02 19:00:39 +00:00
|
|
|
|
2021-12-04 18:08:50 +00:00
|
|
|
inline void copyfloorpal(tspritetype* spr, const sectortype* sect)
|
|
|
|
{
|
|
|
|
if (!lookups.noFloorPal(sect->floorpal)) spr->pal = sect->floorpal;
|
|
|
|
}
|
|
|
|
|
2021-10-13 17:11:34 +00:00
|
|
|
inline void spriteSetSlope(spritetype* spr, int heinum)
|
2021-06-02 19:00:39 +00:00
|
|
|
{
|
|
|
|
if (spr->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)
|
|
|
|
{
|
|
|
|
spr->xoffset = heinum & 255;
|
|
|
|
spr->yoffset = (heinum >> 8) & 255;
|
|
|
|
spr->cstat = (spr->cstat & ~CSTAT_SPRITE_ALIGNMENT_MASK) | (heinum != 0 ? CSTAT_SPRITE_ALIGNMENT_SLOPE : CSTAT_SPRITE_ALIGNMENT_FLOOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 19:27:12 +00:00
|
|
|
inline int spriteGetSlope(const spritetype* spr)
|
2021-06-02 19:00:39 +00:00
|
|
|
{
|
|
|
|
return ((spr->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLOPE) ? 0 : uint8_t(spr->xoffset) + (uint8_t(spr->yoffset) << 8);
|
|
|
|
}
|
2021-08-01 13:02:13 +00:00
|
|
|
|
|
|
|
inline int I_GetBuildTime()
|
|
|
|
{
|
|
|
|
return I_GetTime(120);
|
|
|
|
}
|
2021-11-07 15:46:23 +00:00
|
|
|
|
|
|
|
inline int32_t getangle(walltype* wal)
|
|
|
|
{
|
|
|
|
return getangle(
|
2021-11-26 19:55:13 +00:00
|
|
|
wal->point2Wall()->x - wal->x,
|
|
|
|
wal->point2Wall()->y - wal->y);
|
2021-11-07 15:46:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 15:07:56 +00:00
|
|
|
inline TArrayView<walltype> wallsofsector(const sectortype* sec)
|
2021-11-07 16:27:05 +00:00
|
|
|
{
|
|
|
|
return TArrayView<walltype>(sec->firstWall(), sec->wallnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TArrayView<walltype> wallsofsector(int sec)
|
|
|
|
{
|
|
|
|
return wallsofsector(§or[sec]);
|
|
|
|
}
|
2021-11-16 16:45:41 +00:00
|
|
|
|
|
|
|
// these are mainly meant as refactoring aids to mark function calls to work on.
|
2021-11-11 19:20:00 +00:00
|
|
|
inline int wallnum(const walltype* wal)
|
2021-11-16 16:45:41 +00:00
|
|
|
{
|
2021-11-20 22:42:01 +00:00
|
|
|
return wall.IndexOf(wal);
|
2021-11-16 16:45:41 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 19:20:00 +00:00
|
|
|
inline int sectnum(const sectortype* sect)
|
2021-11-16 16:45:41 +00:00
|
|
|
{
|
2021-11-20 22:20:43 +00:00
|
|
|
return sector.IndexOf(sect);
|
2021-11-16 16:45:41 +00:00
|
|
|
}
|
2021-11-16 19:20:25 +00:00
|
|
|
|
2021-11-16 20:36:46 +00:00
|
|
|
inline double SquareDist(double lx1, double ly1, double lx2, double ly2)
|
|
|
|
{
|
|
|
|
double dx = lx2 - lx1;
|
|
|
|
double dy = ly2 - ly1;
|
|
|
|
return dx * dx + dy * dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double SquareDistToWall(double px, double py, const walltype* wal)
|
|
|
|
{
|
|
|
|
double lx1 = wal->x;
|
|
|
|
double ly1 = wal->y;
|
|
|
|
double lx2 = wal->point2Wall()->x;
|
|
|
|
double ly2 = wal->point2Wall()->y;
|
|
|
|
|
|
|
|
double wall_length = SquareDist(lx1, ly1, lx2, ly2);
|
|
|
|
|
|
|
|
if (wall_length == 0) return SquareDist(px, py, lx1, ly1);
|
|
|
|
|
|
|
|
double t = ((px - lx1) * (lx2 - lx1) + (py - ly1) * (ly2 - ly1)) / wall_length;
|
|
|
|
t = clamp(t, 0., 1.);
|
|
|
|
return SquareDist(px, py, lx1 + t * (lx2 - lx1), ly1 + t * (ly2 - ly1));
|
|
|
|
}
|
|
|
|
|
2021-11-18 18:57:14 +00:00
|
|
|
inline void dragpoint(walltype* pointhighlight, int32_t dax, int32_t day)
|
|
|
|
{
|
|
|
|
dragpoint(wallnum(pointhighlight), dax, day);
|
|
|
|
}
|
|
|
|
|
2021-12-17 22:33:16 +00:00
|
|
|
inline void alignceilslope(sectortype* sect, int x, int y, int z)
|
2021-11-21 08:05:58 +00:00
|
|
|
{
|
2021-12-17 22:33:16 +00:00
|
|
|
sect->setceilingslope(getslopeval(sect, x, y, z, sect->ceilingz));
|
2021-11-21 08:05:58 +00:00
|
|
|
}
|
2021-12-17 22:33:16 +00:00
|
|
|
|
|
|
|
inline void alignflorslope(sectortype* sect, int x, int y, int z)
|
2021-11-21 08:05:58 +00:00
|
|
|
{
|
2021-12-17 22:33:16 +00:00
|
|
|
sect->setfloorslope(getslopeval(sect, x, y, z, sect->floorz));
|
2021-11-21 08:05:58 +00:00
|
|
|
}
|
|
|
|
inline void updatesectorneighbor(int32_t const x, int32_t const y, sectortype* * const sect, int32_t maxDistance = MAXUPDATESECTORDIST)
|
|
|
|
{
|
|
|
|
int sectno = *sect? sector.IndexOf(*sect) : -1;
|
|
|
|
updatesectorneighbor(x, y, §no, maxDistance);
|
|
|
|
*sect = sectno < 0? nullptr : §or[sectno];
|
|
|
|
}
|