Skip to content

Commit

Permalink
- floatified bobpos.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Aug 9, 2022
1 parent c48d128 commit d3bfc78
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
8 changes: 4 additions & 4 deletions source/common/thirdparty/math/cmath.h
Expand Up @@ -54,14 +54,14 @@ extern FFastTrig fasttrig;
#define RAD2BAM(f) ((unsigned)xs_CRoundToInt((f) * (0x80000000/3.14159265358979323846)))


inline double fastcosbam(double v)
inline double fastcosbam(unsigned int v)
{
return fasttrig.cos(xs_CRoundToUInt(v));
return fasttrig.cos(v);
}

inline double fastsinbam(double v)
inline double fastsinbam(unsigned int v)
{
return fasttrig.sin(xs_CRoundToUInt(v));
return fasttrig.sin(v);
}

inline double fastcosdeg(double v)
Expand Down
15 changes: 7 additions & 8 deletions source/games/duke/src/actors.cpp
Expand Up @@ -2685,8 +2685,7 @@ void handle_se00(DDukeActor* actor)

auto result = rotatepoint(Owner->spr.pos, ps[p].pos.XY(), buildang(q * l));

ps[p].bobpos.X += (result.X - ps[p].player_int_pos().X) * worldtoint;
ps[p].bobpos.Y += (result.Y - ps[p].player_int_pos().Y) * worldtoint;
ps[p].bobpos += (result - ps[p].pos.XY());

ps[p].pos.X = result.X;
ps[p].pos.Y = result.Y;
Expand Down Expand Up @@ -2864,8 +2863,8 @@ void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6)

ps[p].player_set_int_xy({ result.X + m, result.Y + x });

ps[p].bobpos.X += m;
ps[p].bobpos.Y += x;
ps[p].bobpos.X += m * inttoworld;
ps[p].bobpos.Y += x * inttoworld;

ps[p].angle.addadjustment(buildang(q));

Expand Down Expand Up @@ -3039,8 +3038,8 @@ void handle_se30(DDukeActor *actor, int JIBS6)
ps[p].backupxy();
}

ps[p].bobpos.X += l;
ps[p].bobpos.Y += x;
ps[p].bobpos.X += l * inttoworld;
ps[p].bobpos.Y += x * inttoworld;
}

if (po[p].os == actor->sector())
Expand Down Expand Up @@ -3165,8 +3164,8 @@ void handle_se02(DDukeActor* actor)
{
ps[p].player_add_int_xy({ m, x });

ps[p].bobpos.X += m;
ps[p].bobpos.Y += x;
ps[p].bobpos.X += m * inttoworld;
ps[p].bobpos.Y += x * inttoworld;
}

DukeSectIterator it(actor->sector());
Expand Down
8 changes: 4 additions & 4 deletions source/games/duke/src/gameexec.cpp
Expand Up @@ -368,13 +368,13 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
break;

case PLAYER_BOBPOSX:
if (bSet) ps[iPlayer].bobpos.X = lValue;
else SetGameVarID(lVar2, ps[iPlayer].bobpos.X, sActor, sPlayer);
if (bSet) ps[iPlayer].bobpos.X = lValue * maptoworld;
else SetGameVarID(lVar2, ps[iPlayer].bobpos.X * (1/maptoworld), sActor, sPlayer);
break;

case PLAYER_BOBPOSY:
if (bSet) ps[iPlayer].bobpos.Y = lValue;
else SetGameVarID(lVar2, ps[iPlayer].bobpos.Y, sActor, sPlayer);
if (bSet) ps[iPlayer].bobpos.Y = lValue * maptoworld;
else SetGameVarID(lVar2, ps[iPlayer].bobpos.Y * (1/maptoworld), sActor, sPlayer);
break;

case PLAYER_OPOSX:
Expand Down
3 changes: 1 addition & 2 deletions source/games/duke/src/player.cpp
Expand Up @@ -775,8 +775,7 @@ void player_struct::backuppos(bool noclipping)
}

opos.Z = pos.Z;
bobpos.X = player_int_pos().X;
bobpos.Y = player_int_pos().Y;
bobpos = pos.XY();
opyoff = pyoff;
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/player_d.cpp
Expand Up @@ -2855,7 +2855,7 @@ void processinput_d(int snum)

p->playerweaponsway(pact->spr.xvel);

pact->spr.xvel = clamp(ksqrt((p->player_int_pos().X - p->bobpos.X) * (p->player_int_pos().X - p->bobpos.X) + (p->player_int_pos().Y - p->bobpos.Y) * (p->player_int_pos().Y - p->bobpos.Y)), 0, 512);
pact->spr.xvel = int(clamp((p->pos.XY() - p->bobpos).Length(), 0., 32.) * worldtoint);
if (p->on_ground) p->bobcounter += p->GetActor()->spr.xvel >> 1;

p->backuppos(ud.clipping == 0 && ((p->insector() && p->cursector->floorpicnum == MIRROR) || !p->insector()));
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/player_r.cpp
Expand Up @@ -3580,7 +3580,7 @@ void processinput_r(int snum)

p->playerweaponsway(pact->spr.xvel);

pact->spr.xvel = clamp(ksqrt((p->player_int_pos().X - p->bobpos.X) * (p->player_int_pos().X - p->bobpos.X) + (p->player_int_pos().Y - p->bobpos.Y) * (p->player_int_pos().Y - p->bobpos.Y)), 0, 512);
pact->spr.xvel = int(clamp((p->pos.XY() - p->bobpos).Length(), 0., 32.) * worldtoint);
if (p->on_ground) p->bobcounter += p->GetActor()->spr.xvel >> 1;

p->backuppos(ud.clipping == 0 && ((p->insector() && p->cursector->floorpicnum == MIRROR) || !p->insector()));
Expand Down
5 changes: 3 additions & 2 deletions source/games/duke/src/types.h
Expand Up @@ -205,6 +205,7 @@ struct player_struct
{
vec3_t vel;
DVector3 pos, opos;
DVector2 bobpos;

// player's horizon and angle structs.
PlayerHorizon horizon;
Expand All @@ -218,7 +219,7 @@ struct player_struct
PalEntry pals;

// this was a global variable originally.
vec2_t fric, exit, loogie[64], bobpos;
vec2_t fric, exit, loogie[64];

// weapon drawer variables and their interpolation counterparts.
int weapon_sway;
Expand Down Expand Up @@ -379,7 +380,7 @@ struct player_struct

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

void getposfromactor(DCoreActor* actor, double addz = 0)
Expand Down

0 comments on commit d3bfc78

Please sign in to comment.