mirror of
https://github.com/chev2/gmod-addons.git
synced 2025-12-18 05:52:15 +00:00
SprayMesh Extended: Simplify spray reload queue code
Removed unneeded for-loop for optimization
This commit is contained in:
parent
a5227bd0e7
commit
3940c88a10
1 changed files with 19 additions and 20 deletions
|
|
@ -909,7 +909,9 @@ end)
|
||||||
|
|
||||||
-- Coroutine function; used to reload sprays with spraymesh_reload
|
-- Coroutine function; used to reload sprays with spraymesh_reload
|
||||||
local function cycleReloadSprays()
|
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))
|
print(("Reloading spray for %s (%s) at %s"):format(id64, data.PlayerName, data.hitpos))
|
||||||
|
|
||||||
local sprayData = {
|
local sprayData = {
|
||||||
|
|
@ -929,14 +931,11 @@ local function cycleReloadSprays()
|
||||||
SPRAY_RELOAD_QUEUE[id64] = nil
|
SPRAY_RELOAD_QUEUE[id64] = nil
|
||||||
|
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local sprayThread = nil
|
local sprayThread = nil
|
||||||
hook.Add("Think", "SprayMesh.ManageSpraysCoroutine", function()
|
hook.Add("Think", "SprayMesh.ManageSprayReloadCoroutine", function()
|
||||||
if (not sprayThread or not coroutine.resume(sprayThread)) and not table.IsEmpty(SPRAY_RELOAD_QUEUE) then
|
if (not sprayThread or not coroutine.resume(sprayThread)) and next(SPRAY_RELOAD_QUEUE) then
|
||||||
sprayThread = coroutine.create(cycleReloadSprays)
|
sprayThread = coroutine.create(cycleReloadSprays)
|
||||||
|
|
||||||
coroutine.resume(sprayThread)
|
coroutine.resume(sprayThread)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue