Skip to content
Draft
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
52 changes: 52 additions & 0 deletions Game.Assets/sdn/shaders/sprite_gl460.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#version 460
// STATIC: "VERTEXCOLOR" "0..1"
// STATIC: "CONSTANTCOLOR" "0..1"
// STATIC: "SRGB" "0..1"
// DYNAMIC: "HDRENABLED" "0..1"
// DYNAMIC: "PIXELFOGTYPE" "0..2"

layout(location = 0) in vec2 vs_BaseTexCoord;
layout(location = 1) in vec4 vs_Color;
layout(location = 2) in vec4 vs_WorldPos_ProjPosZ;

layout(std140, binding = 6) uniform source_ps_constants {
vec4 ps_const[256];
};

out vec4 fragColor;

#include "common_gl460.fs"

layout(binding = 0) uniform sampler2D TexSampler;

#define g_Color ps_const[0]
#define g_HDRColorScale ps_const[1].x
#define g_EyePos_SpecExponent ps_const[11]
#define g_FogParams ps_const[12]

void main()
{
vec4 result;
vec4 color = texture(TexSampler, vs_BaseTexCoord);

#if VERTEXCOLOR
color *= vs_Color;
#endif

#if CONSTANTCOLOR
color *= g_Color;
#endif

#if HDRENABLED
color.xyz *= g_HDRColorScale;
#endif

float fogFactor = CalcPixelFogFactor(PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, vs_WorldPos_ProjPosZ.xyz, vs_WorldPos_ProjPosZ.w);
#if SRGB
result = FinalOutput(color, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR);
#else
result = FinalOutput(color, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_GAMMA);
#endif

fragColor = result;
}
43 changes: 43 additions & 0 deletions Game.Assets/sdn/shaders/sprite_gl460.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#version 460
// STATIC: "VERTEXCOLOR" "0..1"
// STATIC: "SRGB" "0..1"

layout(location = 0) in vec3 v_Position;
layout(location = 2) in vec4 v_Color;
layout(location = 10) in vec4 v_TexCoord0;

layout(std140, binding = 0) uniform source_matrices {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 modelMatrix;
};

#include "common_gl460.glsl"

layout(location = 0) out vec2 vs_BaseTexCoord;
layout(location = 1) out vec4 vs_Color;
layout(location = 2) out vec4 vs_WorldPos_ProjPosZ;

#include "common_clipplanes_gl460.vs"

void main()
{
vec3 worldPos = (modelMatrix * vec4(v_Position, 1.0)).xyz;

vec4 projPos = projectionMatrix * viewMatrix * vec4(worldPos, 1.0);
gl_Position = projPos;
WriteUserClipDistances(gl_Position);

vs_WorldPos_ProjPosZ = vec4(worldPos, projPos.z);

vs_Color = vec4(1.0);
#if VERTEXCOLOR
#if SRGB
vs_Color = vec4(GammaToLinear(v_Color.rgb), v_Color.a);
#else
vs_Color = v_Color;
#endif
#endif

vs_BaseTexCoord = v_TexCoord0.xy;
}
19 changes: 18 additions & 1 deletion Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using Source.Common.Formats.BSP;
using Source.Common.Formats.Keyvalues;
using Source.Common.Mathematics;
using Source.Common.Physics;

using System;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
Expand Down Expand Up @@ -179,6 +181,21 @@ public void StudioFrameAdvance() {
GroundSpeed = (float)GetSequenceGroundSpeed(hdr, GetSequence()) * GetModelScale();
}

public override int VPhysicsGetObjectList(Span<IPhysicsObject?> list){
if (IsRagdoll()) {
int i;
for (i = 0; i < Ragdoll.RagdollBoneCount(); ++i) {
if (i >= list.Length)
break;

list[i] = Ragdoll.GetElement(i);
}
return i;
}

return base.VPhysicsGetObjectList(list);
}

