Skip to content

Commit

Permalink
- adapted several clipmove calls in SW.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Dec 4, 2021
1 parent 94c04ba commit 28f71f0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
6 changes: 0 additions & 6 deletions source/games/sw/src/game.h
Expand Up @@ -2217,12 +2217,6 @@ inline int Facing(DSWActor* actor1, DSWActor* actor2)
return (abs(getincangle(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y), (sp2)->ang)) < 512);
}

// temporary helper.
inline void SetCollision(USER* u, int coll)
{
u->coll.setFromEngine(coll);
}

// just determine if the player is moving
inline bool PLAYER_MOVING(PLAYERp pp)
{
Expand Down
26 changes: 14 additions & 12 deletions source/games/sw/src/mclip.cpp
Expand Up @@ -38,7 +38,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
BEGIN_SW_NS


int MultiClipMove(PLAYERp pp, int z, int floor_dist)
Collision MultiClipMove(PLAYERp pp, int z, int floor_dist)
{
int i;
vec3_t opos[MAX_CLIPBOX], pos[MAX_CLIPBOX];
Expand All @@ -48,9 +48,8 @@ int MultiClipMove(PLAYERp pp, int z, int floor_dist)
int min_dist = 999999;
int dist;

int ret_start;
int ret;
int min_ret=0;
Collision min_ret{};

int xvect,yvect;

Expand All @@ -64,9 +63,13 @@ int MultiClipMove(PLAYERp pp, int z, int floor_dist)

xvect = sop->clipbox_vdist[i] * bcos(ang);
yvect = sop->clipbox_vdist[i] * bsin(ang);
ret_start = clipmove(&spos, &pp->cursectnum, xvect, yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, 1);
Collision coll;
#pragma message(__FILE__ "remove workaround");
sectortype* cursect = pp->cursector();
clipmove(spos, &cursect, xvect, yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, coll, 1);
pp->setcursector(cursect);

if (ret_start)
if (coll.type != kHitNone)
{
// hit something moving into start position
min_dist = 0;
Expand All @@ -87,7 +90,7 @@ int MultiClipMove(PLAYERp pp, int z, int floor_dist)
{
min_dist = dist;
min_ndx = i;
min_ret = ret_start;
min_ret = coll;
}
}
else
Expand All @@ -97,20 +100,19 @@ int MultiClipMove(PLAYERp pp, int z, int floor_dist)
pos[i].z = z;

// move the box
ret = clipmove(&pos[i], &pp->cursectnum, pp->xvect, pp->yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER);
#pragma message(__FILE__ "remove workaround");
sectortype* cursect = pp->cursector();
clipmove(pos[i], &cursect, pp->xvect, pp->yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, coll);
pp->setcursector(cursect);

// save the dist moved
dist = ksqrt(SQ(pos[i].x - opos[i].x) + SQ(pos[i].y - opos[i].y));

if (ret)
{
}

if (dist < min_dist)
{
min_dist = dist;
min_ndx = i;
min_ret = ret;
min_ret = coll;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/mclip.h
Expand Up @@ -27,7 +27,7 @@ BEGIN_SW_NS

#define RECT_CLIP 1

int MultiClipMove(PLAYERp pp, int z, int floor_dist);
Collision MultiClipMove(PLAYERp pp, int z, int floor_dist);
short MultiClipTurn(PLAYERp pp, short new_ang, int z, int floor_dist);
int RectClipMove(PLAYERp pp, int *qx, int *qy);
int testpointinquad(int x, int y, int *qx, int *qy);
Expand Down
8 changes: 4 additions & 4 deletions source/games/sw/src/player.cpp
Expand Up @@ -2715,12 +2715,13 @@ void DoPlayerMoveVehicle(PLAYERp pp)
if (pp->sop->clipdist)
{
vec3_t clippos = { pp->posx, pp->posy, z };
SetCollision(u, clipmove(&clippos, &pp->cursectnum, pp->xvect, pp->yvect, (int)pp->sop->clipdist, Z(4), floor_dist, CLIPMASK_PLAYER));
int cm= clipmove(&clippos, &pp->cursectnum, pp->xvect, pp->yvect, (int)pp->sop->clipdist, Z(4), floor_dist, CLIPMASK_PLAYER);
u->coll.setFromEngine(cm);
pp->pos.vec2 = clippos.vec2;
}
else
{
SetCollision(u, MultiClipMove(pp, z, floor_dist));
u->coll = MultiClipMove(pp, z, floor_dist);
}
psp->cstat = save_cstat;

Expand Down Expand Up @@ -5976,7 +5977,6 @@ void DoPlayerDeathMoveHead(PLAYERp pp)
SPRITEp sp = &pp->Actor()->s();
USERp u = pp->Actor()->u();
int dax,day;
int sectnum;

dax = MOVEx(u->slide_vel, u->slide_ang);
day = MOVEy(u->slide_vel, u->slide_ang);
Expand Down Expand Up @@ -6024,7 +6024,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp)
pp->setcursector(sp->sector());

// try to stay in valid area - death sometimes throws you out of the map
sectnum = pp->cursectnum;
int sectnum = pp->cursectnum;
updatesector(pp->posx, pp->posy, &sectnum);
if (sectnum < 0)
{
Expand Down
5 changes: 3 additions & 2 deletions source/games/sw/src/track.cpp
Expand Up @@ -2823,9 +2823,10 @@ void DoTornadoObject(SECTOR_OBJECTp sop)
pos.z = floor_dist;

PlaceSectorObject(sop, MAXSO, MAXSO);
ret = clipmove(&pos, &cursect, xvect, yvect, (int)sop->clipdist, Z(0), floor_dist, CLIPMASK_ACTOR);
Collision coll;
clipmove(pos, &cursect, xvect, yvect, (int)sop->clipdist, Z(0), floor_dist, CLIPMASK_ACTOR, coll);

if (ret)
if (coll.type != kHitNone)
{
*ang = NORM_ANGLE(*ang + 1024 + RANDOM_P2(512) - 256);
}
Expand Down
38 changes: 19 additions & 19 deletions source/games/sw/src/weapon.cpp
Expand Up @@ -11951,11 +11951,11 @@ int DoSerpRing(DSWActor* actor)
// if ((dist ok and random ok) OR very few skulls left)
if ((dist < 18000 && (RANDOM_P2(2048<<5)>>5) < 16) || ou->Counter < 4)
{
int sectnum = sp->sectnum;
updatesector(sp->x,sp->y,&sectnum);
auto sect = sp->sector();
updatesector(sp->x, sp->y, &sect);

// if (valid sector and can see target)
if (sectnum != -1 && CanSeePlayer(actor))
if (sect != nullptr && CanSeePlayer(actor))
{
extern STATEp sg_SkullJump[];
u->ID = SKULL_R0;
Expand Down Expand Up @@ -16100,7 +16100,6 @@ bool HitscanSpriteAdjust(DSWActor* actor, walltype* hit_wall)
SPRITEp sp = &actor->s();
int16_t ang;
int xvect,yvect;
int sectnum;

if (hit_wall)
{
Expand All @@ -16114,11 +16113,13 @@ bool HitscanSpriteAdjust(DSWActor* actor, walltype* hit_wall)
yvect = bsin(ang, 4);

// must have this
sectnum = sp->sectnum;
clipmove(&sp->pos, &sectnum, xvect, yvect, 4, 4<<8, 4L<<8, CLIPMASK_MISSILE);
auto sect = sp->sector();

if (sp->sectnum != sectnum)
ChangeActorSect(actor, sectnum);
Collision coll;
clipmove(sp->pos, &sect, xvect, yvect, 4, 4 << 8, 4 << 8, CLIPMASK_MISSILE, coll);

if (sp->sector() != sect)
ChangeActorSect(actor, sect);

return true;
}
Expand Down Expand Up @@ -18597,8 +18598,6 @@ void QueueHole(sectortype* hit_sect, walltype* hit_wall, int hit_x, int hit_y, i
DSWActor* spawnedActor;
int nx,ny;
SPRITEp sp;
int sectnum;


if (TestDontStick(nullptr, hit_wall))
return;
Expand Down Expand Up @@ -18637,12 +18636,13 @@ void QueueHole(sectortype* hit_sect, walltype* hit_wall, int hit_x, int hit_y, i
nx = bcos(sp->ang, 4);
ny = bsin(sp->ang, 4);

sectnum = sp->sectnum;
auto sect = sp->sector();

clipmove(&sp->pos, &sectnum, nx, ny, 0L, 0L, 0L, CLIPMASK_MISSILE, 1);
Collision coll;
clipmove(sp->pos, &sect, nx, ny, 0, 0, 0, CLIPMASK_MISSILE, coll, 1);

if (sp->sectnum != sectnum)
ChangeActorSect(spawnedActor, sectnum);
if (sp->sector() != sect)
ChangeActorSect(spawnedActor, sect);

}

Expand Down Expand Up @@ -18873,7 +18873,6 @@ DSWActor* QueueWallBlood(DSWActor* actor, short ang)
DSWActor* spawnedActor;
int nx,ny;
SPRITEp sp;
int sectnum;
short rndnum;
int daz;
HitInfo hit;
Expand Down Expand Up @@ -18968,12 +18967,13 @@ DSWActor* QueueWallBlood(DSWActor* actor, short ang)
nx = bcos(sp->ang, 4);
ny = bsin(sp->ang, 4);

sectnum = sp->sectnum;
auto sect = sp->sector();

clipmove(&sp->pos, &sectnum, nx, ny, 0L, 0L, 0L, CLIPMASK_MISSILE, 1);
Collision coll;
clipmove(sp->pos, &sect, nx, ny, 0, 0, 0, CLIPMASK_MISSILE, coll, 1);

if (sp->sectnum != sectnum)
ChangeActorSect(spawnedActor, sectnum);
if (sp->sector() != sect)
ChangeActorSect(spawnedActor, sect);

return spawnedActor;
}
Expand Down

0 comments on commit 28f71f0

Please sign in to comment.