mirror of
https://github.com/HybridDog/we_undo.git
synced 2025-01-05 20:27:35 +01:00
Simplify mem_use
This commit is contained in:
parent
5385c24888
commit
06a9601da0
@ -24,7 +24,6 @@ Ignored chatcommands:
|
|||||||
|
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
* simplify mem_usage
|
|
||||||
* Add parameters to undo and redo: undo the last n
|
* Add parameters to undo and redo: undo the last n
|
||||||
* Allow undoing changes which happened before other changes (considered unsafe)
|
* Allow undoing changes which happened before other changes (considered unsafe)
|
||||||
e.g. //undo ~1 to undo the change before the latest one
|
e.g. //undo ~1 to undo the change before the latest one
|
||||||
|
34
init.lua
34
init.lua
@ -93,6 +93,8 @@ local function add_to_history(data, name)
|
|||||||
j.entry_count = j.off_start+1
|
j.entry_count = j.off_start+1
|
||||||
end
|
end
|
||||||
-- insert the new data
|
-- insert the new data
|
||||||
|
-- make every entry supposedly have >= 16 bytes
|
||||||
|
data.mem_use = (data.mem_use or 0) + 16
|
||||||
j.ring[(j.start + j.off_start) % max_commands] = data
|
j.ring[(j.start + j.off_start) % max_commands] = data
|
||||||
j.mem_usage = j.mem_usage + data.mem_use
|
j.mem_usage = j.mem_usage + data.mem_use
|
||||||
|
|
||||||
@ -128,14 +130,18 @@ local function trim_undo_history(j)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local undo_funcs = {}
|
local undo_funcs = {}
|
||||||
local function apply_undo(name)
|
local function bare_apply_undo(j, name)
|
||||||
local j = journal[name]
|
|
||||||
local i = (j.start + j.off_start) % max_commands
|
local i = (j.start + j.off_start) % max_commands
|
||||||
local data = j.ring[i]
|
local data = j.ring[i]
|
||||||
local old_memuse = data.mem_use
|
local old_memuse = data.mem_use
|
||||||
undo_funcs[data.type](name, data)
|
undo_funcs[data.type](name, data)
|
||||||
j.mem_usage = j.mem_usage + data.mem_use - old_memuse
|
j.mem_usage = j.mem_usage + (data.mem_use or 0) + 16 - old_memuse
|
||||||
j.ring[i] = data
|
j.ring[i] = data
|
||||||
|
end
|
||||||
|
|
||||||
|
local function apply_undo(name)
|
||||||
|
local j = journal[name]
|
||||||
|
bare_apply_undo(j, name)
|
||||||
j.off_start = j.off_start-1
|
j.off_start = j.off_start-1
|
||||||
if j.mem_usage > max_memory_usage then
|
if j.mem_usage > max_memory_usage then
|
||||||
trim_undo_history(j)
|
trim_undo_history(j)
|
||||||
@ -145,13 +151,8 @@ end
|
|||||||
local function apply_redo(name)
|
local function apply_redo(name)
|
||||||
local j = journal[name]
|
local j = journal[name]
|
||||||
j.off_start = j.off_start+1
|
j.off_start = j.off_start+1
|
||||||
local i = (j.start + j.off_start) % max_commands
|
|
||||||
local data = j.ring[i]
|
|
||||||
local old_memuse = data.mem_use
|
|
||||||
-- undoing an undone undo function is redoing
|
-- undoing an undone undo function is redoing
|
||||||
undo_funcs[data.type](name, data)
|
bare_apply_undo(j, name)
|
||||||
j.mem_usage = j.mem_usage + data.mem_use - old_memuse
|
|
||||||
j.ring[i] = data
|
|
||||||
if j.mem_usage > max_memory_usage then
|
if j.mem_usage > max_memory_usage then
|
||||||
trim_undo_history(j)
|
trim_undo_history(j)
|
||||||
end
|
end
|
||||||
@ -223,7 +224,7 @@ minetest.register_chatcommand("/show_journal", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
----------------- The worldedit stuff ------------------------------------------
|
----------------- Harmless worldedit chatcommands ------------------------------
|
||||||
|
|
||||||
if remember_innocuous then
|
if remember_innocuous then
|
||||||
|
|
||||||
@ -231,7 +232,6 @@ if remember_innocuous then
|
|||||||
function()
|
function()
|
||||||
add_to_history{
|
add_to_history{
|
||||||
type = "marker",
|
type = "marker",
|
||||||
mem_use = 9 * 7,
|
|
||||||
id = 1,
|
id = 1,
|
||||||
pos = worldedit.pos1[command_invoker]
|
pos = worldedit.pos1[command_invoker]
|
||||||
}
|
}
|
||||||
@ -242,7 +242,6 @@ if remember_innocuous then
|
|||||||
function()
|
function()
|
||||||
add_to_history{
|
add_to_history{
|
||||||
type = "marker",
|
type = "marker",
|
||||||
mem_use = 9 * 7,
|
|
||||||
id = 2,
|
id = 2,
|
||||||
pos = worldedit.pos2[command_invoker]
|
pos = worldedit.pos2[command_invoker]
|
||||||
}
|
}
|
||||||
@ -257,14 +256,12 @@ if remember_innocuous then
|
|||||||
or typ == "pos1only" then
|
or typ == "pos1only" then
|
||||||
add_to_history({
|
add_to_history({
|
||||||
type = "marker",
|
type = "marker",
|
||||||
mem_use = 9 * 7,
|
|
||||||
id = 1,
|
id = 1,
|
||||||
pos = worldedit.pos1[name]
|
pos = worldedit.pos1[name]
|
||||||
}, name)
|
}, name)
|
||||||
elseif typ == "pos2" then
|
elseif typ == "pos2" then
|
||||||
add_to_history({
|
add_to_history({
|
||||||
type = "marker",
|
type = "marker",
|
||||||
mem_use = 9 * 7,
|
|
||||||
id = 2,
|
id = 2,
|
||||||
pos = worldedit.pos2[name]
|
pos = worldedit.pos2[name]
|
||||||
}, name)
|
}, name)
|
||||||
@ -296,6 +293,8 @@ if remember_innocuous then
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
----------------------- Functions common to other ones -------------------------
|
||||||
|
|
||||||
-- Catch confirmation requests (/y or /n follows)
|
-- Catch confirmation requests (/y or /n follows)
|
||||||
local y_pending = {}
|
local y_pending = {}
|
||||||
local we_notify = worldedit.player_notify
|
local we_notify = worldedit.player_notify
|
||||||
@ -449,6 +448,9 @@ local function decompress_nodedata(ccontent)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
----------------------- World changing commands --------------------------------
|
||||||
|
|
||||||
local we_set = worldedit.set
|
local we_set = worldedit.set
|
||||||
local function my_we_set(pos1, pos2, ...)
|
local function my_we_set(pos1, pos2, ...)
|
||||||
assert(command_invoker, "Player not known")
|
assert(command_invoker, "Player not known")
|
||||||
@ -494,7 +496,7 @@ local function my_we_set(pos1, pos2, ...)
|
|||||||
}
|
}
|
||||||
add_to_history({
|
add_to_history({
|
||||||
type = "nodeids",
|
type = "nodeids",
|
||||||
mem_use = 9 * (2 * 7) + #compressed_data,
|
mem_use = #compressed_data,
|
||||||
pos1 = pos1,
|
pos1 = pos1,
|
||||||
pos2 = pos2,
|
pos2 = pos2,
|
||||||
count = #nodeids,
|
count = #nodeids,
|
||||||
@ -754,7 +756,7 @@ local function my_we_deserialize(pos, ...)
|
|||||||
}
|
}
|
||||||
add_to_history({
|
add_to_history({
|
||||||
type = "nodes",
|
type = "nodes",
|
||||||
mem_use = 9 * (2 * 7) + #compressed_data,
|
mem_use = #compressed_data,
|
||||||
pos1 = minp,
|
pos1 = minp,
|
||||||
pos2 = maxp,
|
pos2 = maxp,
|
||||||
count_n = #nodeids,
|
count_n = #nodeids,
|
||||||
|
Loading…
Reference in New Issue
Block a user