Skip to content

Commit

Permalink
Replace trajectories' flag with similar rtti as game abstractclass
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Oct 4, 2024
1 parent 27530fa commit b6f96c9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/Ext/Bullet/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ DEFINE_HOOK(0x467CCA, BulletClass_AI_TargetSnapChecks, 0x6)
}
else if (auto const pExt = BulletAITemp::ExtData)
{
if (pExt->Trajectory)
if (auto pTraj = pExt->Trajectory.get())
{
if (pExt->Trajectory->Flag == TrajectoryFlag::Straight)
if (pTraj->Flag() == TrajectoryFlag::Straight)
{
R->EAX(pThis->Type);
return SkipChecks;
Expand Down Expand Up @@ -336,7 +336,7 @@ DEFINE_HOOK(0x468E61, BulletClass_Explode_TargetSnapChecks1, 0x6)
}
else if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory && pExt->Trajectory->Flag == TrajectoryFlag::Straight && !pExt->SnappedToTarget)
if (pExt->Trajectory && pExt->Trajectory->Flag() == TrajectoryFlag::Straight && !pExt->SnappedToTarget)
{
R->EAX(pThis->Type);
return SkipChecks;
Expand Down Expand Up @@ -367,7 +367,7 @@ DEFINE_HOOK(0x468E9F, BulletClass_Explode_TargetSnapChecks2, 0x6)
// Fixes issues with walls etc.
if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory && pExt->Trajectory->Flag == TrajectoryFlag::Straight && !pExt->SnappedToTarget)
if (pExt->Trajectory && pExt->Trajectory->Flag() == TrajectoryFlag::Straight && !pExt->SnappedToTarget)
return SkipSetCoordinate;
}

Expand All @@ -382,7 +382,7 @@ DEFINE_HOOK(0x468D3F, BulletClass_ShouldExplode_AirTarget, 0x6)

if (auto const pExt = BulletExt::ExtMap.Find(pThis))
{
if (pExt->Trajectory && pExt->Trajectory->Flag == TrajectoryFlag::Straight)
if (pExt->Trajectory && pExt->Trajectory->Flag() == TrajectoryFlag::Straight)
return SkipCheck;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class BombardTrajectoryType final : public PhobosTrajectoryType
{
public:
BombardTrajectoryType() : PhobosTrajectoryType(TrajectoryFlag::Bombard)
BombardTrajectoryType() : PhobosTrajectoryType()
, Height { 0.0 }
{ }

virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override;
virtual bool Save(PhobosStreamWriter& Stm) const override;
virtual std::unique_ptr<PhobosTrajectory> CreateInstance() const override;

virtual TrajectoryFlag Flag() const { return TrajectoryFlag::Bombard; }
virtual void Read(CCINIClass* const pINI, const char* pSection) override;

Valueable<double> Height;
Expand All @@ -27,14 +27,14 @@ class BombardTrajectory final : public PhobosTrajectory
public:
BombardTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { }

BombardTrajectory(BombardTrajectoryType const* trajType) : PhobosTrajectory(TrajectoryFlag::Bombard, trajType->Trajectory_Speed)
BombardTrajectory(BombardTrajectoryType const* trajType) : PhobosTrajectory(trajType->Trajectory_Speed)
, IsFalling { false }
, Height { trajType->Height }
{ }

virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override;
virtual bool Save(PhobosStreamWriter& Stm) const override;

virtual TrajectoryFlag Flag() const { return TrajectoryFlag::Bombard; }
virtual void OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity) override;
virtual bool OnAI(BulletClass* pBullet) override;
virtual void OnAIPreDetonate(BulletClass* pBullet) override { };
Expand Down
15 changes: 6 additions & 9 deletions src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TrajectoryTypePointer::TrajectoryTypePointer(TrajectoryFlag flag)
_ptr = std::make_unique<StraightTrajectoryType>();
return;
case TrajectoryFlag::Bombard:
_ptr = std::make_unique<StraightTrajectoryType>();
_ptr = std::make_unique<BombardTrajectoryType>();
return;
}
_ptr.reset();
Expand Down Expand Up @@ -56,7 +56,7 @@ void TrajectoryTypePointer::LoadFromINI(CCINIClass* pINI, const char* pSection)
flag.Read(exINI, pSection, "Trajectory");// I assume this shit is parsed once and only once, so I keep the impl here
if (flag.isset())
{
if (!_ptr || _ptr->Flag != flag.Get())
if (!_ptr || _ptr->Flag() != flag.Get())
std::construct_at(this, flag.Get());
}
if (_ptr)
Expand Down Expand Up @@ -87,7 +87,8 @@ bool TrajectoryTypePointer::Save(PhobosStreamWriter& Stm) const
Stm.Process(raw);
if (raw)
{
Stm.Process(raw->Flag);
auto rtti = raw->Flag();
Stm.Process(rtti);
return raw->Save(Stm);
}
return true;
Expand Down Expand Up @@ -116,7 +117,6 @@ bool TrajectoryPointer::Load(PhobosStreamReader& Stm, bool registerForChange)
if (_ptr.get())
{
// PhobosSwizzle::RegisterChange(PTR, _ptr.get()); // not used elsewhere yet, if anyone does then reenable this shit
_ptr->Flag = flag;
return _ptr->Load(Stm, registerForChange);
}
}
Expand All @@ -129,7 +129,8 @@ bool TrajectoryPointer::Save(PhobosStreamWriter& Stm) const
Stm.Process(raw);
if (raw)
{
Stm.Process(raw->Flag);
auto rtti = raw->Flag();
Stm.Process(rtti);
return raw->Save(Stm);
}
return true;
Expand All @@ -140,23 +141,20 @@ bool TrajectoryPointer::Save(PhobosStreamWriter& Stm) const
bool PhobosTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChange)
{
Stm
.Process(this->Flag)
.Process(this->Trajectory_Speed);
return true;
}

