aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-10-30 02:48:37 -0400
committerkwolekr <kwolekr@minetest.net>2015-11-02 18:43:09 -0500
commitc2b5da735ea0c961d4f6521df9d96142c7143eee (patch)
tree667ffa9cbbf5a606979a942634b030528822762c /builtin
parent5c3546e459ede7fbdfc22b340ed6b2af5073ec5b (diff)
downloadminetest-c2b5da735ea0c961d4f6521df9d96142c7143eee.tar.gz
minetest-c2b5da735ea0c961d4f6521df9d96142c7143eee.tar.bz2
minetest-c2b5da735ea0c961d4f6521df9d96142c7143eee.zip
Add callback parameter for core.emerge_area()
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/chatcommands.lua36
-rw-r--r--builtin/game/constants.lua12
-rw-r--r--builtin/game/init.lua2
3 files changed, 48 insertions, 2 deletions
diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua
index 5f9fcfc7b..6a35c034e 100644
--- a/builtin/game/chatcommands.lua
+++ b/builtin/game/chatcommands.lua
@@ -436,6 +436,31 @@ core.register_chatcommand("set", {
end,
})
+local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
+ if ctx.total_blocks == 0 then
+ ctx.total_blocks = num_calls_remaining + 1
+ ctx.current_blocks = 0
+ end
+ ctx.current_blocks = ctx.current_blocks + 1
+
+ if ctx.current_blocks == ctx.total_blocks then
+ core.chat_send_player(ctx.requestor_name,
+ string.format("Finished emerging %d blocks in %.2fms.",
+ ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
+ end
+end
+
+local function emergeblocks_progress_update(ctx)
+ if ctx.current_blocks ~= ctx.total_blocks then
+ core.chat_send_player(ctx.requestor_name,
+ string.format("emergeblocks update: %d/%d blocks emerged (%.1f%%)",
+ ctx.current_blocks, ctx.total_blocks,
+ (ctx.current_blocks / ctx.total_blocks) * 100))
+
+ core.after(2, emergeblocks_progress_update, ctx)
+ end
+end
+
core.register_chatcommand("emergeblocks", {
params = "(here [radius]) | (<pos1> <pos2>)",
description = "starts loading (or generating, if inexistent) map blocks "
@@ -447,7 +472,16 @@ core.register_chatcommand("emergeblocks", {
return false, p2
end
- core.emerge_area(p1, p2)
+ local context = {
+ current_blocks = 0,
+ total_blocks = 0,
+ start_time = os.clock(),
+ requestor_name = name
+ }
+
+ core.emerge_area(p1, p2, emergeblocks_callback, context)
+ core.after(2, emergeblocks_progress_update, context)
+
return true, "Started emerge of area ranging from " ..
core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
end,
diff --git a/builtin/game/constants.lua b/builtin/game/constants.lua
new file mode 100644
index 000000000..ea3644cfb
--- /dev/null
+++ b/builtin/game/constants.lua
@@ -0,0 +1,12 @@
+-- Minetest: builtin/constants.lua
+
+--
+-- Constants values for use with the Lua API
+--
+
+-- Block emerge status constants (for use with core.emerge_area)
+core.EMERGE_CANCELLED = 0
+core.EMERGE_ERRORED = 1
+core.EMERGE_FROM_MEMORY = 2
+core.EMERGE_FROM_DISK = 3
+core.EMERGE_GENERATED = 4
diff --git a/builtin/game/init.lua b/builtin/game/init.lua
index 72e3f009c..a6cfa3bf8 100644
--- a/builtin/game/init.lua
+++ b/builtin/game/init.lua
@@ -5,6 +5,7 @@ local gamepath = scriptpath.."game"..DIR_DELIM
dofile(commonpath.."vector.lua")
+dofile(gamepath.."constants.lua")
dofile(gamepath.."item.lua")
dofile(gamepath.."register.lua")
@@ -25,4 +26,3 @@ dofile(gamepath.."features.lua")
dofile(gamepath.."voxelarea.lua")
dofile(gamepath.."forceloading.lua")
dofile(gamepath.."statbars.lua")
-