Skip to content

Commit

Permalink
- floatified player_struct::pos.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Aug 9, 2022
1 parent 8595875 commit 682f73f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 61 deletions.
8 changes: 4 additions & 4 deletions source/games/duke/src/actors.cpp
Expand Up @@ -2850,8 +2850,8 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6)
{
if (po[p].os == actor->sector())
{
po[p].opos.X += m;
po[p].opos.Y += x;
po[p].opos.X += m * inttoworld;
po[p].opos.Y += x * inttoworld;
}

if (actor->sector() == psp->sector())
Expand Down Expand Up @@ -3042,8 +3042,8 @@ void handle_se30(DDukeActor *actor, int JIBS6)

if (po[p].os == actor->sector())
{
po[p].opos.X += l;
po[p].opos.Y += x;
po[p].opos.X += l * inttoworld;
po[p].opos.Y += x * inttoworld;
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/actors_d.cpp
Expand Up @@ -1837,7 +1837,7 @@ void movetransports_d(void)
ps[p].backupz();

auto pa = ps[p].GetActor();
pa->opos = DVector3(ps[p].__int_pos.X * inttoworld, ps[p].__int_pos.Y * inttoworld, ps[p].__int_pos.Z * zinttoworld);
pa->opos = ps[p].pos;

ChangeActorSect(act2, Owner->sector());
ps[p].setCursector(Owner->sector());
Expand Down
6 changes: 3 additions & 3 deletions source/games/duke/src/gameexec.cpp
Expand Up @@ -1522,12 +1522,12 @@ int ParseState::parse(void)
parseifelse(ifcanshoottarget(g_ac, g_p, g_x));
break;
case concmd_ifcanseetarget:
j = cansee(g_ac->int_pos().X, g_ac->int_pos().Y, g_ac->int_pos().Z - ((krand() & 41) << 8), g_ac->sector(), ps[g_p].player_int_pos().X, ps[g_p].player_int_pos().Y, ps[g_p].__int_pos.Z/*-((krand()&41)<<8)*/, ps[g_p].GetActor()->sector());
j = cansee(g_ac->spr.pos.plusZ(krand() & 41), g_ac->sector(), ps[g_p].pos, ps[g_p].GetActor()->sector());
parseifelse(j);
if (j) g_ac->timetosleep = SLEEPTIME;
break;
case concmd_ifnocover:
j = cansee(g_ac->int_pos().X, g_ac->int_pos().Y, g_ac->int_pos().Z, g_ac->sector(), ps[g_p].player_int_pos().X, ps[g_p].player_int_pos().Y, ps[g_p].player_int_pos().Z, ps[g_p].GetActor()->sector());
j = cansee(g_ac->spr.pos, g_ac->sector(), ps[g_p].pos, ps[g_p].GetActor()->sector());
parseifelse(j);
if (j) g_ac->timetosleep = SLEEPTIME;
break;
Expand Down Expand Up @@ -2792,7 +2792,7 @@ int ParseState::parse(void)
case concmd_pstomp:
insptr++;
if( ps[g_p].knee_incs == 0 && ps[g_p].GetActor()->spr.xrepeat >= (isRR()? 9: 40) )
if( cansee(g_ac->int_pos().X,g_ac->int_pos().Y,g_ac->int_pos().Z-(4<<8),g_ac->sector(),ps[g_p].player_int_pos().X,ps[g_p].player_int_pos().Y,ps[g_p].__int_pos.Z+(16<<8),ps[g_p].GetActor()->sector()) )
if (cansee(g_ac->spr.pos.plusZ(-4), g_ac->sector(), ps[g_p].pos.plusZ(16), ps[g_p].GetActor()->sector()))
{
ps[g_p].knee_incs = 1;
if(ps[g_p].weapon_pos == 0)
Expand Down
6 changes: 0 additions & 6 deletions source/games/duke/src/inlines.h
Expand Up @@ -247,10 +247,4 @@ inline ESpriteFlags randomXFlip()
return CSTAT_SPRITE_XFLIP;
}

inline int pushmove_p(player_struct* actor, sectortype** const sect, int32_t const walldist, int32_t const ceildist, int32_t const flordist,
uint32_t const cliptype, bool clear = true)
{
return ::pushmove(&actor->__int_pos, sect, walldist, ceildist, flordist, cliptype, clear);
}

END_DUKE_NS
4 changes: 2 additions & 2 deletions source/games/duke/src/player.cpp
Expand Up @@ -618,7 +618,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
}

Collision coll;
clipmove(p->__int_pos, &p->cursector, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0, coll);
clipmove(p->pos, &p->cursector, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0, coll);
}

