Skip to content
Merged
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Every [SourceDll] assembly links Usings/GlobalUsings.cs. Those get the ConVar/ConCommand registration generator,
which emits Source.Generated.CvarRegistration for EngineBuilder.ConVar_Register to use instead of reflection. -->
<ItemGroup Condition="'@(Compile->WithMetadataValue('Identity', '..\Usings\GlobalUsings.cs'))' != ''">
<ItemGroup Condition="'@(Compile->WithMetadataValue('Identity', '..\Usings\GlobalUsings.cs'))@(Compile->WithMetadataValue('Identity', '../Usings/GlobalUsings.cs'))' != ''">
<ProjectReference Include="$(MSBuildThisFileDirectory)Source.CodeAnalysis.ConVars\Source.CodeAnalysis.ConVars.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="$(MSBuildThisFileDirectory)Source.CodeAnalysis.VGUI\Source.CodeAnalysis.VGUI.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
</ItemGroup>
Expand Down
18 changes: 7 additions & 11 deletions Game.Assets/sdn/shaders/blurfilter_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ layout(location = 4) out vec2 vs_CoordTap1Neg;
layout(location = 5) out vec2 vs_CoordTap2Neg;
layout(location = 6) out vec2 vs_CoordTap3Neg;

vec2 FlipV(vec2 uv)
{
return vec2(uv.x, 1.0 - uv.y);
}

#include "common_clipplanes_gl460.vs"

Expand All @@ -31,11 +27,11 @@ void main()
gl_Position = vec4(v_Position, 1.0);
WriteUserClipDistances(gl_Position);

vs_CoordTap0 = FlipV(v_TexCoord);
vs_CoordTap1 = FlipV(v_TexCoord + vsTapOffs0);
vs_CoordTap2 = FlipV(v_TexCoord + vsTapOffs1);
vs_CoordTap3 = FlipV(v_TexCoord + vsTapOffs2);
vs_CoordTap1Neg = FlipV(v_TexCoord - vsTapOffs0);
vs_CoordTap2Neg = FlipV(v_TexCoord - vsTapOffs1);
vs_CoordTap3Neg = FlipV(v_TexCoord - vsTapOffs2);
vs_CoordTap0 = v_TexCoord;
vs_CoordTap1 = v_TexCoord + vsTapOffs0;
vs_CoordTap2 = v_TexCoord + vsTapOffs1;
vs_CoordTap3 = v_TexCoord + vsTapOffs2;
vs_CoordTap1Neg = v_TexCoord - vsTapOffs0;
vs_CoordTap2Neg = v_TexCoord - vsTapOffs1;
vs_CoordTap3Neg = v_TexCoord - vsTapOffs2;
}
6 changes: 6 additions & 0 deletions Game.Assets/sdn/shaders/common_gl460.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const vec3 bumpBasis[3] = vec3[3](
vec3( -0.40824821591377258, -0.7071068286895752, OO_SQRT_3 )
);

vec3 NormalizeD3D9(vec3 v)
{
float lenSq = dot(v, v);
return lenSq > 0.0 ? v * inversesqrt(lenSq) : vec3(0.0);
}

