Skip to content

Commit

Permalink
Fix #806 and address teleport interpolation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pbdot committed Jan 12, 2025
1 parent ab56909 commit b121ef0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 29 deletions.
13 changes: 5 additions & 8 deletions source_files/edge/p_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,6 @@ void A_TurnRandom(MapObject *mo)
}





void A_MoveFwd(MapObject *mo)
{
const State *st = mo->state_;
Expand All @@ -1095,8 +1092,7 @@ void A_MoveFwd(MapObject *mo)
float dx = epi::BAMCos(mo->angle_);
float dy = epi::BAMSin(mo->angle_);

mo->momentum_.X += dx * amount;
mo->momentum_.Y += dy * amount;
mo->AddMomentum(dx * amount, dy * amount, 0);
}
}

Expand All @@ -1111,8 +1107,7 @@ void A_MoveRight(MapObject *mo)
float dx = epi::BAMCos(mo->angle_ - kBAMAngle90);
float dy = epi::BAMSin(mo->angle_ - kBAMAngle90);

mo->momentum_.X += dx * amount;
mo->momentum_.Y += dy * amount;
mo->AddMomentum(dx * amount, dy * amount, 0);
}
}

Expand All @@ -1121,7 +1116,9 @@ void A_MoveUp(MapObject *mo)
const State *st = mo->state_;

if (st && st->action_par)
mo->momentum_.Z += *(float *)st->action_par;
{
mo->AddMomentum(0, 0, *(float *)st->action_par);
}
}

void A_StopMoving(MapObject *mo)
Expand Down
19 changes: 14 additions & 5 deletions source_files/edge/p_enemy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "s_sound.h"
#include "w_wad.h"

extern ConsoleVariable uncapped_frames;

DirectionType opposite[] = {kDirectionWest, kDirectionSouthwest, kDirectionSouth,
kDirectionSoutheast, kDirectionEast, kDirectionNorthEast,
kDirectionNorth, kDirectionNorthWest, kDirectionNone};
Expand Down Expand Up @@ -271,10 +273,17 @@ bool DoMove(MapObject *actor, bool path)
// -AJA- 2008/01/16: position interpolation
if ((actor->state_->flags & kStateFrameFlagModel) || (actor->flags_ & kMapObjectFlagFloat))
{
actor->interpolation_number_ = HMM_Clamp(2, actor->state_->tics, 10);
actor->interpolation_position_ = 1;
if (!uncapped_frames.d_ || actor->old_x_ != kInvalidPosition)
{
actor->interpolation_number_ = HMM_Clamp(2, actor->state_->tics, 10);
actor->interpolation_position_ = 1;

actor->interpolation_from_ = orig_pos;
actor->interpolation_from_ = orig_pos;
}
else
{
actor->interpolation_number_ = 0;
}
}

return true;
Expand Down Expand Up @@ -517,8 +526,8 @@ bool LookForPlayers(MapObject *actor, BAMAngle range, bool ToSupport)
actor->SetSupportObject(player->map_object_);
else // target the player
actor->SetTarget(player->map_object_);
return true;

return true;

}

Expand Down
32 changes: 23 additions & 9 deletions source_files/edge/p_mobj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ bool MapObject::IsRemoved() const
return state_ == nullptr;
}

bool MapObject::IsSpawning()
{
if (!info_ || !info_->spawn_state_)
{
return false;
}

return state_ == &states[info_->spawn_state_];
}

void MapObject::AddMomentum(float xm, float ym, float zm)
{
momentum_.X += xm;
momentum_.Y += ym;
momentum_.Z += zm;

if (IsSpawning())
{
old_x_ = old_y_ = old_z_ = kInvalidPosition;
}
}

#if 1 // DEBUGGING
void P_DumpMobjs(void)
{
Expand Down Expand Up @@ -1354,15 +1376,7 @@ static void P_MobjThinker(MapObject *mobj)

if (!(mobj->player_ != NULL && mobj == mobj->player_->map_object_))
{
// Assume we can interpolate at the beginning
// of the tic unless mid-teleport
if (mobj->teleport_tic_)
{
mobj->teleport_tic_--;
mobj->interpolate_ = false;
}
else
mobj->interpolate_ = true;
mobj->interpolate_ = mobj->old_x_ == kInvalidPosition ? false : true;

// Store starting position for mobj interpolation.
mobj->old_x_ = mobj->x;
Expand Down
8 changes: 6 additions & 2 deletions source_files/edge/p_mobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ struct DynamicLightState
bool bad_wall_glow = false;
};

constexpr float kInvalidPosition = -999999.0f;

// Map Object definition.
struct Position
{
Expand Down Expand Up @@ -378,8 +380,6 @@ class MapObject : public Position

bool slope_sight_hit_ = false;

int teleport_tic_ = 0;

// Uncapped test - Dasho
bool interpolate_ = false;

Expand All @@ -394,6 +394,10 @@ class MapObject : public Position
void SetBelowObject(MapObject *ref);
void SetRealSource(MapObject *ref);

bool IsSpawning();

void AddMomentum(float xm, float ym, float zm);

void ClearStaleReferences();

// Stores what this mobj was before being MORPHed/BECOMEing
Expand Down
4 changes: 3 additions & 1 deletion source_files/edge/p_telept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ bool TeleportMapObject(Line *line, int tag, MapObject *thing, const TeleportDefi
player->delta_view_height_ = 0;
}
else
thing->teleport_tic_ = 18;
{
thing->old_x_ = thing->old_y_ = thing->old_z_ = kInvalidPosition;
}

/* --- Momentum handling --- */

Expand Down
5 changes: 1 addition & 4 deletions source_files/edge/r_things.cc
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,6 @@ void BSPWalkThing(DrawSubsector *dsub, MapObject *mo)
if (AlmostEquals(mo->visibility_, 0.0f))
return;

// ignore things that are mid-teleport
if (mo->teleport_tic_ > 0)
return;

bool is_model = (mo->state_->flags & kStateFrameFlagModel) ? true : false;

// transform the origin point
Expand All @@ -868,6 +864,7 @@ void BSPWalkThing(DrawSubsector *dsub, MapObject *mo)
fz = mo->floor_z_;
}

// This applies to kStateFrameFlagModel and kMapObjectFlagFloat
if (mo->interpolation_number_ > 1)
{
float along = mo->interpolation_position_ / (float)mo->interpolation_number_;
Expand Down

0 comments on commit b121ef0

Please sign in to comment.