Organize builtin into subdirectories

This commit is contained in:
ShadowNinja 2014-04-27 17:55:49 -04:00 committed by Nils Dagsson Moskopp
parent 4f1adce2b2
commit 148b74312e
Signed by: erle
GPG Key ID: A3BC671C35191080
32 changed files with 129 additions and 113 deletions

18
builtin/async/init.lua Normal file
View File

@ -0,0 +1,18 @@
engine.log("info", "Initializing Asynchronous environment")
local core = engine or minetest
function core.job_processor(serialized_func, serialized_param)
local func = loadstring(serialized_func)
local param = core.deserialize(serialized_param)
local retval = nil
if type(func) == "function" then
retval = core.serialize(func(param))
else
core.log("error", "ASYNC WORKER: Unable to deserialize function")
end
return retval or core.serialize(nil)
end

View File

@ -1,21 +0,0 @@
engine.log("info", "Initializing Asynchronous environment")
local tbl = engine or minetest
minetest = tbl
dofile(SCRIPTDIR .. DIR_DELIM .. "serialize.lua")
dofile(SCRIPTDIR .. DIR_DELIM .. "misc_helpers.lua")
function tbl.job_processor(serialized_func, serialized_param)
local func = loadstring(serialized_func)
local param = tbl.deserialize(serialized_param)
local retval = nil
if type(func) == "function" then
retval = tbl.serialize(func(param))
else
tbl.log("error", "ASYNC WORKER: Unable to deserialize function")
end
return retval or tbl.serialize(nil)
end

View File

@ -1,45 +0,0 @@
local tbl = engine or minetest
local SCRIPTDIR = SCRIPTDIR or tbl.get_scriptdir()
minetest = tbl
dofile(SCRIPTDIR .. DIR_DELIM .. "serialize.lua")
tbl.async_jobs = {}
local function handle_job(jobid, serialized_retval)
local retval = tbl.deserialize(serialized_retval)
assert(type(tbl.async_jobs[jobid]) == "function")
tbl.async_jobs[jobid](retval)
tbl.async_jobs[jobid] = nil
end
if engine ~= nil then
tbl.async_event_handler = handle_job
else
minetest.register_globalstep(function(dtime)
for i, job in ipairs(tbl.get_finished_jobs()) do
handle_job(job.jobid, job.retval)
end
end)
end
function tbl.handle_async(func, parameter, callback)
-- Serialize function
local serialized_func = string.dump(func)
assert(serialized_func ~= nil)
-- Serialize parameters
local serialized_param = tbl.serialize(parameter)
if serialized_param == nil then
return false
end
local jobid = tbl.do_async_callback(serialized_func, serialized_param)
tbl.async_jobs[jobid] = callback
return true
end

View File

@ -1,32 +0,0 @@
--
-- This file contains built-in stuff in Minetest implemented in Lua.
--
-- It is always loaded and executed after registration of the C API,
-- before loading and running any mods.
--
-- Initialize some very basic things
print = minetest.debug
math.randomseed(os.time())
os.setlocale("C", "numeric")
-- Load other files
local modpath = minetest.get_modpath("__builtin")
dofile(modpath.."/serialize.lua")
dofile(modpath.."/misc_helpers.lua")
dofile(modpath.."/item.lua")
dofile(modpath.."/misc_register.lua")
dofile(modpath.."/item_entity.lua")
dofile(modpath.."/deprecated.lua")
dofile(modpath.."/misc.lua")
dofile(modpath.."/privileges.lua")
dofile(modpath.."/auth.lua")
dofile(modpath.."/chatcommands.lua")
dofile(modpath.."/static_spawn.lua")
dofile(modpath.."/detached_inventory.lua")
dofile(modpath.."/falling.lua")
dofile(modpath.."/features.lua")
dofile(modpath.."/voxelarea.lua")
dofile(modpath.."/vector.lua")
dofile(modpath.."/forceloading.lua")
dofile(modpath.."/statbars.lua")

View File

