Add mcl_util.queue and use in mods
This commit is contained in:
parent
e632fcb632
commit
59b474df51
@ -1382,4 +1382,28 @@ function mcl_util.to_roman(number)
|
||||
return r
|
||||
end
|
||||
|
||||
function mcl_util.queue()
|
||||
return {
|
||||
front = 1,
|
||||
back = 1,
|
||||
queue = {},
|
||||
enqueue = function(self, value)
|
||||
self.queue[self.back] = value
|
||||
self.back = self.back + 1
|
||||
end,
|
||||
dequeue = function(self) local value = self.queue[self.front]
|
||||
if not value then
|
||||
return
|
||||
end
|
||||
self.queue[self.front] = nil
|
||||
self.front = self.front + 1
|
||||
return value
|
||||
end,
|
||||
size = function(self)
|
||||
return self.back - self.front
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/compat.lua")
|
||||
|
@ -73,29 +73,6 @@ minetest.register_on_mods_loaded(function()
|
||||
end
|
||||
end)
|
||||
|
||||
local function queue()
|
||||
return {
|
||||
front = 1,
|
||||
back = 1,
|
||||
queue = {},
|
||||
enqueue = function(self, value)
|
||||
self.queue[self.back] = value
|
||||
self.back = self.back + 1
|
||||
end,
|
||||
dequeue = function(self) local value = self.queue[self.front]
|
||||
if not value then
|
||||
return
|
||||
end
|
||||
self.queue[self.front] = nil
|
||||
self.front = self.front + 1
|
||||
return value
|
||||
end,
|
||||
size = function(self)
|
||||
return self.back - self.front
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
local directions = {
|
||||
{ rail = vector.new(1, 0, 0) },
|
||||
{ rail = vector.new(-1, 0, 0) },
|
||||
@ -135,8 +112,8 @@ local function propagate_golden_rail_power(pos, new_power, old_power, powered_on
|
||||
param2_data[ind] = power
|
||||
end
|
||||
|
||||
local clear_queue = queue()
|
||||
local fill_queue = queue()
|
||||
local clear_queue = mcl_util.queue()
|
||||
local fill_queue = mcl_util.queue()
|
||||
if old_power then
|
||||
clear_queue:enqueue({ pos = pos, power = old_power })
|
||||
end
|
||||
|
@ -1,26 +1,3 @@
|
||||
local function queue()
|
||||
return {
|
||||
front = 1,
|
||||
back = 1,
|
||||
queue = {},
|
||||
enqueue = function(self, value)
|
||||
self.queue[self.back] = value
|
||||
self.back = self.back + 1
|
||||
end,
|
||||
dequeue = function(self) local value = self.queue[self.front]
|
||||
if not value then
|
||||
return
|
||||
end
|
||||
self.queue[self.front] = nil
|
||||
self.front = self.front + 1
|
||||
return value
|
||||
end,
|
||||
size = function(self)
|
||||
return self.back - self.front
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- Logical wireflags by contentid
|
||||
local lwireflag_tab = {}
|
||||
|
||||
@ -271,8 +248,8 @@ end
|
||||
-- Update neighbouring wires and components at pos. Oldnode is the previous
|
||||
-- node at the position.
|
||||
function update_neighbours(pos, oldnode)
|
||||
local fill_queue = queue()
|
||||
local clear_queue = queue()
|
||||
local fill_queue = mcl_util.queue()
|
||||
local clear_queue = mcl_util.queue()
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
local oldndef = oldnode and minetest.registered_nodes[oldnode.name]
|
||||
@ -326,8 +303,8 @@ function update_neighbours(pos, oldnode)
|
||||
end
|
||||
|
||||
local function opaque_update_neighbours(pos, added)
|
||||
local fill_queue = queue()
|
||||
local clear_queue = queue()
|
||||
local fill_queue = mcl_util.queue()
|
||||
local clear_queue = mcl_util.queue()
|
||||
|
||||
local function update_wire(pos)
|
||||
local oldpower = minetest.get_node(pos).param2
|
||||
@ -356,8 +333,8 @@ local function opaque_update_neighbours(pos, added)
|
||||
end
|
||||
|
||||
local function update_wire(pos, oldnode)
|
||||
local fill_queue = queue()
|
||||
local clear_queue = queue()
|
||||
local fill_queue = mcl_util.queue()
|
||||
local clear_queue = mcl_util.queue()
|
||||
local node = minetest.get_node(pos)
|
||||
local power = get_node_power_2(pos)
|
||||
|
||||
|
@ -135,29 +135,6 @@ local function orient(pos, param2)
|
||||
return pos
|
||||
end
|
||||
|
||||
local function queue()
|
||||
return {
|
||||
front = 1,
|
||||
back = 1,
|
||||
queue = {},
|
||||
enqueue = function(self, value)
|
||||
self.queue[self.back] = value
|
||||
self.back = self.back + 1
|
||||
end,
|
||||
dequeue = function(self) local value = self.queue[self.front]
|
||||
if not value then
|
||||
return
|
||||
end
|
||||
self.queue[self.front] = nil
|
||||
self.front = self.front + 1
|
||||
return value
|
||||
end,
|
||||
size = function(self)
|
||||
return self.back - self.front
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- Check if node is replacable with a portal node.
|
||||
local function replacable_with_portal(name)
|
||||
return name == "air" or
|
||||
@ -199,7 +176,7 @@ local function light_nether_portal(pos, param2)
|
||||
end
|
||||
|
||||
local nodes = {}
|
||||
local queue = queue()
|
||||
local queue = mcl_util.queue()
|
||||
local checked = {}
|
||||
|
||||
queue:enqueue(pos)
|
||||
|
@ -9,29 +9,6 @@ local wood_groups = {
|
||||
|
||||
local wood_sounds = mcl_sounds.node_sound_wood_defaults()
|
||||
|
||||
local function queue()
|
||||
return {
|
||||
front = 1,
|
||||
back = 1,
|
||||
queue = {},
|
||||
enqueue = function(self, value)
|
||||
self.queue[self.back] = value
|
||||
self.back = self.back + 1
|
||||
end,
|
||||
dequeue = function(self) local value = self.queue[self.front]
|
||||
if not value then
|
||||
return
|
||||
end
|
||||
self.queue[self.front] = nil
|
||||
self.front = self.front + 1
|
||||
return value
|
||||
end,
|
||||
size = function(self)
|
||||
return self.back - self.front
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- Make leaves which do not have a log within 6 nodes orphan.
|
||||
local function update_far_away_leaves(pos)
|
||||
local logs = minetest.find_nodes_in_area(pos:subtract(12), pos:add(12), "group:tree")
|
||||
@ -116,8 +93,8 @@ local function update_leaves(pos, old_distance)
|
||||
param2_data[ind] = (distance + 1) * 32 + param2_data[ind] % 32
|
||||
end
|
||||
|
||||
local clear_queue = queue()
|
||||
local fill_queue = queue()
|
||||
local clear_queue = mcl_util.queue()
|
||||
local fill_queue = mcl_util.queue()
|
||||
if old_distance then
|
||||
clear_queue:enqueue({ pos = pos, distance = old_distance })
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user