]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/async/game.lua
Use native packer to transfer globals into async env(s)
[dragonfireclient.git] / builtin / async / game.lua
1 core.log("info", "Initializing asynchronous environment (game)")
2
3 local function pack2(...)
4         return {n=select('#', ...), ...}
5 end
6
7 -- Entrypoint to run async jobs, called by C++
8 function core.job_processor(func, params)
9         local retval = pack2(func(unpack(params, 1, params.n)))
10
11         return retval
12 end
13
14 -- Import a bunch of individual files from builtin/game/
15 local gamepath = core.get_builtin_path() .. "game" .. DIR_DELIM
16
17 dofile(gamepath .. "constants.lua")
18 dofile(gamepath .. "item_s.lua")
19 dofile(gamepath .. "misc_s.lua")
20 dofile(gamepath .. "features.lua")
21 dofile(gamepath .. "voxelarea.lua")
22
23 -- Transfer of globals
24 do
25         local all = assert(core.transferred_globals)
26         core.transferred_globals = nil
27
28         -- reassemble other tables
29         all.registered_nodes = {}
30         all.registered_craftitems = {}
31         all.registered_tools = {}
32         for k, v in pairs(all.registered_items) do
33                 if v.type == "node" then
34                         all.registered_nodes[k] = v
35                 elseif v.type == "craftitem" then
36                         all.registered_craftitems[k] = v
37                 elseif v.type == "tool" then
38                         all.registered_tools[k] = v
39                 end
40         end
41
42         for k, v in pairs(all) do
43                 core[k] = v
44         end
45 end