@ -0,0 +1,42 @@
local core = engine or minetest
core.async_jobs = {}
local function handle_job(jobid, serialized_retval)
local retval = core.deserialize(serialized_retval)
assert(type(core.async_jobs[jobid]) == "function")
core.async_jobs[jobid](retval)
core.async_jobs[jobid] = nil
end
if engine ~= nil then
core.async_event_handler = handle_job
else
minetest.register_globalstep(function(dtime)
for i, job in ipairs(core.get_finished_jobs()) do
handle_job(job.jobid, job.retval)
end
end)
end
function core.handle_async(func, parameter, callback)
-- Serialize function
local serialized_func = string.dump(func)
assert(serialized_func ~= nil)
-- Serialize parameters
local serialized_param = core.serialize(parameter)
if serialized_param == nil then
return false
end
local jobid = core.do_async_callback(serialized_func, serialized_param)
core.async_jobs[jobid] = callback
return true
end

View File

@ -4,7 +4,7 @@
-- Falling stuff
--
minetest.register_entity("__builtin:falling_node", {
minetest.register_entity(":__builtin:falling_node", {
initial_properties = {
physical = true,
collide_with_objects = false,

23
builtin/game/init.lua Normal file
View File

@ -0,0 +1,23 @@
local scriptpath = minetest.get_builtin_path()..DIR_DELIM
local commonpath = scriptpath.."common"..DIR_DELIM
local gamepath = scriptpath.."game"..DIR_DELIM
dofile(commonpath.."vector.lua")
dofile(gamepath.."item.lua")
dofile(gamepath.."register.lua")
dofile(gamepath.."item_entity.lua")
dofile(gamepath.."deprecated.lua")
dofile(gamepath.."misc.lua")
dofile(gamepath.."privileges.lua")
dofile(gamepath.."auth.lua")
dofile(gamepath.."chatcommands.lua")
dofile(gamepath.."static_spawn.lua")
dofile(gamepath.."detached_inventory.lua")
dofile(gamepath.."falling.lua")
dofile(gamepath.."features.lua")
dofile(gamepath.."voxelarea.lua")
dofile(gamepath.."forceloading.lua")
dofile(gamepath.."statbars.lua")

View File

@ -8,7 +8,7 @@ function minetest.spawn_item(pos, item)
return obj
end
minetest.register_entity("__builtin:item", {
minetest.register_entity(":__builtin:item", {
initial_properties = {
hp_max = 1,
physical = true,

34
builtin/init.lua Normal file
View File

@ -0,0 +1,34 @@
--
-- This file contains built-in stuff in Minetest implemented in Lua.
--
-- It is always loaded and executed after registration of the C API,
-- before loading and running any mods.
--
local core = minetest or engine
minetest = core
-- Initialize some very basic things
print = core.debug
math.randomseed(os.time())
os.setlocale("C", "numeric")
-- Load other files
local scriptdir = core.get_builtin_path()..DIR_DELIM
local gamepath = scriptdir.."game"..DIR_DELIM
local commonpath = scriptdir.."common"..DIR_DELIM
local asyncpath = scriptdir.."async"..DIR_DELIM
dofile(commonpath.."serialize.lua")
dofile(commonpath.."misc_helpers.lua")
if INIT == "game" then
dofile(gamepath.."init.lua")
elseif INIT == "mainmenu" then
dofile(core.get_mainmenu_path()..DIR_DELIM.."init.lua")
elseif INIT == "async" then
dofile(asyncpath.."init.lua")
else
error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))
end

View File

@ -1,8 +1,14 @@
print = engine.debug
math.randomseed(os.time())
os.setlocale("C", "numeric")
local scriptpath = engine.get_scriptdir()
local menupath = engine.get_mainmenu_path()..DIR_DELIM
local commonpath = engine.get_builtin_path()..DIR_DELIM.."common"..DIR_DELIM
dofile(menupath.."filterlist.lua")
dofile(menupath.."modmgr.lua")
dofile(menupath.."modstore.lua")
dofile(menupath.."gamemgr.lua")
dofile(menupath.."textures.lua")
dofile(menupath.."menubar.lua")
dofile(commonpath.."async_event.lua")
mt_color_grey = "#AAAAAA"
mt_color_blue = "#0000DD"
@ -11,15 +17,6 @@ mt_color_dark_green = "#003300"
--for all other colors ask sfan5 to complete his worK!
dofile(scriptpath .. DIR_DELIM .. "misc_helpers.lua")
dofile(scriptpath .. DIR_DELIM .. "filterlist.lua")
dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
dofile(scriptpath .. DIR_DELIM .. "mm_textures.lua")
dofile(scriptpath .. DIR_DELIM .. "mm_menubar.lua")
dofile(scriptpath .. DIR_DELIM .. "async_event.lua")
menu = {}
local tabbuilder = {}
local worldlist = nil