make various getter and pure-math methods clearscope, and where applicable, const

Original PR: https://github.com/coelckers/gzdoom/pull/532

Status of the original PR

1. Actor
- [already in] deltaangle
- [already in] absangle
- [already in] AngleToVector
- [already in] RotateVector
- [already in] Normalize180
- [already in] BobSin
- [already in] GetDefaultSpeed
- [this PR] GetBobOffset
- [this PR] InStateSequence
- [already in] FindState
- [already in] GetDropItems
- [this PR] DistanceBySpeed
- [this PR] AccuracyFactor
- [not in original PR, for PlayerInfo.isTotallyFrozen] isFrozen

2. PlayerInfo
- [this PR] GetUserName
- [this PR] GetColor
- [this PR] GetDisplayColor
- [this PR] GetColorSet
- [this PR] GetPlayerClassNum
- [this PR] GetSkin
- [this PR] GetNeverSwitch
- [this PR] GetGender
- [this PR] GetTeam
- [this PR] GetAutoaim
- [this PR] GetNoAutostartMap
- [this PR] GetClassicFlight
- [this PR] IsTotallyFrozen

3. C++ methods, to match ZScript:

- [scriptified] AActor::AccuracyFactor() to Actor.AccuracyFactor
- [this PR] AActor::DistanceBySpeed(AActor *, double) — it is a combination of getter and pure math
- [this PR] AActor::Distance2D(AActor *, bool) — called by DistanceBySpeed
- [this PR] AActor::Distance2D(AActor *, double, double, bool) — called by DistanceBySpeed
- [not in original PR, for PlayerInfo.isTotallyFrozen] AActor::isFrozen
This commit is contained in:
Alexander Kromm 2020-06-07 13:47:27 +07:00 committed by Christoph Oelckers
parent 6b4ec2630c
commit 928c738e19
4 changed files with 23 additions and 23 deletions

View file

@ -857,7 +857,7 @@ public:
return (Pos().XY() - otherpos).LengthSquared(); return (Pos().XY() - otherpos).LengthSquared();
} }
double Distance2D(AActor *other, bool absolute = false) double Distance2D(AActor *other, bool absolute = false) const
{ {
DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this); DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this);
return (Pos().XY() - otherpos).Length(); return (Pos().XY() - otherpos).Length();
@ -868,7 +868,7 @@ public:
return DVector2(X() - x, Y() - y).Length(); return DVector2(X() - x, Y() - y).Length();
} }
double Distance2D(AActor *other, double xadd, double yadd, bool absolute = false) double Distance2D(AActor *other, double xadd, double yadd, bool absolute = false) const
{ {
DVector3 otherpos = absolute ? other->Pos() : other->PosRelative(this); DVector3 otherpos = absolute ? other->Pos() : other->PosRelative(this);
return DVector2(X() - otherpos.X + xadd, Y() - otherpos.Y + yadd).Length(); return DVector2(X() - otherpos.X + xadd, Y() - otherpos.Y + yadd).Length();
@ -1433,7 +1433,7 @@ public:
// This is used by many vertical velocity calculations. // This is used by many vertical velocity calculations.
// Better have it in one place, if something needs to be changed about the formula. // Better have it in one place, if something needs to be changed about the formula.
double DistanceBySpeed(AActor *dest, double speed) double DistanceBySpeed(AActor *dest, double speed) const
{ {
return MAX(1., Distance2D(dest) / speed); return MAX(1., Distance2D(dest) / speed);
} }
@ -1441,7 +1441,7 @@ public:
int ApplyDamageFactor(FName damagetype, int damage) const; int ApplyDamageFactor(FName damagetype, int damage) const;
int GetModifiedDamage(FName damagetype, int damage, bool passive, AActor *inflictor, AActor *source, int flags = 0); int GetModifiedDamage(FName damagetype, int damage, bool passive, AActor *inflictor, AActor *source, int flags = 0);
void DeleteAttachedLights(); void DeleteAttachedLights();
bool isFrozen(); bool isFrozen() const;
bool hasmodel; bool hasmodel;
}; };

View file

