From 19eeafda7acebdfa4715ebc5c83d74429d54fb4c Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Fri, 2 Oct 2026 03:42:44 +0100 Subject: [PATCH 1/2] Add vscode release tasks --- .vscode/launch.json | 42 +++++++++++++++++++++++++++++++++++++++++- .vscode/tasks.json | 28 +++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 83127be38..cde71acdb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,25 @@ "stopAtEntry": false, "console": "externalTerminal" }, + { + "name": "Source.Launcher (Release)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build Source.Launcher (Release)", + "program": "${workspaceFolder}/Source.Launcher/bin/Release/net10.0/Source.Launcher.dll", + "cwd": "${workspaceFolder}/Source.Launcher/bin/Release/net10.0", + "stopAtEntry": false + }, + { + "name": "Source.Launcher (Release, External Terminal)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build Source.Launcher (Release)", + "program": "${workspaceFolder}/Source.Launcher/bin/Release/net10.0/Source.Launcher.dll", + "cwd": "${workspaceFolder}/Source.Launcher/bin/Release/net10.0", + "stopAtEntry": false, + "console": "externalTerminal" + }, { "name": "Source.Dedicated", "type": "coreclr", @@ -40,6 +59,27 @@ "args": ["-maxplayers", "2", "+map", "gm_flatgrass"], "stopAtEntry": false, "console": "externalTerminal" + }, + { + "name": "Source.Dedicated (Release)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build Source.Dedicated (Release)", + "program": "${workspaceFolder}/Source.Dedicated/bin/Release (Dedicated)/net10.0/Source.Dedicated.dll", + "cwd": "${workspaceFolder}/Source.Dedicated/bin/Release (Dedicated)/net10.0", + "args": ["-maxplayers", "2", "+map", "gm_flatgrass"], + "stopAtEntry": false + }, + { + "name": "Source.Dedicated (Release, External Terminal)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build Source.Dedicated (Release)", + "program": "${workspaceFolder}/Source.Dedicated/bin/Release (Dedicated)/net10.0/Source.Dedicated.dll", + "cwd": "${workspaceFolder}/Source.Dedicated/bin/Release (Dedicated)/net10.0", + "args": ["-maxplayers", "2", "+map", "gm_flatgrass"], + "stopAtEntry": false, + "console": "externalTerminal" } ] -} \ No newline at end of file +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7639d02d7..c051cb134 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -12,6 +12,19 @@ ], "problemMatcher": "$msCompile" }, + { + "label": "build Source.Launcher (Release)", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Source.Launcher/Source.Launcher.csproj", + "-p:WarningLevel=0", + "-c", + "Release" + ], + "problemMatcher": "$msCompile" + }, { "label": "build Source.Dedicated", "command": "dotnet", @@ -24,6 +37,19 @@ "Debug (Dedicated)" ], "problemMatcher": "$msCompile" + }, + { + "label": "build Source.Dedicated (Release)", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Source.Dedicated/Source.Dedicated.csproj", + "-p:WarningLevel=0", + "-c", + "Release (Dedicated)" + ], + "problemMatcher": "$msCompile" } ] -} \ No newline at end of file +} From 310feace17d8a4986f20de90ea8558ef3be78382 Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Fri, 2 Oct 2026 03:43:32 +0100 Subject: [PATCH 2/2] Some cleanups Slightly improves perf rendering text --- Source.Common/MaterialSystem/IMesh.cs | 32 ++++++++++++------- Source.Engine/Server/BaseServer.cs | 7 ++-- Source.MaterialSystem/Surface/Clip2D.cs | 4 +-- Source.MaterialSystem/Surface/FontManager.cs | 7 ++-- .../Surface/MatSystemSurface.cs | 10 +++--- Source.ShaderAPI.Gl46/VertexBufferGl46.cs | 11 ++++--- 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Source.Common/MaterialSystem/IMesh.cs b/Source.Common/MaterialSystem/IMesh.cs index b38b33c98..f47ad2927 100644 --- a/Source.Common/MaterialSystem/IMesh.cs +++ b/Source.Common/MaterialSystem/IMesh.cs @@ -253,6 +253,10 @@ public void UserData(ReadOnlySpan pData) { memcpy(pUserData, src, sizeof(float) * userDataSize); } + public void UserData(in Vector4 data) { + *(Vector4*)OffsetFloatPointer(Desc.UserData, CurrentVertex, Desc.UserDataSize) = data; + } + public void Color3f(float r, float g, float b) { byte* pDst = CurrColor; *pDst++ = (byte)Math.Clamp(r * 255, 0, 255); @@ -867,11 +871,13 @@ public void Reset() { public ReadOnlySpan Index() => throw new NotImplementedException(); // position setting - public void Position3f(float x, float y, float z) => VertexBuilder.Position3f(x, y, z); + public void Position3f(float x, float y, float z) { + float* pDst = VertexBuilder.CurrPosition; + pDst[0] = x; pDst[1] = y; pDst[2] = z; + } public void Position3fv(ReadOnlySpan v) => VertexBuilder.Position3fv(v); public void Position3fv(in Vector3 vec) { - fixed (Vector3* ptr = &vec) - VertexBuilder.Position3fv(new(ptr, 3)); + *(Vector3*)VertexBuilder.CurrPosition = vec; } // normal setting @@ -890,16 +896,21 @@ public void Position3fv(in Vector3 vec) { public void Color4fv(ReadOnlySpan rgba) => VertexBuilder.Color4fv(rgba); // Faster versions of color - public void Color3ub(byte r, byte g, byte b) => VertexBuilder.Color3ubv([r, g, b]); + public void Color3ub(byte r, byte g, byte b) { + byte* pDst = VertexBuilder.CurrColor; + pDst[0] = r; pDst[1] = g; pDst[2] = b; + } public void Color3ubv(in Color rgb) { - fixed (Color* ptr = &rgb) - VertexBuilder.Color3ubv(new(ptr, 3)); + byte* pDst = VertexBuilder.CurrColor; + pDst[0] = rgb.R; pDst[1] = rgb.G; pDst[2] = rgb.B; + } + public void Color4ub(byte r, byte g, byte b, byte a) { + byte* pDst = VertexBuilder.CurrColor; + pDst[0] = r; pDst[1] = g; pDst[2] = b; pDst[3] = a; } - public void Color4ub(byte r, byte g, byte b, byte a) => VertexBuilder.Color4ubv([r, g, b, a]); public unsafe void Color4ubv(ReadOnlySpan rgba) => VertexBuilder.Color4ubv(rgba); public unsafe void Color4ubv(in Color rgba) { - fixed (Color* ptr = &rgba) - VertexBuilder.Color4ubv(new(ptr, 4)); + *(Color*)VertexBuilder.CurrColor = rgba; } // specular color setting @@ -949,8 +960,7 @@ public unsafe void Color4ubv(in Color rgba) { // Generic per-vertex data public void UserData(ReadOnlySpan pData) => VertexBuilder.UserData(pData); public void UserData(in Vector4 vec) { - fixed (Vector4* ptr = &vec) - VertexBuilder.UserData(new((float*)ptr, 4)); + VertexBuilder.UserData(in vec); } // Used to define the indices (only used if you aren't using primitives) diff --git a/Source.Engine/Server/BaseServer.cs b/Source.Engine/Server/BaseServer.cs index 43459aed1..249d57148 100644 --- a/Source.Engine/Server/BaseServer.cs +++ b/Source.Engine/Server/BaseServer.cs @@ -415,10 +415,11 @@ public virtual void WriteDeltaEntities(BaseClient client, ClientFrame to, Client client.TraceNetworkData(pBuf, "Delta Finish"); } + + private readonly byte[] tempEntsBuffer = new byte[Protocol.MAX_PAYLOAD]; public virtual void WriteTempEntities(BaseClient client, FrameSnapshot to, FrameSnapshot from, bf_write pBuf, int nMaxEnts) { - byte[] data = new byte[Protocol.MAX_PAYLOAD]; SVC_TempEntities msg = new(); - msg.DataOut.StartWriting(data, data.Length); + msg.DataOut.StartWriting(tempEntsBuffer, tempEntsBuffer.Length); bf_write buffer = msg.DataOut; FrameSnapshot? pSnapshot; @@ -1247,7 +1248,7 @@ protected virtual int GetChallengeType(NetAddress adr) { return Protocol.PROTOCOL_HASHEDCDKEY; else #endif - return Protocol.PROTOCOL_STEAM; + return Protocol.PROTOCOL_STEAM; } protected virtual bool CheckProtocol(NetAddress adr, int nProtocol, int clientChallenge) { diff --git a/Source.MaterialSystem/Surface/Clip2D.cs b/Source.MaterialSystem/Surface/Clip2D.cs index 9facd5f82..756bcc330 100644 --- a/Source.MaterialSystem/Surface/Clip2D.cs +++ b/Source.MaterialSystem/Surface/Clip2D.cs @@ -166,8 +166,8 @@ public unsafe static int ClipPolygon(in ScissorRectState state, Span inUL.Position.X ? scissorRect.Left : inUL.Position.X; outLR.Position.X = scissorRect.Right <= inLR.Position.X ? scissorRect.Right : inLR.Position.X; diff --git a/Source.MaterialSystem/Surface/FontManager.cs b/Source.MaterialSystem/Surface/FontManager.cs index 2aa9a1644..5948fbdc1 100644 --- a/Source.MaterialSystem/Surface/FontManager.cs +++ b/Source.MaterialSystem/Surface/FontManager.cs @@ -100,9 +100,10 @@ public void RemoveAll() { } public BaseFont? GetFontForChar(char ch) { - foreach (var font in Fonts) { - if (ch >= font.LowRange && ch <= font.HighRange) { - return font.Font; + Span fonts = Fonts.AsSpan(); + for (int i = 0; i < fonts.Length; i++) { + if (ch >= fonts[i].LowRange && ch <= fonts[i].HighRange) { + return fonts[i].Font; } } diff --git a/Source.MaterialSystem/Surface/MatSystemSurface.cs b/Source.MaterialSystem/Surface/MatSystemSurface.cs index c227e6ccc..849928d23 100644 --- a/Source.MaterialSystem/Surface/MatSystemSurface.cs +++ b/Source.MaterialSystem/Surface/MatSystemSurface.cs @@ -671,6 +671,8 @@ public void DrawPrintText(ReadOnlySpan text, FontDrawType drawType = FontD int count = 0; Span quads = stackalloc SurfaceVertex[2 * text.Length]; bool underlined = FontManager.GetFontUnderlined(CurrentFont); + if (drawType == FontDrawType.Default) + drawType = IsFontAdditive(CurrentFont) > 0 ? FontDrawType.Additive : FontDrawType.NonAdditive; int totalWidth = 0; Span texID = stackalloc TextureID[1]; @@ -712,10 +714,10 @@ public void DrawPrintText(ReadOnlySpan text, FontDrawType drawType = FontD lr.Position.X = ul.Position.X + textureWide; lr.Position.Y = ul.Position.Y + tall; - ul.TexCoord[0] = texCoords[0].X0; - ul.TexCoord[1] = texCoords[0].Y0; - lr.TexCoord[0] = texCoords[0].X1; - lr.TexCoord[1] = texCoords[0].Y1; + ul.TexCoord.X = texCoords[0].X0; + ul.TexCoord.Y = texCoords[0].Y0; + lr.TexCoord.X = texCoords[0].X1; + lr.TexCoord.Y = texCoords[0].Y1; } totalWidth += (int)MathF.Floor(flWide + 0.6f); } diff --git a/Source.ShaderAPI.Gl46/VertexBufferGl46.cs b/Source.ShaderAPI.Gl46/VertexBufferGl46.cs index de6f195b6..0abde1640 100644 --- a/Source.ShaderAPI.Gl46/VertexBufferGl46.cs +++ b/Source.ShaderAPI.Gl46/VertexBufferGl46.cs @@ -179,7 +179,7 @@ public void RecomputeVBO() { Locked = true; Position = lockOffset; - return (byte*)glMapNamedBufferRange((uint)vbo, lockOffset, Math.Max(1, numVerts * VertexSize), GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); + return (byte*)SysmemBuffer + lockOffset; } public void Unlock(int vertexCount) { @@ -189,7 +189,8 @@ public void Unlock(int vertexCount) { int lockOffset = NextLockOffset(); int bufferSize = vertexCount * VertexSize; - glUnmapNamedBuffer((uint)vbo); + if (bufferSize > 0) + glNamedBufferSubData((uint)vbo, lockOffset, bufferSize, (byte*)SysmemBuffer + lockOffset); Position = lockOffset + bufferSize; Locked = false; } @@ -205,14 +206,15 @@ public void Unlock(int vertexCount) { modifyOffset = firstVertex * VertexSize; baseVertexIndex = firstVertex; Locked = true; - return (byte*)glMapNamedBufferRange((uint)vbo, modifyOffset, Math.Max(1, numVerts * VertexSize), GL_MAP_WRITE_BIT); + return (byte*)SysmemBuffer + modifyOffset; } public void ModifyUnlock(int vertexCount) { if (!Locked) return; - glUnmapNamedBuffer((uint)vbo); + if (vertexCount > 0) + glNamedBufferSubData((uint)vbo, modifyOffset, vertexCount * VertexSize, (byte*)SysmemBuffer + modifyOffset); Locked = false; } @@ -349,6 +351,7 @@ public void Dispose() { fixed (int* ugh = &vbo) glDeleteBuffers(1, (uint*)ugh); vbo = -1; + NativeMemory.Free(SysmemBuffer); SysmemBuffer = null; } }