bool PhobosTrajectoryType::Save(PhobosStreamWriter& Stm) const
{
Stm
.Process(this->Flag)
.Process(this->Trajectory_Speed);
return true;
}

bool PhobosTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
{
Stm
.Process(this->Flag)
.Process(this->Speed)
;
return true;
Expand All @@ -165,7 +163,6 @@ bool PhobosTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
bool PhobosTrajectory::Save(PhobosStreamWriter& Stm) const
{
Stm
.Process(this->Flag, false)
.Process(this->Speed)
;
return true;
Expand Down
12 changes: 4 additions & 8 deletions src/Ext/Bullet/Trajectories/PhobosTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,35 @@ class PhobosTrajectoryType
{
public:
PhobosTrajectoryType() { }
PhobosTrajectoryType(TrajectoryFlag flag) : Flag { flag }, Trajectory_Speed { 100.0 }
{ }

virtual ~PhobosTrajectoryType() noexcept = default;
virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange);
virtual bool Save(PhobosStreamWriter& Stm) const;

virtual TrajectoryFlag Flag() const = 0;
virtual void Read(CCINIClass* const pINI, const char* pSection) = 0;
virtual std::unique_ptr<PhobosTrajectory> CreateInstance() const = 0;

TrajectoryFlag Flag;
Valueable<double> Trajectory_Speed;
Valueable<double> Trajectory_Speed { 100.0 };
};

class PhobosTrajectory
{
public:
PhobosTrajectory(noinit_t) { }
PhobosTrajectory(TrajectoryFlag flag, double speed = 100.0) : Flag { flag }, Speed { speed }
PhobosTrajectory(double speed = 100.0) : Speed { speed }
{ }

virtual ~PhobosTrajectory() noexcept = default;
virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange);
virtual bool Save(PhobosStreamWriter& Stm) const;

virtual TrajectoryFlag Flag() const = 0;
virtual void OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity) = 0;
virtual bool OnAI(BulletClass* pBullet) = 0;
virtual void OnAIPreDetonate(BulletClass* pBullet) = 0;
virtual void OnAIVelocity(BulletClass* pBullet, BulletVelocity* pSpeed, BulletVelocity* pPosition) = 0;
virtual TrajectoryCheckReturnType OnAITargetCoordCheck(BulletClass* pBullet) = 0;
virtual TrajectoryCheckReturnType OnAITechnoCheck(BulletClass* pBullet, TechnoClass* pTechno) = 0;

TrajectoryFlag Flag;
double Speed;
};

Expand Down
8 changes: 4 additions & 4 deletions src/Ext/Bullet/Trajectories/StraightTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class StraightTrajectoryType final : public PhobosTrajectoryType
{
public:
StraightTrajectoryType() : PhobosTrajectoryType(TrajectoryFlag::Straight)
StraightTrajectoryType() : PhobosTrajectoryType()
, DetonationDistance { Leptons(102) }
, ApplyRangeModifiers { false }
, TargetSnapDistance { Leptons(128) }
Expand All @@ -16,7 +16,7 @@ class StraightTrajectoryType final : public PhobosTrajectoryType
virtual bool Save(PhobosStreamWriter& Stm) const override;
virtual std::unique_ptr<PhobosTrajectory> CreateInstance() const override;
virtual void Read(CCINIClass* const pINI, const char* pSection) override;

virtual TrajectoryFlag Flag() const { return TrajectoryFlag::Straight; }
Valueable<Leptons> DetonationDistance;
Valueable<bool> ApplyRangeModifiers;
Valueable<Leptons> TargetSnapDistance;
Expand All @@ -32,7 +32,7 @@ class StraightTrajectory final : public PhobosTrajectory
public:
StraightTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { }

StraightTrajectory(StraightTrajectoryType const* trajType) : PhobosTrajectory(TrajectoryFlag::Straight, trajType->Trajectory_Speed)
StraightTrajectory(StraightTrajectoryType const* trajType) : PhobosTrajectory(trajType->Trajectory_Speed)
, DetonationDistance { trajType->DetonationDistance }
, TargetSnapDistance { trajType->TargetSnapDistance }
, FirerZPosition { 0 }
Expand All @@ -42,7 +42,7 @@ class StraightTrajectory final : public PhobosTrajectory

virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override;
virtual bool Save(PhobosStreamWriter& Stm) const override;

virtual TrajectoryFlag Flag() const { return TrajectoryFlag::Straight; }
virtual void OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity) override;
virtual bool OnAI(BulletClass* pBullet) override;
virtual void OnAIPreDetonate(BulletClass* pBullet) override;
Expand Down

0 comments on commit b6f96c9

Please sign in to comment.