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,34 +909,33 @@ 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)
|
||||||
print(("Reloading spray for %s (%s) at %s"):format(id64, data.PlayerName, data.hitpos))
|
if not id64 then return end
|
||||||
|
|
||||||
local sprayData = {
|
print(("Reloading spray for %s (%s) at %s"):format(id64, data.PlayerName, data.hitpos))
|
||||||
SteamID64 = id64,
|
|
||||||
PlayerName = data.PlayerName,
|
|
||||||
HitPos = data.hitpos,
|
|
||||||
HitNormal = data.hitnormal,
|
|
||||||
TraceNormal = data.TraceNormal,
|
|
||||||
URL = data.url,
|
|
||||||
CoordDistance = data.CoordDistance,
|
|
||||||
SprayTime = data.Time,
|
|
||||||
PlaySpraySound = false
|
|
||||||
}
|
|
||||||
|
|
||||||
spraymesh.PlaceSpray(sprayData)
|
local sprayData = {
|
||||||
|
SteamID64 = id64,
|
||||||
|
PlayerName = data.PlayerName,
|
||||||
|
HitPos = data.hitpos,
|
||||||
|
HitNormal = data.hitnormal,
|
||||||
|
TraceNormal = data.TraceNormal,
|
||||||
|
URL = data.url,
|
||||||
|
CoordDistance = data.CoordDistance,
|
||||||
|
SprayTime = data.Time,
|
||||||
|
PlaySpraySound = false
|
||||||
|
}
|
||||||
|
|
||||||
SPRAY_RELOAD_QUEUE[id64] = nil
|
spraymesh.PlaceSpray(sprayData)
|
||||||
|
|
||||||
coroutine.yield()
|
SPRAY_RELOAD_QUEUE[id64] = nil
|
||||||
|
|
||||||
break
|
coroutine.yield()
|
||||||
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