public TimeUnit_t GetSequenceMoveDist(StudioHdr? studioHdr, int sequence) {
Animation.GetSequenceLinearMotion(studioHdr, sequence, PoseParameter, out Vector3 vecReturn);

Expand Down Expand Up @@ -830,7 +847,7 @@ public string GetSequenceName(int sequence) {
return Animation.GetSequenceName(GetModelPtr(), sequence);
}

public object? Ragdoll; // TODO
public ClientRagdoll? Ragdoll = null;

public override void OnDataChanged(DataUpdateType updateType) {
if (Ragdoll != null && GetSequence() != PrevSequence) {
Expand Down
5 changes: 4 additions & 1 deletion Game.Client/C_BaseCombatWeapon.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Game.Client.HUD;
using Game.Client.HUD;
using Game.Shared;

using Source;
using Source.Common;
using Source.Common.Input;

using System.Runtime.CompilerServices;

Expand All @@ -16,6 +17,8 @@ public partial class C_BaseCombatWeapon : C_BaseAnimating
public virtual bool WasDropped() => Dropped;
public virtual void SetDropped() => Dropped = true;
public virtual void DrawHUD() { }
public virtual bool ShouldFreezeViewAngles() => false;
public virtual int KeyInput(int down, ButtonCode keynum, ReadOnlySpan<char> currentBinding) => 1;
public virtual void DrawHUDBackground() { }
public override bool IsWeapon() => true;
public static BaseCombatWeapon? GetActiveWeapon() {
Expand Down
25 changes: 22 additions & 3 deletions Game.Client/C_BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,17 @@ public C_BaseEntity() {
IPhysicsObject? PhysicsObject = null!;
public void VPhysicsUpdate(IPhysicsObject physics) { }
public IPhysicsObject? VPhysicsGetObject() => PhysicsObject;
public int VPhysicsGetObjectList(Span<IPhysicsObject> list) => throw new NotImplementedException();
public virtual int VPhysicsGetObjectList(Span<IPhysicsObject?> list) {
IPhysicsObject? phys = VPhysicsGetObject();
if (phys != null) {
Assert((phys.GetGameFlags() & PhysicsFlags.MultiObjectEntity) == 0);
if (list.Length > 0) {
list[0] = phys;
return 1;
}
}
return 0;
}

public bool IsFloating() => false;

Expand Down Expand Up @@ -1183,8 +1193,17 @@ public void GetRenderBounds(out Vector3 mins, out Vector3 maxs) {
if (nModelType == ModelType.Studio || nModelType == ModelType.Brush)
modelinfo.GetModelRenderBounds(GetModel(), out mins, out maxs);
else {
// todo
mins = maxs = default;
if (GetRenderAngles() == CollisionProp().GetCollisionAngles()) {
mins = CollisionProp().OBBMins();
maxs = CollisionProp().OBBMaxs();
}
else {
Assert(CollisionProp().GetCollisionAngles() == vec3_angle);
if (CollisionProp().BoundingRadius() == 0.0f)
mins = maxs = vec3_origin;
else
MathLib.IRotateAABB(EntityToWorldTransform(), CollisionProp().OBBMins(), CollisionProp().OBBMaxs(), out mins, out maxs);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion Game.Client/ClientModeShared.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Game.Client.HUD;
using Game.Client.HUD;
using Game.Shared;

using Source;
Expand Down Expand Up @@ -165,6 +165,15 @@ public virtual int KeyInput(int down, ButtonCode keynum, ReadOnlySpan<char> curr
if (HudElementKeyInput(down, keynum, currentBinding) == 0)
return 0;

#if GMOD_DLL
if (surface.IsCursorVisible() && (keynum == ButtonCode.MouseWheelUp || keynum == ButtonCode.MouseWheelDown))
return 0;
#endif

BaseCombatWeapon? activeWeapon = C_BaseCombatWeapon.GetActiveWeapon();
if (activeWeapon != null)
return activeWeapon.KeyInput(down, keynum, currentBinding);

return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion Game.Client/ClientThinkList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,12 @@ private void CleanUpDeleteList() {
pEntity.SetRemovalFlag(false);

IClientThinkable? pThink = cl_entitylist.GetClientThinkableFromHandle(handle);
if (pThink != null)
if (pThink != null)
pThink.Release();
}
}

DeleteList.Clear();
}

private void AddEntityToFrameThinkList(ThinkEntry pEntry, bool bAlwaysChain, ref int count, Span<ThinkEntry> ppFrameThinkList) {
Expand Down
1 change: 1 addition & 0 deletions Game.Client/GarrysMod/C_GMOD_Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public partial class C_GMOD_Player() : C_HL2MP_Player()
public Vector3 WeaponColor;

public virtual Vector3 GetPlayerColor() => PlayerColor;
public virtual Vector3 GetWeaponColor() => WeaponColor;

public virtual void SetPlayerColor(in Vector3 color) {
if (PlayerColor != color)
Expand Down
4 changes: 1 addition & 3 deletions Game.Client/HLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,7 @@ public void GMOD_OnDrawSkybox() {
throw new NotImplementedException();
}

public void IN_MouseWheelAnalog(int value) {
throw new NotImplementedException();
}
public void IN_MouseWheelAnalog(int value) => input.MouseWheeled(value);

public void GMOD_SignOnStateChanged(int userID, int oldState, int newState) {
throw new NotImplementedException();
Expand Down
3 changes: 3 additions & 0 deletions Game.Client/IInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public interface IInput
void ExtraMouseSample(double frametime, bool active);
void ActivateMouse();
void DeactivateMouse();
#if GMOD_DLL
void MouseWheeled(int delta);
#endif
void ClearStates();
void CAM_Think();
ref UserCmd GetUserCmd(int sequenceNumber);
Expand Down
13 changes: 13 additions & 0 deletions Game.Client/InMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ public void CreateMove(int sequenceNumber, double inputSampleFrametime, bool act
cmd.Buttons |= InButtons.Forward;
else if (cmd.ForwardMove < 0)
cmd.Buttons |= InButtons.Back;

#if GMOD_DLL
MouseWheel = 0;
#endif
}

private void ApplyExtras(ref UserCmd cmd) {
Expand Down Expand Up @@ -494,6 +498,7 @@ private void ControllerMove(double frametime, ref UserCmd cmd) {

private void MouseMove(ref UserCmd cmd) {
engine.GetViewAngles(out QAngle viewangles);
QAngle originalViewangles = viewangles;
view.StopPitchDrift();

if (!CameraInterceptingMouse && !Surface.IsCursorVisible()) {
Expand All @@ -506,10 +511,18 @@ private void MouseMove(ref UserCmd cmd) {
ResetMouse();
}

#if GMOD_DLL
if (C_BasePlayer.GetLocalPlayer()?.GetActiveWeapon()?.ShouldFreezeViewAngles() == true)
viewangles = originalViewangles;
#endif

engine.SetViewAngles(in viewangles);
}

private void ApplyMouse(ref QAngle viewangles, ref UserCmd cmd, float mouse_x, float mouse_y) {
#if GMOD_DLL
cmd.ScrollWheelSpeed = (sbyte)MouseWheel;
#endif
if ((in_strafe.State & KeyButtonStateFlags.Down) == 0 || lookstrafe.GetInt() != 0) {
if (CAM_IsThirdPerson() && thirdperson_platformer.GetInt() != 0) {
if (mouse_x != 0) {
Expand Down
18 changes: 18 additions & 0 deletions Game.Client/InMouse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Source.Common.Commands;
using Source.Common.GUI;
using Source.Common.Launcher;
using Source.GUI.Controls;

namespace Game.Client;

Expand Down Expand Up @@ -43,10 +44,27 @@ public void DeactivateMouse() {

AccumulatedMouseXMovement = 0;
AccumulatedMouseYMovement = 0;
#if GMOD_DLL
MouseWheel = 0;
#endif
launcher.SetWindowRelativeMouseMode(false);
}
}

#if GMOD_DLL
int MouseWheel;

public void MouseWheeled(int delta) {
if (!Surface.IsCursorVisible()) {
MouseWheel += delta;
return;
}

if (input.GetMouseOver() is Panel panel && panel.IsWorldClicker())
MouseWheel += delta;
}
#endif

ConVar m_filter = new("0", FCvar.Archive, "Mouse filtering (set this to 1 to average the mouse over 2 frames).");
ConVar sensitivity = new("3", FCvar.Archive, "Mouse sensitivity.", 0.0001f, 1000);
ConVar m_side = new("0.8", FCvar.Archive, "Mouse side factor.", 0.0001f, 1000);
Expand Down
Loading
Loading