vec3 CalcReflectionVectorUnnormalized(vec3 normal, vec3 eyeVector)
{
// FIXME: might be better of normalizing with a normalizing cube map and
Expand Down
12 changes: 4 additions & 8 deletions Game.Assets/sdn/shaders/downsample_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ layout(location = 1) out vec2 vs_CoordTap1;
layout(location = 2) out vec2 vs_CoordTap2;
layout(location = 3) out vec2 vs_CoordTap3;

vec2 FlipV(vec2 uv)
{
return vec2(uv.x, 1.0 - uv.y);
}

#include "common_clipplanes_gl460.vs"

Expand All @@ -29,8 +25,8 @@ void main()
gl_Position = vec4(v_Position, 1.0);
WriteUserClipDistances(gl_Position);

vs_CoordTap0 = FlipV(v_TexCoord + vsTapOffs0);
vs_CoordTap1 = FlipV(v_TexCoord + vsTapOffs1);
vs_CoordTap2 = FlipV(v_TexCoord + vsTapOffs2);
vs_CoordTap3 = FlipV(v_TexCoord + vsTapOffs3);
vs_CoordTap0 = v_TexCoord + vsTapOffs0;
vs_CoordTap1 = v_TexCoord + vsTapOffs1;
vs_CoordTap2 = v_TexCoord + vsTapOffs2;
vs_CoordTap3 = v_TexCoord + vsTapOffs3;
}
2 changes: 1 addition & 1 deletion Game.Assets/sdn/shaders/g_screenquad_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ void main()
{
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(v_Position, 1.0);
WriteUserClipDistances(gl_Position);
vs_TexCoord = vec2(v_TexCoord.x, 1.0 - v_TexCoord.y);
vs_TexCoord = v_TexCoord;
}
2 changes: 1 addition & 1 deletion Game.Assets/sdn/shaders/g_sobel_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ void main()
{
gl_Position = projectionMatrix * viewMatrix * vec4(v_Position, 1.0);
WriteUserClipDistances(gl_Position);
vs_TexCoord = vec2(v_TexCoord.x, 1.0 - v_TexCoord.y);
vs_TexCoord = v_TexCoord;
}
2 changes: 1 addition & 1 deletion Game.Assets/sdn/shaders/screenspaceeffect_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main()
gl_Position = vec4(v_Position, 1.0);
#endif
WriteUserClipDistances(gl_Position);
vs_BaseTexCoord = vec2(v_TexCoord.x, 1.0 - v_TexCoord.y);
vs_BaseTexCoord = v_TexCoord;
vs_TexCoord0 = vec4(vs_BaseTexCoord, 0.0, 1.0);
vs_TexCoord1 = vec4(0.0, 0.0, 0.0, 1.0);
vs_TexCoord2 = vs_TexCoord0;
Expand Down
4 changes: 2 additions & 2 deletions Game.Assets/sdn/shaders/skin_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void main()
// Always normalize since flex path is controlled by runtime
// constant not a shader combo and will always generate the normalization
worldNormal = normalize(worldNormal);
worldTangentS = normalize(worldTangentS);
worldTangentT = normalize(worldTangentT);
worldTangentS = NormalizeD3D9(worldTangentS);
worldTangentT = NormalizeD3D9(worldTangentT);

// Transform into projection space
vec4 vProjPos = projectionMatrix * viewMatrix * vec4(worldPos, 1.0);
Expand Down
4 changes: 2 additions & 2 deletions Game.Assets/sdn/shaders/teeth_bump_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void main()
#endif

worldNormal = normalize(worldNormal);
worldTangentS = normalize(worldTangentS);
worldTangentT = normalize(worldTangentT);
worldTangentS = NormalizeD3D9(worldTangentS);
worldTangentT = NormalizeD3D9(worldTangentT);

vec4 vProjPos = projectionMatrix * viewMatrix * vec4(worldPos, 1.0);
gl_Position = vProjPos;
Expand Down
4 changes: 2 additions & 2 deletions Game.Assets/sdn/shaders/vertexlitgeneric_bump_gl460.vs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void main()
// Always normalize since flex path is controlled by runtime
// constant not a shader combo and will always generate the normalization
worldNormal = normalize(worldNormal);
worldTangentS = normalize(worldTangentS);
worldTangentT = normalize(worldTangentT);
worldTangentS = NormalizeD3D9(worldTangentS);
worldTangentT = NormalizeD3D9(worldTangentT);

vs_WorldNormal.xyz = worldNormal.xyz;
vs_WorldTangent = vec4(worldTangentS.xyz, vTangent.w); // Propagate binormal sign in world tangent.w
Expand Down
7 changes: 7 additions & 0 deletions Game.Client/CDLL_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public static int EntitiesInSphere(Span<C_BaseEntity?> list, in Vector3 center,
return sphereEnum.GetCount();
}

