aboutsummaryrefslogtreecommitdiff
path: root/assets/interlocking.html.LyXconv/interlocking.pdf
Commit message (Collapse)AuthorAge
* Update interlocking manualorwell962019-01-15
|
* Update manual againorwell962018-10-15
ef='#n72'>72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
-- Minetest: builtin/misc.lua

--
-- Misc. API functions
--

local timers = {}
local mintime
local function update_timers(delay)
	mintime = false
	local sub = 0
	for index = 1, #timers do
		index = index - sub
		local timer = timers[index]
		timer.time = timer.time - delay
		if timer.time <= 0 then
			core.set_last_run_mod(timer.mod_origin)
			timer.func(unpack(timer.args or {}))
			table.remove(timers, index)
			sub = sub + 1
		elseif mintime then
			mintime = math.min(mintime, timer.time)
		else
			mintime = timer.time
		end
	end
end

local timers_to_add
local function add_timers()
	for _, timer in ipairs(timers_to_add) do
		table.insert(timers, timer)
	end
	timers_to_add = false
end

local delay = 0
core.register_globalstep(function(dtime)
	if not mintime then
		-- abort if no timers are running
		return
	end
	if timers_to_add then
		add_timers()
	end
	delay = delay + dtime
	if delay < mintime then
		return
	end
	update_timers(delay)
	delay = 0
end)

function core.after(time, func, ...)
	assert(tonumber(time) and type(func) == "function",
			"Invalid core.after invocation")
	if not mintime then
		mintime = time
		timers_to_add = {{
			time   = time+delay,
			func   = func,
			args   = {...},
			mod_origin = core.get_last_run_mod(),
		}}
		return
	end
	mintime = math.min(mintime, time)
	timers_to_add = timers_to_add or {}
	timers_to_add[#timers_to_add+1] = {
		time   = time+delay,
		func   = func,
		args   = {...},
		mod_origin = core.get_last_run_mod(),
	}
end

function core.check_player_privs(player_or_name, ...)
	local name = player_or_name