2022-01-22 13:37:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gamecontrol.h"
|
2022-09-28 03:37:30 +00:00
|
|
|
#include "gamestruct.h"
|
2022-01-22 13:37:17 +00:00
|
|
|
#include "build.h"
|
|
|
|
#include "coreactor.h"
|
2022-08-04 21:47:01 +00:00
|
|
|
#include "intrect.h"
|
2022-09-26 09:27:48 +00:00
|
|
|
#include "geometry.h"
|
2022-09-30 17:06:44 +00:00
|
|
|
#include "c_cvars.h"
|
2022-08-04 21:47:01 +00:00
|
|
|
|
|
|
|
extern IntRect viewport3d;
|
2022-01-22 13:37:17 +00:00
|
|
|
|
2022-09-30 17:06:44 +00:00
|
|
|
EXTERN_CVAR(Bool, hw_hightile)
|
|
|
|
EXTERN_CVAR(Bool, hw_models)
|
|
|
|
EXTERN_CVAR(Float, gl_texture_filter_anisotropic)
|
|
|
|
EXTERN_CVAR(Int, gl_texture_filter)
|
|
|
|
extern bool hw_int_useindexedcolortextures;
|
|
|
|
EXTERN_CVAR(Bool, hw_useindexedcolortextures)
|
|
|
|
EXTERN_CVAR(Bool, r_voxels)
|
|
|
|
|
2022-09-30 17:40:37 +00:00
|
|
|
inline int leveltimer;
|
|
|
|
inline int Numsprites;
|
|
|
|
inline int display_mirror;
|
|
|
|
inline int randomseed;
|
|
|
|
inline int g_visibility = 512, g_relvisibility = 0;
|
2022-09-30 17:06:44 +00:00
|
|
|
|
2022-09-24 11:11:17 +00:00
|
|
|
constexpr int SLOPEVAL_FACTOR = 4096;
|
|
|
|
|
2022-09-30 17:40:37 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CLIPMASK0 = (1 << 16) + 1,
|
|
|
|
CLIPMASK1 = (256 << 16) + 64
|
|
|
|
};
|
|
|
|
|
2022-09-26 09:27:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2022-01-22 13:37:17 +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.
|
2022-09-26 09:27:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2022-01-22 13:37:17 +00:00
|
|
|
class BFSSearch
|
|
|
|
{
|
|
|
|
static inline TArray<unsigned> store;
|
|
|
|
|
|
|
|
unsigned bitpos;
|
|
|
|
unsigned startpos;
|
|
|
|
unsigned curpos;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum { EOL = ~0u };
|
|
|
|
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;
|
|
|
|
Set(startnode);
|
|
|
|
store.Push(startnode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
~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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
unsigned GetNext()
|
|
|
|
{
|
|
|
|
curpos++;
|
|
|
|
if (curpos <= store.Size())
|
|
|
|
return store[curpos-1];
|
|
|
|
else
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
curpos = startpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(unsigned elem)
|
|
|
|
{
|
|
|
|
if (!Check(elem))
|
|
|
|
{
|
|
|
|
Set(elem);
|
|
|
|
store.Push(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BFSSectorSearch : public BFSSearch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
BFSSectorSearch(const sectortype* startnode) : BFSSearch(sector.Size(), sector.IndexOf(startnode))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Check(const sectortype* index) const
|
|
|
|
{
|
|
|
|
return BFSSearch::Check(sector.IndexOf(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(const sectortype* index)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// scans all vertices equivalent with a given spot and performs some work on them.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
template<class func>
|
|
|
|
void vertexscan(walltype* startwall, func mark)
|
|
|
|
{
|
|
|
|
BFSSearch walbitmap(wall.Size());
|
|
|
|
|
|
|
|
// first pass: scan the the next-in-loop of the partner
|
|
|
|
auto wal = startwall;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
mark(wal);
|
|
|
|
walbitmap.Set(wall.IndexOf(wal));
|
|
|
|
if (wal->nextwall < 0) break;
|
|
|
|
wal = wal->nextWall()->point2Wall();
|
|
|
|
} while (!walbitmap.Check(wall.IndexOf(wal)));
|
|
|
|
|
|
|
|
// second pass: scan the partner of the previous-in-loop.
|
|
|
|
wal = startwall;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
auto thelastwall = wal->lastWall();
|
2022-02-15 21:47:53 +00:00
|
|
|
// thelastwall can be null here if the map is bogus.
|
|
|
|
if (!thelastwall || thelastwall->nextwall < 0) break;
|
2022-01-22 13:37:17 +00:00
|
|
|
wal = thelastwall->nextWall();
|
|
|
|
if (walbitmap.Check(wall.IndexOf(wal))) break;
|
|
|
|
mark(wal);
|
|
|
|
walbitmap.Set(wall.IndexOf(wal));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-30 04:22:38 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
inline void dragpoint(walltype* startwall, const DVector2& pos)
|
|
|
|
{
|
|
|
|
vertexscan(startwall, [&](walltype* wal)
|
|
|
|
{
|
|
|
|
wal->move(pos);
|
|
|
|
wal->sectorp()->exflags |= SECTOREX_DRAGGED;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-28 02:42:57 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Constants used for Build sine/cosine functions.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BAMBITS = 21,
|
|
|
|
BAMUNIT = 1 << BAMBITS,
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr double BAngRadian = pi::pi() * (1. / 1024.);
|
|
|
|
constexpr double BAngToDegree = 360. / 2048.;
|
2022-08-28 04:41:05 +00:00
|
|
|
constexpr DAngle DAngleBuildToDeg = DAngle::fromDeg(BAngToDegree);
|
2022-08-28 02:42:57 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Build sine inline functions.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-10-04 16:49:04 +00:00
|
|
|
inline int bsin(const int ang)
|
2022-09-25 10:26:37 +00:00
|
|
|
{
|
2022-10-04 16:49:04 +00:00
|
|
|
return int(g_sinbam(ang * BAMUNIT) * 16384);
|
2022-09-25 10:26:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 02:42:57 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Build cosine inline functions.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-10-04 16:49:04 +00:00
|
|
|
inline int bcos(const int ang)
|
2022-09-25 10:26:37 +00:00
|
|
|
{
|
2022-10-04 16:49:04 +00:00
|
|
|
return int(g_cosbam(ang * BAMUNIT) * 16384);
|
2022-09-25 10:26:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 03:42:46 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-09-27 21:30:57 +00:00
|
|
|
//
|
2022-08-28 03:42:46 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-09-06 11:06:35 +00:00
|
|
|
extern double cameradist, cameraclock;
|
2022-01-22 13:37:17 +00:00
|
|
|
|
|
|
|
void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false);
|
|
|
|
|
2022-09-30 04:28:16 +00:00
|
|
|
bool calcChaseCamPos(DVector3& ppos, DCoreActor* pspr, sectortype** psectnum, DAngle ang, DAngle horiz, double const interpfrac, double const backamp);
|
2022-09-24 11:11:17 +00:00
|
|
|
int getslopeval(sectortype* sect, const DVector3& pos, double bazez);
|
2022-09-24 18:30:00 +00:00
|
|
|
bool cansee(const DVector3& start, sectortype* sect1, const DVector3& end, sectortype* sect2);
|
2022-09-26 06:33:23 +00:00
|
|
|
double intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
|
|
|
|
double intersectWallSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor, bool checktex = false);
|
|
|
|
double intersectFloorSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
|
|
|
|
double intersectSlopeSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
|
2022-09-26 13:04:20 +00:00
|
|
|
double checkWallHit(walltype* wal, EWallFlags flagmask, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
|
|
|
|
double checkSectorPlaneHit(sectortype* sec, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
|
2022-09-25 08:57:46 +00:00
|
|
|
void neartag(const DVector3& start, sectortype* sect, DAngle angle, HitInfoBase& result, double neartagrange, int tagsearch);
|
2022-09-26 06:33:23 +00:00
|
|
|
int testpointinquad(const DVector2& pt, const DVector2* quad);
|
2022-09-27 14:36:19 +00:00
|
|
|
int hitscan(const DVector3& start, const sectortype* startsect, const DVector3& vect, HitInfoBase& hitinfo, unsigned cliptype, double maxrange = -1);
|
2022-09-24 18:30:00 +00:00
|
|
|
|
2022-09-29 14:39:24 +00:00
|
|
|
bool checkRangeOfWall(walltype* wal, EWallFlags flagmask, const DVector3& pos, double maxdist, double* theZs);
|
|
|
|
bool checkRangeOfFaceSprite(DCoreActor* itActor, const DVector3& pos, double maxdist, double* theZs);
|
|
|
|
bool checkRangeOfWallSprite(DCoreActor* itActor, const DVector3& pos, double maxdist, double* theZs);
|
|
|
|
bool checkRangeOfFloorSprite(DCoreActor* itActor, const DVector3& pos, double maxdist, double& theZ);
|
|
|
|
void getzrange(const DVector3& pos, sectortype* sect, double* ceilz, CollisionBase& ceilhit, double* florz, CollisionBase& florhit, double walldist, uint32_t cliptype);
|
|
|
|
|
2022-01-22 13:37:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setWallSectors();
|
2022-08-17 20:06:39 +00:00
|
|
|
void GetWallSpritePosition(const spritetypebase* spr, const DVector2& pos, DVector2* out, bool render = false);
|
2022-09-06 18:19:55 +00:00
|
|
|
void GetFlatSpritePosition(DCoreActor* spr, const DVector2& pos, DVector2* out, double* outz = nullptr, bool render = false);
|
2022-08-17 18:40:11 +00:00
|
|
|
void GetFlatSpritePosition(const tspritetype* spr, const DVector2& pos, DVector2* out, double* outz, bool render = false);
|
2022-08-17 21:24:44 +00:00
|
|
|
|
|
|
|
enum class EClose
|
|
|
|
{
|
|
|
|
Outside,
|
|
|
|
InFront,
|
|
|
|
Behind
|
|
|
|
};
|
|
|
|
EClose IsCloseToLine(const DVector2& vect, const DVector2& start, const DVector2& end, double walldist);
|
|
|
|
EClose IsCloseToWall(const DVector2& vect, walltype* wal, double walldist);
|
|
|
|
|
2022-01-22 13:37:17 +00:00
|
|
|
void checkRotatedWalls();
|
|
|
|
bool sectorsConnected(int sect1, int sect2);
|
2022-01-29 08:29:01 +00:00
|
|
|
int32_t inside(double x, double y, const sectortype* sect);
|
2022-09-06 18:19:55 +00:00
|
|
|
int insidePoly(double x, double y, const DVector2* points, int count);
|
2022-09-17 19:18:04 +00:00
|
|
|
|
2022-09-25 08:57:46 +00:00
|
|
|
enum {
|
|
|
|
NT_Lotag = 1,
|
|
|
|
NT_Hitag = 2,
|
|
|
|
NT_NoSpriteCheck = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-09-17 19:18:04 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2022-09-26 09:27:48 +00:00
|
|
|
// slope getter stuff (many wrappers, one worker only)
|
2022-09-17 19:18:04 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void calcSlope(const sectortype* sec, double xpos, double ypos, double* pceilz, double* pflorz);
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// for the renderer
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
inline void PlanesAtPoint(const sectortype* sec, float dax, float day, float* pceilz, float* pflorz)
|
|
|
|
{
|
|
|
|
double f, c;
|
|
|
|
calcSlope(sec, dax, day, &c, &f);
|
|
|
|
if (pceilz) *pceilz = -float(c);
|
|
|
|
if (pflorz) *pflorz = -float(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// only used by clipmove et.al.
|
2022-09-27 19:21:20 +00:00
|
|
|
void getcorrectzsofslope(int sectnum, int dax, int day, double* ceilz, double* florz);
|
2022-09-17 19:18:04 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2022-09-26 09:27:48 +00:00
|
|
|
// for the game engine
|
2022-09-17 19:18:04 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
inline void getzsofslopeptr(const sectortype* sec, double dax, double day, double* ceilz, double* florz)
|
|
|
|
{
|
|
|
|
calcSlope(sec, dax, day, ceilz, florz);
|
|
|
|
}
|
|
|
|
|
2022-08-23 20:43:06 +00:00
|
|
|
template<class Vector>
|
|
|
|
inline void getzsofslopeptr(const sectortype* sec, const Vector& pos, double* ceilz, double* florz)
|
2022-08-23 20:24:01 +00:00
|
|
|
{
|
2022-09-17 19:18:04 +00:00
|
|
|
calcSlope(sec, pos.X, pos.Y, ceilz, florz);
|
2022-08-23 20:24:01 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 11:59:57 +00:00
|
|
|
inline double getceilzofslopeptr(const sectortype* sec, double dax, double day)
|
2022-02-03 23:37:59 +00:00
|
|
|
{
|
2022-09-17 19:18:04 +00:00
|
|
|
double c;
|
|
|
|
calcSlope(sec, dax, day, &c, nullptr);
|
|
|
|
return c;
|
2022-02-03 23:37:59 +00:00
|
|
|
}
|
2022-09-27 11:59:57 +00:00
|
|
|
inline double getflorzofslopeptr(const sectortype* sec, double dax, double day)
|
2022-02-03 23:37:59 +00:00
|
|
|
{
|
2022-09-17 19:18:04 +00:00
|
|
|
double f;
|
|
|
|
calcSlope(sec, dax, day, nullptr, &f);
|
|
|
|
return f;
|
2022-02-03 23:37:59 +00:00
|
|
|
}
|
2022-09-17 19:18:04 +00:00
|
|
|
template<class Vector>
|
2022-09-27 11:59:57 +00:00
|
|
|
inline double getceilzofslopeptr(const sectortype* sec, const Vector& pos)
|
2022-08-23 20:52:22 +00:00
|
|
|
{
|
2022-09-27 11:59:57 +00:00
|
|
|
return getceilzofslopeptr(sec, pos.X, pos.Y);
|
2022-08-23 20:52:22 +00:00
|
|
|
}
|
2022-09-17 19:18:04 +00:00
|
|
|
template<class Vector>
|
2022-09-27 11:59:57 +00:00
|
|
|
inline double getflorzofslopeptr(const sectortype* sec, const Vector& pos)
|
2022-08-23 20:24:01 +00:00
|
|
|
{
|
2022-09-27 11:59:57 +00:00
|
|
|
return getflorzofslopeptr(sec, pos.X, pos.Y);
|
2022-08-23 20:24:01 +00:00
|
|
|
}
|
2022-02-03 23:37:59 +00:00
|
|
|
|
2022-09-17 19:18:04 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2022-09-26 09:27:48 +00:00
|
|
|
// slope setters
|
2022-09-17 19:18:04 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2022-09-26 09:27:48 +00:00
|
|
|
inline void alignceilslope(sectortype* sect, const DVector3& pos)
|
|
|
|
{
|
|
|
|
sect->setceilingslope(getslopeval(sect, pos, sect->ceilingz));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void alignflorslope(sectortype* sect, const DVector3& pos)
|
|
|
|
{
|
|
|
|
sect->setfloorslope(getslopeval(sect, pos, sect->floorz));
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// slope sprites
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2022-09-17 19:18:04 +00:00
|
|
|
|
2022-09-26 09:27:48 +00:00
|
|
|
inline void spriteSetSlope(DCoreActor* actor, int heinum)
|
2022-09-05 12:10:23 +00:00
|
|
|
{
|
2022-09-26 09:27:48 +00:00
|
|
|
if (actor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)
|
|
|
|
{
|
|
|
|
actor->spr.xoffset = heinum & 255;
|
|
|
|
actor->spr.yoffset = (heinum >> 8) & 255;
|
|
|
|
actor->spr.cstat = (actor->spr.cstat & ~CSTAT_SPRITE_ALIGNMENT_MASK) | (heinum != 0 ? CSTAT_SPRITE_ALIGNMENT_SLOPE : CSTAT_SPRITE_ALIGNMENT_FLOOR);
|
|
|
|
}
|
2022-09-05 12:10:23 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 09:27:48 +00:00
|
|
|
inline int spriteGetSlope(DCoreActor* actor)
|
|
|
|
{
|
2022-09-30 02:12:37 +00:00
|
|
|
return ((actor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLOPE) ? 0 : uint8_t(actor->spr.xoffset) + (int8_t(actor->spr.yoffset) << 8);
|
2022-09-26 09:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// same stuff, different flag...
|
|
|
|
inline int tspriteGetSlope(const tspritetype* spr)
|
|
|
|
{
|
|
|
|
return !(spr->clipdist & TSPR_SLOPESPRITE) ? 0 : uint8_t(spr->xoffset) + (int8_t(spr->yoffset) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double spriteGetZOfSlopef(const spritetypebase* tspr, const DVector2& pos, int heinum)
|
|
|
|
{
|
|
|
|
if (heinum == 0) return tspr->pos.Z;
|
2022-09-30 02:11:12 +00:00
|
|
|
return tspr->pos.Z + heinum * -tspr->angle.ToVector().dot(pos - tspr->pos.XY()) * (1. / SLOPEVAL_FACTOR);
|
2022-09-26 09:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// end of slopes
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2022-02-03 23:37:59 +00:00
|
|
|
|
2022-08-05 16:43:48 +00:00
|
|
|
enum EFindNextSector
|
|
|
|
{
|
|
|
|
Find_Floor = 0,
|
|
|
|
Find_Ceiling = 1,
|
|
|
|
|
|
|
|
Find_Down = 0,
|
|
|
|
Find_Up = 2,
|
|
|
|
|
|
|
|
Find_Safe = 4,
|
|
|
|
|
|
|
|
Find_CeilingUp = Find_Ceiling | Find_Up,
|
|
|
|
Find_CeilingDown = Find_Ceiling | Find_Down,
|
|
|
|
Find_FloorUp = Find_Floor | Find_Up,
|
|
|
|
Find_FloorDown = Find_Floor | Find_Down,
|
|
|
|
};
|
2022-09-03 15:27:41 +00:00
|
|
|
sectortype* nextsectorneighborzptr(sectortype* sectp, double startz, int flags);
|
2022-09-13 17:40:32 +00:00
|
|
|
bool isAwayFromWall(DCoreActor* ac, double delta);
|
2022-08-05 16:43:48 +00:00
|
|
|
|
2022-01-22 13:37:17 +00:00
|
|
|
|
2022-09-26 09:27:48 +00:00
|
|
|
// important note: This returns positive for 'in front' with renderer coordinates.
|
|
|
|
// Due to Build's inverted coordinate system it will return negative for 'in front' there.
|
2022-01-22 13:37:17 +00:00
|
|
|
inline double PointOnLineSide(const DVector2 &pos, const walltype *line)
|
|
|
|
{
|
2022-09-16 17:37:22 +00:00
|
|
|
return (pos.X - line->pos.X) * line->delta().Y - (pos.Y - line->pos.Y) * line->delta().X;
|
2022-01-22 13:37:17 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void copyfloorpal(tspritetype* spr, const sectortype* sect)
|
|
|
|
{
|
|
|
|
if (!lookups.noFloorPal(sect->floorpal)) spr->pal = sect->floorpal;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int I_GetBuildTime()
|
|
|
|
{
|
|
|
|
return I_GetTime(120);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TArrayView<walltype> wallsofsector(const sectortype* sec)
|
|
|
|
{
|
|
|
|
return TArrayView<walltype>(sec->firstWall(), sec->wallnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TArrayView<walltype> wallsofsector(int sec)
|
|
|
|
{
|
|
|
|
return wallsofsector(§or[sec]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// these are mainly meant as refactoring aids to mark function calls to work on.
|
|
|
|
inline int wallnum(const walltype* wal)
|
|
|
|
{
|
|
|
|
return wall.IndexOf(wal);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int sectnum(const sectortype* sect)
|
|
|
|
{
|
|
|
|
return sector.IndexOf(sect);
|
|
|
|
}
|
|
|
|
|
2022-09-24 20:53:45 +00:00
|
|
|
inline DVector2 NearestPointOnWall(double px, double py, const walltype* wal, bool clamp = true)
|
|
|
|
{
|
|
|
|
return NearestPointOnLine(px, py, wal->pos.X, wal->pos.Y, wal->point2Wall()->pos.X, wal->point2Wall()->pos.Y, clamp);
|
|
|
|
}
|
|
|
|
|
2022-08-04 21:47:29 +00:00
|
|
|
inline double SquareDistToWall(double px, double py, const walltype* wal, DVector2* point = nullptr)
|
|
|
|
{
|
|
|
|
auto pt = NearestPointOnWall(px, py, wal);
|
|
|
|
if (point) *point = pt;
|
|
|
|
return SquareDist(px, py, pt.X, pt.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
double SquareDistToSector(double px, double py, const sectortype* sect, DVector2* point = nullptr);
|
|
|
|
|
2022-09-24 15:03:03 +00:00
|
|
|
inline double GetRayIntersect(const DVector3& start1, const DVector3& vect1, const DVector2& start2, const DVector2& vect2, DVector3& retv)
|
|
|
|
{
|
|
|
|
double factor2;
|
|
|
|
double factor = InterceptLineSegments(start1.X, start1.Y, vect1.X, vect1.Y, start2.X, start2.Y, vect2.X, vect2.Y, &factor2);
|
|
|
|
if (factor <= 0) return -1;
|
|
|
|
retv = start1 + factor * vect1;
|
|
|
|
return factor2;
|
|
|
|
}
|
2022-09-24 12:44:21 +00:00
|
|
|
|
2022-09-03 22:04:01 +00:00
|
|
|
inline double BobVal(int val)
|
|
|
|
{
|
|
|
|
return g_sinbam((unsigned)val << 21);
|
|
|
|
}
|
|
|
|
|
2022-09-13 16:30:23 +00:00
|
|
|
inline double BobVal(double val)
|
|
|
|
{
|
2022-10-22 02:33:14 +00:00
|
|
|
return g_sinbam(xs_CRoundToUInt(val * (1 << 21)));
|
2022-09-13 16:30:23 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 03:39:01 +00:00
|
|
|
inline DAngle GetMinPitch()
|
2022-09-28 03:37:30 +00:00
|
|
|
{
|
2022-10-11 06:46:56 +00:00
|
|
|
return !cl_clampedpitch ? DAngle90 : gi->playerPitchMin();
|
2022-09-28 03:37:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 03:39:01 +00:00
|
|
|
inline DAngle GetMaxPitch()
|
2022-09-28 03:37:30 +00:00
|
|
|
{
|
2022-10-11 06:46:56 +00:00
|
|
|
return !cl_clampedpitch ? -DAngle90 : gi->playerPitchMax();
|
2022-09-28 03:37:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 03:39:01 +00:00
|
|
|
inline DAngle ClampViewPitch(const DAngle pitch)
|
2022-09-28 03:37:30 +00:00
|
|
|
{
|
2022-10-11 06:46:56 +00:00
|
|
|
return clamp(pitch, GetMaxPitch(), GetMinPitch());
|
2022-09-28 03:37:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-24 16:30:57 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// old deprecated integer versions
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
[[deprecated]]
|
2022-09-27 11:59:57 +00:00
|
|
|
inline int int_getceilzofslopeptr(const sectortype* sec, int dax, int day)
|
2022-09-24 16:30:57 +00:00
|
|
|
{
|
|
|
|
double z;
|
|
|
|
calcSlope(sec, dax * inttoworld, day * inttoworld, &z, nullptr);
|
|
|
|
return int(z * zworldtoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[deprecated]]
|
2022-09-27 11:59:57 +00:00
|
|
|
inline int int_getflorzofslopeptr(const sectortype* sec, int dax, int day)
|
2022-09-24 16:30:57 +00:00
|
|
|
{
|
|
|
|
double z;
|
|
|
|
calcSlope(sec, dax * inttoworld, day * inttoworld, nullptr, &z);
|
|
|
|
return int(z * zworldtoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[deprecated]]
|
2022-09-27 11:59:57 +00:00
|
|
|
inline void int_getzsofslopeptr(const sectortype* sec, int dax, int day, int* ceilz, int* florz)
|
2022-09-24 16:30:57 +00:00
|
|
|
{
|
|
|
|
double c, f;
|
|
|
|
calcSlope(sec, dax * inttoworld, day * inttoworld, &c, &f);
|
|
|
|
*ceilz = int(c * zworldtoint);
|
|
|
|
*florz = int(f * zworldtoint);
|
|
|
|
}
|
|
|
|
|
2022-09-24 15:03:03 +00:00
|
|
|
[[deprecated]]
|
|
|
|
inline int rintersect(int x1, int y1, int z1, int vx, int vy, int vz, int x3, int y3, int x4, int y4, int* intx, int* inty, int* intz)
|
|
|
|
{
|
|
|
|
DVector3 retv;
|
|
|
|
double result = GetRayIntersect(DVector3(x1 * inttoworld, y1 * inttoworld, z1 * zinttoworld), DVector3(vx * inttoworld, vy * inttoworld, vz * zinttoworld),
|
|
|
|
DVector2(x3 * inttoworld, y3 * inttoworld), DVector2((x4 - x3) * inttoworld, (y4 - y3) * inttoworld), retv);
|
|
|
|
if (result < 0) return -1;
|
|
|
|
*intx = retv.X * worldtoint;
|
|
|
|
*inty = retv.Y * worldtoint;
|
|
|
|
*intz = retv.Z * zworldtoint;
|
|
|
|
return FloatToFixed(result);
|
|
|
|
}
|
|
|
|
|
2022-09-24 18:30:00 +00:00
|
|
|
[[deprecated]]
|
|
|
|
inline int cansee(int x1, int y1, int z1, sectortype* sect1, int x2, int y2, int z2, sectortype* sect2)
|
|
|
|
{
|
|
|
|
return cansee(DVector3(x1 * inttoworld, y1 * inttoworld, z1 * zinttoworld), sect1, DVector3(x2 * inttoworld, y2 * inttoworld, z2 * zinttoworld), sect2);
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:27:48 +00:00
|
|
|
[[deprecated]]
|
|
|
|
inline int inside(int x, int y, const sectortype* sect)
|
|
|
|
{
|
|
|
|
return inside(x * inttoworld, y * inttoworld, sect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// still needed by some parts in the engine.
|
|
|
|
[[deprecated]]
|
|
|
|
inline int inside_p(int x, int y, int sectnum) { return (sectnum >= 0 && inside(x * inttoworld, y * inttoworld, §or[sectnum]) == 1); }
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-09-24 17:00:06 +00:00
|
|
|
|
2022-09-24 15:03:03 +00:00
|
|
|
|
2022-08-04 21:48:07 +00:00
|
|
|
#include "updatesector.h"
|