2022-05-02 20:55:04 +02:00
|
|
|
core.log("info", "Initializing asynchronous environment (game)")
|
|
|
|
|
|
|
|
local function pack2(...)
|
|
|
|
return {n=select('#', ...), ...}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Entrypoint to run async jobs, called by C++
|
|
|
|
function core.job_processor(func, params)
|
|
|
|
local retval = pack2(func(unpack(params, 1, params.n)))
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Import a bunch of individual files from builtin/game/
|
|
|
|
local gamepath = core.get_builtin_path() .. "game" .. DIR_DELIM
|
2022-09-18 17:46:48 +02:00
|
|
|
local commonpath = core.get_builtin_path() .. "common" .. DIR_DELIM
|
|
|
|
|
|
|
|
local builtin_shared = {}
|
2022-05-02 20:55:04 +02:00
|
|
|
|
|
|
|
dofile(gamepath .. "constants.lua")
|
2022-09-18 17:46:48 +02:00
|
|
|
assert(loadfile(commonpath .. "item_s.lua"))(builtin_shared)
|
2022-05-02 20:55:04 +02:00
|
|
|
dofile(gamepath .. "misc_s.lua")
|
|
|
|
dofile(gamepath .. "features.lua")
|
|
|
|
dofile(gamepath .. "voxelarea.lua")
|
|
|
|
|
|
|
|
-- Transfer of globals
|
|
|
|
do
|
2022-05-09 18:20:10 +02:00
|
|
|
local all = assert(core.transferred_globals)
|
2022-05-02 20:55:04 +02:00
|
|
|
core.transferred_globals = nil
|
|
|
|
|
|
|
|
all.registered_nodes = {}
|
|
|
|
all.registered_craftitems = {}
|
|
|
|
all.registered_tools = {}
|
|
|
|
for k, v in pairs(all.registered_items) do
|
2022-07-04 01:06:42 +02:00
|
|
|
-- Disable further modification
|
|
|
|
setmetatable(v, {__newindex = {}})
|
|
|
|
-- Reassemble the other tables
|
2022-05-02 20:55:04 +02:00
|
|
|
if v.type == "node" then
|
2023-06-24 17:58:43 +02:00
|
|
|
getmetatable(v).__index = all.nodedef_default
|
2022-05-02 20:55:04 +02:00
|
|
|
all.registered_nodes[k] = v
|
2023-08-14 15:07:16 +02:00
|
|
|
elseif v.type == "craft" then
|
2023-06-24 17:58:43 +02:00
|
|
|
getmetatable(v).__index = all.craftitemdef_default
|
2022-05-02 20:55:04 +02:00
|
|
|
all.registered_craftitems[k] = v
|
|
|
|
elseif v.type == "tool" then
|
2023-06-24 17:58:43 +02:00
|
|
|
getmetatable(v).__index = all.tooldef_default
|
2022-05-02 20:55:04 +02:00
|
|
|
all.registered_tools[k] = v
|
2023-06-24 17:58:43 +02:00
|
|
|
else
|
|
|
|
getmetatable(v).__index = all.noneitemdef_default
|
2022-05-02 20:55:04 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, v in pairs(all) do
|
|
|
|
core[k] = v
|
|
|
|
end
|
|
|
|
end
|
2022-07-04 01:06:42 +02:00
|
|
|
|
|
|
|
-- For tables that are indexed by item name:
|
|
|
|
-- If table[X] does not exist, default to table[core.registered_aliases[X]]
|
|
|
|
local alias_metatable = {
|
|
|
|
__index = function(t, name)
|
|
|
|
return rawget(t, core.registered_aliases[name])
|
|
|
|
end
|
|
|
|
}
|
|
|
|
setmetatable(core.registered_items, alias_metatable)
|
|
|
|
setmetatable(core.registered_nodes, alias_metatable)
|
|
|
|
setmetatable(core.registered_craftitems, alias_metatable)
|
|
|
|
setmetatable(core.registered_tools, alias_metatable)
|
2022-09-18 17:46:48 +02:00
|
|
|
|
|
|
|
builtin_shared.cache_content_ids()
|