diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d403b43ae..0ec18032e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1152,6 +1152,7 @@ set (PCH_SOURCES scripting/symbols.cpp scripting/vmiterators.cpp scripting/vmthunks.cpp + scripting/vmthunks_actors.cpp scripting/types.cpp scripting/thingdef.cpp scripting/thingdef_data.cpp diff --git a/src/actor.h b/src/actor.h index 0539edaa5..260bde8da 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1010,11 +1010,6 @@ public: void AttachLight(unsigned int count, const FLightDefaults *lightdef); void SetDynamicLights(); - // When was this actor spawned? (relative to the current level) - int GetLevelSpawnTime() const; - // How many ticks passed since this actor was spawned? - int GetAge() const; - // info for drawing // NOTE: The first member variable *must* be snext. AActor *snext, **sprev; // links in sector (if needed) diff --git a/src/actorinlines.h b/src/actorinlines.h index 36e90652c..9da6b6d3d 100644 --- a/src/actorinlines.h +++ b/src/actorinlines.h @@ -54,3 +54,12 @@ inline double sector_t::LowestFloorAt(AActor *a, sector_t **resultsec) return ::LowestFloorAt(this, a->X(), a->Y(), resultsec); } +inline double AActor::GetBobOffset(double ticfrac) const +{ + if (!(flags2 & MF2_FLOATBOB)) + { + return 0; + } + return BobSin(FloatBobPhase + level.maptime + ticfrac) * FloatBobStrength; +} + diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 9e7e1b5d1..d8c24b5fa 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -3158,25 +3158,6 @@ void AActor::RemoveFromHash () tid = 0; } -DEFINE_ACTION_FUNCTION(AActor, RemoveFromHash) -{ - PARAM_SELF_PROLOGUE(AActor); - self->RemoveFromHash(); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, ChangeTid) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(tid); - self->RemoveFromHash(); - self->tid = tid; - self->AddToHash(); - return 0; -} - - - //========================================================================== // // P_IsTIDUsed @@ -3259,16 +3240,6 @@ int P_FindUniqueTID(int start_tid, int limit) return 0; } -DEFINE_ACTION_FUNCTION(AActor, FindUniqueTid) -{ - PARAM_PROLOGUE; - PARAM_INT(start); - PARAM_INT(limit); - ACTION_RETURN_INT(P_FindUniqueTID(start, limit)); -} - - - CCMD(utid) { @@ -6130,12 +6101,6 @@ int P_GetThingFloorType (AActor *thing) } } -DEFINE_ACTION_FUNCTION(AActor, GetFloorTerrain) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_POINTER(&Terrains[P_GetThingFloorType(self)]); -} - //--------------------------------------------------------------------------- // @@ -6496,7 +6461,8 @@ DEFINE_ACTION_FUNCTION(AActor, PlaySpawnSound) } -static double GetDefaultSpeed(PClassActor *type) + +double GetDefaultSpeed(PClassActor *type) { if (type == NULL) return 0; @@ -6510,13 +6476,6 @@ static double GetDefaultSpeed(PClassActor *type) return def->Speed; } -DEFINE_ACTION_FUNCTION(AActor, GetDefaultSpeed) -{ - PARAM_PROLOGUE; - PARAM_CLASS(type, AActor); - ACTION_RETURN_FLOAT(GetDefaultSpeed(type)); -} - //--------------------------------------------------------------------------- // // FUNC P_SpawnMissile @@ -7010,13 +6969,6 @@ bool AActor::IsTeammate (AActor *other) return false; } -DEFINE_ACTION_FUNCTION(AActor, isTeammate) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_BOOL(self->IsTeammate(other)); -} - //========================================================================== // // AActor :: GetSpecies @@ -7050,12 +7002,6 @@ FName AActor::GetSpecies() return Species = thistype->TypeName; // [GZ] Speeds up future calls. } -DEFINE_ACTION_FUNCTION(AActor, GetSpecies) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_INT(self->GetSpecies()); -} - //========================================================================== // // AActor :: IsFriend @@ -7085,13 +7031,6 @@ bool AActor::IsFriend (AActor *other) return false; } -DEFINE_ACTION_FUNCTION(AActor, isFriend) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_BOOL(self->IsFriend(other)); -} - //========================================================================== // // AActor :: IsHostile @@ -7122,14 +7061,6 @@ bool AActor::IsHostile (AActor *other) return true; } -DEFINE_ACTION_FUNCTION(AActor, isHostile) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_BOOL(self->IsHostile(other)); -} - - //========================================================================== // // AActor :: DoSpecialDamage @@ -7236,6 +7167,7 @@ DEFINE_ACTION_FUNCTION(AActor, TakeSpecialDamage) ACTION_RETURN_INT(self->TakeSpecialDamage(inflictor, source, damage, damagetype)); } + int AActor::CallTakeSpecialDamage(AActor *inflictor, AActor *source, int damage, FName damagetype) { IFVIRTUAL(AActor, TakeSpecialDamage) @@ -7301,13 +7233,6 @@ void AActor::SetIdle(bool nofunction) SetState(idle, nofunction); } -DEFINE_ACTION_FUNCTION(AActor, SetIdle) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_BOOL(nofunction); - self->SetIdle(nofunction); - return 0; -} int AActor::SpawnHealth() const { @@ -7328,12 +7253,6 @@ int AActor::SpawnHealth() const } } -DEFINE_ACTION_FUNCTION(AActor, SpawnHealth) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_INT(self->SpawnHealth()); -} - FState *AActor::GetRaiseState() { if (!(flags & MF_CORPSE)) @@ -7387,13 +7306,6 @@ void AActor::Revive() E_WorldThingRevived(this); } -DEFINE_ACTION_FUNCTION(AActor, Revive) -{ - PARAM_SELF_PROLOGUE(AActor); - self->Revive(); - return 0; -} - int AActor::GetGibHealth() const { IFVIRTUAL(AActor, GetGibHealth) @@ -7412,36 +7324,18 @@ double AActor::GetCameraHeight() const return CameraHeight == INT_MIN ? Height / 2 : CameraHeight; } -DEFINE_ACTION_FUNCTION(AActor, GetCameraHeight) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_FLOAT(self->GetCameraHeight()); -} - FDropItem *AActor::GetDropItems() const { return GetInfo()->DropItems; } -DEFINE_ACTION_FUNCTION(AActor, GetDropItems) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_POINTER(self->GetDropItems()); -} - double AActor::GetGravity() const { if (flags & MF_NOGRAVITY) return 0; return level.gravity * Sector->gravity * Gravity * 0.00125; } -DEFINE_ACTION_FUNCTION(AActor, GetGravity) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_FLOAT(self->GetGravity()); -} - // killough 11/98: // Whether an object is "sentient" or not. Used for environmental influences. @@ -7478,28 +7372,12 @@ const char *AActor::GetTag(const char *def) const } } -DEFINE_ACTION_FUNCTION(AActor, GetTag) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_STRING(def); - ACTION_RETURN_STRING(self->GetTag(def.Len() == 0? nullptr : def.GetChars())); -} - void AActor::SetTag(const char *def) { if (def == NULL || *def == 0) Tag = nullptr; else Tag = mStringPropertyData.Alloc(def); } -DEFINE_ACTION_FUNCTION(AActor, SetTag) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_STRING(def); - if (def.IsEmpty()) self->Tag = nullptr; - else self->Tag = self->mStringPropertyData.Alloc(def); - return 0; -} - void AActor::ClearCounters() { @@ -7522,13 +7400,6 @@ void AActor::ClearCounters() } } -DEFINE_ACTION_FUNCTION(AActor, ClearCounters) -{ - PARAM_SELF_PROLOGUE(AActor); - self->ClearCounters(); - return 0; -} - int AActor::GetModifiedDamage(FName damagetype, int damage, bool passive) { auto inv = Inventory; @@ -7544,14 +7415,6 @@ int AActor::GetModifiedDamage(FName damagetype, int damage, bool passive) return damage; } -DEFINE_ACTION_FUNCTION(AActor, GetModifiedDamage) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_NAME(type); - PARAM_INT(damage); - PARAM_BOOL(passive); - ACTION_RETURN_INT(self->GetModifiedDamage(type, damage, passive)); -} int AActor::ApplyDamageFactor(FName damagetype, int damage) const { @@ -7563,15 +7426,6 @@ int AActor::ApplyDamageFactor(FName damagetype, int damage) const return damage; } -DEFINE_ACTION_FUNCTION(AActor, ApplyDamageFactor) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_NAME(type); - PARAM_INT(damage); - ACTION_RETURN_INT(self->ApplyDamageFactor(type, damage)); -} - - void AActor::SetTranslation(FName trname) { // There is no constant for the empty name... @@ -7590,43 +7444,6 @@ void AActor::SetTranslation(FName trname) // silently ignore if the name does not exist, this would create some insane message spam otherwise. } -//========================================================================== -// -// AActor :: GetLevelSpawnTime -// -// Returns the time when this actor was spawned, -// relative to the current level. -// -//========================================================================== -int AActor::GetLevelSpawnTime() const -{ - return SpawnTime - level.totaltime + level.time; -} - -DEFINE_ACTION_FUNCTION(AActor, GetLevelSpawnTime) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_INT(self->GetLevelSpawnTime()); -} - -//========================================================================== -// -// AActor :: GetAge -// -// Returns the number of ticks passed since this actor was spawned. -// -//========================================================================== -int AActor::GetAge() const -{ - return level.totaltime - SpawnTime; -} - -DEFINE_ACTION_FUNCTION(AActor, GetAge) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_INT(self->GetAge()); -} - //--------------------------------------------------------------------------- // // PROP A_RestoreSpecialPosition @@ -7683,355 +7500,6 @@ void AActor::RestoreSpecialPosition() ClearInterpolation(); } -DEFINE_ACTION_FUNCTION(AActor, A_RestoreSpecialPosition) -{ - PARAM_SELF_PROLOGUE(AActor); - self->RestoreSpecialPosition(); - return 0; -} - -double AActor::GetBobOffset(double ticfrac) const -{ - if (!(flags2 & MF2_FLOATBOB)) - { - return 0; - } - return BobSin(FloatBobPhase + level.maptime + ticfrac) * FloatBobStrength; -} - -DEFINE_ACTION_FUNCTION(AActor, GetBobOffset) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(frac); - ACTION_RETURN_FLOAT(self->GetBobOffset(frac)); -} - - - -DEFINE_ACTION_FUNCTION(AActor, deltaangle) // should this be global? -{ - PARAM_PROLOGUE; - PARAM_FLOAT(a1); - PARAM_FLOAT(a2); - ACTION_RETURN_FLOAT(deltaangle(DAngle(a1), DAngle(a2)).Degrees); -} - -DEFINE_ACTION_FUNCTION(AActor, absangle) // should this be global? -{ - PARAM_PROLOGUE; - PARAM_FLOAT(a1); - PARAM_FLOAT(a2); - ACTION_RETURN_FLOAT(absangle(DAngle(a1), DAngle(a2)).Degrees); -} - -DEFINE_ACTION_FUNCTION(AActor, Distance2DSquared) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_FLOAT(self->Distance2DSquared(other)); -} - -DEFINE_ACTION_FUNCTION(AActor, Distance3DSquared) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_FLOAT(self->Distance3DSquared(other)); -} - -DEFINE_ACTION_FUNCTION(AActor, Distance2D) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_FLOAT(self->Distance2D(other)); -} - -DEFINE_ACTION_FUNCTION(AActor, Distance3D) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(other, AActor); - ACTION_RETURN_FLOAT(self->Distance3D(other)); -} - -DEFINE_ACTION_FUNCTION(AActor, AddZ) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(addz); - PARAM_BOOL(moving); - self->AddZ(addz, moving); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, SetZ) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(z); - self->SetZ(z); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, SetDamage) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(dmg); - self->SetDamage(dmg); - return 0; -} - -// This combines all 3 variations of the internal function -DEFINE_ACTION_FUNCTION(AActor, VelFromAngle) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(speed); - PARAM_ANGLE(angle); - - if (speed == 1e37) - { - self->VelFromAngle(); - } - else - { - if (angle == 1e37) - - { - self->VelFromAngle(speed); - } - else - { - self->VelFromAngle(speed, angle); - } - } - return 0; -} - -// This combines all 3 variations of the internal function -DEFINE_ACTION_FUNCTION(AActor, Vel3DFromAngle) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(speed); - PARAM_ANGLE(angle); - PARAM_ANGLE(pitch); - self->Vel3DFromAngle(angle, pitch, speed); - return 0; -} - -// This combines all 3 variations of the internal function -DEFINE_ACTION_FUNCTION(AActor, Thrust) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(speed); - PARAM_ANGLE(angle); - - if (speed == 1e37) - { - self->Thrust(); - } - else - { - if (angle == 1e37) - { - self->Thrust(speed); - } - else - { - self->Thrust(angle, speed); - } - } - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, AngleTo) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(targ, AActor); - PARAM_BOOL(absolute); - ACTION_RETURN_FLOAT(self->AngleTo(targ, absolute).Degrees); -} - -DEFINE_ACTION_FUNCTION(AActor, AngleToVector) -{ - PARAM_PROLOGUE; - PARAM_ANGLE(angle); - PARAM_FLOAT(length); - ACTION_RETURN_VEC2(angle.ToVector(length)); -} - -DEFINE_ACTION_FUNCTION(AActor, RotateVector) -{ - PARAM_PROLOGUE; - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_ANGLE(angle); - ACTION_RETURN_VEC2(DVector2(x, y).Rotated(angle)); -} - -DEFINE_ACTION_FUNCTION(AActor, Normalize180) -{ - PARAM_PROLOGUE; - PARAM_ANGLE(angle); - ACTION_RETURN_FLOAT(angle.Normalized180().Degrees); -} - -DEFINE_ACTION_FUNCTION(AActor, DistanceBySpeed) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(targ, AActor); - PARAM_FLOAT(speed); - ACTION_RETURN_FLOAT(self->DistanceBySpeed(targ, speed)); -} - -DEFINE_ACTION_FUNCTION(AActor, SetXYZ) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(z); - self->SetXYZ(x, y, z); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, Vec2Angle) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(length); - PARAM_ANGLE(angle); - PARAM_BOOL(absolute); - ACTION_RETURN_VEC2(self->Vec2Angle(length, angle, absolute)); -} - - -DEFINE_ACTION_FUNCTION(AActor, Vec3To) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(t, AActor) - ACTION_RETURN_VEC3(self->Vec3To(t)); -} - -DEFINE_ACTION_FUNCTION(AActor, Vec2To) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_OBJECT_NOT_NULL(t, AActor) - ACTION_RETURN_VEC2(self->Vec2To(t)); -} - -DEFINE_ACTION_FUNCTION(AActor, Vec3Angle) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(length) - PARAM_ANGLE(angle); - PARAM_FLOAT(z); - PARAM_BOOL(absolute); - ACTION_RETURN_VEC3(self->Vec3Angle(length, angle, z, absolute)); -} - -DEFINE_ACTION_FUNCTION(AActor, Vec2OffsetZ) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(z); - PARAM_BOOL(absolute); - ACTION_RETURN_VEC3(self->Vec2OffsetZ(x, y, z, absolute)); -} - -DEFINE_ACTION_FUNCTION(AActor, Vec2Offset) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_BOOL(absolute); - ACTION_RETURN_VEC2(self->Vec2Offset(x, y, absolute)); -} - -DEFINE_ACTION_FUNCTION(AActor, Vec3Offset) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(z); - PARAM_BOOL(absolute); - ACTION_RETURN_VEC3(self->Vec3Offset(x, y, z, absolute)); -} - -DEFINE_ACTION_FUNCTION(AActor, PosRelative) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_POINTER(sec, sector_t); - ACTION_RETURN_VEC3(self->PosRelative(sec)); -} - -DEFINE_ACTION_FUNCTION(AActor, RestoreDamage) -{ - PARAM_SELF_PROLOGUE(AActor); - self->RestoreDamage(); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, PlayerNumber) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_INT(self->player ? int(self->player - players) : 0); -} - -DEFINE_ACTION_FUNCTION(AActor, SetFriendPlayer) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_POINTER(player, player_t); - self->SetFriendPlayer(player); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, ClearBounce) -{ - PARAM_SELF_PROLOGUE(AActor); - self->BounceFlags = 0; - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, AccuracyFactor) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_FLOAT(self->AccuracyFactor()); -} - -DEFINE_ACTION_FUNCTION(AActor, CountsAsKill) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_BOOL(self->CountsAsKill()); -} - -DEFINE_ACTION_FUNCTION(AActor, IsZeroDamage) -{ - PARAM_SELF_PROLOGUE(AActor); - ACTION_RETURN_BOOL(self->IsZeroDamage()); -} - -DEFINE_ACTION_FUNCTION(AActor, ClearInterpolation) -{ - PARAM_SELF_PROLOGUE(AActor); - self->ClearInterpolation(); - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, ApplyDamageFactors) -{ - PARAM_PROLOGUE; - PARAM_CLASS(itemcls, AActor); - PARAM_NAME(damagetype); - PARAM_INT(damage); - PARAM_INT(defdamage); - - DmgFactors &df = itemcls->ActorInfo()->DamageFactors; - if (df.Size() != 0) - { - ACTION_RETURN_INT(df.Apply(damagetype, damage)); - } - else - { - ACTION_RETURN_INT(defdamage); - } -} - - //---------------------------------------------------------------------------- // // DropItem handling @@ -8111,8 +7579,5 @@ void PrintMiscActorInfo(AActor *query) Printf("FriendlySeeBlocks: %d\n", query->friendlyseeblocks); Printf("Target: %s\n", query->target ? query->target->GetClass()->TypeName.GetChars() : "-"); Printf("Last enemy: %s\n", query->lastenemy ? query->lastenemy->GetClass()->TypeName.GetChars() : "-"); - Printf("Spawn time: %d ticks (%f seconds) after game start, %d ticks (%f seconds) after level start\n", - query->SpawnTime, (double) query->SpawnTime / TICRATE, - query->GetLevelSpawnTime(), (double) query->GetLevelSpawnTime() / TICRATE); } } diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index ed504691d..15124fe9e 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -52,14 +52,6 @@ int Net_GetLatency(int *ld, int *ad); void PrintPickupMessage(bool localview, const FString &str); -DEFINE_ACTION_FUNCTION_NATIVE(DObject, SetMusicVolume, I_SetMusicVolume) -{ - PARAM_PROLOGUE; - PARAM_FLOAT(vol); - I_SetMusicVolume(vol); - return 0; -} - //===================================================================================== // // FString exports @@ -1819,77 +1811,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetCursor, GetCursor) ACTION_RETURN_STRING(FString(self->GetCursor())); } -//===================================================================================== -// -// AActor exports (this will be expanded) -// -//===================================================================================== - -DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetPointer, COPY_AAPTR) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(ptr); - ACTION_RETURN_OBJECT(COPY_AAPTR(self, ptr)); -} - - -DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_PlaySound, A_PlaySound) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_SOUND(soundid); - PARAM_INT(channel); - PARAM_FLOAT(volume); - PARAM_BOOL(looping); - PARAM_FLOAT(attenuation); - PARAM_BOOL(local); - A_PlaySound(self, soundid, channel, volume, looping, attenuation, local); - return 0; -} - -DEFINE_ACTION_FUNCTION_NATIVE(AActor, CheckKeys, P_CheckKeys) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(locknum); - PARAM_BOOL(remote); - PARAM_BOOL(quiet); - ACTION_RETURN_BOOL(P_CheckKeys(self, locknum, remote, quiet)); -} - - -//===================================================================================== -// -// Inventory exports -// -//===================================================================================== - -DEFINE_ACTION_FUNCTION_NATIVE(AInventory, PrintPickupMessage, PrintPickupMessage) -{ - PARAM_PROLOGUE; - PARAM_BOOL(localview); - PARAM_STRING(str); - PrintPickupMessage(localview, str); - return 0; -} - -//===================================================================================== -// -// Key exports -// -//===================================================================================== - -DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyTypeCount, P_GetKeyTypeCount) -{ - PARAM_PROLOGUE; - ACTION_RETURN_INT(P_GetKeyTypeCount()); -} - -DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyType, P_GetKeyType) -{ - PARAM_PROLOGUE; - PARAM_INT(num); - ACTION_RETURN_POINTER(P_GetKeyType(num)); -} - //===================================================================================== // // WeaponSlots exports diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp new file mode 100644 index 000000000..05bcff74e --- /dev/null +++ b/src/scripting/vmthunks_actors.cpp @@ -0,0 +1,620 @@ +//----------------------------------------------------------------------------- +// +// Copyright 2016-2018 Christoph Oelckers +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see http://www.gnu.org/licenses/ +// +//----------------------------------------------------------------------------- +// +// VM thunks for internal functions of actor classes +// +// Important note about this file: Since everything in here is supposed to be called +// from JIT-compiled VM code it needs to be very careful about calling conventions. +// As a result none of the integer sized struct types may be used as function +// arguments, because current C++ calling conventions require them to be passed +// by reference. The JIT code, however will pass them by value so any direct native function +// taking such an argument needs to receive it as a naked int. +// +//----------------------------------------------------------------------------- + +#include "vm.h" +#include "r_defs.h" +#include "g_levellocals.h" +#include "s_sound.h" +#include "p_local.h" +#include "v_font.h" +#include "gstrings.h" +#include "a_keys.h" +#include "sbar.h" +#include "doomstat.h" +#include "p_acs.h" +#include "a_pickups.h" +#include "a_specialspot.h" +#include "actorptrselect.h" +#include "a_weapons.h" +#include "d_player.h" +#include "p_setup.h" +#include "i_music.h" +#include "p_terrain.h" + +DVector2 AM_GetPosition(); +int Net_GetLatency(int *ld, int *ad); +void PrintPickupMessage(bool localview, const FString &str); + + +DEFINE_ACTION_FUNCTION_NATIVE(DObject, SetMusicVolume, I_SetMusicVolume) +{ + PARAM_PROLOGUE; + PARAM_FLOAT(vol); + I_SetMusicVolume(vol); + return 0; +} + +//===================================================================================== +// +// AActor exports (this will be expanded) +// +//===================================================================================== + +DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetPointer, COPY_AAPTR) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(ptr); + ACTION_RETURN_OBJECT(COPY_AAPTR(self, ptr)); +} + + +DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_PlaySound, A_PlaySound) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_SOUND(soundid); + PARAM_INT(channel); + PARAM_FLOAT(volume); + PARAM_BOOL(looping); + PARAM_FLOAT(attenuation); + PARAM_BOOL(local); + A_PlaySound(self, soundid, channel, volume, looping, attenuation, local); + return 0; +} + +DEFINE_ACTION_FUNCTION_NATIVE(AActor, CheckKeys, P_CheckKeys) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(locknum); + PARAM_BOOL(remote); + PARAM_BOOL(quiet); + ACTION_RETURN_BOOL(P_CheckKeys(self, locknum, remote, quiet)); +} + +DEFINE_ACTION_FUNCTION(AActor, deltaangle) // should this be global? +{ + PARAM_PROLOGUE; + PARAM_FLOAT(a1); + PARAM_FLOAT(a2); + ACTION_RETURN_FLOAT(deltaangle(DAngle(a1), DAngle(a2)).Degrees); +} + +DEFINE_ACTION_FUNCTION(AActor, absangle) // should this be global? +{ + PARAM_PROLOGUE; + PARAM_FLOAT(a1); + PARAM_FLOAT(a2); + ACTION_RETURN_FLOAT(absangle(DAngle(a1), DAngle(a2)).Degrees); +} + +DEFINE_ACTION_FUNCTION(AActor, Distance2DSquared) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_FLOAT(self->Distance2DSquared(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, Distance3DSquared) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_FLOAT(self->Distance3DSquared(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, Distance2D) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_FLOAT(self->Distance2D(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, Distance3D) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_FLOAT(self->Distance3D(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, AddZ) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(addz); + PARAM_BOOL(moving); + self->AddZ(addz, moving); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, SetZ) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(z); + self->SetZ(z); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, SetDamage) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(dmg); + self->SetDamage(dmg); + return 0; +} + +// This combines all 3 variations of the internal function +DEFINE_ACTION_FUNCTION(AActor, VelFromAngle) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(speed); + PARAM_ANGLE(angle); + + if (speed == 1e37) + { + self->VelFromAngle(); + } + else + { + if (angle == 1e37) + + { + self->VelFromAngle(speed); + } + else + { + self->VelFromAngle(speed, angle); + } + } + return 0; +} + +// This combines all 3 variations of the internal function +DEFINE_ACTION_FUNCTION(AActor, Vel3DFromAngle) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(speed); + PARAM_ANGLE(angle); + PARAM_ANGLE(pitch); + self->Vel3DFromAngle(angle, pitch, speed); + return 0; +} + +// This combines all 3 variations of the internal function +DEFINE_ACTION_FUNCTION(AActor, Thrust) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(speed); + PARAM_ANGLE(angle); + + if (speed == 1e37) + { + self->Thrust(); + } + else + { + if (angle == 1e37) + { + self->Thrust(speed); + } + else + { + self->Thrust(angle, speed); + } + } + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, AngleTo) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(targ, AActor); + PARAM_BOOL(absolute); + ACTION_RETURN_FLOAT(self->AngleTo(targ, absolute).Degrees); +} + +DEFINE_ACTION_FUNCTION(AActor, AngleToVector) +{ + PARAM_PROLOGUE; + PARAM_ANGLE(angle); + PARAM_FLOAT(length); + ACTION_RETURN_VEC2(angle.ToVector(length)); +} + +DEFINE_ACTION_FUNCTION(AActor, RotateVector) +{ + PARAM_PROLOGUE; + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_ANGLE(angle); + ACTION_RETURN_VEC2(DVector2(x, y).Rotated(angle)); +} + +DEFINE_ACTION_FUNCTION(AActor, Normalize180) +{ + PARAM_PROLOGUE; + PARAM_ANGLE(angle); + ACTION_RETURN_FLOAT(angle.Normalized180().Degrees); +} + +DEFINE_ACTION_FUNCTION(AActor, DistanceBySpeed) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(targ, AActor); + PARAM_FLOAT(speed); + ACTION_RETURN_FLOAT(self->DistanceBySpeed(targ, speed)); +} + +DEFINE_ACTION_FUNCTION(AActor, SetXYZ) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + self->SetXYZ(x, y, z); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, Vec2Angle) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(length); + PARAM_ANGLE(angle); + PARAM_BOOL(absolute); + ACTION_RETURN_VEC2(self->Vec2Angle(length, angle, absolute)); +} + + +DEFINE_ACTION_FUNCTION(AActor, Vec3To) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(t, AActor) + ACTION_RETURN_VEC3(self->Vec3To(t)); +} + +DEFINE_ACTION_FUNCTION(AActor, Vec2To) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(t, AActor) + ACTION_RETURN_VEC2(self->Vec2To(t)); +} + +DEFINE_ACTION_FUNCTION(AActor, Vec3Angle) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(length) + PARAM_ANGLE(angle); + PARAM_FLOAT(z); + PARAM_BOOL(absolute); + ACTION_RETURN_VEC3(self->Vec3Angle(length, angle, z, absolute)); +} + +DEFINE_ACTION_FUNCTION(AActor, Vec2OffsetZ) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + PARAM_BOOL(absolute); + ACTION_RETURN_VEC3(self->Vec2OffsetZ(x, y, z, absolute)); +} + +DEFINE_ACTION_FUNCTION(AActor, Vec2Offset) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_BOOL(absolute); + ACTION_RETURN_VEC2(self->Vec2Offset(x, y, absolute)); +} + +DEFINE_ACTION_FUNCTION(AActor, Vec3Offset) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + PARAM_BOOL(absolute); + ACTION_RETURN_VEC3(self->Vec3Offset(x, y, z, absolute)); +} + +DEFINE_ACTION_FUNCTION(AActor, PosRelative) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_POINTER(sec, sector_t); + ACTION_RETURN_VEC3(self->PosRelative(sec)); +} + +DEFINE_ACTION_FUNCTION(AActor, RestoreDamage) +{ + PARAM_SELF_PROLOGUE(AActor); + self->RestoreDamage(); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, PlayerNumber) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->player ? int(self->player - players) : 0); +} + +DEFINE_ACTION_FUNCTION(AActor, SetFriendPlayer) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_POINTER(player, player_t); + self->SetFriendPlayer(player); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, ClearBounce) +{ + PARAM_SELF_PROLOGUE(AActor); + self->BounceFlags = 0; + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, AccuracyFactor) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_FLOAT(self->AccuracyFactor()); +} + +DEFINE_ACTION_FUNCTION(AActor, CountsAsKill) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_BOOL(self->CountsAsKill()); +} + +DEFINE_ACTION_FUNCTION(AActor, IsZeroDamage) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_BOOL(self->IsZeroDamage()); +} + +DEFINE_ACTION_FUNCTION(AActor, ClearInterpolation) +{ + PARAM_SELF_PROLOGUE(AActor); + self->ClearInterpolation(); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, ApplyDamageFactors) +{ + PARAM_PROLOGUE; + PARAM_CLASS(itemcls, AActor); + PARAM_NAME(damagetype); + PARAM_INT(damage); + PARAM_INT(defdamage); + + DmgFactors &df = itemcls->ActorInfo()->DamageFactors; + if (df.Size() != 0) + { + ACTION_RETURN_INT(df.Apply(damagetype, damage)); + } + else + { + ACTION_RETURN_INT(defdamage); + } +} + +DEFINE_ACTION_FUNCTION(AActor, A_RestoreSpecialPosition) +{ + PARAM_SELF_PROLOGUE(AActor); + self->RestoreSpecialPosition(); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, GetBobOffset) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(frac); + ACTION_RETURN_FLOAT(self->GetBobOffset(frac)); +} + +DEFINE_ACTION_FUNCTION(AActor, SetIdle) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_BOOL(nofunction); + self->SetIdle(nofunction); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, SpawnHealth) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->SpawnHealth()); +} + +DEFINE_ACTION_FUNCTION(AActor, Revive) +{ + PARAM_SELF_PROLOGUE(AActor); + self->Revive(); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, GetCameraHeight) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_FLOAT(self->GetCameraHeight()); +} + +DEFINE_ACTION_FUNCTION(AActor, GetDropItems) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_POINTER(self->GetDropItems()); +} + +DEFINE_ACTION_FUNCTION(AActor, GetGravity) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_FLOAT(self->GetGravity()); +} + + +DEFINE_ACTION_FUNCTION(AActor, GetTag) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_STRING(def); + ACTION_RETURN_STRING(self->GetTag(def.Len() == 0 ? nullptr : def.GetChars())); +} + + +DEFINE_ACTION_FUNCTION(AActor, SetTag) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_STRING(def); + if (def.IsEmpty()) self->Tag = nullptr; + else self->Tag = self->mStringPropertyData.Alloc(def); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, ClearCounters) +{ + PARAM_SELF_PROLOGUE(AActor); + self->ClearCounters(); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, GetModifiedDamage) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_NAME(type); + PARAM_INT(damage); + PARAM_BOOL(passive); + ACTION_RETURN_INT(self->GetModifiedDamage(type, damage, passive)); +} +DEFINE_ACTION_FUNCTION(AActor, ApplyDamageFactor) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_NAME(type); + PARAM_INT(damage); + ACTION_RETURN_INT(self->ApplyDamageFactor(type, damage)); +} + +double GetDefaultSpeed(PClassActor *type); + +DEFINE_ACTION_FUNCTION(AActor, GetDefaultSpeed) +{ + PARAM_PROLOGUE; + PARAM_CLASS(type, AActor); + ACTION_RETURN_FLOAT(GetDefaultSpeed(type)); +} + +DEFINE_ACTION_FUNCTION(AActor, isTeammate) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_BOOL(self->IsTeammate(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, GetSpecies) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->GetSpecies()); +} + +DEFINE_ACTION_FUNCTION(AActor, isFriend) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_BOOL(self->IsFriend(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, isHostile) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(other, AActor); + ACTION_RETURN_BOOL(self->IsHostile(other)); +} + +DEFINE_ACTION_FUNCTION(AActor, GetFloorTerrain) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_POINTER(&Terrains[P_GetThingFloorType(self)]); +} + +DEFINE_ACTION_FUNCTION(AActor, FindUniqueTid) +{ + PARAM_PROLOGUE; + PARAM_INT(start); + PARAM_INT(limit); + ACTION_RETURN_INT(P_FindUniqueTID(start, limit)); +} + +DEFINE_ACTION_FUNCTION(AActor, RemoveFromHash) +{ + PARAM_SELF_PROLOGUE(AActor); + self->RemoveFromHash(); + return 0; +} + +DEFINE_ACTION_FUNCTION(AActor, ChangeTid) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(tid); + self->RemoveFromHash(); + self->tid = tid; + self->AddToHash(); + return 0; +} + + + + +//===================================================================================== +// +// Inventory exports +// +//===================================================================================== + +DEFINE_ACTION_FUNCTION_NATIVE(AInventory, PrintPickupMessage, PrintPickupMessage) +{ + PARAM_PROLOGUE; + PARAM_BOOL(localview); + PARAM_STRING(str); + PrintPickupMessage(localview, str); + return 0; +} + +//===================================================================================== +// +// Key exports +// +//===================================================================================== + +DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyTypeCount, P_GetKeyTypeCount) +{ + PARAM_PROLOGUE; + ACTION_RETURN_INT(P_GetKeyTypeCount()); +} + +DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyType, P_GetKeyType) +{ + PARAM_PROLOGUE; + PARAM_INT(num); + ACTION_RETURN_POINTER(P_GetKeyType(num)); +} + diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 00671c802..e6048080b 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -737,9 +737,36 @@ class Actor : Thinker native native void GiveSecret(bool printmsg = true, bool playsound = true); native clearscope double GetCameraHeight() const; native clearscope double GetGravity() const; - native clearscope int GetLevelSpawnTime() const; - native clearscope int GetAge() const; + //========================================================================== + // + // AActor :: GetLevelSpawnTime + // + // Returns the time when this actor was spawned, + // relative to the current level. + // + //========================================================================== + clearscope int GetLevelSpawnTime() const + { + return SpawnTime - level.totaltime + level.time; + } + + //========================================================================== + // + // AActor :: GetAge + // + // Returns the number of ticks passed since this actor was spawned. + // + //========================================================================== + + clearscope int GetAge() const + { + return level.totaltime - SpawnTime; + } + + + + native bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false); protected native void DestroyAllInventory(); // This is not supposed to be called by user code! native clearscope Inventory FindInventory(class itemtype, bool subclass = false) const;