@ -157,7 +157,7 @@ inline DVector3 AActor::Vec3Angle(double length, DAngle angle, double dz, bool a
} }
} }
inline bool AActor::isFrozen() inline bool AActor::isFrozen() const
{ {
if (!(flags5 & MF5_NOTIMEFREEZE)) if (!(flags5 & MF5_NOTIMEFREEZE))
{ {

View file

@ -450,7 +450,7 @@ class Actor : Thinker native
return sin(fb * (180./32)) * 8; return sin(fb * (180./32)) * 8;
} }
native bool isFrozen(); native clearscope bool isFrozen() const;
virtual native void BeginPlay(); virtual native void BeginPlay();
virtual native void Activate(Actor activator); virtual native void Activate(Actor activator);
virtual native void Deactivate(Actor activator); virtual native void Deactivate(Actor activator);
@ -607,7 +607,7 @@ class Actor : Thinker native
native clearscope string GetTag(string defstr = "") const; native clearscope string GetTag(string defstr = "") const;
native void SetTag(string defstr = ""); native void SetTag(string defstr = "");
native double GetBobOffset(double frac = 0); native clearscope double GetBobOffset(double frac = 0) const;
native void ClearCounters(); native void ClearCounters();
native bool GiveBody (int num, int max=0); native bool GiveBody (int num, int max=0);
native bool HitFloor(); native bool HitFloor();
@ -703,7 +703,7 @@ class Actor : Thinker native
native void FindFloorCeiling(int flags = 0); native void FindFloorCeiling(int flags = 0);
native double, double GetFriction(); native double, double GetFriction();
native bool, Actor TestMobjZ(bool quick = false); native bool, Actor TestMobjZ(bool quick = false);
native static bool InStateSequence(State newstate, State basestate); native clearscope static bool InStateSequence(State newstate, State basestate);
bool TryWalk () bool TryWalk ()
{ {
@ -751,7 +751,7 @@ class Actor : Thinker native
native bool LookForEnemies(bool allaround, LookExParams params = null); native bool LookForEnemies(bool allaround, LookExParams params = null);
native bool LookForPlayers(bool allaround, LookExParams params = null); native bool LookForPlayers(bool allaround, LookExParams params = null);
native bool TeleportMove(Vector3 pos, bool telefrag, bool modifyactor = true); native bool TeleportMove(Vector3 pos, bool telefrag, bool modifyactor = true);
native double DistanceBySpeed(Actor other, double speed); native clearscope double DistanceBySpeed(Actor other, double speed) const;
native name GetSpecies(); native name GetSpecies();
native void PlayActiveSound(); native void PlayActiveSound();
native void Howl(); native void Howl();
@ -787,7 +787,7 @@ class Actor : Thinker native
return level.totaltime - SpawnTime; return level.totaltime - SpawnTime;
} }
double AccuracyFactor() clearscope double AccuracyFactor() const
{ {
return 1. / (1 << (accuracy * 5 / 100)); return 1. / (1 << (accuracy * 5 / 100));
} }

View file

@ -2698,23 +2698,23 @@ struct PlayerInfo native play // self is what internally is known as player_t
native void SetSubtitleNumber (int text, Sound sound_id = 0); native void SetSubtitleNumber (int text, Sound sound_id = 0);
native bool Resurrect(); native bool Resurrect();
native String GetUserName() const; native clearscope String GetUserName() const;
native Color GetColor() const; native clearscope Color GetColor() const;
native Color GetDisplayColor() const; native clearscope Color GetDisplayColor() const;
native int GetColorSet() const; native clearscope int GetColorSet() const;
native int GetPlayerClassNum() const; native clearscope int GetPlayerClassNum() const;
native int GetSkin() const; native clearscope int GetSkin() const;
native bool GetNeverSwitch() const; native clearscope bool GetNeverSwitch() const;
native int GetGender() const; native clearscope int GetGender() const;
native int GetTeam() const; native clearscope int GetTeam() const;
native float GetAutoaim() const; native clearscope float GetAutoaim() const;
native bool GetNoAutostartMap() const; native clearscope bool GetNoAutostartMap() const;
native double GetWBobSpeed() const; native double GetWBobSpeed() const;
native double GetWBobFire() const; native double GetWBobFire() const;
native double GetMoveBob() const; native double GetMoveBob() const;
native double GetStillBob() const; native double GetStillBob() const;
native void SetFOV(float fov); native void SetFOV(float fov);
native bool GetClassicFlight() const; native clearscope bool GetClassicFlight() const;
native void SendPitchLimits(); native void SendPitchLimits();
native clearscope bool HasWeaponsInSlot(int slot) const; native clearscope bool HasWeaponsInSlot(int slot) const;
@ -2751,7 +2751,7 @@ struct PlayerInfo native play // self is what internally is known as player_t
if (mo) mo.BringUpWeapon(); if (mo) mo.BringUpWeapon();
} }
bool IsTotallyFrozen() clearscope bool IsTotallyFrozen() const
{ {
return return
gamestate == GS_TITLELEVEL || gamestate == GS_TITLELEVEL ||