From 33fb76698bd8d05000c2b28c370dfaea0b783f5f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 15:25:37 +0100 Subject: [PATCH] Avoid using argument count for any kind of decision making in native VM functions. This allows retaining the functionality, even if for the JIT compiler's benefit all default arguments are pushed onto the stack instead of reading them from the defaults array. --- src/p_enemy.cpp | 6 +++--- src/p_mobj.cpp | 21 ++++++++++++--------- src/p_sectors.cpp | 3 ++- src/r_data/r_sections.h | 4 ++-- wadsrc/static/zscript/actor.txt | 8 ++++---- wadsrc/static/zscript/mapdata.txt | 2 +- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index f49da9983..14715608b 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -2976,17 +2976,17 @@ DEFINE_ACTION_FUNCTION(AActor, A_Chase) PARAM_STATE_DEF (missile) PARAM_INT_DEF (flags) - if (numparam > 1) + if (melee != nullptr || missile != nullptr || flags != 0x40000000) { if ((flags & CHF_RESURRECT) && P_CheckForResurrection(self, false)) return 0; A_DoChase(self, !!(flags&CHF_FASTCHASE), melee, missile, !(flags&CHF_NOPLAYACTIVE), - !!(flags&CHF_NIGHTMAREFAST), !!(flags&CHF_DONTMOVE), flags); + !!(flags&CHF_NIGHTMAREFAST), !!(flags&CHF_DONTMOVE), flags & 0x3fffffff); } else // this is the old default A_Chase { - A_DoChase(self, false, self->MeleeState, self->MissileState, true, gameinfo.nightmarefast, false, flags); + A_DoChase(self, false, self->MeleeState, self->MissileState, true, gameinfo.nightmarefast, false, 0); } return 0; } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 8f2cf64ff..ef77b77d3 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -7432,7 +7432,7 @@ DEFINE_ACTION_FUNCTION(AActor, SpawnPlayerMissile) PARAM_BOOL_DEF(noautoaim); PARAM_INT_DEF(aimflags); AActor *missileactor; - if (numparam == 2) angle = self->Angles.Yaw; + if (angle == 1e37) angle = self->Angles.Yaw; AActor *misl = P_SpawnPlayerMissile(self, x, y, z, type, angle, lt, &missileactor, nofreeaim, noautoaim, aimflags); if (numret > 0) ret[0].SetObject(misl); if (numret > 1) ret[1].SetObject(missileactor), numret = 2; @@ -8292,20 +8292,22 @@ DEFINE_ACTION_FUNCTION(AActor, GetDefaultByType) DEFINE_ACTION_FUNCTION(AActor, VelFromAngle) { PARAM_SELF_PROLOGUE(AActor); - if (numparam == 1) + PARAM_FLOAT(speed); + PARAM_ANGLE(angle); + + if (speed == 1e37) { self->VelFromAngle(); } else { - PARAM_FLOAT(speed); - if (numparam == 2) + if (angle == 1e37) + { self->VelFromAngle(speed); } else { - PARAM_ANGLE(angle); self->VelFromAngle(speed, angle); } } @@ -8327,20 +8329,21 @@ DEFINE_ACTION_FUNCTION(AActor, Vel3DFromAngle) DEFINE_ACTION_FUNCTION(AActor, Thrust) { PARAM_SELF_PROLOGUE(AActor); - if (numparam == 1) + PARAM_FLOAT(speed); + PARAM_ANGLE(angle); + + if (speed == 1e37) { self->Thrust(); } else { - PARAM_FLOAT(speed); - if (numparam == 2) + if (angle == 1e37) { self->Thrust(speed); } else { - PARAM_ANGLE(angle); self->Thrust(angle, speed); } } diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 1abb971b6..14cd4a4d1 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -2603,7 +2603,8 @@ DEFINE_ACTION_FUNCTION(_Secplane, HeightDiff) { PARAM_SELF_STRUCT_PROLOGUE(secplane_t); PARAM_FLOAT(oldd); - if (numparam == 2) + PARAM_FLOAT(newd); + if (newd != 1e37) { ACTION_RETURN_FLOAT(self->HeightDiff(oldd)); } diff --git a/src/r_data/r_sections.h b/src/r_data/r_sections.h index 35f61cb7c..13172f0cf 100644 --- a/src/r_data/r_sections.h +++ b/src/r_data/r_sections.h @@ -33,8 +33,8 @@ struct BoundingRect void setEmpty() { - left = top = 1e38; - bottom = right = -1e38; + left = top = FLT_MAX; + bottom = right = FLT_MIN; } bool contains(const BoundingRect & other) const diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 7f9cd5afd..c5426936e 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -616,7 +616,7 @@ class Actor : Thinker native native Actor SpawnMissileAngleZSpeed (double z, class type, double angle, double vz, double speed, Actor owner = null, bool checkspawn = true); native Actor SpawnMissileZAimed (double z, Actor dest, Class type); native Actor SpawnSubMissile(Class type, Actor target); - native Actor, Actor SpawnPlayerMissile(class type, double angle = 0, double x = 0, double y = 0, double z = 0, out FTranslatedLineTarget pLineTarget = null, bool nofreeaim = false, bool noautoaim = false, int aimflags = 0); + native Actor, Actor SpawnPlayerMissile(class type, double angle = 1e37, double x = 0, double y = 0, double z = 0, out FTranslatedLineTarget pLineTarget = null, bool nofreeaim = false, bool noautoaim = false, int aimflags = 0); native void SpawnTeleportFog(Vector3 pos, bool beforeTele, bool setTarget); native Actor RoughMonsterSearch(int distance, bool onlyseekable = false, bool frontonly = false); native int ApplyDamageFactor(Name damagetype, int damage); @@ -696,9 +696,9 @@ class Actor : Thinker native native clearscope vector2 Vec2Offset(double x, double y, bool absolute = false) const; native clearscope vector3 Vec2OffsetZ(double x, double y, double atz, bool absolute = false) const; native void VelIntercept(Actor targ, double speed = -1, bool aimpitch = true, bool oldvel = false); - native void VelFromAngle(double speed = 0, double angle = 0); + native void VelFromAngle(double speed = 1e37, double angle = 1e37); native void Vel3DFromAngle(double speed, double angle, double pitch); - native void Thrust(double speed = 0, double angle = 0); + native void Thrust(double speed = 1e37, double angle = 1e37); native clearscope bool isFriend(Actor other) const; native clearscope bool isHostile(Actor other) const; native void AdjustFloorClip(); @@ -1030,7 +1030,7 @@ class Actor : Thinker native void A_Fall() { A_NoBlocking(); } native void A_XScream(); native void A_Look(); - native void A_Chase(statelabel melee = null, statelabel missile = null, int flags = 0); + native void A_Chase(statelabel melee = null, statelabel missile = null, int flags = 0x40000000); native void A_Scream(); native void A_VileChase(); native bool A_CheckForResurrection(); diff --git a/wadsrc/static/zscript/mapdata.txt b/wadsrc/static/zscript/mapdata.txt index 11827e3ad..3440d4b24 100644 --- a/wadsrc/static/zscript/mapdata.txt +++ b/wadsrc/static/zscript/mapdata.txt @@ -206,7 +206,7 @@ struct SecPlane native play native bool isEqual(Secplane other) const; native void ChangeHeight(double hdiff); native double GetChangedHeight(double hdiff) const; - native double HeightDiff(double oldd, double newd = 0.0) const; + native double HeightDiff(double oldd, double newd = 1e37) const; native double PointToDist(Vector2 xy, double z) const; }