game.lua 1.1 KB

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