backupplayer(p);
Expand All @@ -627,7 +627,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)

updatesector(p->player_int_pos().X, p->player_int_pos().Y, &p->cursector);

pushmove_p(p, &p->cursector, 128L, (4 << 8), (20 << 8), CLIPMASK0);
pushmove(p->pos, &p->cursector, 128L, (4 << 8), (20 << 8), CLIPMASK0);

if (fz > cz + (16 << 8) && actor->spr.pal != 1)
p->angle.rotscrnang = buildang(p->dead_flag + ((fz + p->player_int_pos().Z) >> 7));
Expand Down
7 changes: 3 additions & 4 deletions source/games/duke/src/player_d.cpp
Expand Up @@ -3031,7 +3031,7 @@ void processinput_d(int snum)
ChangeActorSect(pact, p->cursector);
}
else
clipmove(p->__int_pos, &p->cursector, p->vel.X, p->vel.Y, 164, (4 << 8), ii, CLIPMASK0, clip);
clipmove(p->pos, &p->cursector, p->vel.X, p->vel.Y, 164, (4 << 8), ii, CLIPMASK0, clip);

if (p->jetpack_on == 0 && psectlotag != 2 && psectlotag != 1 && shrunk)
p->player_add_int_z(32 << 8);
Expand Down Expand Up @@ -3082,7 +3082,7 @@ void processinput_d(int snum)
while (ud.clipping == 0)
{
int blocked;
blocked = (pushmove_p(p, &p->cursector, 164, (4 << 8), (4 << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512);
blocked = (pushmove(p->pos, &p->cursector, 164, (4 << 8), (4 << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512);

if (fabs(pact->floorz - pact->ceilingz) < 48 || blocked)
{
Expand All @@ -3093,8 +3093,7 @@ void processinput_d(int snum)
{
if (!retry++)
{
p->opos = oldpos;
p->restorexyz();
p->pos = p->opos = oldpos;
continue;
}
quickkill(p);
Expand Down
13 changes: 6 additions & 7 deletions source/games/duke/src/player_r.cpp
Expand Up @@ -3800,7 +3800,7 @@ void processinput_r(int snum)
ChangeActorSect(pact, p->cursector);
}
else
clipmove(p->__int_pos, &p->cursector, p->vel.X, p->vel.Y, 164, (4 << 8), i, CLIPMASK0, clip);
clipmove(p->pos, &p->cursector, p->vel.X, p->vel.Y, 164, (4 << 8), i, CLIPMASK0, clip);

if (p->jetpack_on == 0 && psectlotag != 2 && psectlotag != 1 && shrunk)
p->player_add_int_z(32 << 8);
Expand Down Expand Up @@ -3829,10 +3829,10 @@ void processinput_r(int snum)
if (wal->lotag < 44)
{
dofurniture(clip.hitWall, p->cursector, snum);
pushmove_p(p, &p->cursector, 172L, (4L << 8), (4L << 8), CLIPMASK0);
pushmove(p->pos, &p->cursector, 172L, (4L << 8), (4L << 8), CLIPMASK0);
}
else
pushmove_p(p, &p->cursector, 172L, (4L << 8), (4L << 8), CLIPMASK0);
pushmove(p->pos, &p->cursector, 172L, (4L << 8), (4L << 8), CLIPMASK0);
}
}
}
Expand Down Expand Up @@ -3933,9 +3933,9 @@ void processinput_r(int snum)
{
int blocked;
if (pact->spr.clipdist == 64)
blocked = (pushmove_p(p, &p->cursector, 128, (4 << 8), (4 << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512);
blocked = (pushmove(p->pos, &p->cursector, 128, (4 << 8), (4 << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512);
else
blocked = (pushmove_p(p, &p->cursector, 16, (4 << 8), (4 << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512);
blocked = (pushmove(p->pos, &p->cursector, 16, (4 << 8), (4 << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512);

if (fabs(pact->floorz - pact->ceilingz) < 48 || blocked)
{
Expand All @@ -3946,8 +3946,7 @@ void processinput_r(int snum)
{
if (!retry++)
{
p->opos = oldpos;
p->restorexyz();
p->pos = p->opos = oldpos;
continue;
}
quickkill(p);
Expand Down
6 changes: 3 additions & 3 deletions source/games/duke/src/premap.cpp
Expand Up @@ -95,7 +95,7 @@ void pickrandomspot(int snum)
i = krand()%numplayersprites;
else i = snum;

p->__int_pos = po[i].opos;
p->pos = po[i].opos;
p->backupxyz();
p->setbobpos();
p->angle.oang = p->angle.ang = buildang(po[i].oa);
Expand Down Expand Up @@ -615,7 +615,7 @@ void resetpspritevars(int g)
firsty = ps[0].player_int_pos().Y;
}

po[numplayersprites].opos = act->int_pos();
po[numplayersprites].opos = act->spr.pos;
po[numplayersprites].oa = act->spr.ang;
po[numplayersprites].os = act->sector();

Expand Down Expand Up @@ -1005,7 +1005,7 @@ static int LoadTheMap(MapRecord *mi, struct player_struct *p, int gamemode)
SpawnSpriteDef sprites;
vec3_t pos;
loadMap(mi->fileName, isShareware(), &pos, &lbang, &sect, sprites);
p->__int_pos = pos;
p->pos = { pos.X * inttoworld, pos.Y * inttoworld, pos.Z * zinttoworld };
p->cursector = &sector[sect];

SECRET_SetMapName(mi->DisplayName(), mi->name);
Expand Down
6 changes: 3 additions & 3 deletions source/games/duke/src/savegame.cpp
Expand Up @@ -107,9 +107,9 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w,
{
if (arc.BeginObject(keyname))
{
arc("posx", w.__int_pos.X)
("posy", w.__int_pos.Y)
("posz", w.__int_pos.Z)
arc("posx", w.pos.X)
("posy", w.pos.Y)
("posz", w.pos.Z)
("angle", w.angle)
("horizon", w.horizon)
.Array("gotweapon", w.gotweapon, MAX_WEAPONS)
Expand Down
50 changes: 22 additions & 28 deletions source/games/duke/src/types.h
Expand Up @@ -189,7 +189,7 @@ struct user_defs

struct player_orig
{
vec3_t opos;
DVector3 opos;
short oa;
sectortype* os;
};
Expand All @@ -203,12 +203,8 @@ struct CraneDef

struct player_struct
{
// This is basically the version from JFDuke but this first block contains a few changes to make it work with other parts of Raze.

// The sound code wants to read a vector out of this so we need to define one for the main coordinate.
vec3_t __int_pos, vel;

DVector3 opos;
vec3_t vel;
DVector3 pos, opos;

// player's horizon and angle structs.
PlayerHorizon horizon;
Expand Down Expand Up @@ -362,55 +358,51 @@ struct player_struct

void backupxyz()
{
opos.X = __int_pos.X * inttoworld;
opos.Y = __int_pos.Y * inttoworld;
opos.Z = __int_pos.Z * zinttoworld;
opos = pos;
}

void restorexyz()
{
__int_pos.X = opos.X * worldtoint;
__int_pos.Y = opos.Y * worldtoint;
__int_pos.Z = opos.Z * zworldtoint;
pos = opos;
}

void backupxy()
{
opos.X = __int_pos.X * inttoworld;
opos.Y = __int_pos.Y * inttoworld;
opos.X = pos.X;
opos.Y = pos.Y;
}

void restorexy()
{
__int_pos.X = opos.X * worldtoint;
__int_pos.Y = opos.Y * worldtoint;
pos.X = opos.X;
pos.Y = opos.Y;
}

void backupz()
{
opos.Z = __int_pos.Z * zinttoworld;
opos.Z = pos.Z;
}

void setbobpos()
{
bobpos = __int_pos.vec2;
bobpos = player_int_pos().vec2;
}

void getposfromactor(DCoreActor* actor, double addz = 0)
{
__int_pos = actor->int_pos();
if (addz) __int_pos.Z += int(addz * worldtoint);
pos = actor->spr.pos;
if (addz) pos.Z += addz;
}

void getxyfromactor(DCoreActor* actor)
{
__int_pos.X = actor->int_pos().X;
__int_pos.Y = actor->int_pos().Y;
pos.X = actor->spr.pos.X;
pos.Y = actor->spr.pos.Y;
}

vec3_t player_int_pos() const
{
return __int_pos;
return { int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint) };
}

vec3_t player_int_opos() const
Expand All @@ -420,20 +412,22 @@ struct player_struct

void player_add_int_z(int z)
{
__int_pos.Z += z;
pos.Z += z * zinttoworld;
}

void player_set_int_z(int z)
{
__int_pos.Z = z;
pos.Z = z * zinttoworld;
}
void player_add_int_xy(const vec2_t& v)
{
__int_pos.vec2 += v;
pos.X += v.X * inttoworld;
pos.Y += v.Y * inttoworld;
}
void player_set_int_xy(const vec2_t& v)
{
__int_pos.vec2 = v;
pos.X = v.X * inttoworld;
pos.Y = v.Y * inttoworld;
}


Expand Down

0 comments on commit 682f73f

Please sign in to comment.