Re-implement settings system:

Settings can now be retrieved by mesecon.setting(<name>, <default>) and can be modified without
editing the source code by adding the setting to minetest.conf
For instance, you can add mesecon.blinky_plant_interval = 0.5 to minetest.conf in order to
increase the blinking speed.
Rewrite the blinky plant with nodetimers.
Fixes #161
This commit is contained in:
Jeija 2014-11-22 22:09:26 +01:00
parent 80d136125e
commit f977ac821a
9 changed files with 64 additions and 109 deletions

@ -57,9 +57,12 @@ local get_highest_priority = function (actions)
end end
local m_time = 0 local m_time = 0
local resumetime = mesecon.setting("resumetime", 4)
minetest.register_globalstep(function (dtime) minetest.register_globalstep(function (dtime)
m_time = m_time + dtime m_time = m_time + dtime
if (m_time < MESECONS_RESUMETIME) then return end -- don't even try if server has not been running for XY seconds -- don't even try if server has not been running for XY seconds; resumetime = time to wait
-- after starting the server before processing the ActionQueue, don't set this too low
if (m_time < resumetime) then return end
local actions = mesecon.tablecopy(mesecon.queue.actions) local actions = mesecon.tablecopy(mesecon.queue.actions)
local actions_now={} local actions_now={}

@ -61,7 +61,7 @@ mesecon.do_overheat = function(pos)
heat = heat + 1 heat = heat + 1
meta:set_int("heat", heat) meta:set_int("heat", heat)
if heat < OVERHEAT_MAX then if heat < mesecon.setting("overheat_max", 20) then
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0) mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
else else
return true return true

@ -1,14 +1,10 @@
-- SETTINGS -- SETTINGS
BLINKY_PLANT_INTERVAL = 3 function mesecon.setting(setting, default)
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires if type(default) == "bool" then
PRESSURE_PLATE_INTERVAL = 0.1 return minetest.setting_getbool("mesecon."..setting) or default
OBJECT_DETECTOR_RADIUS = 6 elseif type(default) == "string" then
PISTON_MAXIMUM_PUSH = 15 return minetest.setting_get("mesecon."..setting) or default
MOVESTONE_MAXIMUM_PUSH = 100 elseif type(default) == "number" then
MESECONS_RESUMETIME = 4 -- time to wait when starting the server before return tonumber(minetest.setting_get("mesecon."..setting) or default)
-- processing the ActionQueue, don't set this too low end
OVERHEAT_MAX = 20 -- maximum heat of any component that directly sends an output end
-- signal when the input changes (e.g. luacontroller, gates)
-- Unit: actions per second, checks are every 1 second
STACK_SIZE = 3000 -- Recursive functions will abort when this is reached. Therefore,
-- this is also limits the maximum circuit size.

@ -1,98 +1,51 @@
-- The BLINKY_PLANT -- The BLINKY_PLANT
minetest.register_node("mesecons_blinkyplant:blinky_plant", {
drawtype = "plantlike",
visual_scale = 1,
tiles = {"jeija_blinky_plant_off.png"},
inventory_image = "jeija_blinky_plant_off.png",
walkable = false,
groups = {dig_immediate=3, not_in_creative_inventory=1},
drop="mesecons_blinkyplant:blinky_plant_off 1",
description="Deactivated Blinky Plant",
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
},
mesecons = {receptor = {
state = mesecon.state.off
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
end
})
minetest.register_node("mesecons_blinkyplant:blinky_plant_off", { local toggle_timer = function (pos)
drawtype = "plantlike", local timer = minetest.get_node_timer(pos)
visual_scale = 1, if timer:is_started() then
tiles = {"jeija_blinky_plant_off.png"}, timer:stop()
inventory_image = "jeija_blinky_plant_off.png", else
paramtype = "light", timer:start(mesecon.setting("blinky_plant_interval", 3))
walkable = false, end
groups = {dig_immediate=3, mesecon=2}, end
description="Blinky Plant",
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
},
mesecons = {receptor = {
state = mesecon.state.off
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant"})
end
})
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", { local on_timer = function (pos)
drawtype = "plantlike", local node = minetest.get_node(pos)
visual_scale = 1, if(mesecon.flipstate(pos, node) == "on") then
tiles = {"jeija_blinky_plant_on.png"}, mesecon.receptor_on(pos)
inventory_image = "jeija_blinky_plant_off.png", else
paramtype = "light",
walkable = false,
groups = {dig_immediate=3, not_in_creative_inventory=1, mesecon=2},
drop="mesecons_blinkyplant:blinky_plant_off 1",
light_source = LIGHT_MAX-7,
description = "Blinky Plant",
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
},
mesecons = {receptor = {
state = mesecon.state.on
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name = "mesecons_blinkyplant:blinky_plant"})
mesecon.receptor_off(pos) mesecon.receptor_off(pos)
end end
toggle_timer(pos)
end
mesecon.register_node("mesecons_blinkyplant:blinky_plant", {
description="Blinky Plant",
drawtype = "plantlike",
inventory_image = "jeija_blinky_plant_off.png",
paramtype = "light",
walkable = false,
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
},
on_timer = on_timer,
on_rightclick = toggle_timer,
on_construct = toggle_timer
},{
tiles = {"jeija_blinky_plant_off.png"},
groups = {dig_immediate=3},
mesecons = {receptor = { state = mesecon.state.off }}
},{
tiles = {"jeija_blinky_plant_on.png"},
groups = {dig_immediate=3, not_in_creative_inventory=1},
mesecons = {receptor = { state = mesecon.state.on }}
}) })
minetest.register_craft({ minetest.register_craft({
output = "mesecons_blinkyplant:blinky_plant_off 1", output = "mesecons_blinkyplant:blinky_plant_off 1",
recipe = { recipe = { {"","group:mesecon_conductor_craftable",""},
{"","group:mesecon_conductor_craftable",""}, {"","group:mesecon_conductor_craftable",""},
{"","group:mesecon_conductor_craftable",""}, {"default:sapling","default:sapling","default:sapling"}}
{"default:sapling","default:sapling","default:sapling"},
}
}) })
minetest.register_abm({
nodenames = {
"mesecons_blinkyplant:blinky_plant_off",
"mesecons_blinkyplant:blinky_plant_on"
},
interval = BLINKY_PLANT_INTERVAL,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if node.name == "mesecons_blinkyplant:blinky_plant_off" then
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_on"})
mesecon.receptor_on(pos)
else
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
mesecon.receptor_off(pos)
end
nodeupdate(pos)
end,
})

