mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:01:22 +00:00
refactor(client/functions): ESX.SetTimeout and ESX.ClearTimeout
timeout functions moved to shared file and removed thread from client side
This commit is contained in:
@@ -4,7 +4,6 @@ ESX.PlayerData = {}
|
||||
ESX.PlayerLoaded = false
|
||||
Core.CurrentRequestId = 0
|
||||
Core.ServerCallbacks = {}
|
||||
Core.TimeoutCallbacks = {}
|
||||
Core.Input = {}
|
||||
ESX.UI = {}
|
||||
ESX.UI.HUD = {}
|
||||
@@ -21,18 +20,6 @@ ESX.Scaleform.Utils = {}
|
||||
|
||||
ESX.Streaming = {}
|
||||
|
||||
function ESX.SetTimeout(msec, cb)
|
||||
table.insert(Core.TimeoutCallbacks, {
|
||||
time = GetGameTimer() + msec,
|
||||
cb = cb
|
||||
})
|
||||
return #Core.TimeoutCallbacks
|
||||
end
|
||||
|
||||
function ESX.ClearTimeout(i)
|
||||
Core.TimeoutCallbacks[i] = nil
|
||||
end
|
||||
|
||||
function ESX.IsPlayerLoaded()
|
||||
return ESX.PlayerLoaded
|
||||
end
|
||||
@@ -1392,22 +1379,4 @@ AddEventHandler('esx:showAdvancedNotification',
|
||||
RegisterNetEvent('esx:showHelpNotification')
|
||||
AddEventHandler('esx:showHelpNotification', function(msg, thisFrame, beep, duration)
|
||||
ESX.ShowHelpNotification(msg, thisFrame, beep, duration)
|
||||
end)
|
||||
|
||||
-- SetTimeout
|
||||
CreateThread(function()
|
||||
while true do
|
||||
local sleep = 100
|
||||
if #Core.TimeoutCallbacks > 0 then
|
||||
local currTime = GetGameTimer()
|
||||
sleep = 0
|
||||
for i = 1, #Core.TimeoutCallbacks, 1 do
|
||||
if currTime >= Core.TimeoutCallbacks[i].time then
|
||||
Core.TimeoutCallbacks[i].cb()
|
||||
Core.TimeoutCallbacks[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
Wait(sleep)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
@@ -0,0 +1,23 @@
|
||||
local TimeoutCount = 0
|
||||
local CancelledTimeouts = {}
|
||||
|
||||
ESX.SetTimeout = function(msec, cb)
|
||||
local id <const> = TimeoutCount + 1
|
||||
|
||||
SetTimeout(msec, function()
|
||||
if CancelledTimeouts[id] then
|
||||
CancelledTimeouts[id] = nil
|
||||
return
|
||||
end
|
||||
|
||||
cb()
|
||||
end)
|
||||
|
||||
TimeoutCount = id
|
||||
|
||||
return id
|
||||
end
|
||||
|
||||
ESX.ClearTimeout = function(id)
|
||||
CancelledTimeouts[id] = true
|
||||
end
|
||||
@@ -27,8 +27,7 @@ server_scripts {
|
||||
'server/main.lua',
|
||||
'server/commands.lua',
|
||||
|
||||
'common/modules/math.lua',
|
||||
'common/modules/table.lua',
|
||||
'common/modules/*.lua',
|
||||
'common/functions.lua'
|
||||
}
|
||||
|
||||
@@ -42,8 +41,7 @@ client_scripts {
|
||||
'client/modules/scaleform.lua',
|
||||
'client/modules/streaming.lua',
|
||||
|
||||
'common/modules/math.lua',
|
||||
'common/modules/table.lua',
|
||||
'common/modules/*.lua',
|
||||
'common/functions.lua'
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ Core.UsableItemsCallbacks = {}
|
||||
Core.ServerCallbacks = {}
|
||||
Core.ClientCallbacks = {}
|
||||
Core.CurrentRequestId = 0
|
||||
Core.TimeoutCount = -1
|
||||
Core.CancelledTimeouts = {}
|
||||
Core.RegisteredCommands = {}
|
||||
Core.Pickups = {}
|
||||
Core.PickupId = 0
|
||||
|
||||
@@ -4,22 +4,6 @@ function ESX.Trace(msg)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.SetTimeout(msec, cb)
|
||||
local id = Core.TimeoutCount + 1
|
||||
|
||||
SetTimeout(msec, function()
|
||||
if Core.CancelledTimeouts[id] then
|
||||
Core.CancelledTimeouts[id] = nil
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
|
||||
Core.TimeoutCount = id
|
||||
|
||||
return id
|
||||
end
|
||||
|
||||
function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
||||
if type(name) == 'table' then
|
||||
for k, v in ipairs(name) do
|
||||
@@ -159,10 +143,6 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.ClearTimeout(id)
|
||||
Core.CancelledTimeouts[id] = true
|
||||
end
|
||||
|
||||
function ESX.RegisterServerCallback(name, cb)
|
||||
Core.ServerCallbacks[name] = cb
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user