Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Game.Client/CDLL_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

using Game.Client;

using Source;
using Source.Common;

using System.Numerics;
using System.Runtime.CompilerServices;

Expand Down Expand Up @@ -56,10 +59,77 @@ public static void Remove(C_BaseEntity? entity) {
ClientThinkList().AddToDeleteList(entity.GetClientHandle());
}

public static int EntitiesInSphere(Span<C_BaseEntity?> list, in Vector3 center, float radius, EntityFlags flagMask, PartitionListMask partitionMask) {
FlaggedEntitiesEnum sphereEnum = new(list, flagMask);
partition.EnumerateElementsInSphere((SpatialPartitionListMask_t)partitionMask, center, radius, false, ref sphereEnum);

return sphereEnum.GetCount();
}

}
public static partial class Util_Globals
{
public static bool FStrEq(ReadOnlySpan<char> sz1, ReadOnlySpan<char> sz2)
=> Unsafe.AreSame(in sz1.DangerousGetReference(), in sz2.DangerousGetReference()) || stricmp(sz1, sz2) == 0;
}

public ref struct FlaggedEntitiesEnum : IPartitionEnumerator
{
public FlaggedEntitiesEnum(Span<C_BaseEntity?> list, EntityFlags flagMask) {
List = list;
FlagMask = flagMask;
Count = 0;
}

public int GetCount() => Count;

public bool AddToList(C_BaseEntity entity) {
if (Count >= List.Length)
return false;
List[Count] = entity;
Count++;
return true;
}

public IterationRetval EnumElement(IHandleEntity? handleEntity) {
IClientEntity? clientEntity = cl_entitylist.GetClientEntityFromHandle(handleEntity!.GetRefEHandle());
C_BaseEntity? entity = clientEntity?.GetBaseEntity();
if (entity != null) {
if (FlagMask != 0 && (entity.GetFlags() & FlagMask) == 0)
return IterationRetval.Continue;

if (!AddToList(entity))
return IterationRetval.Stop;
}

return IterationRetval.Continue;
}

Span<C_BaseEntity?> List;
EntityFlags FlagMask;
int Count;
}

public struct EntitySphereQuery
{
public const int MAX_SPHERE_QUERY = 256;

public EntitySphereQuery(in Vector3 center, float radius, EntityFlags flagMask = 0, PartitionListMask partitionMask = PartitionListMask.ClientNonStaticEdicts) {
ListIndex = 0;
ListCount = Util.EntitiesInSphere(List, center, radius, flagMask, partitionMask);
}

public C_BaseEntity? GetCurrentEntity() {
if (ListIndex < ListCount)
return List[ListIndex];
return null;
}

public void NextEntity() => ListIndex++;

[InlineArray(MAX_SPHERE_QUERY)] struct InlineArrayMaxSphereQuery<T> { public T first; }
int ListIndex;
int ListCount;
InlineArrayMaxSphereQuery<C_BaseEntity?> List;
}
}
10 changes: 10 additions & 0 deletions Game.Client/C_AI_BaseNPC.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Source.Common;
using Source.Common.Formats.BSP;
using Source;

using Game.Shared;
Expand Down Expand Up @@ -37,4 +38,13 @@ public class C_AI_BaseNPC : C_BaseCombatCharacter
[NetworkName("m_bImportanRagdoll")]
public bool ImportantRagdoll;
public float TimePingEffect;

public override bool IsNPC() => true;

public override Mask PhysicsSolidMaskForEntity() {
if (!IsRagdoll())
return Mask.NPCSolid;

return Mask.Solid;
}
}
42 changes: 39 additions & 3 deletions Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Source.Common;
using Source.Common.Commands;
using Source.Common.Engine;
using Source.Common.Formats.BSP;
using Source.Common.Formats.Keyvalues;
using Source.Common.Mathematics;

