Facepunch / garrysmod-requests

Feature requests for Garry's Mod
83 stars 24 forks source link

version of timer.Simple(0, fn) that runs as soon as possible #2382

Open mgetJane opened 1 month ago

mgetJane commented 1 month ago

basically should just run at the end of the current tick/frame instead of at the start of the next tick (specifically right before GM:Tick) like timer.Simple(0, function() end) does

could be called something like Defer(function() end)

the main difference is that it would execute the function before any further simulation happens and without the 1-tick delay in real time

also, using a zero-second timer.Simple is such a common pattern in gmod coding and its uses only very occasionally actually require a 1-tick delay, it would be better if we had a more intentioned function instead of practically jury-rigging with timers for this purpose

robotboy655 commented 1 month ago

This sounds like a duplicate of https://github.com/Facepunch/garrysmod-requests/issues/894

mgetJane commented 1 month ago

one of my use cases is accumulating shotgun pellet hits so i can send them all in one go for clientside hitreg

using timer.Simple would add a relatively considerable delay to this for my purposes so i had to resort to doing this mess:

hook.Add("SetupMove", "CLHR_SendToServer", s2s)
hook.Add("StartCommand", "CLHR_SendToServer", s2s)
hook.Add("CreateMove", "CLHR_SendToServer", s2s)
hook.Add("PreRender", "CLHR_SendToServer", s2s)
hook.Add("Think", "CLHR_SendToServer", s2s)

(clientside, whichever one of these will get executed first is just random)

mgetJane commented 1 month ago

This sounds like a duplicate of #894

that one is only serverside and seems to be tied to physics (though still might be a good place to execute stuff at the end of a tick?)