feat(resource/streaming): timeout functions after 20 ticks

This commit is contained in:
Linden
2021-11-17 03:37:59 +11:00
parent 55a857fbf8
commit 6c2658c302
3 changed files with 37 additions and 31 deletions

View File

@@ -1,9 +1,9 @@
-- Creates exports from values assigned to lib.
-- Hacky workaround for Lua Language Server support.
-- Creates exports from values assigned to lib
-- Hacky workaround for Lua Language Server support
--- Alias for `exports['pe-lualib']`
lib = setmetatable({}, {
__newindex = function(self, name, fn)
print('created '..name)
exports(name, fn)
end
})

View File

@@ -1,51 +1,57 @@
local function hasLoaded(fn, name)
local timeout = 0
while not fn(name) do
Wait(0)
timeout += 1
if timeout > 20 then return false end
end
return true
end
---@param dict string
--- Loads an animation dictionary.
function lib.requestAnimDict(dict)
if not HasAnimDictLoaded(dict) then
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do Wait(0) end
end
return true
if HasAnimDictLoaded(dict) then return true end
assert(DoesAnimDictExist(dict), ('Attempted to load an invalid animdict (%s)'):format(dict))
RequestAnimDict(dict)
if hasLoaded(HasAnimDictLoaded, dict) then return true end
print(('Unable to load animdict after 20 ticks (%s)'):format(dict))
end
---@param set string
--- Loads an animation clipset.
function lib.requestAnimSet(set)
if not HasAnimSetLoaded(set) then
RequestAnimSet(set)
while not HasAnimSetLoaded(set) do Wait(0) end
end
return true
if HasAnimSetLoaded(set) then return true end
RequestAnimSet(set)
if hasLoaded(HasAnimSetLoaded, set) then return true end
print(('Unable to load animset after 20 ticks (%s)'):format(set))
end
---@param model string|number
--- Loads a model.
function lib.requestModel(model)
model = type(model) == 'number' and model or joaat(model)
if not HasModelLoaded(model) then
assert(IsModelValid(model), ('Attempted to load an invalid model (%s)'):format(model))
RequestModel(model)
while not HasModelLoaded(model) do Wait(0) end
end
return true
model = type(model) == 'number' and model or joaat(model)
if HasModelLoaded(model) then return true end
assert(IsModelValid(model), ('Attempted to load an invalid model (%s)'):format(model))
RequestModel(model)
if hasLoaded(HasModelLoaded, model) then return true end
print(('Unable to load model after 20 ticks (%s)'):format(model))
end
---@param dict string
--- Loads a texture dictionary.
function lib.requestStreamedTextureDict(dict)
if not HasStreamedTextureDictLoaded(dict) then
RequestStreamedTextureDict(dict)
while not HasStreamedTextureDictLoaded(dict) do Wait(0) end
end
return true
if HasStreamedTextureDictLoaded(dict) then return true end
RequestStreamedTextureDict(dict)
if hasLoaded(HasStreamedTextureDictLoaded, dict) then return true end
print(('Unable to load texture dict after 20 ticks (%s)'):format(name))
end
---@param fxName string
--- Loads a named particle effect.
function lib.requestNamedPtfxAsset(fxName)
if not HasNamedPtfxAssetLoaded(fxName) then
RequestNamedPtfxAsset(fxName)
while not HasNamedPtfxAssetLoaded(fxName) do Wait(0) end
end
return true
if HasNamedPtfxAssetLoaded(fxName) then return true end
RequestNamedPtfxAsset(fxName)
if hasLoaded(RequestNamedPtfxAsset, fxName) then return true end
print(('Unable to load named ptfx after 20 ticks (%s)'):format(name))
end