Added weapon interpolation.

This commit is contained in:
Leonard 2015-08-19 15:59:54 +02:00
commit 86e9504d04
8 changed files with 254 additions and 4 deletions

View file

@ -151,6 +151,35 @@ public:
};
//==========================================================================
//
//
//
//==========================================================================
class DPSpriteInterpolation : public DInterpolation
{
DECLARE_CLASS(DPSpriteInterpolation, DInterpolation)
pspdef_t *psp;
int player, position;
fixed_t oldx, oldy;
fixed_t bakx, baky;
fixed_t ofsx, ofsy;
fixed_t nfsx, nfsy;
public:
DPSpriteInterpolation() {}
DPSpriteInterpolation(pspdef_t *psp, int player, int position);
void UpdatePointer(int player);
void Destroy();
void UpdateInterpolation();
void Restore();
void Interpolate(fixed_t smoothratio);
void Serialize(FArchive &arc);
};
//==========================================================================
//
//
@ -162,6 +191,7 @@ IMPLEMENT_CLASS(DSectorPlaneInterpolation)
IMPLEMENT_CLASS(DSectorScrollInterpolation)
IMPLEMENT_CLASS(DWallScrollInterpolation)
IMPLEMENT_CLASS(DPolyobjInterpolation)
IMPLEMENT_CLASS(DPSpriteInterpolation)
//==========================================================================
//
@ -628,7 +658,6 @@ void DSectorScrollInterpolation::Serialize(FArchive &arc)
arc << sector << ceiling << oldx << oldy;
}
//==========================================================================
//
//
@ -824,6 +853,115 @@ void DPolyobjInterpolation::Serialize(FArchive &arc)
if (arc.IsLoading()) bakverts.Resize(oldverts.Size());
}
//==========================================================================
//
//
//
//==========================================================================
//==========================================================================
//
//
//
//==========================================================================
DPSpriteInterpolation::DPSpriteInterpolation(pspdef_t *_psp, int _player, int _position)
: nfsx(0), nfsy(0), ofsx(0), ofsy(0)
{
psp = _psp;
player = _player;
position = _position;
UpdateInterpolation ();
interpolator.AddInterpolation(this);
}
//==========================================================================
//
//
//
//==========================================================================
void DPSpriteInterpolation::UpdatePointer(int _player)
{
player = _player;
psp = &players[player].psprites[position];
}
//==========================================================================
//
//
//
//==========================================================================
void DPSpriteInterpolation::Destroy()
{
psp->interpolation = NULL;
Super::Destroy();
}
//==========================================================================
//
//
//
//==========================================================================
void DPSpriteInterpolation::UpdateInterpolation()
{
if ( position == ps_weapon )
P_BobWeapon( &players[player], psp, &ofsx, &ofsy );
oldx = psp->sx + ofsx;
oldy = psp->sy + ofsy;
}
//==========================================================================
//
//
//
//==========================================================================
void DPSpriteInterpolation::Restore()
{
psp->sx = bakx - nfsx;
psp->sy = baky - nfsy;
}
//==========================================================================
//
//
//
//==========================================================================
void DPSpriteInterpolation::Interpolate(fixed_t smoothratio)
{
if ( position == ps_weapon )
P_BobWeapon( &players[player], psp, &nfsx, &nfsy );
bakx = psp->sx + nfsx;
baky = psp->sy + nfsy;
psp->sx = oldx + FixedMul(bakx - oldx, smoothratio) - nfsx;
psp->sy = oldy + FixedMul(baky - oldy, smoothratio) - nfsy;
}
//==========================================================================
//
//
//
//==========================================================================
void DPSpriteInterpolation::Serialize(FArchive &arc)
{
Super::Serialize(arc);
arc << player << position << oldx << oldy << ofsx << ofsy;
UpdatePointer(player);
}
//==========================================================================
//
//
//
//==========================================================================
//==========================================================================
//
@ -944,6 +1082,63 @@ void FPolyObj::StopInterpolation()
}
}
//==========================================================================
//
//
//
//==========================================================================
DInterpolation *pspdef_t::SetInterpolation(int player, int position)
{
if (interpolation == NULL)
{
interpolation = new DPSpriteInterpolation(this, player, position);
}
interpolation->AddRef();
GC::WriteBarrier(interpolation);
return interpolation;
}
//==========================================================================
//
//
//
//==========================================================================
void pspdef_t::UpdateInterpolation(int player)
{
if (interpolation != NULL)
{
DInterpolation *pointer = interpolation;
static_cast<DPSpriteInterpolation *>(pointer)->UpdatePointer(player);
}
}
//==========================================================================
//
//
//
//==========================================================================
void pspdef_t::StopInterpolation()
{
if (interpolation != NULL)
{
interpolation->DelRef();
}
}
//==========================================================================
//
//
//
//==========================================================================
//==========================================================================
//
//
//
//==========================================================================
ADD_STAT (interpolations)
{
@ -951,5 +1146,3 @@ ADD_STAT (interpolations)
out.Format ("%d interpolations", interpolator.CountInterpolations ());
return out;
}