Skip to content

Commit

Permalink
Short demo on refactoring new trajectories' boilerplates
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Oct 2, 2024
1 parent 78ed44a commit a236394
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ bool BombardTrajectoryType::Save(PhobosStreamWriter& Stm) const

void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
{
this->Height = pINI->ReadDouble(pSection, "Trajectory.Bombard.Height", 0.0);
INI_EX exINI(pINI);
this->Height.Read(exINI, pSection, "Trajectory.Bombard.Height");
}

template<typename T>
Expand Down Expand Up @@ -61,7 +62,7 @@ bool BombardTrajectory::Save(PhobosStreamWriter& Stm) const

void BombardTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity)
{
this->Height = this->GetTrajectoryType<BombardTrajectoryType>(pBullet)->Height + pBullet->TargetCoords.Z;
this->Height += pBullet->TargetCoords.Z;

pBullet->Velocity.X = static_cast<double>(pBullet->TargetCoords.X - pBullet->SourceCoords.X);
pBullet->Velocity.Y = static_cast<double>(pBullet->TargetCoords.Y - pBullet->SourceCoords.Y);
Expand Down
6 changes: 3 additions & 3 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BombardTrajectoryType final : public PhobosTrajectoryType

virtual void Read(CCINIClass* const pINI, const char* pSection) override;

double Height;
Valueable<double> Height;

private:
template <typename T>
Expand All @@ -27,9 +27,9 @@ class BombardTrajectory final : public PhobosTrajectory
public:
BombardTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { }

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

virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override;
Expand Down
10 changes: 6 additions & 4 deletions src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "BombardTrajectory.h"
#include "StraightTrajectory.h"

#pragma region RedoAllThesePleaseItsInFactVerySimpleJustFollowTemplateDef_h
bool PhobosTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChange)
{
Stm.Process(this->Flag, false);
Expand Down Expand Up @@ -56,7 +56,7 @@ PhobosTrajectoryType* PhobosTrajectoryType::LoadFromStream(PhobosStreamReader& S
if (pType)
{
Stm.Process(flag, false);

auto old = pType;
switch (flag)
{
case TrajectoryFlag::Straight:
Expand All @@ -71,6 +71,7 @@ PhobosTrajectoryType* PhobosTrajectoryType::LoadFromStream(PhobosStreamReader& S

pType->Flag = flag;
pType->Load(Stm, false);
PhobosSwizzle::RegisterChange(old, pType);
}

return pType;
Expand Down Expand Up @@ -128,7 +129,7 @@ PhobosTrajectory* PhobosTrajectory::LoadFromStream(PhobosStreamReader& Stm)
if (pTraj)
{
Stm.Process(flag, false);

auto old = pTraj;
switch (flag)
{
case TrajectoryFlag::Straight:
Expand All @@ -143,6 +144,7 @@ PhobosTrajectory* PhobosTrajectory::LoadFromStream(PhobosStreamReader& Stm)

pTraj->Flag = flag;
pTraj->Load(Stm, false);
PhobosSwizzle::RegisterChange(old, pTraj);
}

return pTraj;
Expand All @@ -169,7 +171,7 @@ PhobosTrajectory* PhobosTrajectory::ProcessFromStream(PhobosStreamWriter& Stm, P
WriteToStream(Stm, pTraj);
return pTraj;
}

#pragma endregion

DEFINE_HOOK(0x4666F7, BulletClass_AI_Trajectories, 0x6)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Ext/Bullet/Trajectories/StraightTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,10 @@ bool StraightTrajectory::Save(PhobosStreamWriter& Stm) const
void StraightTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity)
{
auto const pType = this->GetTrajectoryType<StraightTrajectoryType>(pBullet);
this->DetonationDistance = pType->DetonationDistance;

if (pType->ApplyRangeModifiers)
this->DetonationDistance = Leptons(WeaponTypeExt::GetRangeWithModifiers(pBullet->WeaponType, pBullet->Owner, this->DetonationDistance));

this->TargetSnapDistance = pType->TargetSnapDistance;
this->PassThrough = pType->PassThrough;
this->FirerZPosition = this->GetFirerZPosition(pBullet);
this->TargetZPosition = this->GetTargetZPosition(pBullet);

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 @@ -32,10 +32,10 @@ class StraightTrajectory final : public PhobosTrajectory
public:
StraightTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { }

StraightTrajectory(PhobosTrajectoryType const* pType) : PhobosTrajectory(TrajectoryFlag::Straight)
, DetonationDistance { Leptons(102) }
, TargetSnapDistance { Leptons(128) }
, PassThrough { false }
StraightTrajectory(StraightTrajectoryType const* trajType) : PhobosTrajectory(TrajectoryFlag::Straight)
, DetonationDistance { trajType->DetonationDistance }
, TargetSnapDistance { trajType->TargetSnapDistance }
, PassThrough { trajType->PassThrough }
, FirerZPosition { 0 }
, TargetZPosition { 0 }
{}
Expand Down

0 comments on commit a236394

Please sign in to comment.