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
4 changes: 2 additions & 2 deletions Game.Client/C_Func_LOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class C_Func_LOD : C_BaseEntity
public static readonly new ClientClass ClientClass = new ClientClass(DT_Func_LOD);

[NetworkName("m_fDisappearMinDist")]
public float DisappearMinDist;
public float DisappearMinDist = 5000.0f;
[NetworkName("m_fDisappearMaxDist")]
public float DisappearMaxDist;
public float DisappearMaxDist = 5800.0f;
}
28 changes: 27 additions & 1 deletion Game.Server/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,33 @@ public virtual int OnTakeDamage(in TakeDamageInfo info) {

public virtual void DeathNotice(BaseEntity victim) { }

public IPhysicsObject? VPhysicsInitStatic() => throw new NotImplementedException();
public IPhysicsObject? VPhysicsInitStatic() {
if (!VPhysicsInitSetup())
return null;

if (GetMoveParent() != null) {
if (GetSolid() == SolidType.BSP && GetRootMoveParent().GetSolid() != SolidType.BSP)
SetSolid(SolidType.VPhysics);

VPhysicsInitShadow(false, false);
return VPhysicsGetObject();
}

if (GetSolid() == SolidType.None)
return null;

IPhysicsObject? physicsObject;
if (GetSolid() == SolidType.BBox)
physicsObject = PhysModelCreateBox(this, WorldAlignMins(), WorldAlignMaxs(), GetAbsOrigin(), true);
else
physicsObject = PhysModelCreateUnmoveable(this, GetModelIndex(), GetAbsOrigin(), GetAbsAngles());

if (PhysicsObject != null)
Error("VPhysicsInitStatic got a physics object at unexpected time!\n");

VPhysicsSetObject(physicsObject);
return physicsObject;
}

public virtual void Event_KilledOther(BaseEntity killed, in TakeDamageInfo info) {

Expand Down
34 changes: 34 additions & 0 deletions Game.Server/Func_LOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Game.Server;

using FIELD = FIELD<Func_LOD>;
using DEFINE = Source.DEFINE<Func_LOD>;

[LinkEntityToClass("func_lod")]
[NetworkName("CFunc_LOD")]
Expand All @@ -17,8 +18,41 @@ public class Func_LOD : BaseEntity
]);
public static readonly new ServerClass ServerClass = new ServerClass(DT_Func_LOD);

public static readonly new DataMap DataDesc = new(typeof(Func_LOD), BaseEntity.DataDesc, [
DEFINE.KEYFIELD(nameof(DisappearMinDist), FieldType.Float, "DisappearMinDist"),
DEFINE.KEYFIELD(nameof(DisappearMaxDist), FieldType.Float, "DisappearMaxDist"),
]);
public override DataMap? GetDataDescMap() => DataDesc;

[NetworkName("m_fDisappearMinDist")]
public float DisappearMinDist;
[NetworkName("m_fDisappearMaxDist")]
public float DisappearMaxDist;

public override void Spawn() {
SetModel(GetModelName());
SetSolid(SolidType.BSP);
base.Spawn();
CreateVPhysics();
}

public bool CreateVPhysics() {
VPhysicsInitStatic();
return true;
}

public override bool KeyValue(ReadOnlySpan<char> keyName, ReadOnlySpan<char> value) {
if (FStrEq(keyName, "DisappearDist")) {
DisappearMinDist = atoi(value);
DisappearMaxDist = DisappearMinDist + 800.0f;
}
else if (FStrEq(keyName, "Solid")) {
if (atoi(value) != 0)
AddSolidFlags(SolidFlags.NotSolid);
}
else
return base.KeyValue(keyName, value);

return true;
}
}
39 changes: 38 additions & 1 deletion Game.Shared/PhysicsShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public static bool PhysModelParseSolidByIndex(ref Solid solid, BaseEntity entity
solid.Params.EnableCollisions = true;

solid.Params.GameData = entity;
solid.Params.Name = new string(((ReadOnlySpan<char>)entity.GetModelName()).SliceNullTerminatedString());
solid.Params.Name = new string(entity.GetModelName());
return parsed;
}

