Pulled from master, fixed conflict
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
-- @name koptilnya/libs/render
|
||||
--@client
|
||||
|
||||
function render.drawWedge(x, y, w, h, angle, mouthSize, fidelity)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- @name koptilnya/libs/table
|
||||
|
||||
function table.chunk(tbl, size)
|
||||
size = size or 1
|
||||
size = size > 0 and size or 1
|
||||
@@ -41,4 +43,24 @@ function table.merge(table1, table2)
|
||||
end
|
||||
|
||||
return newTable
|
||||
end
|
||||
end
|
||||
|
||||
function table.contains(tbl, ...)
|
||||
local argCount = #arg
|
||||
|
||||
if argCount == 1 then
|
||||
return table.hasValue(tbl, arg[1])
|
||||
elseif argCount > 1 then
|
||||
local result = true
|
||||
|
||||
for _, v in pairs(arg) do
|
||||
if not table.hasValue(tbl, v) then
|
||||
result = true
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- @name koptilnya/libs/utils
|
||||
|
||||
function checkVarClass(var, class, message)
|
||||
if type(var) ~= "table" or var["class"] == nil or not var:isInstanceOf(class) then
|
||||
throw(message == nil and "Wrong variable class." or message, 1, true)
|
||||
@@ -14,11 +16,11 @@ function accessorFunc(tbl, varName, name, defaultValue)
|
||||
end
|
||||
end
|
||||
|
||||
function rotateAround(entity, pivot, angles)
|
||||
function rotateAround(entity, pivot, angles)
|
||||
local pos = entity:getPos()
|
||||
local localPivotPos = entity:worldToLocal(pivot)
|
||||
|
||||
entity:setAngles(angles)
|
||||
pos = pos + (pivot - entity:localToWorld(localPivotPos))
|
||||
pos = pos + (pivot - entity:localToWorld(localPivotPos))
|
||||
entity:setPos(pos)
|
||||
end
|
||||
|
||||
49
koptilnya/libs/workers.txt
Normal file
49
koptilnya/libs/workers.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
-- @name koptilnya/libs/workers
|
||||
|
||||
WORKERS = {}
|
||||
WORKERS_QUOTA = 0.4
|
||||
|
||||
local function execWorker(worker)
|
||||
local status
|
||||
|
||||
while math.max(quotaAverage(), quotaUsed()) < quotaMax() * WORKERS_QUOTA do
|
||||
status = worker()
|
||||
|
||||
if status == 1 or status == 2 then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return status
|
||||
end
|
||||
|
||||
local function procWorkers()
|
||||
local i = 1
|
||||
while i <= #WORKERS do
|
||||
local status = execWorker(WORKERS[i])
|
||||
|
||||
if status == 2 then
|
||||
table.remove(WORKERS, i)
|
||||
elseif status == 1 then
|
||||
i = i + 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if #WORKERS == 0 then
|
||||
hook.remove("think", "workers_think")
|
||||
end
|
||||
end
|
||||
|
||||
function addWorker(worker)
|
||||
local status = execWorker(worker)
|
||||
|
||||
if status ~= 2 then
|
||||
if #WORKERS == 0 then
|
||||
hook.add("think", "workers_think", procWorkers)
|
||||
end
|
||||
|
||||
WORKERS[#WORKERS + 1] = worker
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user