aboutsummaryrefslogtreecommitdiff
path: root/overrides.lua
blob: b50b6e56e74fa9145d9541458ead67719c674267 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

-- execute()
local old_execute = mesecon.queue.execute
mesecon.queue.execute = function(self, action)
	if mesecons_debug.enabled then
		local t0 = minetest.get_us_time()
		old_execute(self, action)
		local t1 = minetest.get_us_time()
		local micros = t1 - t0

		local ctx = mesecons_debug.get_context(action.pos)
		ctx.micros = ctx.micros + micros
		ctx.mtime = t0

		--print("execute() func=" .. action.func .. " pos=" .. minetest.pos_to_string(action.pos) .. " micros=" .. micros)
	end
end


-- add_action()
local old_add_action = mesecon.queue.add_action
mesecon.queue.add_action = function(self, pos, func, params, time, overwritecheck, priority)
	if mesecons_debug.enabled then
		local ctx = mesecons_debug.get_context(pos)

		time = time or 0
		time = time + ctx.penalty
		if time > mesecons_debug.penalty_mapblock_disabled then
			-- penalty exceeded disable-threshold, don't even add the action
			return
		end

		old_add_action(self, pos, func, params, time, overwritecheck, priority)
		--print("add_action() pos=" .. minetest.pos_to_string(pos))
	end
end