2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
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
|
2018-01-22 03:52:51 +00:00
|
|
|
if ctx.name then
|
|
|
|
minetest.chat_send_player(ctx.name,
|
|
|
|
string.format("Finished emerging %d blocks in %.2fms.",
|
|
|
|
ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
|
|
|
|
end
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
ctx:callback()
|
2018-01-22 03:52:51 +00:00
|
|
|
elseif ctx.progress then
|
2017-12-23 16:33:05 +00:00
|
|
|
ctx:progress()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ctf_map.emerge_with_callbacks(name, pos1, pos2, callback, progress)
|
|
|
|
local context = {
|
|
|
|
current_blocks = 0,
|
|
|
|
total_blocks = 0,
|
|
|
|
start_time = os.clock(),
|
|
|
|
name = name,
|
|
|
|
callback = callback,
|
|
|
|
progress = progress
|
|
|
|
}
|
|
|
|
|
|
|
|
minetest.emerge_area(pos1, pos2, emergeblocks_callback, context)
|
|
|
|
end
|