- changed thinker initialization to occur in a Construct function instead of the constructor itself.

This was done to ensure that this code only runs when the thinker itself is fully set up.
With a constructor there is no control about such things, if some common initialization needs to be done it has to be in the base constructor, but that makes the entire approach chosen here to ensure proper linking into the thinker chains impossible.
ZDoom originally did it that way, which resulted in a very inflexible system and required some awful hacks to let the serializer work with it - the corresponding bSerialOverride flag is now gone.

The only thinker class still having a constructor is DFraggleThinker, because it contains non-serializable data that needs to be initialized in a piece of code that always runs, regardless of whether the object is created explicitly or from a savegame.
This commit is contained in:
Christoph Oelckers 2019-01-27 13:08:54 +01:00
commit e7aa10b5c8
37 changed files with 234 additions and 326 deletions

View file

@ -110,11 +110,12 @@ struct DDecalThinker : public DThinker
HAS_OBJECT_POINTERS
public:
static const int DEFAULT_STAT = STAT_DECALTHINKER;
DDecalThinker (DBaseDecal *decal) : TheDecal (decal) {}
void Construct(DBaseDecal *decal)
{
TheDecal = decal;
}
void Serialize(FSerializer &arc);
TObjPtr<DBaseDecal*> TheDecal;
protected:
DDecalThinker() = default;
};
IMPLEMENT_CLASS(DDecalThinker, false, true)
@ -142,15 +143,16 @@ class DDecalFader : public DDecalThinker
{
DECLARE_CLASS (DDecalFader, DDecalThinker)
public:
DDecalFader (DBaseDecal *decal) : DDecalThinker (decal) {}
void Construct(DBaseDecal *decal)
{
Super::Construct(decal);
}
void Serialize(FSerializer &arc);
void Tick ();
int TimeToStartDecay;
int TimeToEndDecay;
double StartTrans;
private:
DDecalFader () {}
};
struct FDecalColorerAnim : public FDecalAnimator
@ -167,7 +169,10 @@ class DDecalColorer : public DDecalThinker
{
DECLARE_CLASS (DDecalColorer, DDecalThinker)
public:
DDecalColorer (DBaseDecal *decal) : DDecalThinker (decal) {}
void Construct(DBaseDecal *decal)
{
Super::Construct(decal);
}
void Serialize(FSerializer &arc);
void Tick ();
@ -175,8 +180,6 @@ public:
int TimeToEndDecay;
PalEntry StartColor;
PalEntry GoalColor;
private:
DDecalColorer () {}
};
struct FDecalStretcherAnim : public FDecalAnimator
@ -193,7 +196,10 @@ class DDecalStretcher : public DDecalThinker
{
DECLARE_CLASS (DDecalStretcher, DDecalThinker)
public:
DDecalStretcher (DBaseDecal *decal) : DDecalThinker (decal) {}
void Construct(DBaseDecal *decal)
{
Super::Construct(decal);
}
void Serialize(FSerializer &arc);
void Tick ();
@ -206,8 +212,6 @@ public:
bool bStretchX;
bool bStretchY;
bool bStarted;
private:
DDecalStretcher () {}
};
struct FDecalSliderAnim : public FDecalAnimator
@ -224,7 +228,10 @@ class DDecalSlider : public DDecalThinker
{
DECLARE_CLASS (DDecalSlider, DDecalThinker)
public:
DDecalSlider (DBaseDecal *decal) : DDecalThinker (decal) {}
void Construct(DBaseDecal *decal)
{
Super::Construct(decal);
}
void Serialize(FSerializer &arc);
void Tick ();
@ -235,8 +242,6 @@ public:
double StartX;
double StartY;
bool bStarted;
private:
DDecalSlider () {}
};
struct FDecalCombinerAnim : public FDecalAnimator