mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-08-20 21:44:06 +02:00
os.clock() → minetest.get_us_time()
....how did I miss that :P
This commit is contained in:
parent
5aec4d756c
commit
0afbba4deb
@ -17,7 +17,7 @@ local function printspace(space, w, h)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function generate_maze(seed, width, height, path_length, path_width)
|
local function generate_maze(seed, width, height, path_length, path_width)
|
||||||
start_time = os.clock()
|
start_time = worldeditadditions.get_ms_time()
|
||||||
|
|
||||||
if not path_length then path_length = 2 end
|
if not path_length then path_length = 2 end
|
||||||
if not path_width then path_width = 1 end
|
if not path_width then path_width = 1 end
|
||||||
@ -112,7 +112,7 @@ local function generate_maze(seed, width, height, path_length, path_width)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local end_time = os.clock()
|
local end_time = worldeditadditions.get_ms_time()
|
||||||
return world, (end_time - start_time) * 1000
|
return world, (end_time - start_time) * 1000
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ function printspace3d(space, w, h, d)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Initialise the world
|
-- Initialise the world
|
||||||
start_time = os.clock()
|
start_time = worldeditadditions.get_ms_time()
|
||||||
|
|
||||||
local function generate_maze3d(seed, width, height, depth, path_length, path_width, path_depth)
|
local function generate_maze3d(seed, width, height, depth, path_length, path_width, path_depth)
|
||||||
|
|
||||||
|
@ -9,3 +9,19 @@ function worldeditadditions.hypotenuse(x1, y1, x2, y2)
|
|||||||
local ySquare = math.pow(y1 - y2, 2);
|
local ySquare = math.pow(y1 - y2, 2);
|
||||||
return math.sqrt(xSquare + ySquare);
|
return math.sqrt(xSquare + ySquare);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function worldeditadditions.average(list)
|
||||||
|
if #list == 0 then return 0 end
|
||||||
|
local sum = 0
|
||||||
|
for i,value in ipairs(list) do
|
||||||
|
sum = sum + value
|
||||||
|
end
|
||||||
|
return sum / #list
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Returns the minetest.get_us_time() in ms
|
||||||
|
-- @return float
|
||||||
|
function worldeditadditions.get_ms_time()
|
||||||
|
return minetest.get_us_time() / 1000
|
||||||
|
end
|
||||||
|
@ -46,14 +46,14 @@ worldedit.register_command("bonemeal", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) / 2
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) / 2
|
||||||
end,
|
end,
|
||||||
func = function(name, strength, chance)
|
func = function(name, strength, chance)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local success, nodes_bonemealed, candidates = worldeditadditions.bonemeal(worldedit.pos1[name], worldedit.pos2[name], strength, chance)
|
local success, nodes_bonemealed, candidates = worldeditadditions.bonemeal(worldedit.pos1[name], worldedit.pos2[name], strength, chance)
|
||||||
if not success then
|
if not success then
|
||||||
-- nodes_bonemealed is an error message here because success == false
|
-- nodes_bonemealed is an error message here because success == false
|
||||||
return success, nodes_bonemealed
|
return success, nodes_bonemealed
|
||||||
end
|
end
|
||||||
local percentage = worldeditadditions.round((nodes_bonemealed / candidates)*100, 2)
|
local percentage = worldeditadditions.round((nodes_bonemealed / candidates)*100, 2)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //bonemeal at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", bonemealing " .. nodes_bonemealed.." nodes (out of "..candidates.." nodes) at strength "..strength.." in "..time_taken.."s")
|
minetest.log("action", name .. " used //bonemeal at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", bonemealing " .. nodes_bonemealed.." nodes (out of "..candidates.." nodes) at strength "..strength.." in "..time_taken.."s")
|
||||||
return true, nodes_bonemealed.." out of "..candidates.." (~"..percentage.."%) candidates bonemealed in "..time_taken.."s"
|
return true, nodes_bonemealed.." out of "..candidates.." (~"..percentage.."%) candidates bonemealed in "..time_taken.."s"
|
||||||
|
@ -50,7 +50,7 @@ worldedit.register_command("convolve", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, kernel_name, kernel_width, kernel_height, sigma)
|
func = function(name, kernel_name, kernel_width, kernel_height, sigma)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
|
|
||||||
print("[exec] kernel_width", kernel_width, "kernel_height", kernel_height)
|
print("[exec] kernel_width", kernel_width, "kernel_height", kernel_height)
|
||||||
local success, kernel = worldeditadditions.get_conv_kernel(kernel_name, kernel_width, kernel_height, sigma)
|
local success, kernel = worldeditadditions.get_conv_kernel(kernel_name, kernel_width, kernel_height, sigma)
|
||||||
@ -65,7 +65,7 @@ worldedit.register_command("convolve", {
|
|||||||
kernel, kernel_size
|
kernel, kernel_size
|
||||||
)
|
)
|
||||||
|
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
|
|
||||||
minetest.log("action", name.." used //convolve at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", adding "..stats.added.." nodes and removing "..stats.removed.." nodes in "..time_taken.."s")
|
minetest.log("action", name.." used //convolve at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", adding "..stats.added.." nodes and removing "..stats.removed.." nodes in "..time_taken.."s")
|
||||||
|
@ -17,14 +17,14 @@ worldedit.register_command("count", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name)
|
func = function(name)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
|
|
||||||
local success, counts, total = worldeditadditions.count(worldedit.pos1[name], worldedit.pos2[name], target_node)
|
local success, counts, total = worldeditadditions.count(worldedit.pos1[name], worldedit.pos2[name], target_node)
|
||||||
local result = worldeditadditions.make_ascii_table(counts).."\n"..
|
local result = worldeditadditions.make_ascii_table(counts).."\n"..
|
||||||
string.rep("=", 6 + #tostring(total) + 6).."\n"..
|
string.rep("=", 6 + #tostring(total) + 6).."\n"..
|
||||||
"Total "..total.." nodes\n"
|
"Total "..total.." nodes\n"
|
||||||
|
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
|
|
||||||
minetest.log("action", name.." used //count at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", counting "..total.." nodes in "..time_taken.."s")
|
minetest.log("action", name.." used //count at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", counting "..total.." nodes in "..time_taken.."s")
|
||||||
|
@ -43,9 +43,9 @@ worldedit.register_command("ellipsoid", {
|
|||||||
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, radius)
|
func = function(name, target_node, radius)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, false)
|
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, false)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
@ -66,9 +66,9 @@ worldedit.register_command("hollowellipsoid", {
|
|||||||
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, radius)
|
func = function(name, target_node, radius)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, true)
|
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, true)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //hollowellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //hollowellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
|
@ -35,9 +35,9 @@ worldedit.register_command("floodfill", {
|
|||||||
return math.ceil(((4 * math.pi * (tonumber(radius) ^ 3)) / 3) / 2)
|
return math.ceil(((4 * math.pi * (tonumber(radius) ^ 3)) / 3) / 2)
|
||||||
end,
|
end,
|
||||||
func = function(name, replace_node, radius)
|
func = function(name, replace_node, radius)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local nodes_replaced = worldeditadditions.floodfill(worldedit.pos1[name], radius, replace_node)
|
local nodes_replaced = worldeditadditions.floodfill(worldedit.pos1[name], radius, replace_node)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
if nodes_replaced == false then
|
if nodes_replaced == false then
|
||||||
return false, "Error: The search node is the same as the replace node."
|
return false, "Error: The search node is the same as the replace node."
|
||||||
|
@ -23,9 +23,9 @@ worldedit.register_command("layers", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, node_list)
|
func = function(name, node_list)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local changes = worldeditadditions.layers(worldedit.pos1[name], worldedit.pos2[name], node_list)
|
local changes = worldeditadditions.layers(worldedit.pos1[name], worldedit.pos2[name], node_list)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //layers at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.replaced .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //layers at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.replaced .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s")
|
||||||
return true, changes.replaced .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s"
|
return true, changes.replaced .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s"
|
||||||
|
@ -72,9 +72,9 @@ worldedit.register_command("maze", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, replace_node, seed, path_length, path_width)
|
func = function(name, replace_node, seed, path_length, path_width)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.maze2d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width)
|
local replaced = worldeditadditions.maze2d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //maze at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. " - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //maze at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. " - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
@ -102,9 +102,9 @@ worldedit.register_command("maze3d", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, replace_node, seed, path_length, path_width, path_depth)
|
func = function(name, replace_node, seed, path_length, path_width, path_depth)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.maze3d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width, path_depth)
|
local replaced = worldeditadditions.maze3d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width, path_depth)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
|
|
||||||
minetest.log("action", name .. " used //maze3d at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. " - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //maze3d at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. " - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
|
@ -20,9 +20,9 @@ worldedit.register_command("overlay", {
|
|||||||
return (pos2.x - pos1.x) * (pos2.y - pos1.y)
|
return (pos2.x - pos1.x) * (pos2.y - pos1.y)
|
||||||
end,
|
end,
|
||||||
func = function(name, node_list)
|
func = function(name, node_list)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local changes = worldeditadditions.overlay(worldedit.pos1[name], worldedit.pos2[name], node_list)
|
local changes = worldeditadditions.overlay(worldedit.pos1[name], worldedit.pos2[name], node_list)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //overlay at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.updated .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //overlay at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.updated .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s")
|
||||||
return true, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s"
|
return true, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s"
|
||||||
|
@ -64,7 +64,7 @@ worldedit.register_command("replacemix", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, target_node_chance, replace_nodes)
|
func = function(name, target_node, target_node_chance, replace_nodes)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
|
|
||||||
local success, changed, candidates, distribution = worldeditadditions.replacemix(
|
local success, changed, candidates, distribution = worldeditadditions.replacemix(
|
||||||
worldedit.pos1[name], worldedit.pos2[name],
|
worldedit.pos1[name], worldedit.pos2[name],
|
||||||
@ -83,7 +83,7 @@ worldedit.register_command("replacemix", {
|
|||||||
changed
|
changed
|
||||||
)
|
)
|
||||||
|
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
|
|
||||||
minetest.log("action", name .. " used //replacemix at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. changed.." nodes (out of "..nodes_total.." nodes) in "..time_taken.."s")
|
minetest.log("action", name .. " used //replacemix at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing " .. changed.." nodes (out of "..nodes_total.." nodes) in "..time_taken.."s")
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
local wea = worldeditadditions
|
||||||
|
|
||||||
-- Test command:
|
-- Test command:
|
||||||
-- //multi //fp set1 1330 60 5455 //fp set2 1355 35 5430 //subdivide 10 10 10 fixlight //y
|
-- //multi //fp set1 1330 60 5455 //fp set2 1355 35 5430 //subdivide 10 10 10 fixlight //y
|
||||||
|
|
||||||
local function will_trigger_saferegion(name, cmd_name, args)
|
local function will_trigger_saferegion(name, cmd_name, args)
|
||||||
if not worldedit.registered_commands[cmd_name] then return nil, "Error: That worldedit command could not be found (perhaps it hasn't been upgraded to worldedit.register_command() yet?)" end
|
if not worldedit.registered_commands[cmd_name] then return nil, "Error: That worldedit command could not be found (perhaps it hasn't been upgraded to worldedit.register_command() yet?)" end
|
||||||
local def = worldedit.registered_commands[cmd_name]
|
local def = worldedit.registered_commands[cmd_name]
|
||||||
@ -22,7 +25,7 @@ worldedit.register_command("subdivide", {
|
|||||||
privs = { worldedit = true },
|
privs = { worldedit = true },
|
||||||
require_pos = 2,
|
require_pos = 2,
|
||||||
parse = function(params_text)
|
parse = function(params_text)
|
||||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
local parts = wea.split(params_text, "%s+", false)
|
||||||
|
|
||||||
if #parts < 4 then
|
if #parts < 4 then
|
||||||
return false, "Error: Not enough arguments (try /help /subdivide)."
|
return false, "Error: Not enough arguments (try /help /subdivide)."
|
||||||
@ -55,7 +58,7 @@ worldedit.register_command("subdivide", {
|
|||||||
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, chunk_size, cmd_name, args)
|
func = function(name, chunk_size, cmd_name, args)
|
||||||
local time_total = os.clock()
|
local time_total = worldeditadditions.get_ms_time()
|
||||||
|
|
||||||
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])
|
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
local volume = worldedit.volume(pos1, pos2)
|
local volume = worldedit.volume(pos1, pos2)
|
||||||
@ -68,12 +71,13 @@ worldedit.register_command("subdivide", {
|
|||||||
chunk_size.y = chunk_size.y - 1 -- WorldEdit regions are inclusive
|
chunk_size.y = chunk_size.y - 1 -- WorldEdit regions are inclusive
|
||||||
chunk_size.z = chunk_size.z - 1 -- WorldEdit regions are inclusive
|
chunk_size.z = chunk_size.z - 1 -- WorldEdit regions are inclusive
|
||||||
|
|
||||||
worldedit.player_notify(name, worldeditadditions.vector.tostring(pos1).." - "..worldeditadditions.vector.tostring(pos2).." chunk size: "..worldeditadditions.vector.tostring(chunk_size))
|
worldedit.player_notify(name, wea.vector.tostring(pos1).." - "..wea.vector.tostring(pos2).." chunk size: "..wea.vector.tostring(chunk_size))
|
||||||
local i = 1
|
local i = 1
|
||||||
local chunks_total = math.ceil((pos2.x - pos1.x) / chunk_size.x)
|
local chunks_total = math.ceil((pos2.x - pos1.x) / chunk_size.x)
|
||||||
* math.ceil((pos2.y - pos1.y) / chunk_size.y)
|
* math.ceil((pos2.y - pos1.y) / chunk_size.y)
|
||||||
* math.ceil((pos2.z - pos1.z) / chunk_size.z)
|
* math.ceil((pos2.z - pos1.z) / chunk_size.z)
|
||||||
|
|
||||||
|
local time_last_msg = worldeditadditions.get_ms_time()
|
||||||
local time_chunks = {}
|
local time_chunks = {}
|
||||||
for z = pos2.z, pos1.z, -(chunk_size.z + 1) do
|
for z = pos2.z, pos1.z, -(chunk_size.z + 1) do
|
||||||
for y = pos2.y, pos1.y, -(chunk_size.y + 1) do
|
for y = pos2.y, pos1.y, -(chunk_size.y + 1) do
|
||||||
@ -84,36 +88,36 @@ worldedit.register_command("subdivide", {
|
|||||||
y = y - chunk_size.y,
|
y = y - chunk_size.y,
|
||||||
z = z - chunk_size.z
|
z = z - chunk_size.z
|
||||||
}
|
}
|
||||||
print("c1", worldeditadditions.vector.tostring(c_pos1), "c2", worldeditadditions.vector.tostring(c_pos2), "volume", worldedit.volume(c_pos1, c_pos2))
|
-- print("c1", wea.vector.tostring(c_pos1), "c2", wea.vector.tostring(c_pos2), "volume", worldedit.volume(c_pos1, c_pos2))
|
||||||
if c_pos1.x < pos1.x then
|
if c_pos1.x < pos1.x then c_pos1.x = pos1.x end
|
||||||
print("clamping c1.x", c_pos1.x, "to", pos1.x)
|
if c_pos1.y < pos1.y then c_pos1.y = pos1.y end
|
||||||
c_pos1.x = pos1.x
|
if c_pos1.z < pos1.z then c_pos1.z = pos1.z end
|
||||||
end
|
|
||||||
if c_pos1.y < pos1.y then
|
|
||||||
print("clamping c1.y", c_pos1.y, "to", pos1.y)
|
|
||||||
c_pos1.y = pos1.y
|
|
||||||
end
|
|
||||||
if c_pos1.z < pos1.z then
|
|
||||||
print("clamping c1.z", c_pos1.z, "to", pos1.z)
|
|
||||||
c_pos1.z = pos1.z
|
|
||||||
end
|
|
||||||
|
|
||||||
local time_this = os.clock()
|
local time_this = worldeditadditions.get_ms_time()
|
||||||
worldedit.pos1[name] = c_pos1
|
worldedit.pos1[name] = c_pos1
|
||||||
worldedit.pos2[name] = c_pos2
|
worldedit.pos2[name] = c_pos2
|
||||||
cmd.func(name, args)
|
cmd.func(name, args)
|
||||||
if will_trigger_saferegion(name, cmd_name, args) then
|
if will_trigger_saferegion(name, cmd_name, args) then
|
||||||
minetest.chatcommands["/y"].func()
|
minetest.chatcommands["/y"].func()
|
||||||
end
|
end
|
||||||
time_this = os.clock() - time_this
|
time_this = worldeditadditions.get_ms_time() - time_this
|
||||||
|
table.insert(time_chunks, time_this)
|
||||||
|
|
||||||
worldedit.player_notify(name,
|
local time_average = wea.average(time_chunks)
|
||||||
"[ //subdivide "..cmd_name.." "..args.." ] "
|
local eta = (chunks_total - i) * time_average
|
||||||
..i.." / "..chunks_total.." (~"
|
|
||||||
..string.format("%.2f", (i / chunks_total) * 100).."%) complete | "..
|
if worldeditadditions.get_ms_time() - time_last_msg > 5 * 1000 then
|
||||||
worldeditadditions.vector.tostring(c_pos1).." - "..
|
worldedit.player_notify(name,
|
||||||
worldeditadditions.vector.tostring(c_pos2).."("..worldedit.volume(c_pos1, c_pos2).." nodes)"
|
"[ //subdivide "..cmd_name.." "..args.." ] "
|
||||||
)
|
..i.." / "..chunks_total.." (~"
|
||||||
|
..string.format("%.2f", (i / chunks_total) * 100).."%) complete | "
|
||||||
|
.."this chunk: "..wea.human_time(time_this)
|
||||||
|
.."("..worldedit.volume(c_pos1, c_pos2).." nodes)"
|
||||||
|
..", average: "..wea.human_time(time_average)
|
||||||
|
..", ETA: ~"..wea.human_time(eta)
|
||||||
|
)
|
||||||
|
time_last_msg = worldeditadditions.get_ms_time()
|
||||||
|
end
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
@ -121,10 +125,10 @@ worldedit.register_command("subdivide", {
|
|||||||
end
|
end
|
||||||
worldedit.pos1[name] = pos1
|
worldedit.pos1[name] = pos1
|
||||||
worldedit.pos2[name] = pos2
|
worldedit.pos2[name] = pos2
|
||||||
time_total = os.clock() - time_total
|
time_total = worldeditadditions.get_ms_time() - time_total
|
||||||
|
|
||||||
|
|
||||||
minetest.log("action", name.." used //subdivide at "..worldeditadditions.vector.tostring(pos1).." - "..worldeditadditions.vector.tostring(pos2)..", with "..i.." chunks and "..worldedit.volume(pos1, pos2).." total nodes in "..time_total.."s")
|
minetest.log("action", name.." used //subdivide at "..wea.vector.tostring(pos1).." - "..wea.vector.tostring(pos2)..", with "..i.." chunks and "..worldedit.volume(pos1, pos2).." total nodes in "..time_total.."s")
|
||||||
return true, "/subdivide complete"
|
return true, "/subdivide complete"
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -41,9 +41,9 @@ worldedit.register_command("torus", {
|
|||||||
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, major_radius, minor_radius)
|
func = function(name, target_node, major_radius, minor_radius)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, false)
|
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, false)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
@ -64,9 +64,9 @@ worldedit.register_command("hollowtorus", {
|
|||||||
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, major_radius, minor_radius)
|
func = function(name, target_node, major_radius, minor_radius)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, true)
|
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, true)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
|
@ -24,9 +24,9 @@ worldedit.register_command("walls", {
|
|||||||
return worldedit.volume(pos1, pos2) - worldedit.volume(pos1, pos3)
|
return worldedit.volume(pos1, pos2) - worldedit.volume(pos1, pos3)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node)
|
func = function(name, target_node)
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local success, replaced = worldeditadditions.walls(worldedit.pos1[name], worldedit.pos2[name], target_node)
|
local success, replaced = worldeditadditions.walls(worldedit.pos1[name], worldedit.pos2[name], target_node)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //walls from "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." to "..worldeditadditions.vector.tostring(worldedit.pos1[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //walls from "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." to "..worldeditadditions.vector.tostring(worldedit.pos1[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
|
@ -38,12 +38,12 @@ minetest.register_chatcommand("/multi", {
|
|||||||
func = function(name, params_text)
|
func = function(name, params_text)
|
||||||
|
|
||||||
local i = 1 -- For feedback only
|
local i = 1 -- For feedback only
|
||||||
local master_start_time = os.clock()
|
local master_start_time = worldeditadditions.get_ms_time()
|
||||||
local times = {}
|
local times = {}
|
||||||
|
|
||||||
-- Things start at 1, not 0 in Lua :-(
|
-- Things start at 1, not 0 in Lua :-(
|
||||||
for command in explode(" /", string.sub(params_text, 2)) do
|
for command in explode(" /", string.sub(params_text, 2)) do
|
||||||
local start_time = os.clock()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local found, _, command_name, args = command:find("^([^%s]+)%s(.+)$")
|
local found, _, command_name, args = command:find("^([^%s]+)%s(.+)$")
|
||||||
if not found then command_name = command end
|
if not found then command_name = command end
|
||||||
command_name = trim(command_name)
|
command_name = trim(command_name)
|
||||||
@ -61,11 +61,11 @@ minetest.register_chatcommand("/multi", {
|
|||||||
minetest.log("action", name.." runs "..command)
|
minetest.log("action", name.." runs "..command)
|
||||||
cmd.func(name, args)
|
cmd.func(name, args)
|
||||||
|
|
||||||
times[#times + 1] = (os.clock() - start_time) * 1000
|
times[#times + 1] = (worldeditadditions.get_ms_time() - start_time) * 1000
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local total_time = (os.clock() - master_start_time) * 1000
|
local total_time = (worldeditadditions.get_ms_time() - master_start_time) * 1000
|
||||||
local done_message = {}
|
local done_message = {}
|
||||||
table.insert(done_message,
|
table.insert(done_message,
|
||||||
string.format("Executed %d commands in %s (",
|
string.format("Executed %d commands in %s (",
|
||||||
|
Loading…
Reference in New Issue
Block a user