- got rid of the global compatibility modes and made 'precise' a parameter for clipmove.

This better reflects how this stuff gets used.
This commit is contained in:
Christoph Oelckers 2022-10-23 23:23:10 +02:00
parent 5bfe62d7b6
commit 43f4962561
38 changed files with 54 additions and 79 deletions

View file

@ -10,36 +10,12 @@
#ifndef build_h_
#define build_h_
#define TRANSPARENT_INDEX 0
static_assert('\xff' == 255, "Char must be unsigned!");
/*
#include "printf.h"
#include "palette.h"
#include "c_cvars.h"
#include "cmdlib.h"
typedef int64_t coord_t;
#define POINT2(i) (wall[wall[i].point2])
#include "maptypes.h"
enum {
ENGINECOMPATIBILITY_NONE = 0,
ENGINECOMPATIBILITY_19950829, // Powerslave/Exhumed
ENGINECOMPATIBILITY_19960925, // Blood v1.21
ENGINECOMPATIBILITY_19961112, // Duke 3d v1.5, Redneck Rampage
};
inline int32_t enginecompatibility_mode;
inline int32_t ksqrt(uint64_t num)
{
return int(sqrt(double(num)));
}
*/
#endif // build_h_

View file

@ -106,7 +106,7 @@ static inline void keepaway(MoveClipper& clip, int32_t *x, int32_t *y, int32_t w
// clipmove
//
CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, int32_t yvect,
int32_t const walldist, int32_t const ceildist, int32_t const flordist, uint32_t const cliptype, int clipmoveboxtracenum)
int32_t const walldist, int32_t const ceildist, int32_t const flordist, uint32_t const cliptype, int clipmoveboxtracenum, bool precise)
{
if ((xvect|yvect) == 0 || *sectnum < 0)
return {};
@ -119,7 +119,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
//Extra walldist for sprites on sector lines
vec2_t const diff = { goal.X - (pos->X), goal.Y - (pos->Y) };
int32_t const rad = ksqrt((int64_t)diff.X * diff.X + (int64_t)diff.Y * diff.Y) + MAXCLIPDIST + walldist + 8;
int32_t const rad = (int)g_sqrt(diff.X * diff.X + diff.Y * diff.Y) + MAXCLIPDIST + walldist + 8;
vec2_t const clipMin = { cent.X - rad, cent.Y - rad };
vec2_t const clipMax = { cent.X + rad, cent.Y + rad };
@ -136,6 +136,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
clip.dest = { goal.X * inttoworld, goal.Y * inttoworld };
clip.center = (clip.pos.XY() + clip.dest) * 0.5;
clip.movedist = clip.moveDelta.Length() + clip.walldist + 0.5 + MAXCLIPDIST * inttoworld;
clip.precise = precise;
collectClipObjects(clip, (cliptype >> 16));
@ -146,7 +147,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
do
{
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE && (xvect|yvect))
if (clip.precise && (xvect|yvect))
{
for (int i=clip.clipobjects.Size() - 1; i >= 0; --i)
{
@ -192,7 +193,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
if ((tempint ^ tempint2) < 0)
{
if (enginecompatibility_mode == ENGINECOMPATIBILITY_19961112)
if (!clip.precise)
{
auto sectp = &sector[*sectnum];
updatesector(DVector2(pos->X * inttoworld, pos->Y * inttoworld), &sectp);
@ -211,7 +212,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
hitwalls[cnt] = hitwall;
}
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE)
if (clip.precise)
{
DVector2 v(vec.X* inttoworld, vec.Y* inttoworld);
sectortype* sect = &sector[*sectnum];
@ -224,7 +225,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
cnt--;
} while ((xvect|yvect) != 0 && hitwall >= 0 && cnt > 0);
if (enginecompatibility_mode != ENGINECOMPATIBILITY_NONE)
if (!clip.precise)
{
DVector3 fpos(pos->X* inttoworld, pos->Y* inttoworld, pos->Z* zinttoworld);

View file

@ -2,6 +2,7 @@
#define __RES_VOXEL_H
#include <stdint.h>
#include "vectors.h"
// [RH] Voxels from Build
enum

View file

@ -1538,7 +1538,7 @@ TAngle<T> TVector3<T>::Pitch() const
template<class T>
constexpr inline TVector2<T> clamp(const TVector2<T> &vec, const TVector2<T> &min, const TVector2<T> &max)
{
return TVector2<T>(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y));
return TVector2<T>(std::clamp<T>(vec.X, min.X, max.X), std::clamp<T>(vec.Y, min.Y, max.Y));
}
template<class T>

View file

@ -32,7 +32,6 @@
**
*/
#include "build.h"
#include "coreactor.h"
#include "gamefuncs.h"
#include "raze_sound.h"

View file

@ -4,6 +4,7 @@
#include "build.h"
#include "c_cvars.h"
#include "palentry.h"
#include "maptypes.h"
class FSerializer;
struct event_t;

View file

@ -33,7 +33,6 @@
**
*/
#include "build.h"
#include "gamestruct.h"
#include "printf.h"
#include "c_cvars.h"
@ -46,6 +45,7 @@
#include "screenjob.h"
#include "mapinfo.h"
#include "statistics.h"
#include "filesystem.h"
CVAR(Bool, sv_cheats, false, CVAR_ARCHIVE|CVAR_SERVERINFO)
CVAR(Bool, cl_blockcheats, false, 0)

View file

@ -483,14 +483,14 @@ void SetActorZ(DCoreActor* actor, const DVector3& newpos);
void SetActor(DCoreActor* actor, const DVector3& newpos);
CollisionBase clipmove_(vec3_t* const pos, int* const sectnum, int32_t xvect, int32_t yvect, int32_t const walldist, int32_t const ceildist,
int32_t const flordist, uint32_t const cliptype, int clipmoveboxtracenum = 3);
int32_t const flordist, uint32_t const cliptype, int clipmoveboxtracenum, bool precise);
inline int clipmove(DVector3& pos, sectortype** const sect, const DVector2& mvec,
double const walldist, double const ceildist, double const flordist, unsigned const cliptype, CollisionBase& result, int clipmoveboxtracenum = 3)
double const walldist, double const ceildist, double const flordist, unsigned const cliptype, CollisionBase& result, int clipmoveboxtracenum = 3, bool precise = false)
{
auto vect = vec3_t(int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint));
int sectno = *sect ? sector.IndexOf(*sect) : -1;
result = clipmove_(&vect, &sectno, FloatToFixed<18>(mvec.X), FloatToFixed<18>(mvec.Y), int(walldist * worldtoint), int(ceildist * zworldtoint), int(flordist * zworldtoint), cliptype, clipmoveboxtracenum);
result = clipmove_(&vect, &sectno, FloatToFixed<18>(mvec.X), FloatToFixed<18>(mvec.Y), int(walldist * worldtoint), int(ceildist * zworldtoint), int(flordist * zworldtoint), cliptype, clipmoveboxtracenum, precise);
pos = { vect.X * inttoworld, vect.Y * inttoworld, vect.Z * zinttoworld };
*sect = sectno == -1 ? nullptr : &sector[sectno];
return result.type;

View file

@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "c_cvars.h"
#include "gameconfigfile.h"
#include "gamecvars.h"
#include "build.h"
#include "buildtiles.h"
#include "inputstate.h"
#include "m_argv.h"
#include "rts.h"

View file

@ -11,7 +11,7 @@
#include "stats.h"
#include "i_time.h"
#include "palentry.h"
#include "build.h"
#include "dobject.h"
EXTERN_CVAR(Bool, hud_textfont)

View file

@ -29,9 +29,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "hw_voxels.h"
#include "texinfo.h"
#include "buildtiles.h"
#include "c_cvars.h"
IntRect viewport3d;
constexpr double MAXCLIPDISTF = 64;
CVAR(Int, strict_compatibility, 0, 0)
//---------------------------------------------------------------------------
//
@ -860,7 +862,7 @@ bool checkRangeOfWall(walltype* wal, EWallFlags flagmask, const DVector3& pos, d
if (BoxOnLineSide(boxtl, boxbr, pos1, pos2 - pos1) != -1) return false;
auto closest = pos.XY();
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE) // todo: need to check if it makes sense to have this always on.
if (!strict_compatibility)
SquareDistToSector(closest.X, closest.Y, nextsect, &closest);
calcSlope(nextsect, closest.X, closest.Y, &theZs[0], &theZs[1]);
@ -953,7 +955,7 @@ void getzrange(const DVector3& pos, sectortype* sect, double* ceilz, CollisionBa
const ESpriteFlags dasprclipmask = ESpriteFlags::FromInt(cliptype >> 16);
auto closest = pos.XY();
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE)
if (!strict_compatibility)
SquareDistToSector(closest.X, closest.Y, sect, &closest);
calcSlope(sect, closest, ceilz, florz);
@ -1314,7 +1316,7 @@ static void addWallToClipSet(MoveClipper& clip, walltype* wal)
#if 0
// What EDuke32 added here, this doesn't seem to make much sense
// because it leaves gaps in the path from the 5 line segments being added here
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE)
if (!strict_compatibility)
{
if (wal->delta().RotatedCCW().dot(pos - startpt - distv1) < 0)
v *= 0.5;

View file

@ -2,11 +2,14 @@
#include "gamecontrol.h"
#include "gamestruct.h"
#include "build.h"
#include "palette.h"
#include "coreactor.h"
#include "intrect.h"
#include "geometry.h"
#include "c_cvars.h"
#include "cmdlib.h"
static_assert('\xff' == 255, "Char must be unsigned!");
extern IntRect viewport3d;
@ -271,6 +274,7 @@ struct MoveClipper
double movedist;
TArray<ClipObject> clipobjects;
BFSSectorSearch search;
bool precise;
MoveClipper(sectortype* start) : search(start) {}
};

