Merge branch 'dev' into pathfinding

This commit is contained in:
MihailRis
2025-08-19 19:47:10 +03:00
57 changed files with 818 additions and 207 deletions
+3
View File
@@ -21,6 +21,9 @@ function on_hud_open()
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
local drop = base_util.drop(ppos, itemid, 1, data, 1.5)
if not drop then
return
end
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
drop.rigidbody:set_vel(velocity)
end)
+6 -2
View File
@@ -81,6 +81,11 @@ local function refresh_file_title()
document.saveIcon.enabled = edited
document.title.text = gui.str('File')..' - '..current_file.filename
..(edited and ' *' or '')
local info = registry.get_info(current_file.filename)
if info and info.type == "model" then
pcall(run_current_file)
end
end
function on_control_combination(keycode)
@@ -118,7 +123,6 @@ function run_current_file()
local unit = info and info.unit
if script_type == "model" then
print(current_file.filename)
clear_output()
local _, err = pcall(reload_model, current_file.filename, unit)
if err then
@@ -256,7 +260,7 @@ function open_file_in_editor(filename, line, mutable)
end
function on_open(mode)
registry = require "core:internal/scripts_registry"
registry = __vc_scripts_registry
document.codePanel:setInterval(200, refresh_file_title)
+1 -1
View File
@@ -4,7 +4,7 @@ history = session.get_entry("commands_history")
history_pointer = #history
events.on("core:open_traceback", function()
if modes then
if modes and modes.current ~= 'debug' then
modes:set('debug')
end
end)
+2 -5
View File
@@ -43,11 +43,8 @@ function build_files_list(filenames, highlighted_part)
end
end
function on_open(mode)
registry = require "core:internal/scripts_registry"
local files_list = document.filesList
function on_open()
registry = __vc_scripts_registry
filenames = registry.filenames
table.sort(filenames)
build_files_list(filenames)
+48
View File
@@ -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
+212
View File
@@ -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
+3 -2
View File
@@ -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
+26
View File
@@ -0,0 +1,26 @@
local menubg
function on_menu_clear()
if menubg then
menubg:destruct()
menubg = nil
end
end
function on_menu_setup()
local controller = {}
function controller.resize_menu_bg()
local w, h = unpack(gui.get_viewport())
if menubg then
menubg.region = {0, math.floor(h / 48), math.floor(w / 48), 0}
menubg.pos = {0, 0}
end
return w, h
end
gui.root.root:add(
"<image id='menubg' src='gui/menubg' size-func='DATA.resize_menu_bg' "..
"z-index='-1' interactive='true'/>", controller)
menubg = gui.root.menubg
controller.resize_menu_bg()
menu.page = "main"
end
+1 -2
View File
@@ -62,5 +62,4 @@ end
cache_names(block)
cache_names(item)
local scripts_registry = require "core:internal/scripts_registry"
scripts_registry.build_registry()
__vc_scripts_registry.build_registry()
+11 -50
View File
@@ -1,3 +1,5 @@
local enable_experimental = core.get_setting("debug.enable-experimental")
------------------------------------------------
------ Extended kit of standard functions ------
------------------------------------------------
@@ -36,7 +38,6 @@ local function complete_app_lib(app)
app.set_setting = core.set_setting
app.tick = function()
coroutine.yield()
network.__process_events()
end
app.get_version = core.get_version
app.get_setting_info = core.get_setting_info
@@ -169,61 +170,16 @@ function inventory.set_description(invid, slot, description)
inventory.set_data(invid, slot, "description", description)
end
------------------------------------------------
------------------- Events ---------------------
------------------------------------------------
events = {
handlers = {}
}
function events.on(event, func)
if events.handlers[event] == nil then
events.handlers[event] = {}
end
table.insert(events.handlers[event], func)
if enable_experimental then
require "core:internal/maths_inline"
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
events = require "core:internal/events"
function pack.unload(prefix)
events.remove_by_prefix(prefix)
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
gui_util = require "core:internal/gui_util"
Document = gui_util.Document
@@ -238,6 +194,7 @@ end
_GUI_ROOT = Document.new("core:root")
_MENU = _GUI_ROOT.menu
menu = _MENU
gui.root = _GUI_ROOT
--- Console library extension ---
console.cheats = {}
@@ -319,11 +276,12 @@ entities.get_all = function(uids)
end
local bytearray = require "core:internal/bytearray"
Bytearray = bytearray.FFIBytearray
Bytearray_as_string = bytearray.FFIBytearray_as_string
Bytearray_construct = function(...) return Bytearray(...) end
__vc_scripts_registry = require "core:internal/scripts_registry"
file.open = require "core:internal/stream_providers/file"
file.open_named_pipe = require "core:internal/stream_providers/named_pipe"
@@ -342,6 +300,7 @@ else
end
ffi = nil
__vc_lock_internal_modules()
math.randomseed(time.uptime() * 1536227939)
@@ -612,6 +571,8 @@ function __process_post_runnables()
for _, name in ipairs(dead) do
__vc_named_coroutines[name] = nil
end
network.__process_events()
end
function time.post_runnable(runnable)
+11
View File
@@ -550,6 +550,8 @@ function reload_module(name)
end
end
local internal_locked = false
-- Load script with caching
--
-- path - script path `contentpack:filename`.
@@ -559,6 +561,11 @@ end
function __load_script(path, nocache)
local packname, filename = parse_path(path)
if internal_locked and (packname == "res" or packname == "core")
and filename:starts_with("modules/internal") then
error("access to core:internal modules outside of [core]")
end
-- __cached_scripts used in condition because cached result may be nil
if not nocache and __cached_scripts[path] ~= nil then
return package.loaded[path]
@@ -579,6 +586,10 @@ function __load_script(path, nocache)
return result
end
function __vc_lock_internal_modules()
internal_locked = true
end
function require(path)
if not string.find(path, ':') then
local prefix, _ = parse_path(_debug_getinfo(2).source)