@ -23,7 +23,7 @@ end
-- returns true if player was found, false if not -- returns true if player was found, false if not
local object_detector_scan = function (pos) local object_detector_scan = function (pos)
local objs = minetest.get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS) local objs = minetest.get_objects_inside_radius(pos, mesecon.setting("detector_radius", 6))
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil! local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
local scanname = minetest.get_meta(pos):get_string("scanname") local scanname = minetest.get_meta(pos):get_string("scanname")

@ -201,7 +201,8 @@ local create_environment = function(pos, mem, event)
tostring = tostring, tostring = tostring,
tonumber = tonumber, tonumber = tonumber,
heat = minetest.get_meta(pos):get_int("heat"), heat = minetest.get_meta(pos):get_int("heat"),
heat_max = OVERHEAT_MAX, -- overheat_max Unit: actions per second, checks are every 1 second
heat_max = mesecon.setting("overheat_max", 20),
string = { string = {
byte = string.byte, byte = string.byte,
char = string.char, char = string.char,

@ -91,13 +91,14 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
pos.x, pos.y, pos.z = math.floor(pos.x+0.5), math.floor(pos.y+0.5), math.floor(pos.z+0.5) pos.x, pos.y, pos.z = math.floor(pos.x+0.5), math.floor(pos.y+0.5), math.floor(pos.z+0.5)
local direction = mesecon.get_movestone_direction(pos) local direction = mesecon.get_movestone_direction(pos)
local maxpush = mesecon.setting("movestone_max_push", 50)
if not direction then -- no mesecon power if not direction then -- no mesecon power
--push only solid nodes --push only solid nodes
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
if name ~= "air" and name ~= "ignore" if name ~= "air" and name ~= "ignore"
and ((not minetest.registered_nodes[name]) and ((not minetest.registered_nodes[name])
or minetest.registered_nodes[name].liquidtype == "none") then or minetest.registered_nodes[name].liquidtype == "none") then
mesecon.mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH) mesecon.mvps_push(pos, self.lastdir, maxpush)
end end
minetest.add_node(pos, {name="mesecons_movestones:movestone"}) minetest.add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove() self.object:remove()
@ -105,7 +106,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
end end
local success, stack, oldstack = local success, stack, oldstack =
mesecon.mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH) mesecon.mvps_push(pos, direction, maxpush)
if not success then -- Too large stack/stopper in the way if not success then -- Too large stack/stopper in the way
minetest.add_node(pos, {name="mesecons_movestones:movestone"}) minetest.add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove() self.object:remove()

@ -79,7 +79,8 @@ local piston_on = function(pos, node)
local dir = piston_get_direction(pistonspec.dir, node) local dir = piston_get_direction(pistonspec.dir, node)
local np = mesecon.addPosRule(pos, dir) local np = mesecon.addPosRule(pos, dir)
local success, stack, oldstack = mesecon.mvps_push(np, dir, PISTON_MAXIMUM_PUSH) local maxpush = mesecon.setting("piston_max_push", 15)
local success, stack, oldstack = mesecon.mvps_push(np, dir, maxpush)
if success then if success then
minetest.add_node(pos, {param2 = node.param2, name = pistonspec.onname}) minetest.add_node(pos, {param2 = node.param2, name = pistonspec.onname})
minetest.add_node(np, {param2 = node.param2, name = pistonspec.pusher}) minetest.add_node(np, {param2 = node.param2, name = pistonspec.pusher})

@ -59,7 +59,7 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te
pressureplate_basename = basename, pressureplate_basename = basename,
on_timer = pp_on_timer, on_timer = pp_on_timer,
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) minetest.get_node_timer(pos):start(mesecon.setting("pplate_interval", 0.1))
end, end,
},{ },{
mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }}, mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }},