Clipping function tweaks. Fixes building without HAVE_CLIPSHAPE_FEATURE.

git-svn-id: https://svn.eduke32.com/eduke32@5793 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2016-06-21 00:33:35 +00:00
parent 32450bdd68
commit 3b7aa279b1
3 changed files with 77 additions and 77 deletions

View file

@ -3,6 +3,8 @@
#ifndef clip_h_ #ifndef clip_h_
#define clip_h_ #define clip_h_
#define MAXCLIPNUM 1024
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
#define CM_MAX 256 // must be a power of 2 #define CM_MAX 256 // must be a power of 2
@ -31,8 +33,6 @@
#define CM_NOROT(Spri) (sprite[Spri].cstat&2) #define CM_NOROT(Spri) (sprite[Spri].cstat&2)
#define CM_NOROTS(Sect) (sector[Sect].CM_CSTAT&2) #define CM_NOROTS(Sect) (sector[Sect].CM_CSTAT&2)
#define MAXCLIPNUM 1024
typedef struct typedef struct
{ {
int16_t qbeg, qend; // indices into sectq int16_t qbeg, qend; // indices into sectq
@ -51,6 +51,17 @@ typedef struct
extern mapinfo_t origmapinfo, clipmapinfo; extern mapinfo_t origmapinfo, clipmapinfo;
extern void clipmapinfo_init();
extern int32_t quickloadboard;
extern int16_t *sectq;
extern int16_t pictoidx[MAXTILES]; // maps tile num to clipinfo[] index
extern int16_t clipspritelist[MAXCLIPNUM];
extern void mapinfo_set(mapinfo_t *bak, mapinfo_t *newmap);
extern int32_t clipsprite_try(const spritetype *spr, int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax);
extern int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t *clipsectcnt, const vec3_t *vect);
#endif // HAVE_CLIPSHAPE_FEATURE
typedef struct typedef struct
{ {
int32_t x1, y1, x2, y2; int32_t x1, y1, x2, y2;
@ -58,31 +69,20 @@ typedef struct
extern linetype clipit[MAXCLIPNUM]; extern linetype clipit[MAXCLIPNUM];
extern void clipmapinfo_init();
extern int32_t quickloadboard;
extern int16_t *sectq;
extern int16_t pictoidx[MAXTILES]; // maps tile num to clipinfo[] index
extern int16_t clipnum; extern int16_t clipnum;
extern int32_t clipsectnum, origclipsectnum, clipspritenum; extern int32_t clipsectnum, origclipsectnum, clipspritenum;
extern int16_t clipsectorlist[MAXCLIPNUM], origclipsectorlist[MAXCLIPNUM]; extern int16_t clipsectorlist[MAXCLIPNUM], origclipsectorlist[MAXCLIPNUM];
extern int16_t clipspritelist[MAXCLIPNUM];
extern void mapinfo_set(mapinfo_t *bak, mapinfo_t *newmap);
extern int32_t clipsprite_try(const spritetype *spr, int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax);
extern int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t *clipsectcnt, const vec3_t *vect);
int32_t clipinsidebox(int32_t x, int32_t y, int16_t wallnum, int32_t walldist); int32_t clipinsidebox(vec2_t *vect, int16_t wallnum, int32_t walldist);
int32_t clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1, int32_t clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t walldist);
int32_t x2, int32_t y2, int32_t walldist);
extern int32_t clipmoveboxtracenum; extern int32_t clipmoveboxtracenum;
int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist, int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist, int32_t ceildist,
int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1, 2))); int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1, 2)));
int32_t clipmovex(vec3_t *pos, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t clipmovex(vec3_t *pos, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist, int32_t ceildist,
int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype, int32_t flordist, uint32_t cliptype, uint8_t noslidep) ATTRIBUTE((nonnull(1, 2)));
uint8_t noslidep) ATTRIBUTE((nonnull(1, 2))); int32_t pushmove(vec3_t *vect, int16_t *sectnum, int32_t walldist, int32_t ceildist, int32_t flordist,
int32_t pushmove(vec3_t *vect, int16_t *sectnum, int32_t walldist, uint32_t cliptype) ATTRIBUTE((nonnull(1, 2)));
int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1, 2)));
#endif
#endif #endif

View file

@ -1,6 +1,15 @@
#include "build.h" #include "build.h"
#include "engine_priv.h" #include "engine_priv.h"
int16_t clipnum;
linetype clipit[MAXCLIPNUM];
int32_t clipsectnum, origclipsectnum, clipspritenum;
int16_t clipsectorlist[MAXCLIPNUM], origclipsectorlist[MAXCLIPNUM];
#ifdef HAVE_CLIPSHAPE_FEATURE
int16_t clipspritelist[MAXCLIPNUM]; // sector-like sprite clipping
#endif
static int16_t clipobjectval[MAXCLIPNUM];
////// sector-like clipping for sprites ////// ////// sector-like clipping for sprites //////
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
void mapinfo_set(mapinfo_t *bak, mapinfo_t *newmap) void mapinfo_set(mapinfo_t *bak, mapinfo_t *newmap)
@ -38,14 +47,6 @@ static tsectortype *loadsector;
static twalltype *loadwall, *loadwallinv; static twalltype *loadwall, *loadwallinv;
static tspritetype *loadsprite; static tspritetype *loadsprite;
int16_t clipnum;
linetype clipit[MAXCLIPNUM];
int32_t clipsectnum, origclipsectnum, clipspritenum;
int16_t clipsectorlist[MAXCLIPNUM], origclipsectorlist[MAXCLIPNUM];
#ifdef HAVE_CLIPSHAPE_FEATURE
int16_t clipspritelist[MAXCLIPNUM]; // sector-like sprite clipping
#endif
static int16_t clipobjectval[MAXCLIPNUM];
void clipmapinfo_init() void clipmapinfo_init()
{ {
@ -532,17 +533,17 @@ int32_t clipmoveboxtracenum = 3;
// //
// clipinsidebox // clipinsidebox
// //
int32_t clipinsidebox(int32_t x, int32_t y, int16_t wallnum, int32_t walldist) int32_t clipinsidebox(vec2_t *vect, int16_t wallnum, int32_t walldist)
{ {
int32_t const r = walldist<<1; int32_t const r = walldist<<1;
twalltype const *wal = (twalltype *) &wall[wallnum]; twalltype const *wal = (twalltype *) &wall[wallnum];
vec2_t const v1 ={ wal->x + walldist - x, wal->y + walldist - y }; vec2_t const v1 ={ wal->x + walldist - vect->x, wal->y + walldist - vect->y };
wal = (twalltype *) &wall[wal->point2]; wal = (twalltype *) &wall[wal->point2];
vec2_t v2 ={ wal->x + walldist - x, wal->y + walldist - y }; vec2_t v2 ={ wal->x + walldist - vect->x, wal->y + walldist - vect->y };
if (((v1.x < 0) && (v2.x < 0)) || ((v1.y < 0) && (v2.y < 0)) || if (((v1.x < 0) && (v2.x < 0)) || ((v1.y < 0) && (v2.y < 0)) ||
((v1.x >= r) && (v2.x >= r)) || ((v1.y >= r) && (v2.y >= r))) ((v1.x >= r) && (v2.x >= r)) || ((v1.y >= r) && (v2.y >= r)))
return (0); return 0;
v2.x -= v1.x; v2.y -= v1.y; v2.x -= v1.x; v2.y -= v1.y;
@ -569,12 +570,12 @@ int32_t clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1, int32_t
x1 += walldist-x; x2 += walldist-x; x1 += walldist-x; x2 += walldist-x;
if (((x1 < 0) && (x2 < 0)) || ((x1 >= r) && (x2 >= r))) if (((x1 < 0) && (x2 < 0)) || ((x1 >= r) && (x2 >= r)))
return (0); return 0;
y1 += walldist-y; y2 += walldist-y; y1 += walldist-y; y2 += walldist-y;
if (((y1 < 0) && (y2 < 0)) || ((y1 >= r) && (y2 >= r))) if (((y1 < 0) && (y2 < 0)) || ((y1 >= r) && (y2 >= r)))
return (0); return 0;
x2 -= x1; y2 -= y1; x2 -= x1; y2 -= y1;
@ -607,23 +608,22 @@ int32_t clipsprite_try(const spritetype *spr, int32_t xmin, int32_t ymin, int32_
if ((spr->cstat&48)!=32) // face/wall sprite if ((spr->cstat&48)!=32) // face/wall sprite
{ {
int32_t tempint1 = clipmapinfo.sector[k].CM_XREPEAT; int32_t const tempint1 = clipmapinfo.sector[k].CM_XREPEAT;
maxcorrection = divideu32_noinline(maxcorrection * (int32_t) spr->xrepeat, tempint1); maxcorrection = divideu32_noinline(maxcorrection * (int32_t) spr->xrepeat, tempint1);
} }
else // floor sprite else // floor sprite
{ {
int32_t tempint1 = clipmapinfo.sector[k].CM_XREPEAT; int32_t const tempint1 = clipmapinfo.sector[k].CM_XREPEAT;
int32_t tempint2 = clipmapinfo.sector[k].CM_YREPEAT; int32_t const tempint2 = clipmapinfo.sector[k].CM_YREPEAT;
maxcorrection = max(divideu32_noinline(maxcorrection * (int32_t) spr->xrepeat, tempint1), maxcorrection = max(divideu32_noinline(maxcorrection * (int32_t) spr->xrepeat, tempint1),
divideu32_noinline(maxcorrection * (int32_t) spr->yrepeat, tempint2)); divideu32_noinline(maxcorrection * (int32_t) spr->yrepeat, tempint2));
} }
maxcorrection -= MAXCLIPDIST; maxcorrection -= MAXCLIPDIST;
if (spr->x < xmin - maxcorrection) return 1; if ((spr->x < xmin - maxcorrection) || (spr->y < ymin - maxcorrection) ||
if (spr->y < ymin - maxcorrection) return 1; (spr->x > xmax + maxcorrection) || (spr->y > ymax + maxcorrection))
if (spr->x > xmax + maxcorrection) return 1; return 1;
if (spr->y > ymax + maxcorrection) return 1;
if (clipspritenum < MAXCLIPNUM) if (clipspritenum < MAXCLIPNUM)
clipspritelist[clipspritenum++] = spr-sprite; clipspritelist[clipspritenum++] = spr-sprite;
@ -681,17 +681,17 @@ int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t *clipse
for (k=clipinfo[curidx].qbeg; k<=clipinfo[curidx].qend; k++) for (k=clipinfo[curidx].qbeg; k<=clipinfo[curidx].qend; k++)
{ {
const int32_t j = sectq[k]; const int32_t j = sectq[k];
sectortype *const sec = &sector[j]; tsectortype *const sec = (tsectortype *)&sector[j];
const int32_t startwall = sec->wallptr, endwall = startwall+sec->wallnum; const int32_t startwall = sec->wallptr, endwall = startwall+sec->wallnum;
int32_t w; int32_t w;
walltype *wal; twalltype *wal;
sec->floorz = daz + mulscale22(scalez, CM_FLOORZ(j)); sec->floorz = daz + mulscale22(scalez, CM_FLOORZ(j));
sec->ceilingz = daz + mulscale22(scalez, CM_CEILINGZ(j)); sec->ceilingz = daz + mulscale22(scalez, CM_CEILINGZ(j));
//initprintf("sec %d: f=%d, c=%d\n", j, sec->floorz, sec->ceilingz); //initprintf("sec %d: f=%d, c=%d\n", j, sec->floorz, sec->ceilingz);
for (w=startwall, wal=&wall[startwall]; w<endwall; w++, wal++) for (w=startwall, wal=(twalltype *)&wall[startwall]; w<endwall; w++, wal++)
{ {
wal->x = mulscale22(scalex, CM_WALL_X(w)); wal->x = mulscale22(scalex, CM_WALL_X(w));
wal->y = mulscale22(scaley, CM_WALL_Y(w)); wal->y = mulscale22(scaley, CM_WALL_Y(w));
@ -717,6 +717,7 @@ int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t *clipse
return flipmul; return flipmul;
} }
#endif #endif
static int32_t clipmove_warned=0; static int32_t clipmove_warned=0;
@ -737,9 +738,8 @@ static void addclipline(int32_t dax1, int32_t day1, int32_t dax2, int32_t day2,
} }
} }
static inline void clipmove_tweak_pos(const vec3_t *pos, int32_t gx, int32_t gy, FORCE_INLINE void clipmove_tweak_pos(const vec3_t *pos, int32_t gx, int32_t gy, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, int32_t *daxptr, int32_t *dayptr)
int32_t *daxptr, int32_t *dayptr)
{ {
int32_t daz; int32_t daz;
@ -751,11 +751,11 @@ static inline void clipmove_tweak_pos(const vec3_t *pos, int32_t gx, int32_t gy,
} }
// Returns: should clip? // Returns: should clip?
static int32_t check_floor_curb(int32_t dasect, int32_t nextsect, int32_t flordist, static int32_t check_floor_curb(int32_t dasect, int32_t nextsect, int32_t flordist, int32_t posz,
int32_t posz, int32_t dax, int32_t day) int32_t dax, int32_t day)
{ {
const sectortype *sec2 = &sector[nextsect]; tsectortype const * const sec2 = (tsectortype *)&sector[nextsect];
int32_t daz2 = getflorzofslope(nextsect, dax, day); int32_t const daz2 = getflorzofslope(nextsect, dax, day);
return ((sec2->floorstat&1) == 0 && // parallaxed floor curbs don't clip return ((sec2->floorstat&1) == 0 && // parallaxed floor curbs don't clip
posz >= daz2-(flordist-1) && // also account for desired z distance tolerance posz >= daz2-(flordist-1) && // also account for desired z distance tolerance
@ -763,9 +763,9 @@ static int32_t check_floor_curb(int32_t dasect, int32_t nextsect, int32_t flordi
} }
int32_t clipmovex(vec3_t *pos, int16_t *sectnum, int32_t clipmovex(vec3_t *pos, int16_t *sectnum,
int32_t xvect, int32_t yvect, int32_t xvect, int32_t yvect,
int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype, int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype,
uint8_t noslidep) uint8_t noslidep)
{ {
const int32_t oboxtracenum = clipmoveboxtracenum; const int32_t oboxtracenum = clipmoveboxtracenum;
@ -860,6 +860,9 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
int32_t xvect, int32_t yvect, int32_t xvect, int32_t yvect,
int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype) int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype)
{ {
if ((xvect|yvect) == 0 || *sectnum < 0)
return 0;
int32_t i, j, k, tempint1, tempint2; int32_t i, j, k, tempint1, tempint2;
int32_t x1, y1, x2, y2; int32_t x1, y1, x2, y2;
int32_t dax, day; int32_t dax, day;
@ -884,8 +887,6 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
const int32_t xmin = cx-rad, ymin = cy-rad; const int32_t xmin = cx-rad, ymin = cy-rad;
const int32_t xmax = cx+rad, ymax = cy+rad; const int32_t xmax = cx+rad, ymax = cy+rad;
if ((xvect|yvect) == 0 || *sectnum < 0)
return 0;
clipmove_warned = 0; clipmove_warned = 0;
clipnum = 0; clipnum = 0;
@ -895,8 +896,8 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
clipspritecnt = 0; clipspritenum = 0; clipspritecnt = 0; clipspritenum = 0;
do do
{ {
const walltype *wal; const twalltype *wal;
const sectortype *sec; const tsectortype *sec;
int32_t dasect, startwall, endwall; int32_t dasect, startwall, endwall;
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
@ -935,17 +936,16 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
////////// Walls ////////// ////////// Walls //////////
sec = &sector[dasect]; sec = (tsectortype *)&sector[dasect];
startwall = sec->wallptr; endwall = startwall + sec->wallnum; startwall = sec->wallptr; endwall = startwall + sec->wallnum;
for (j=startwall, wal=&wall[startwall]; j<endwall; j++, wal++) for (j=startwall, wal=(twalltype *)&wall[startwall]; j<endwall; j++, wal++)
{ {
int32_t clipyou = 0, dx, dy; int32_t clipyou = 0, dx, dy;
const walltype *const wal2 = &wall[wal->point2]; const twalltype *const wal2 = (twalltype *)&wall[wal->point2];
if (wal->x < xmin && wal2->x < xmin) continue; if ((wal->x < xmin && wal2->x < xmin) || (wal->x > xmax && wal2->x > xmax) ||
if (wal->x > xmax && wal2->x > xmax) continue; (wal->y < ymin && wal2->y < ymin) || (wal->y > ymax && wal2->y > ymax))
if (wal->y < ymin && wal2->y < ymin) continue; continue;
if (wal->y > ymax && wal2->y > ymax) continue;
x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y; x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y;
@ -961,7 +961,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
{ {
if (wal->nextsector>=0) if (wal->nextsector>=0)
{ {
const sectortype *sec2 = &sector[wal->nextsector]; const tsectortype *sec2 = (tsectortype *)&sector[wal->nextsector];
clipmove_tweak_pos(pos, gx, gy, x1, y1, x2, y2, &dax, &day); clipmove_tweak_pos(pos, gx, gy, x1, y1, x2, y2, &dax, &day);
@ -1012,7 +1012,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
if (clipyou == 0) if (clipyou == 0)
{ {
const sectortype *sec2 = &sector[wal->nextsector]; const tsectortype *sec2 = (tsectortype *)&sector[wal->nextsector];
int32_t daz2 = getceilzofslope(wal->nextsector, dax, day); int32_t daz2 = getceilzofslope(wal->nextsector, dax, day);
clipyou = ((sec2->ceilingstat&1) == 0 && clipyou = ((sec2->ceilingstat&1) == 0 &&
@ -1308,8 +1308,8 @@ int32_t pushmove(vec3_t *vect, int16_t *sectnum,
clipsectcnt = 0; clipsectnum = 1; clipsectcnt = 0; clipsectnum = 1;
do do
{ {
const walltype *wal; const twalltype *wal;
const sectortype *sec; const tsectortype *sec;
int32_t startwall, endwall; int32_t startwall, endwall;
#if 0 #if 0
// Push FACE sprites // Push FACE sprites
@ -1344,21 +1344,21 @@ int32_t pushmove(vec3_t *vect, int16_t *sectnum,
} }
} }
#endif #endif
sec = &sector[clipsectorlist[clipsectcnt]]; sec = (tsectortype *)&sector[clipsectorlist[clipsectcnt]];
if (dir > 0) if (dir > 0)
startwall = sec->wallptr, endwall = startwall + sec->wallnum; startwall = sec->wallptr, endwall = startwall + sec->wallnum;
else else
endwall = sec->wallptr, startwall = endwall + sec->wallnum; endwall = sec->wallptr, startwall = endwall + sec->wallnum;
for (i=startwall, wal=&wall[startwall]; i!=endwall; i+=dir, wal+=dir) for (i=startwall, wal=(twalltype *)&wall[startwall]; i!=endwall; i+=dir, wal+=dir)
if (clipinsidebox(vect->x, vect->y, i, walldist-4) == 1) if (clipinsidebox((vec2_t *)vect, i, walldist-4) == 1)
{ {
j = 0; j = 0;
if (wal->nextsector < 0) j = 1; if (wal->nextsector < 0) j = 1;
if (wal->cstat&dawalclipmask) j = 1; if (wal->cstat&dawalclipmask) j = 1;
if (j == 0) if (j == 0)
{ {
const sectortype *const sec2 = &sector[wal->nextsector]; const tsectortype *const sec2 = (tsectortype *)&sector[wal->nextsector];
int32_t daz2; int32_t daz2;
//Find closest point on wall (dax, day) to (vect->x, vect->y) //Find closest point on wall (dax, day) to (vect->x, vect->y)
@ -1397,7 +1397,7 @@ int32_t pushmove(vec3_t *vect, int16_t *sectnum,
{ {
vect->x = (vect->x) + dx; vect->y = (vect->y) + dy; vect->x = (vect->x) + dx; vect->y = (vect->y) + dy;
bad2--; if (bad2 == 0) break; bad2--; if (bad2 == 0) break;
} while (clipinsidebox(vect->x, vect->y, i, walldist-4) != 0); } while (clipinsidebox((vec2_t *)vect, i, walldist-4) != 0);
bad = -1; bad = -1;
k--; if (k <= 0) return(bad); k--; if (k <= 0) return(bad);
updatesector(vect->x, vect->y, sectnum); updatesector(vect->x, vect->y, sectnum);

View file

@ -6565,13 +6565,13 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
for (SPRITES_OF(STAT_ACTOR, k)) for (SPRITES_OF(STAT_ACTOR, k))
{ {
if (sprite[k].extra > 0 && A_CheckEnemySprite(&sprite[k]) if (sprite[k].extra > 0 && A_CheckEnemySprite(&sprite[k])
&& clipinsidebox(sprite[k].x, sprite[k].y, j, 256) == 1) && clipinsidebox((vec2_t *)&sprite[k], j, 256) == 1)
goto BOLT; goto BOLT;
} }
for (SPRITES_OF(STAT_PLAYER, k)) for (SPRITES_OF(STAT_PLAYER, k))
{ {
if (sprite[k].owner >= 0 && clipinsidebox(sprite[k].x, sprite[k].y, j, 144) == 1) if (sprite[k].owner >= 0 && clipinsidebox((vec2_t *)&sprite[k], j, 144) == 1)
{ {
t[5] = 8; // Delay t[5] = 8; // Delay
k = (SP>>3)*t[3]; k = (SP>>3)*t[3];