aboutsummaryrefslogtreecommitdiff
path: root/builtin/async
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-05-02 20:55:04 +0200
committersfan5 <sfan5@live.de>2022-05-02 20:56:06 +0200
commite7659883cc6fca343785da2a1af3890ae273abbf (patch)
treeb8d2e3bdbe10ed0e99074207113e24ccca3fb5df /builtin/async
parent663c9364289dae45aeb86a87cba826f577d84a9c (diff)
downloadminetest-e7659883cc6fca343785da2a1af3890ae273abbf.tar.gz
minetest-e7659883cc6fca343785da2a1af3890ae273abbf.tar.bz2
minetest-e7659883cc6fca343785da2a1af3890ae273abbf.zip
Async environment for mods to do concurrent tasks (#11131)
Diffstat (limited to 'builtin/async')
-rw-r--r--builtin/async/game.lua46
-rw-r--r--builtin/async/mainmenu.lua (renamed from builtin/async/init.lua)4
2 files changed, 47 insertions, 3 deletions
diff --git a/builtin/async/game.lua b/builtin/async/game.lua
new file mode 100644
index 000000000..212a33e17
--- /dev/null
+++ b/builtin/async/game.lua
@@ -0,0 +1,46 @@
+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
+
+dofile(gamepath .. "constants.lua")
+dofile(gamepath .. "item_s.lua")
+dofile(gamepath .. "misc_s.lua")
+dofile(gamepath .. "features.lua")
+dofile(gamepath .. "voxelarea.lua")
+
+-- Transfer of globals
+do
+ assert(core.transferred_globals)
+ local all = core.deserialize(core.transferred_globals, true)
+ core.transferred_globals = nil
+
+ -- reassemble other tables
+ all.registered_nodes = {}
+ all.registered_craftitems = {}
+ all.registered_tools = {}
+ for k, v in pairs(all.registered_items) do
+ if v.type == "node" then
+ all.registered_nodes[k] = v
+ elseif v.type == "craftitem" then
+ all.registered_craftitems[k] = v
+ elseif v.type == "tool" then
+ all.registered_tools[k] = v
+ end
+ end
+
+ for k, v in pairs(all) do
+ core[k] = v
+ end
+end
diff --git a/builtin/async/init.lua b/builtin/async/mainmenu.lua
index 3803994d6..0e9c222d1 100644
--- a/builtin/async/init.lua
+++ b/builtin/async/mainmenu.lua
@@ -1,5 +1,4 @@
-
-core.log("info", "Initializing Asynchronous environment")
+core.log("info", "Initializing asynchronous environment")
function core.job_processor(func, serialized_param)
local param = core.deserialize(serialized_param)
@@ -8,4 +7,3 @@ function core.job_processor(func, serialized_param)
return retval or core.serialize(nil)
end
-