From 56c3f2b2cf96f673e53144179bf1087b6cb09189 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:22:22 +0300 Subject: [PATCH 1/3] Remove arguments overloading in chathud (#129) Works 60-70% faster --- lua/easychat/chathud.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lua/easychat/chathud.lua b/lua/easychat/chathud.lua index f47e02d..fda081e 100644 --- a/lua/easychat/chathud.lua +++ b/lua/easychat/chathud.lua @@ -604,7 +604,7 @@ function text_part:DrawShadow(ctx) if not self.ShouldDrawShadow then return end shadow_col.a = ctx.Alpha - surface_SetTextColor(shadow_col) + surface_SetTextColor(shadow_col.r, shadow_col.g, shadow_col.b, shadow_col.a) surface_SetFont(self.ShadowFont and self.ShadowFont or self.HUD.DefaultShadowFont) local x, y = self:GetTextDrawPos(ctx) @@ -624,8 +624,9 @@ function text_part:Draw(ctx) self:DrawShadow(ctx) + local color = ctx.Color surface_SetTextPos(x, y) - surface_SetTextColor(ctx.Color) + surface_SetTextColor(color.r, color.g, color.b, color.a) surface_SetFont(self.Font) surface_DrawText(self.Content) @@ -1305,8 +1306,8 @@ local draw_context = { function draw_context:UpdateColor(col) col.a = self.Alpha - surface_SetDrawColor(col) - surface_SetTextColor(col) + surface_SetDrawColor(col.r, col.g, col.b, col.a) + surface_SetTextColor(col.r, col.g, col.b, col.a) self.Color = col end @@ -1344,8 +1345,8 @@ end function draw_context:ResetColors() local default_col = self.HUD.DefaultColor - surface_SetDrawColor(default_col) - surface_SetTextColor(default_col) + surface_SetDrawColor(default_col.r, default_col.g, default_col.b, default_col.a) + surface_SetTextColor(default_col.r, default_col.g, default_col.b, default_col.a) self.Color = Color(default_col.r, default_col.g, default_col.b, self.Alpha) end From 4118edb92824bbbead398b30f5c59f6d9752e679 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:09:34 +0300 Subject: [PATCH 2/3] Reduce network usage for messages (#130) * Reduce networking * Reduce network usage even more * Also reduce for NET_SEND_MSG --- lua/easychat/networking.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/easychat/networking.lua b/lua/easychat/networking.lua index 1527cef..b4cf19b 100644 --- a/lua/easychat/networking.lua +++ b/lua/easychat/networking.lua @@ -124,10 +124,11 @@ if SERVER then net.Start(NET_BROADCAST_MSG) net.WriteUInt(ply:UserID(), 16) net.WriteString(ply:RichNick()) - net.WriteString(msg) + net.WriteBool(is_dead) net.WriteBool(is_team) net.WriteBool(is_local) + net.WriteData(util.Compress(msg)) net.Send(filter) if game.IsDedicated() and not is_local then @@ -229,9 +230,9 @@ if SERVER then end net.Receive(NET_SEND_MSG, function(_, ply) - local msg = net.ReadString() local is_team = net.ReadBool() local is_local = net.ReadBool() + local msg = util.Decompress(net.ReadData(net.BytesLeft())) EasyChat.ReceiveGlobalMessage(ply, msg, is_team, is_local) end) @@ -438,10 +439,10 @@ if CLIENT then net.Receive(NET_BROADCAST_MSG, function() local user_id = net.ReadUInt(16) local user_name = net.ReadString() - local msg = net.ReadString() local is_dead = net.ReadBool() local is_team = net.ReadBool() local is_local = net.ReadBool() + local msg = util.Decompress(net.ReadData(net.BytesLeft())) local function receive(retries) retries = retries or 0 @@ -526,16 +527,16 @@ if CLIENT then if not no_translate and EC_TRANSLATE_OUT_MSG:GetBool() and source_lang ~= target_lang then EasyChat.Translator:Translate(msg, source_lang, target_lang, function(success, _, translation) net.Start(NET_SEND_MSG) - net.WriteString(success and translation or msg) net.WriteBool(is_team) net.WriteBool(is_local) + net.WriteData(util.Compress(success and translation or msg)) net.SendToServer() end) else net.Start(NET_SEND_MSG) - net.WriteString(msg) net.WriteBool(is_team) net.WriteBool(is_local) + net.WriteData(util.Compress(msg)) net.SendToServer() end end From 2605fdcdda5041b136e2592d498648ff25a7ae36 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 25 Oct 2024 21:13:27 +0300 Subject: [PATCH 3/3] Revert "Reduce network usage for messages (#130)" (#131) This reverts commit 4118edb92824bbbead398b30f5c59f6d9752e679. --- lua/easychat/networking.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lua/easychat/networking.lua b/lua/easychat/networking.lua index b4cf19b..1527cef 100644 --- a/lua/easychat/networking.lua +++ b/lua/easychat/networking.lua @@ -124,11 +124,10 @@ if SERVER then net.Start(NET_BROADCAST_MSG) net.WriteUInt(ply:UserID(), 16) net.WriteString(ply:RichNick()) - + net.WriteString(msg) net.WriteBool(is_dead) net.WriteBool(is_team) net.WriteBool(is_local) - net.WriteData(util.Compress(msg)) net.Send(filter) if game.IsDedicated() and not is_local then @@ -230,9 +229,9 @@ if SERVER then end net.Receive(NET_SEND_MSG, function(_, ply) + local msg = net.ReadString() local is_team = net.ReadBool() local is_local = net.ReadBool() - local msg = util.Decompress(net.ReadData(net.BytesLeft())) EasyChat.ReceiveGlobalMessage(ply, msg, is_team, is_local) end) @@ -439,10 +438,10 @@ if CLIENT then net.Receive(NET_BROADCAST_MSG, function() local user_id = net.ReadUInt(16) local user_name = net.ReadString() + local msg = net.ReadString() local is_dead = net.ReadBool() local is_team = net.ReadBool() local is_local = net.ReadBool() - local msg = util.Decompress(net.ReadData(net.BytesLeft())) local function receive(retries) retries = retries or 0 @@ -527,16 +526,16 @@ if CLIENT then if not no_translate and EC_TRANSLATE_OUT_MSG:GetBool() and source_lang ~= target_lang then EasyChat.Translator:Translate(msg, source_lang, target_lang, function(success, _, translation) net.Start(NET_SEND_MSG) + net.WriteString(success and translation or msg) net.WriteBool(is_team) net.WriteBool(is_local) - net.WriteData(util.Compress(success and translation or msg)) net.SendToServer() end) else net.Start(NET_SEND_MSG) + net.WriteString(msg) net.WriteBool(is_team) net.WriteBool(is_local) - net.WriteData(util.Compress(msg)) net.SendToServer() end end