Skip to content

Commit

Permalink
- got rid of the global compatibility modes and made 'precise' a para…
Browse files Browse the repository at this point in the history
…meter for clipmove.

This better reflects how this stuff gets used.
  • Loading branch information
coelckers committed Nov 12, 2023
1 parent 5bfe62d commit 43f4962
Show file tree
Hide file tree
Showing 38 changed files with 54 additions and 79 deletions.
28 changes: 2 additions & 26 deletions source/build/include/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
13 changes: 7 additions & 6 deletions source/build/src/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand All @@ -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 };

Expand All @@ -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));

Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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];
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions source/common/models/voxels.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __RES_VOXEL_H

#include <stdint.h>
#include "vectors.h"
// [RH] Voxels from Build

enum
Expand Down
2 changes: 1 addition & 1 deletion source/common/utility/vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion source/core/actorlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
**
*/

#include "build.h"
#include "coreactor.h"
#include "gamefuncs.h"
#include "raze_sound.h"
Expand Down
1 change: 1 addition & 0 deletions source/core/automap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "build.h"
#include "c_cvars.h"
#include "palentry.h"
#include "maptypes.h"

class FSerializer;
struct event_t;
Expand Down
2 changes: 1 addition & 1 deletion source/core/cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
**
*/

#include "build.h"
#include "gamestruct.h"
#include "printf.h"
#include "c_cvars.h"
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions source/core/coreactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/core/gamecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion source/core/gamecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 5 additions & 3 deletions source/core/gamefuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

//---------------------------------------------------------------------------
//
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion source/core/gamefuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -271,6 +274,7 @@ struct MoveClipper
double movedist;
TArray<ClipObject> clipobjects;
BFSSectorSearch search;
bool precise;

MoveClipper(sectortype* start) : search(start) {}
};
Expand Down
2 changes: 1 addition & 1 deletion source/core/gamehud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion source/core/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion source/core/maploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*/

#include <stdint.h>
#include "build.h"
#include "files.h"
#include "automap.h"
#include "printf.h"
Expand Down
2 changes: 0 additions & 2 deletions source/core/models/modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "tiletexture.h"
#include "buildtiles.h"

#include "build.h"


int ModelManager::LoadModel(const char* fn)
{
Expand Down
1 change: 1 addition & 0 deletions source/core/music/s_advsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <zmusic.h>

#include "raze_music.h"
#include "ns.h"
#include "games/duke/src/sounds.h"

// MACROS ------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion source/core/precache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
**
*/
#include "ns.h"
#include "build.h"
#include "buildtiles.h"
#include "palette.h"
#include "v_video.h"
#include "hw_material.h"
Expand Down
2 changes: 1 addition & 1 deletion source/core/rendering/hw_palmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion source/core/rendering/hw_sections.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "build.h"
#include "vectors.h"
#include "maptypes.h"

enum ESectionFlag
{
Expand Down
2 changes: 1 addition & 1 deletion source/core/rendering/hw_voxels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions source/core/rendering/scene/hw_bunchdrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "tarray.h"
#include "basics.h"
#include "maptypes.h"

struct HWDrawInfo;
class Clipper;
Expand Down
2 changes: 1 addition & 1 deletion source/core/rendering/scene/hw_drawstructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion source/core/sectorgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/

#include "sectorgeometry.h"
#include "build.h"
#include "buildtiles.h"
#include "gamefuncs.h"
#include "texturemanager.h"
Expand Down
2 changes: 1 addition & 1 deletion source/core/sectorgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "tarray.h"
#include "vectors.h"
#include "build.h"
#include "maptypes.h"

struct Section;

Expand Down
4 changes: 2 additions & 2 deletions source/core/textures/buildtiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "texinfo.h"
#include "texturemanager.h"

// all that's left here is the wrappers that need to go away.

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);
Expand Down
1 change: 1 addition & 0 deletions source/core/thingdef_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "texturemanager.h"
#include "coreactor.h"
#include "thingdef.h"
#include "buildtiles.h"

//==========================================================================
//
Expand Down
Loading

0 comments on commit 43f4962

Please sign in to comment.