SprayMesh Extended: Simplify spray reload queue code

Removed unneeded for-loop for optimization
This commit is contained in:
Chev 2023-11-06 10:41:49 -08:00
parent a5227bd0e7
commit 3940c88a10
Signed by: chev2
GPG key ID: BE0CFBD5DCBB2511

View file

@ -909,7 +909,9 @@ end)
-- Coroutine function; used to reload sprays with spraymesh_reload
local function cycleReloadSprays()
for id64, data in pairs(SPRAY_RELOAD_QUEUE) do
local id64, data = next(SPRAY_RELOAD_QUEUE)
if not id64 then return end
print(("Reloading spray for %s (%s) at %s"):format(id64, data.PlayerName, data.hitpos))
local sprayData = {
@ -929,14 +931,11 @@ local function cycleReloadSprays()
SPRAY_RELOAD_QUEUE[id64] = nil
coroutine.yield()
break
end
end
local sprayThread = nil
hook.Add("Think", "SprayMesh.ManageSpraysCoroutine", function()
if (not sprayThread or not coroutine.resume(sprayThread)) and not table.IsEmpty(SPRAY_RELOAD_QUEUE) then
hook.Add("Think", "SprayMesh.ManageSprayReloadCoroutine", function()
if (not sprayThread or not coroutine.resume(sprayThread)) and next(SPRAY_RELOAD_QUEUE) then
sprayThread = coroutine.create(cycleReloadSprays)
coroutine.resume(sprayThread)