From 6de44caeed332210922c55255cfe343c8d66b534 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Fri, 12 Apr 2024 21:55:07 -0400 Subject: [PATCH 1/2] throttles mouse movement calls --- code/_onclick/drag_drop.dm | 4 ++++ code/modules/client/client_defines.dm | 3 +++ 2 files changed, 7 insertions(+) diff --git a/code/_onclick/drag_drop.dm b/code/_onclick/drag_drop.dm index bd1509d88b..c474be82af 100644 --- a/code/_onclick/drag_drop.dm +++ b/code/_onclick/drag_drop.dm @@ -92,7 +92,11 @@ . = 1 //Please don't roast me too hard +//Oh don't worry, We Will. /client/MouseMove(object, location, control, params) + if(next_mousemove > world.time) + return + next_mousemove = world.time + world.tick_lag mouseParams = params mouse_location_ref = WEAKREF(location) mouse_object_ref = WEAKREF(object) diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 14224cf02e..4f5624578c 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -189,3 +189,6 @@ /// AFK tracking var/last_activity = 0 + + /// The next point in time at which the client is allowed to send a mousemove() + var/next_mousemove = 0 From 51a264c9a711e925d5a1aa6d978184d69c43f657 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Wed, 23 Oct 2024 19:51:18 -0400 Subject: [PATCH 2/2] Replaces throttle with cooldown define and also adds it to mousedrag --- code/_onclick/drag_drop.dm | 7 +++++-- code/modules/client/client_defines.dm | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/code/_onclick/drag_drop.dm b/code/_onclick/drag_drop.dm index c474be82af..7672bcf452 100644 --- a/code/_onclick/drag_drop.dm +++ b/code/_onclick/drag_drop.dm @@ -94,9 +94,9 @@ //Please don't roast me too hard //Oh don't worry, We Will. /client/MouseMove(object, location, control, params) - if(next_mousemove > world.time) + if(!COOLDOWN_FINISHED(src, next_mousemove)) return - next_mousemove = world.time + world.tick_lag + COOLDOWN_START(src, next_mousemove, 0) //COOLDOWN_FINISHED() sees the world tick and cooldown timer being equal as a state wherein the cooldown has not finished. So the cooldown timer here is 0 to throttle only for the rest of the tick. mouseParams = params mouse_location_ref = WEAKREF(location) mouse_object_ref = WEAKREF(object) @@ -110,6 +110,9 @@ ..() /client/MouseDrag(src_object,atom/over_object,src_location,over_location,src_control,over_control,params) + if(!COOLDOWN_FINISHED(src, next_mousedrag)) + return + COOLDOWN_START(src, next_mousedrag, 0) //See comment in MouseMove() for why this is 0. mouseParams = params mouse_location_ref = WEAKREF(over_location) mouse_object_ref = WEAKREF(over_object) diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 4f5624578c..65db62abf9 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -190,5 +190,6 @@ /// AFK tracking var/last_activity = 0 - /// The next point in time at which the client is allowed to send a mousemove() - var/next_mousemove = 0 + /// The next point in time at which the client is allowed to send a mousemove() or mousedrag() + COOLDOWN_DECLARE(next_mousemove) + COOLDOWN_DECLARE(next_mousedrag)