View file

@ -41,7 +41,7 @@
#include "gamecontrol.h"
#include "v_2ddrawer.h"
#include "v_video.h"
#include "build.h"
#include "buildtiles.h"
#include "v_draw.h"
#include "v_font.h"
#include "gamestruct.h"

View file

@ -78,7 +78,7 @@
#include "uiinput.h"
#include "v_video.h"
#include "palette.h"
#include "build.h"
#include "buildtiles.h"
#include "mapinfo.h"
#include "automap.h"
#include "statusbar.h"

View file

@ -34,7 +34,6 @@
*/
#include <stdint.h>
#include "build.h"
#include "files.h"
#include "automap.h"
#include "printf.h"

View file

@ -7,8 +7,6 @@
#include "tiletexture.h"
#include "buildtiles.h"
#include "build.h"
int ModelManager::LoadModel(const char* fn)
{

View file

@ -46,6 +46,7 @@
#include <zmusic.h>
#include "raze_music.h"
#include "ns.h"
#include "games/duke/src/sounds.h"
// MACROS ------------------------------------------------------------------

View file

@ -33,7 +33,7 @@
**
*/
#include "ns.h"
#include "build.h"
#include "buildtiles.h"
#include "palette.h"
#include "v_video.h"
#include "hw_material.h"

View file

@ -41,7 +41,7 @@
#include "imagehelpers.h"
#include "v_font.h"
#include "palette.h"
#include "build.h"
#include "printf.h"
#include "v_video.h"
static PaletteManager* palmanager;

View file

@ -1,6 +1,7 @@
#pragma once
#include "build.h"
#include "vectors.h"
#include "maptypes.h"
enum ESectionFlag
{

View file

@ -26,11 +26,11 @@
**
**/
#include "build.h"
#include "voxels.h"
#include "hw_voxels.h"
#include "tiletexture.h"
#include "gamecontrol.h"
#include "filesystem.h"
static int voxlumps[MAXVOXELS];
float voxscale[MAXVOXELS];

View file

@ -2,6 +2,7 @@
#include "tarray.h"
#include "basics.h"
#include "maptypes.h"
struct HWDrawInfo;
class Clipper;

View file

@ -7,7 +7,7 @@
#include "renderstyle.h"
#include "textures.h"
#include "fcolormap.h"
#include "build.h"
#include "buildtiles.h"
#include "gamefuncs.h"
#include "render.h"
#include "matrix.h"

View file

@ -35,7 +35,6 @@
*/
#include "sectorgeometry.h"
#include "build.h"
#include "buildtiles.h"
#include "gamefuncs.h"
#include "texturemanager.h"

View file

@ -2,7 +2,7 @@
#include "tarray.h"
#include "vectors.h"
#include "build.h"
#include "maptypes.h"
struct Section;

View file

@ -11,9 +11,9 @@
#include "texinfo.h"
#include "texturemanager.h"
constexpr int TRANSPARENT_INDEX = 0;
// all that's left here is the wrappers that need to go away.
inline const FTextureID spritetypebase::spritetexture() const
{
return tileGetTextureID(picnum);

View file

@ -45,6 +45,7 @@
#include "texturemanager.h"
#include "coreactor.h"
#include "thingdef.h"
#include "buildtiles.h"
//==========================================================================
//

View file

@ -2652,16 +2652,13 @@ static Collision MoveThing(DBloodActor* actor)
lhit.setNone();
GetActorExtents(actor, &top, &bottom);
const int bakCompat = enginecompatibility_mode;
if (actor->vel.X != 0 || actor->vel.Y != 0)
{
auto bakCstat = actor->spr.cstat;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
if ((actor->GetOwner()) && !cl_bloodvanillaexplosions && !VanillaMode())
enginecompatibility_mode = ENGINECOMPATIBILITY_NONE; // improved clipmove accuracy
ClipMove(actor->spr.pos, &pSector, actor->vel.XY(), actor->clipdist, (actor->spr.pos.Z - top) * 0.25, (bottom - actor->spr.pos.Z) * 0.25, CLIPMASK0, lhit);
bool precise = ((actor->GetOwner()) && !cl_bloodvanillaexplosions && !VanillaMode());
ClipMove(actor->spr.pos, &pSector, actor->vel.XY(), actor->clipdist, (actor->spr.pos.Z - top) * 0.25, (bottom - actor->spr.pos.Z) * 0.25, CLIPMASK0, lhit, 3, precise);
actor->hit.hit = lhit;
enginecompatibility_mode = bakCompat; // restore
actor->spr.cstat = bakCstat;
assert(pSector);
if (actor->sector() != pSector)
@ -3355,21 +3352,20 @@ int MoveMissile(DBloodActor* actor)
double top, bottom;
GetActorExtents(actor, &top, &bottom);
int i = 1;
const int bakCompat = enginecompatibility_mode;
const bool isFlameSprite = (actor->GetType() == kMissileFlameSpray || actor->GetType() == kMissileFlameHound); // do not use accurate clipmove for flame based sprites (changes damage too much)
while (1)
{
auto ppos = actor->spr.pos;
auto pSector2 = actor->sector();
const auto bakSpriteCstat = actor->spr.cstat;
bool precise = false;
if (Owner && !isFlameSprite && !cl_bloodvanillaexplosions && !VanillaMode())
{
enginecompatibility_mode = ENGINECOMPATIBILITY_NONE; // improved clipmove accuracy
precise = true;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL; // remove self collisions for accurate clipmove
}
Collision clipmoveresult;
ClipMove(ppos, &pSector2, vel.XY(), actor->clipdist, (ppos.Z - top) / 4, (bottom - ppos.Z) / 4, CLIPMASK0, clipmoveresult, 1);
enginecompatibility_mode = bakCompat; // restore
ClipMove(ppos, &pSector2, vel.XY(), actor->clipdist, (ppos.Z - top) / 4, (bottom - ppos.Z) / 4, CLIPMASK0, clipmoveresult, 1, precise);
actor->spr.cstat = bakSpriteCstat;
auto pSector = pSector2;
if (pSector2 == nullptr)

View file

@ -647,8 +647,6 @@ void GameInterface::app_init()
gChoke.init(518, chokeCallback);
UpdateDacs(0, true);
enginecompatibility_mode = ENGINECOMPATIBILITY_19960925;
gViewIndex = myconnectindex;
}

View file

@ -513,7 +513,7 @@ void GetZRangeAtXYZ(const DVector3& pos, sectortype* pSector, double* ceilZ, Col
//
//---------------------------------------------------------------------------
void ClipMove(DVector3& pos, sectortype** pSector, const DVector2& vect, double wd, double cd, double fd, unsigned int nMask, CollisionBase& hit, int tracecount)
void ClipMove(DVector3& pos, sectortype** pSector, const DVector2& vect, double wd, double cd, double fd, unsigned int nMask, CollisionBase& hit, int tracecount, bool precise)
{
auto opos = pos;
sectortype* bakSect = *pSector;
@ -524,7 +524,7 @@ void ClipMove(DVector3& pos, sectortype** pSector, const DVector2& vect, double
vel.X = (FloatToFixed(vect.X) >> 12) / 16.;
vel.Y = (FloatToFixed(vect.Y) >> 12) / 16.;
clipmove(pos, &bakSect, vel, wd, cd, fd, nMask, hit, tracecount);
clipmove(pos, &bakSect, vel, wd, cd, fd, nMask, hit, tracecount, precise);
if (bakSect == nullptr)
{
pos = opos;

View file

@ -39,7 +39,7 @@ int VectorScan(DBloodActor* pSprite, double nOffset, double nZOffset, const DVec
void GetZRange(DBloodActor* pSprite, double* ceilZ, Collision* ceilHit, double* floorZ, Collision* floorHit, double nDist, unsigned int nMask, unsigned int nClipParallax = 0);
void GetZRangeAtXYZ(const DVector3& pos, sectortype* pSector, double* ceilZ, Collision* ceilHit, double* floorZ, Collision* floorHit, double nDist, unsigned int nMask, unsigned int nClipParallax = 0);
void ClipMove(DVector3& pos, sectortype** pSector, const DVector2& vect, double wd, double cd, double fd, unsigned int nMask, CollisionBase& hit, int tracecount = 3);
void ClipMove(DVector3& pos, sectortype** pSector, const DVector2& vect, double wd, double cd, double fd, unsigned int nMask, CollisionBase& hit, int tracecount = 3, bool precise = false);
BitArray GetClosestSpriteSectors(sectortype* pSector, const DVector2& pos, int nDist, TArray<walltype*>* pWalls, bool newSectCheckMethod = false);
END_BLD_NS

View file

@ -1,6 +1,7 @@
#pragma once
#include "tflags.h"
#include "coreactor.h"
#include "buildtiles.h"
// all game constants got collected here.

View file

@ -458,7 +458,6 @@ void GameInterface::app_init()
}
ud.last_level = -1;
enginecompatibility_mode = ENGINECOMPATIBILITY_19961112;//bVanilla;
S_ParseDeveloperCommentary();
}

View file

@ -2369,7 +2369,7 @@ int ParseState::parse(void)
lInVarID = *(insptr++);
lOutVarID = *(insptr++);
lIn = GetGameVarID(lInVarID, g_ac, g_p).safeValue();
SetGameVarID(lOutVarID, ksqrt(lIn), g_ac, g_p);
SetGameVarID(lOutVarID, (int)g_sqrt(lIn), g_ac, g_p);
break;
}
case concmd_findnearactor:

View file

@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//-------------------------------------------------------------------------
#include "ns.h"
#include "build.h"
#include "buildtiles.h"
#include "exhumed.h"
#include "names.h"
#include "engine.h"

View file

@ -453,8 +453,6 @@ void GameInterface::app_init()
GrabPalette();
enginecompatibility_mode = ENGINECOMPATIBILITY_19961112;
myconnectindex = connecthead = 0;
numplayers = 1;
connectpoint2[0] = -1;

View file

@ -308,7 +308,6 @@ void GameInterface::app_init()
INITLIST(getPlayer(i)->PanelSpriteList);
DebugOperate = true;
enginecompatibility_mode = ENGINECOMPATIBILITY_19961112;
if (SW_SHAREWARE)
Printf("SHADOW WARRIOR(tm) Version 1.2 (Shareware Version)\n");

View file

@ -32,7 +32,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#pragma warning(disable:4101) // there's too many of these... :(
#endif
#include "build.h"
#include "buildtiles.h"
#include "d_net.h"
#include "gamefuncs.h"
#include "coreactor.h"