From 994078feaef07b57bdcc431b0dcb64dc4be3919e Mon Sep 17 00:00:00 2001 From: jekyllgrim Date: Fri, 30 Aug 2024 13:06:26 +0300 Subject: [PATCH] Added FloatBobFactor This adds a new actor property: `FloatBobFactor` (default 1.0). This will be a multiplier for level.time in `AActor::GetBobOffset`, which finally allows to control not only the range of float bobbing (which is FloatBobStrength) but also the frequency of bobbing. --- src/namedef_custom.h | 1 + src/playsim/actor.h | 1 + src/playsim/actorinlines.h | 2 +- src/playsim/p_mobj.cpp | 1 + src/scripting/thingdef_properties.cpp | 10 ++++++++++ src/scripting/vmthunks_actors.cpp | 1 + wadsrc/static/zscript/actors/actor.zs | 2 ++ 7 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/namedef_custom.h b/src/namedef_custom.h index 082a254c9..3144d46f9 100644 --- a/src/namedef_custom.h +++ b/src/namedef_custom.h @@ -625,6 +625,7 @@ xx(ScaleY) xx(FriendlySeeBlocks) xx(Floatbobphase) xx(Floatbobstrength) +xx(FloatBobFactor) xx(Target) xx(Master) xx(Tracer) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index bbf2eaf98..40be0c599 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -1304,6 +1304,7 @@ public: uint8_t FloatBobPhase; uint8_t FriendPlayer; // [RH] Player # + 1 this friendly monster works for (so 0 is no player, 1 is player 0, etc) double FloatBobStrength; + double FloatBobFactor; PalEntry BloodColor; FTranslationID BloodTranslation; diff --git a/src/playsim/actorinlines.h b/src/playsim/actorinlines.h index 939807c98..bbc173801 100644 --- a/src/playsim/actorinlines.h +++ b/src/playsim/actorinlines.h @@ -69,7 +69,7 @@ inline double AActor::GetBobOffset(double ticfrac) const { return 0; } - return BobSin(FloatBobPhase + Level->maptime + ticfrac) * FloatBobStrength; + return BobSin(FloatBobPhase + Level->maptime * FloatBobFactor + ticfrac) * FloatBobStrength; } inline double AActor::GetCameraHeight() const diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index e8a6c247a..7df73be6d 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -289,6 +289,7 @@ void AActor::Serialize(FSerializer &arc) A("inventoryid", InventoryID) A("floatbobphase", FloatBobPhase) A("floatbobstrength", FloatBobStrength) + A("floatbobfactor", FloatBobFactor) A("translation", Translation) A("bloodcolor", BloodColor) A("bloodtranslation", BloodTranslation) diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index bedd66cd3..f6cd07335 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -642,6 +642,16 @@ DEFINE_PROPERTY(floatbobstrength, F, Actor) defaults->FloatBobStrength = id; } +//========================================================================== +// +//========================================================================== +DEFINE_PROPERTY(floatbobfactor, F, Actor) +{ + PROP_DOUBLE_PARM(id, 0); + if (id <= 0) I_Error ("FloatBobFactor must be above 0.0"); + defaults->FloatBobFactor = id; +} + //========================================================================== // //========================================================================== diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index acf253807..53fc0a062 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -2035,6 +2035,7 @@ DEFINE_FIELD(AActor, DamageType) DEFINE_FIELD(AActor, DamageTypeReceived) DEFINE_FIELD(AActor, FloatBobPhase) DEFINE_FIELD(AActor, FloatBobStrength) +DEFINE_FIELD(AActor, FloatBobFactor) DEFINE_FIELD(AActor, RipperLevel) DEFINE_FIELD(AActor, RipLevelMin) DEFINE_FIELD(AActor, RipLevelMax) diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 31dc08052..7a9a53929 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -178,6 +178,7 @@ class Actor : Thinker native native name DamageTypeReceived; native uint8 FloatBobPhase; native double FloatBobStrength; + native double FloatBobFactor; native int RipperLevel; native int RipLevelMin; native int RipLevelMax; @@ -413,6 +414,7 @@ class Actor : Thinker native FloatSpeed 4; FloatBobPhase -1; // randomly initialize by default FloatBobStrength 1.0; + FloatBobFactor 1.0; Gravity 1; Friction 1; DamageFactor 1.0; // damage multiplier as target of damage.