public static int EntitiesInBox(Span<C_BaseEntity?> list, in Vector3 mins, in Vector3 maxs, EntityFlags flagMask, PartitionListMask partitionMask) {
FlaggedEntitiesEnum boxEnum = new(list, flagMask);
partition.EnumerateElementsInBox((SpatialPartitionListMask_t)partitionMask, mins, maxs, false, ref boxEnum);

return boxEnum.GetCount();
}

}
public static partial class Util_Globals
{
Expand Down
5 changes: 1 addition & 4 deletions Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ public TimeUnit_t GetSequenceGroundSpeed(StudioHdr? studioHdr, int sequence) {
return 0;
}

public virtual void UpdateModelScale() {
// todo
}

bool SequenceLoops;
bool SequenceFinished;
Expand Down Expand Up @@ -1132,7 +1129,7 @@ public int FindTransitionSequence(int currentSequence, int goalSequence, ref int

public bool ReceivedSequence;
public void SetReceivedSequence() => ReceivedSequence = true;
public bool ShouldResetSequenceOnNewModel() => ReceivedSequence == false;
public virtual bool ShouldResetSequenceOnNewModel() => ReceivedSequence == false;
private void UpdateRelevantInterpolatedVars() {
if (!IsMarkedForDeletion() && !GetPredictable() && !IsClientCreated() && GetModelPtr() != null && GetModelPtr()!.SequencesAvailable())
AddBaseAnimatingInterpolatedVars();
Expand Down
18 changes: 14 additions & 4 deletions Game.Client/C_BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2520,15 +2520,17 @@ public void SetAbsOrigin(in Vector3 absOrigin) {
RemoveEFlags(EFL.DirtyAbsTransform);

AbsOrigin = absOrigin;
// TODO: Coordinate frame...
MathLib.MatrixSetColumn(absOrigin, 3, ref CoordinateFrame);

C_BaseEntity? moveParent = GetMoveParent();

if (moveParent == null) {
Origin = absOrigin;
return;
}

// TODO: Handle move parents...
MathLib.VectorITransform(absOrigin, moveParent.EntityToWorldTransform(), out Vector3 origin);
Origin = origin;
}

public void SetAbsAngles(in QAngle absAngles) {
Expand All @@ -2541,7 +2543,8 @@ public void SetAbsAngles(in QAngle absAngles) {
RemoveEFlags(EFL.DirtyAbsTransform);

AbsRotation = absAngles;
// TODO: Set coordinate frame
MathLib.AngleMatrix(absAngles, out CoordinateFrame);
MathLib.MatrixSetColumn(AbsOrigin, 3, ref CoordinateFrame);

C_BaseEntity? moveParent = GetMoveParent();

Expand All @@ -2550,7 +2553,14 @@ public void SetAbsAngles(in QAngle absAngles) {
return;
}

// TODO: Handle move parents...
if (AbsRotation == moveParent.GetAbsAngles())
Rotation = default;
else {
MathLib.MatrixInvert(moveParent.EntityToWorldTransform(), out Matrix3x4 worldToParent);
MathLib.ConcatTransforms(worldToParent, CoordinateFrame, out Matrix3x4 localMatrix);
MathLib.MatrixAngles(localMatrix, out QAngle rotation);
Rotation = rotation;
}
}

public void MoveToAimEnt() {
Expand Down
14 changes: 7 additions & 7 deletions Game.Client/C_BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public partial class C_BaseViewModel
[PredictionTable]
public static readonly new PredictionField[] Prediction = [
new(nameof(ModelIndex)) { Type = FieldType.Short, Flags = FieldTypeDescFlags.InSendTable | FieldTypeDescFlags.ModelIndex },
new(nameof(Skin)) { Type = FieldType.Integer },
new(nameof(Body)) { Type = FieldType.Integer },
new(nameof(Sequence)) { Type = FieldType.Integer },
new(nameof(_ViewModelIndex)) { Type = FieldType.Integer },
new(nameof(PlaybackRate)) { Type = FieldType.Float, Tolerance = 0.125f },
new(nameof(Skin)) { Type = FieldType.Integer, Flags = FieldTypeDescFlags.InSendTable },
new(nameof(Body)) { Type = FieldType.Integer, Flags = FieldTypeDescFlags.InSendTable },
new(nameof(Sequence)) { Type = FieldType.Integer, Flags = FieldTypeDescFlags.InSendTable },
new(nameof(_ViewModelIndex)) { Type = FieldType.Integer, Flags = FieldTypeDescFlags.InSendTable },
new(nameof(PlaybackRate)) { Type = FieldType.Float, Flags = FieldTypeDescFlags.InSendTable, Tolerance = 0.125f },
new(nameof(Effects)) { Type = FieldType.Integer, Flags = FieldTypeDescFlags.InSendTable | FieldTypeDescFlags.Override },
new(nameof(AnimationParity)) { Type = FieldType.Integer },
nameof(Weapon),
new(nameof(AnimationParity)) { Type = FieldType.Integer, Flags = FieldTypeDescFlags.InSendTable },
new(nameof(Weapon)) { Flags = FieldTypeDescFlags.InSendTable },
new(nameof(AnimTime)) { Type = FieldType.Float, Flags = 0 },
new(nameof(Owner)) { Flags = FieldTypeDescFlags.Save },
new(nameof(TimeWeaponIdle)) { Type = FieldType.Float },
Expand Down
2 changes: 1 addition & 1 deletion Game.Client/C_TEParticleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class C_TEParticleSystem : C_BaseTempEntity
{
[NetworkTable]
public static readonly NetworkProp[] Props = [
new(nameof(Origin)) { Encoding = NetEncoding.VectorElements, Bits = 0, Flags = PropFlags.Coord | PropFlags.NoScale | PropFlags.IsAVectorElem },
new(nameof(Origin)) { Encoding = NetEncoding.VectorElements, Bits = 0, Flags = PropFlags.Coord | PropFlags.NoScale },
];

[NetworkVar("m_vecOrigin")]
Expand Down
11 changes: 7 additions & 4 deletions Game.Client/GarrysMod/LuaRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ static int SetModelLighting(ILuaInterface lua) {

[LuaFunction]
static int UpdateScreenEffectTexture(ILuaInterface lua) {
int textureIndex = 0;
if (lua.GetType(1) == LuaType.Number)
textureIndex = (int)lua.GetNumber(1);
ViewScene.UpdateScreenEffectTexture(textureIndex, 0, 0, ScreenWidth(), ScreenHeight(), false);
uint textureIndex = 0;
if (lua.GetType(1) == LuaType.Number) {
textureIndex = (uint)lua.CheckNumber(1);
if (textureIndex > 4)
return 0;
}
ViewScene.UpdateScreenEffectTexture((int)textureIndex, 0, 0, ScreenWidth(), ScreenHeight(), false);
return 0;
}
#endif
Expand Down
20 changes: 15 additions & 5 deletions Game.Client/GarrysMod/LuaSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ static int DrawPoly(ILuaInterface lua) {
vertex.UnReference();
}

if (count < 3) {
vertices.UnReference();
lua.ArgError(1, "table must contain at least three vertices");
Comment thread
callumok2004 marked this conversation as resolved.
Resolved
return 0;
}

surface.DrawTexturedPolygon(((Span<SurfaceVertex>)PolyVerts)[..count], true);
vertices.UnReference();
return 0;
Expand All @@ -414,12 +420,16 @@ static int DrawCircle(ILuaInterface lua) {
}
[LuaFunction]
static int DrawTexturedRectUV(ILuaInterface lua) {
int x = (int)lua.GetNumber(1);
int y = (int)lua.GetNumber(2);
int w = (int)lua.GetNumber(3);
int h = (int)lua.GetNumber(4);
int x = (int)lua.CheckNumber(1);
int y = (int)lua.CheckNumber(2);
int w = (int)lua.CheckNumber(3);
int h = (int)lua.CheckNumber(4);
// TODO: poster cmd split scaling (?)
surface.DrawTexturedSubRect(x, y, w + x, h + y, (float)lua.GetNumber(5), (float)lua.GetNumber(6), (float)lua.GetNumber(7), (float)lua.GetNumber(8));
float v1 = (float)lua.CheckNumber(8);
float u1 = (float)lua.CheckNumber(7);
float v0 = (float)lua.CheckNumber(6);
float u0 = (float)lua.CheckNumber(5);
surface.DrawTexturedSubRect(x, y, w + x, h + y, u0, v0, u1, v1);
return 0;
}

Expand Down
25 changes: 25 additions & 0 deletions Game.Client/Physics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,34 @@ public override void LevelInitPostEntity() {

static readonly ConVar cl_phys_timescale = new("cl_phys_timescale", "1.0", FCvar.Cheat, "Sets the scale of time for client-side physics (ragdolls)");

#if GMOD_DLL
public static float g_GMOD_PhysTimeScale = 1.0f;
public static bool g_GMOD_PhysicsPaused;
public static TimeUnit_t g_GMOD_LastSimulationTime;

public static void GMOD_PhysicsSetTimeScale(float scale) {
if (scale <= 0.001f)
scale = 0.001f;
if (5.0f <= scale)
scale = 5.0f;
g_GMOD_PhysTimeScale = scale;
}

public static float GMOD_PhysicsGetTotalTimeScale() => cl_phys_timescale.GetFloat() * g_GMOD_PhysTimeScale;
#endif

internal void PhysicsSimulate() {
TimeUnit_t frametime = gpGlobals.FrameTime;
if (physenv != null) {
#if GMOD_DLL
TimeUnit_t startTime = engine.Time();
#endif
physenv.DebugCheckContacts();
#if GMOD_DLL
physenv.Simulate(GMOD_PhysicsGetTotalTimeScale() * frametime);
#else
physenv.Simulate(frametime * cl_phys_timescale.GetDouble());
#endif

int activeCount = physenv.GetActiveObjectCount();
IPhysicsObject?[]? activeList = null;
Expand All @@ -67,6 +89,9 @@ internal void PhysicsSimulate() {

ArrayPool<IPhysicsObject>.Shared.Return(activeList, true);
}
#if GMOD_DLL
g_GMOD_LastSimulationTime = engine.Time() - startTime;
#endif

// g_Collisions.BufferTouchEvents(false);
// g_Collisions.FrameUpdate();
Expand Down
3 changes: 2 additions & 1 deletion Game.Client/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class ViewRender : IViewRender

static ConVar r_nearz = new(VIEW_NEARZ.ToString(), FCvar.Cheat, "Override the near clipping plane.");
static ConVar r_farz = new("-1", FCvar.Cheat, "Override the far clipping plane. -1 means to use the value in env_fog_controller.");
static ConVar mat_viewportscale = new("1.0", FCvar.Archive, "Scale down the main viewport (to reduce GPU impact on CPU profiling)", (1.0f / 640f /*BASE_WIDTH*/), 1.0f);

public ViewSetup CurrentView;
bool ForceNoVis;
Expand Down Expand Up @@ -321,7 +322,7 @@ public void Render(ViewRects rect) {
viewEye.FOV = ScaleFOVByWidthRatio(viewEye.FOV, limitedAspectRatio);
viewEye.FOVViewmodel = ScaleFOVByWidthRatio(viewEye.FOVViewmodel, limitedAspectRatio);

float viewportScale = 1.0f; // mat_viewportscale todo
float viewportScale = mat_viewportscale.GetFloat();
viewEye.UnscaledX = vr.X;
viewEye.UnscaledY = vr.Y;
viewEye.UnscaledWidth = vr.Width;
Expand Down
4 changes: 2 additions & 2 deletions Game.Server.Tests/NetworkTableCRCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static readonly (string Table, int Props, uint CRC)[] ExpectedSendTables = [
("DT_Sun", 9, 0x4DF9570F),
("DT_Team", 6, 0xE8978EEF),
("DT_TEAntlionDust", 4, 0x586372F5),
("DT_TEParticleSystem", 4, 0x065AB3D7),
("DT_TEParticleSystem", 4, 0x5BCAB5BE),
("DT_TEArmorRicochet", 1, 0xB4D64715),
("DT_TEMetalSparks", 2, 0x2414F0A1),
("DT_BaseBeam", 15, 0x28E975D5),
Expand Down Expand Up @@ -259,7 +259,7 @@ static readonly (string Table, int Props, uint CRC)[] ExpectedSendTables = [
("DT_TEKillPlayerAttachments", 2, 0x9540E3DA),
("DT_TELargeFunnel", 2, 0x59A289D4),
("DT_TEMuzzleFlash", 5, 0x4D3036F3),
("DT_TEPhysicsProp", 12, 0x778EA75F),
("DT_TEPhysicsProp", 12, 0x46C6424C),
("DT_TEPlayerAnimEvent", 3, 0x532041F7),
("DT_TEPlayerDecal", 4, 0xFE26A6F9),
("DT_TEProjectedDecal", 5, 0x42A7776F),
Expand Down
17 changes: 17 additions & 0 deletions Game.Server/BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ public BaseAnimating() {
[NetworkVar("m_pFlexManipulator")]
public partial EHANDLE FlexManipulator { get; set; }

public virtual void SetBoneManipulator(BaseEntity? manipulator) => BoneManipulator = EHANDLE.FromEntity(manipulator);

public virtual BaseEntity? GetBoneManipulator(bool create) {
if (BoneManipulator.Get() == null && create) {
BaseEntity? manipulator = CreateEntityByName("manipulate_bone");
if (manipulator == null)
return null;

manipulator.SetParent(this, -1);
manipulator.SetLocalOrigin(default);
manipulator.Spawn();
SetBoneManipulator(manipulator);
}

return BoneManipulator.Get();
}

public virtual void SetFlexManipulator(BaseEntity? manipulator) => FlexManipulator = EHANDLE.FromEntity(manipulator);

public virtual BaseEntity? GetFlexManipulator(bool create) {
Expand Down
Loading
Loading