Expand All @@ -432,6 +432,43 @@ public static bool PhysModelParseSolidByIndex(ref Solid solid, BaseEntity entity
return PhysModelCreateInternal(entity, collide, in origin, in angles, ref solid);
}

public static IPhysicsObject? PhysModelCreateUnmoveable(BaseEntity entity, int modelIndex, in Vector3 origin, in QAngle angles) {
if (physenv == null)
return null;

VCollide? collide = modelinfo.GetVCollide(modelIndex);
if (collide == null || collide.SolidCount == 0 || collide.Solids == null)
return null;

Solid solid = default;
if (!PhysModelParseSolidByIndex(ref solid, entity, collide, -1))
return null;

solid.Params.EnableCollisions = true;

int surfaceProp = -1;
ReadOnlySpan<char> surfacePropName = ((ReadOnlySpan<char>)solid.SurfaceProp).SliceNullTerminatedString();
if (!surfacePropName.IsEmpty)
surfaceProp = (int)physprops.GetSurfaceIndex(surfacePropName);

solid.Params.GameData = entity;
solid.Params.Name = new string(entity.GetModelName());
IPhysicsObject? obj = physenv.CreatePolyObjectStatic(collide.Solids[0]!, surfaceProp, origin, angles, ref solid.Params);

if (obj != null) {
if (modelinfo.GetModelType(modelinfo.GetModel(modelIndex)) == ModelType.Brush) {
uint contents = (uint)modelinfo.GetModelContents(modelIndex);
Assert(contents != 0);
if (contents != obj.GetContents() && contents != 0) {
obj.SetContents(contents);
obj.RecheckCollisionFilter();
}
}
}

return obj;
}

static IPhysicsObject? PhysModelCreateInternal(BaseEntity entity, VCollide collide, in Vector3 origin, in QAngle angles, ref Solid solid) {
int surfaceProp = -1;
ReadOnlySpan<char> surfacePropName = ((ReadOnlySpan<char>)solid.SurfaceProp).SliceNullTerminatedString();
Expand Down
30 changes: 30 additions & 0 deletions Source.Engine/CollisionModelSubsystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,36 @@ private static void DispTreeLeafnum(CollisionBSPData bspData) {
return (bspData.MapCollisionModels[index]);
}

static Contents BrushContents_r(CollisionBSPData bspData, int nodenum) {
Contents contents = 0;

while (true) {
if (nodenum < 0) {
int leafIndex = -1 - nodenum;
ref CollisionLeaf leaf = ref bspData.MapLeafs.AsSpan()[leafIndex];

for (int i = 0; i < leaf.NumLeafBrushes; i++) {
ushort brushIndex = bspData.MapLeafBrushes[leaf.FirstLeafBrush + i];
contents |= bspData.MapBrushes.AsSpan()[brushIndex].Contents;
}

return contents;
}

ref CollisionNode node = ref bspData.MapNodes.AsSpan()[bspData.MapRootNode + nodenum];
contents |= BrushContents_r(bspData, node.Children[0]);
nodenum = node.Children[1];
}
}

public static Contents InlineModelContents(int index) {
CollisionModel? model = InlineModelNumber(index);
if (model == null)
return 0;

return BrushContents_r(GetCollisionBSPData(), model.HeadNode);
}

internal static void ClearTrace(ref Trace trace) {
trace = default;
trace.Fraction = 1;
Expand Down
12 changes: 11 additions & 1 deletion Source.Engine/ModelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Source.Common.DataCache;
using Source.Common.Engine;
using Source.Common.Filesystem;
using Source.Common.Formats.BSP;
using Source.Common.MaterialSystem;
using Source.Common.Mathematics;
using Source.Common.Physics;
Expand Down Expand Up @@ -317,7 +318,16 @@ public void GetIlluminationPoint(Model? model, IClientRenderable? renderable, in
}

public int GetModelContents(int modelIndex) {
throw new NotImplementedException();
Model? model = GetModel(modelIndex);
if (model != null) {
switch (model.Type) {
case ModelType.Brush:
return (int)CM.InlineModelContents(modelIndex - 1);
case ModelType.Studio:
return (int)Contents.Solid;
}
}
return 0;
}

public void SetLevelScreenFadeRange(float minSize, float maxSize) {
Expand Down
Loading