From 76f389dff9fe526c324b3d6cd89feb8c4f07be22 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Tue, 7 Sep 2021 11:02:24 -0300 Subject: [PATCH] new signalReceived hook with better performance signalReceived.YourComponent, with the checks in the lua-side this hook was being called too many times and it was using up to 10% cpu of the server --- .../ServerSource/Lua/LuaClasses.cs | 19 ++++++++----------- .../Items/Components/ItemComponent.cs | 4 +++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs index 24fddcec8..6a91d9724 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs @@ -574,21 +574,18 @@ namespace Barotrauma foreach (HookFunction hf in hookFunctions[name].Values) { - if (hf.name == name) + try { - try + var result = env.lua.Call(hf.function, args); + if (result.IsNil() == false) { - var result = env.lua.Call(hf.function, args); - if (result.IsNil() == false) - { - return result; - } - } - catch (Exception e) - { - env.HandleLuaException(e); + return result; } } + catch (Exception e) + { + env.HandleLuaException(e); + } } return null; diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs index fff2793cd..a5e19f9ac 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs @@ -441,7 +441,9 @@ namespace Barotrauma.Items.Components #if SERVER if (!lastSignal.ContainsValue(connection.Name) || lastSignal[connection.Name] != signal.value) { - GameMain.Lua.hook.Call("signalReceived", new object[] { signal, connection }); + object[] obj = new object[] { signal, connection }; + GameMain.Lua.hook.Call("signalReceived", obj); + GameMain.Lua.hook.Call("signalReceived." + item.prefab.Identifier, obj); lastSignal[connection.Name] = signal.value; }