- implement proper GC handling for AActor::ViewPos.

This commit is contained in:
Christoph Oelckers 2022-04-02 07:52:22 +02:00
parent 4049a0d8f1
commit 27cba4c990
6 changed files with 13 additions and 12 deletions

View file

@ -660,9 +660,9 @@ enum EViewPosFlags // [MC] Flags for SetViewPos.
VPSF_ABSOLUTEPOS = 1 << 2, // Use absolute position.
};
class FViewPosition : public DObject
class DViewPosition : public DObject
{
DECLARE_CLASS(FViewPosition, DObject);
DECLARE_CLASS(DViewPosition, DObject);
public:
// Variables
// Exposed to ZScript
@ -670,7 +670,7 @@ public:
int Flags;
// Functions
FViewPosition()
DViewPosition()
{
Offset = { 0,0,0 };
Flags = 0;
@ -1011,7 +1011,7 @@ public:
DAngle SpriteRotation;
DRotator Angles;
DRotator ViewAngles; // Angle offsets for cameras
FViewPosition *ViewPos; // Position offsets for cameras
TObjPtr<DViewPosition*> ViewPos; // Position offsets for cameras
DVector2 Scale; // Scaling values; 1 is normal size
double Alpha; // Since P_CheckSight makes an alpha check this can't be a float. It has to be a double.

View file

@ -50,7 +50,7 @@ struct secplane_t;
struct FCheckPosition;
struct FTranslatedLineTarget;
struct FLinePortal;
class FViewPosition;
class DViewPosition;
#include <stdlib.h>
@ -394,7 +394,7 @@ void P_PlaySpawnSound(AActor *missile, AActor *spawner);
void P_AimCamera (AActor *t1, DVector3 &, DAngle &, sector_t *&sec, bool &unlinked);
// [MC] Aiming for ViewPos
void P_AdjustViewPos(AActor *t1, DVector3 orig, DVector3 &, sector_t *&sec, bool &unlinked, FViewPosition *VP);
void P_AdjustViewPos(AActor *t1, DVector3 orig, DVector3 &, sector_t *&sec, bool &unlinked, DViewPosition *VP);
// [RH] Means of death

View file

@ -5424,7 +5424,7 @@ void P_AimCamera(AActor *t1, DVector3 &campos, DAngle &camangle, sector_t *&Came
}
// [MC] Used for ViewPos. Uses code borrowed from P_AimCamera.
void P_AdjustViewPos(AActor *t1, DVector3 orig, DVector3 &campos, sector_t *&CameraSector, bool &unlinked, FViewPosition *VP)
void P_AdjustViewPos(AActor *t1, DVector3 orig, DVector3 &campos, sector_t *&CameraSector, bool &unlinked, DViewPosition *VP)
{
FTraceResults trace;
const DVector3 vvec = campos - orig;

View file

@ -171,6 +171,7 @@ IMPLEMENT_POINTERS_START(AActor)
IMPLEMENT_POINTER(master)
IMPLEMENT_POINTER(Poisoner)
IMPLEMENT_POINTER(alternative)
IMPLEMENT_POINTER(ViewPos)
IMPLEMENT_POINTERS_END
AActor::~AActor ()

View file

@ -793,7 +793,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
// Handles offsetting the camera with ChaseCam and/or viewpos.
{
AActor *mo = viewpoint.camera;
FViewPosition *VP = mo->ViewPos;
DViewPosition *VP = mo->ViewPos;
const DVector3 orig = { mo->Pos().XY(), mo->player ? mo->player->viewz : mo->Z() + mo->GetCameraHeight() };
viewpoint.ActorPos = orig;

View file

@ -1821,7 +1821,7 @@ static void SetViewPos(AActor *self, double x, double y, double z, int flags)
{
if (!self->ViewPos)
{
self->ViewPos = Create<FViewPosition>();
self->ViewPos = Create<DViewPosition>();
}
DVector3 pos = { x,y,z };
@ -1839,9 +1839,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetViewPos, SetViewPos)
return 0;
}
IMPLEMENT_CLASS(FViewPosition, false, false);
DEFINE_FIELD_X(ViewPosition, FViewPosition, Offset)
DEFINE_FIELD_X(ViewPosition, FViewPosition, Flags)
IMPLEMENT_CLASS(DViewPosition, false, false);
DEFINE_FIELD_X(ViewPosition, DViewPosition, Offset)
DEFINE_FIELD_X(ViewPosition, DViewPosition, Flags)
DEFINE_FIELD(DThinker, Level)
DEFINE_FIELD(AActor, snext)