Merge branch 'dev' into pathfinding
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
local events = {
|
||||
handlers = {}
|
||||
}
|
||||
|
||||
function events.on(event, func)
|
||||
if events.handlers[event] == nil then
|
||||
events.handlers[event] = {}
|
||||
end
|
||||
table.insert(events.handlers[event], func)
|
||||
end
|
||||
|
||||
function events.reset(event, func)
|
||||
if func == nil then
|
||||
events.handlers[event] = nil
|
||||
else
|
||||
events.handlers[event] = {func}
|
||||
end
|
||||
end
|
||||
|
||||
function events.remove_by_prefix(prefix)
|
||||
for name, handlers in pairs(events.handlers) do
|
||||
local actualname = name
|
||||
if type(name) == 'table' then
|
||||
actualname = name[1]
|
||||
end
|
||||
if actualname:sub(1, #prefix+1) == prefix..':' then
|
||||
events.handlers[actualname] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function events.emit(event, ...)
|
||||
local result = nil
|
||||
local handlers = events.handlers[event]
|
||||
if handlers == nil then
|
||||
return nil
|
||||
end
|
||||
for _, func in ipairs(handlers) do
|
||||
local status, newres = xpcall(func, __vc__error, ...)
|
||||
if not status then
|
||||
debug.error("error in event ("..event..") handler: "..newres)
|
||||
else
|
||||
result = result or newres
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
return events
|
||||
@@ -0,0 +1,212 @@
|
||||
-- =================================================== --
|
||||
-- ====================== vec3 ======================= --
|
||||
-- =================================================== --
|
||||
function vec3.add(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] + b[1]
|
||||
dst[2] = a[2] + b[2]
|
||||
dst[3] = a[3] + b[3]
|
||||
else
|
||||
dst[1] = a[1] + b
|
||||
dst[2] = a[2] + b
|
||||
dst[3] = a[3] + b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] + b[1], a[2] + b[2], a[3] + b[3]}
|
||||
else
|
||||
return {a[1] + b, a[2] + b, a[3] + b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec3.sub(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] - b[1]
|
||||
dst[2] = a[2] - b[2]
|
||||
dst[3] = a[3] - b[3]
|
||||
else
|
||||
dst[1] = a[1] - b
|
||||
dst[2] = a[2] - b
|
||||
dst[3] = a[3] - b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] - b[1], a[2] - b[2], a[3] - b[3]}
|
||||
else
|
||||
return {a[1] - b, a[2] - b, a[3] - b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec3.mul(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] * b[1]
|
||||
dst[2] = a[2] * b[2]
|
||||
dst[3] = a[3] * b[3]
|
||||
else
|
||||
dst[1] = a[1] * b
|
||||
dst[2] = a[2] * b
|
||||
dst[3] = a[3] * b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] * b[1], a[2] * b[2], a[3] * b[3]}
|
||||
else
|
||||
return {a[1] * b, a[2] * b, a[3] * b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec3.div(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] / b[1]
|
||||
dst[2] = a[2] / b[2]
|
||||
dst[3] = a[3] / b[3]
|
||||
else
|
||||
dst[1] = a[1] / b
|
||||
dst[2] = a[2] / b
|
||||
dst[3] = a[3] / b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] / b[1], a[2] / b[2], a[3] / b[3]}
|
||||
else
|
||||
return {a[1] / b, a[2] / b, a[3] / b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec3.abs(a, dst)
|
||||
local x = a[1]
|
||||
local y = a[2]
|
||||
local z = a[3]
|
||||
if dst then
|
||||
dst[1] = x < 0.0 and -x or x
|
||||
dst[2] = y < 0.0 and -y or y
|
||||
dst[3] = z < 0.0 and -z or z
|
||||
else
|
||||
return {
|
||||
x < 0.0 and -x or x,
|
||||
y < 0.0 and -y or y,
|
||||
z < 0.0 and -z or z,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function vec3.dot(a, b)
|
||||
return a[1] * b[1] + a[2] * b[2] + a[3] * b[3]
|
||||
end
|
||||
|
||||
-- =================================================== --
|
||||
-- ====================== vec2 ======================= --
|
||||
-- =================================================== --
|
||||
function vec2.add(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] + b[1]
|
||||
dst[2] = a[2] + b[2]
|
||||
else
|
||||
dst[1] = a[1] + b
|
||||
dst[2] = a[2] + b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] + b[1], a[2] + b[2]}
|
||||
else
|
||||
return {a[1] + b, a[2] + b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec2.sub(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] - b[1]
|
||||
dst[2] = a[2] - b[2]
|
||||
else
|
||||
dst[1] = a[1] - b
|
||||
dst[2] = a[2] - b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] - b[1], a[2] - b[2]}
|
||||
else
|
||||
return {a[1] - b, a[2] - b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec2.mul(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] * b[1]
|
||||
dst[2] = a[2] * b[2]
|
||||
else
|
||||
dst[1] = a[1] * b
|
||||
dst[2] = a[2] * b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] * b[1], a[2] * b[2]}
|
||||
else
|
||||
return {a[1] * b, a[2] * b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec2.div(a, b, dst)
|
||||
local btype = type(b)
|
||||
if dst then
|
||||
if btype == "table" then
|
||||
dst[1] = a[1] / b[1]
|
||||
dst[2] = a[2] / b[2]
|
||||
else
|
||||
dst[1] = a[1] / b
|
||||
dst[2] = a[2] / b
|
||||
end
|
||||
return dst
|
||||
else
|
||||
if btype == "table" then
|
||||
return {a[1] / b[1], a[2] / b[2]}
|
||||
else
|
||||
return {a[1] / b, a[2] / b}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vec2.abs(a, dst)
|
||||
local x = a[1]
|
||||
local y = a[2]
|
||||
if dst then
|
||||
dst[1] = x < 0.0 and -x or x
|
||||
dst[2] = y < 0.0 and -y or y
|
||||
else
|
||||
return {
|
||||
x < 0.0 and -x or x,
|
||||
y < 0.0 and -y or y,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function vec2.dot(a, b)
|
||||
return a[1] * b[1] + a[2] * b[2]
|
||||
end
|
||||
@@ -22,16 +22,16 @@ local O_NONBLOCK = 0x800
|
||||
local F_GETFL = 3
|
||||
|
||||
local function getError()
|
||||
local err = ffi.errno()
|
||||
local err = FFI.errno()
|
||||
|
||||
return ffi.string(C.strerror(err)).." ("..err..")"
|
||||
return FFI.string(C.strerror(err)).." ("..err..")"
|
||||
end
|
||||
|
||||
local lib = {}
|
||||
|
||||
function lib.read(fd, len)
|
||||
local buffer = FFI.new("uint8_t[?]", len)
|
||||
local result = C.read(fd, buffer, len)
|
||||
local result = tonumber(C.read(fd, buffer, len))
|
||||
|
||||
local out = Bytearray()
|
||||
|
||||
@@ -101,4 +101,4 @@ return function(path, mode)
|
||||
end
|
||||
|
||||
return io_stream.new(fd, mode:find('b') ~= nil, lib)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,8 +15,9 @@ local Schedule = {
|
||||
local timer = self._timer + dt
|
||||
for id, interval in pairs(self._intervals) do
|
||||
if timer - interval.last_called >= interval.delay then
|
||||
xpcall(interval.callback, function(s)
|
||||
debug.error(s..'\n'..debug.traceback())
|
||||
local stack_size = debug.count_frames()
|
||||
xpcall(interval.callback, function(msg)
|
||||
__vc__error(msg, 1, 1, stack_size)
|
||||
end)
|
||||
interval.last_called = timer
|
||||
local repetions = interval.repetions
|
||||
|
||||
Reference in New Issue
Block a user