Expand Down Expand Up @@ -102,6 +103,8 @@ public bool IsSelfAnimating() {
}
public bool IsSequenceFinished() => SequenceFinished;
public override void ResetLatched() {
Ik = null;

base.ResetLatched();
}
public bool IsRagdoll() => Ragdoll != null && RenderFX == (byte)RenderFx.Ragdoll;
Expand Down Expand Up @@ -456,6 +459,24 @@ public void RemoveBaseAnimatingInterpolatedVars() {

public bool ComputeHitboxSurroundingBox(out Vector3 vecWorldMins, out Vector3 vecWorldMaxs) => throw new NotImplementedException();

public override bool GetSoundSpatialization(ref SpatializationInfo info) {
using (AutoAllowBoneAccess boneaccess = new(true, false)) {
if (!base.GetSoundSpatialization(ref info))
return false;
}

if (!Unsafe.IsNullRef(ref info.Origin) && IsNPC() && Ik != null) {
info.Origin = GetAbsOrigin();

modelinfo.GetModelBounds(GetModel(), out Vector3 mins, out Vector3 maxs);
MathLib.VectorAdd(mins, maxs, out Vector3 center);
MathLib.VectorScale(center, 0.5f, out center);

info.Origin += center;
}
return true;
}

public override bool SetupBones(Span<Matrix3x4> boneToWorldOut, int maxBones, int boneMask, double currentTime) {
if (!boneToWorldOut.IsEmpty && !IsBoneAccessAllowed()) {
if (gpGlobals.RealTime >= SetupBones__lastWarning + 1.0f) {
Expand Down Expand Up @@ -502,16 +523,28 @@ public override bool SetupBones(Span<Matrix3x4> boneToWorldOut, int maxBones, in

AddFlag((EntityFlags)EFL.SettingUpBones);

UpdateIKContext(hdr);

Span<Vector3> pos = stackalloc Vector3[Studio.MAXSTUDIOBONES];
Span<Quaternion> q = stackalloc Quaternion[Studio.MAXSTUDIOBONES];
memset(pos.Cast<Vector3, float>(), float.NaN);
memset(q.Cast<Quaternion, float>(), float.NaN);

int bonesMaskNeedRecalc = boneMask | oldReadableBones;

if (Ik != null) {
if (Teleported() || IsNoInterpolationFrame())
Ik.ClearTargets();

InitIK(hdr, currentTime, bonesMaskNeedRecalc);
}

StandardBlendingRules(hdr, pos, q, currentTime, bonesMaskNeedRecalc);

BoneBitList boneComputed = new();
if (Ik != null && !IsRagdoll())
SolveIK(pos, q, BoneAccessor.GetBoneArrayForWrite(), ref boneComputed, currentTime);

BuildTransformations(hdr, pos, q, parentTransform, bonesMaskNeedRecalc, ref boneComputed);

RemoveFlag((EntityFlags)EFL.SettingUpBones);
Expand Down Expand Up @@ -632,10 +665,11 @@ public virtual void StandardBlendingRules(StudioHdr hdr, Span<Vector3> pos, Span
TimeUnit_t cycle = GetCycle();
BoneSetup setup = new(hdr, boneMask, poseparam);
setup.InitPose(pos, q);
setup.AccumulatePose(pos, q, GetSequence(), cycle, 1.0f, currentTime, null);
setup.AccumulatePose(pos, q, GetSequence(), cycle, 1.0f, currentTime, Ik);
MaintainSequenceTransitions(ref setup, cycle, pos, q);
AccumulateLayers(ref setup, pos, q, currentTime);
setup.CalcAutoplaySequences(pos, q, currentTime, null);

setup.CalcAutoplaySequences(pos, q, currentTime, CreateAutoplayIK(hdr, currentTime, boneMask));

if (hdr.NumBoneControllers() != 0) {
// todo
Expand Down Expand Up @@ -709,7 +743,7 @@ private void MaintainSequenceTransitions(ref BoneSetup boneSetup, double cycle,
cycle = blend.Cycle + dt * blend.PlaybackRate * GetSequenceCycleRate(boneSetup.GetStudioHdr(), blend.Sequence);
cycle = ClampCycle(cycle, IsSequenceLooping(boneSetup.GetStudioHdr(), blend.Sequence));

boneSetup.AccumulatePose(pos, q, blend.Sequence, cycle, blend.Weight, gpGlobals.CurTime, null);
boneSetup.AccumulatePose(pos, q, blend.Sequence, cycle, blend.Weight, gpGlobals.CurTime, Ik);
}
}

Expand Down Expand Up @@ -924,6 +958,8 @@ private static void RecvProxy_Sequence(ref readonly RecvProxyData data, object i
}
BoneAccessor.Init(CachedBoneData.Base());

Ik = null;

if (Attachments.Count != hdr.GetNumAttachments())
Attachments.SetSizeInitialized(hdr.GetNumAttachments());

Expand Down
2 changes: 1 addition & 1 deletion Game.Client/C_BaseAnimatingOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public override void AccumulateLayers(ref BoneSetup boneSetup, Span<Vector3> pos
if (fWeight > 1)
fWeight = 1;

boneSetup.AccumulatePose(pos, q, AnimOverlay[i].Sequence, fCycle, fWeight, currentTime, null);
boneSetup.AccumulatePose(pos, q, AnimOverlay[i].Sequence, fCycle, fWeight, currentTime, Ik);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Game.Client/C_BasePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public C_BasePlayer() {
public int ButtonsArray;

public override bool IsPlayer() => true;
public override Mask PhysicsSolidMaskForEntity() => Mask.PlayerSolid;
public TimeUnit_t GetFinalPredictedTime() => FinalPredictedTick * TICK_INTERVAL;
public bool IsLocalPlayer() => GetLocalPlayer() == this;

Expand Down
1 change: 1 addition & 0 deletions Game.Server/AI_BaseNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ public AI_BaseNPC() {
InChoreo = true;

SetCollisionGroup(Source.CollisionGroup.NPC);
EnableServerIK();
}

public override void PostConstructor(ReadOnlySpan<char> classname) {
Expand Down
Loading
Loading