v0.09, bug fixes and improvements
parent
69c9f04b4a
commit
5e1ce2055c
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
A library to build and manage networks based on tubelib2 tubes, pipes, or cables.
|
A library to build and manage networks based on tubelib2 tubes, pipes, or cables.
|
||||||
|
|
||||||
**This library is heavily under development. API changes and crashes are likely!**
|
|
||||||
|
|
||||||
![networks](https://github.com/joe7575/networks/blob/main/screenshot.png)
|
![networks](https://github.com/joe7575/networks/blob/main/screenshot.png)
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,5 +114,7 @@ Required: tubelib2
|
||||||
- Add 'control' API
|
- Add 'control' API
|
||||||
|
|
||||||
**2021-07-06 V0.08**
|
**2021-07-06 V0.08**
|
||||||
|
- Add 'transfer' functions to the 'power' API
|
||||||
|
|
||||||
- Add 'transfer' functions to the 'power' API
|
**2021-07-23 V0.09**
|
||||||
|
- bug fixes and improvements
|
||||||
|
|
|
@ -23,11 +23,9 @@ networks.control = {}
|
||||||
|
|
||||||
-- return list of nodes {pos = ..., indir = ...} of given node_type
|
-- return list of nodes {pos = ..., indir = ...} of given node_type
|
||||||
local function get_network_table(pos, tlib2, outdir, node_type)
|
local function get_network_table(pos, tlib2, outdir, node_type)
|
||||||
if networks.determine_netID(pos, tlib2, outdir) then
|
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||||
local netw = networks.get_network_table(pos, tlib2, outdir)
|
if netw then
|
||||||
if netw then
|
return netw[node_type] or {}
|
||||||
return netw[node_type] or {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
8
init.lua
8
init.lua
|
@ -13,7 +13,7 @@
|
||||||
networks = {}
|
networks = {}
|
||||||
|
|
||||||
-- Version for compatibility checks, see readme.md/history
|
-- Version for compatibility checks, see readme.md/history
|
||||||
networks.version = 0.08
|
networks.version = 0.09
|
||||||
|
|
||||||
if not minetest.global_exists("tubelib2") or tubelib2.version < 2.1 then
|
if not minetest.global_exists("tubelib2") or tubelib2.version < 2.1 then
|
||||||
minetest.log("error", "[networks] Networks requires tubelib2 version 2.1 or newer!")
|
minetest.log("error", "[networks] Networks requires tubelib2 version 2.1 or newer!")
|
||||||
|
@ -32,6 +32,6 @@ dofile(MP .. "/control.lua")
|
||||||
|
|
||||||
-- Only for testing/demo purposes
|
-- Only for testing/demo purposes
|
||||||
--dofile(MP .. "/test/test_liquid.lua")
|
--dofile(MP .. "/test/test_liquid.lua")
|
||||||
local Cable = dofile(MP .. "/test/test_power.lua")
|
--local Cable = dofile(MP .. "/test/test_power.lua")
|
||||||
assert(loadfile(MP .. "/test/test_control.lua"))(Cable)
|
--assert(loadfile(MP .. "/test/test_control.lua"))(Cable)
|
||||||
dofile(MP .. "/test/test_tool.lua")
|
--dofile(MP .. "/test/test_tool.lua")
|
||||||
|
|
|
@ -24,11 +24,9 @@ networks.registered_networks.liquid = {}
|
||||||
|
|
||||||
-- return list of nodes {pos = ..., indir = ...} of given node_type
|
-- return list of nodes {pos = ..., indir = ...} of given node_type
|
||||||
local function get_network_table(pos, tlib2, outdir, node_type)
|
local function get_network_table(pos, tlib2, outdir, node_type)
|
||||||
if networks.determine_netID(pos, tlib2, outdir) then
|
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||||
local netw = networks.get_network_table(pos, tlib2, outdir)
|
if netw then
|
||||||
if netw then
|
return netw[node_type] or {}
|
||||||
return netw[node_type] or {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
23
networks.lua
23
networks.lua
|
@ -274,7 +274,7 @@ local function collect_network_nodes(pos, tlib2, outdir)
|
||||||
netw.ttl = minetest.get_gametime() + TTL
|
netw.ttl = minetest.get_gametime() + TTL
|
||||||
netw.num_nodes = NumNodes
|
netw.num_nodes = NumNodes
|
||||||
t = minetest.get_us_time() - t
|
t = minetest.get_us_time() - t
|
||||||
print("collect_network_nodes in " .. t .. " us", NumNodes, P2S(pos), N(pos).name)
|
--print("collect_network_nodes in " .. t .. " us", NumNodes, P2S(pos), N(pos).name)
|
||||||
return netw
|
return netw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -471,11 +471,9 @@ end
|
||||||
function networks.determine_netID(pos, tlib2, outdir)
|
function networks.determine_netID(pos, tlib2, outdir)
|
||||||
assert(outdir)
|
assert(outdir)
|
||||||
local netID = get_netID(pos, outdir)
|
local netID = get_netID(pos, outdir)
|
||||||
if netID then
|
if netID and Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then
|
||||||
if netID > 0 then -- real netID
|
return netID
|
||||||
get_network(tlib2.tube_type, netID)
|
elseif netID == 0 then
|
||||||
return netID
|
|
||||||
end
|
|
||||||
return -- no network available
|
return -- no network available
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -485,20 +483,15 @@ function networks.determine_netID(pos, tlib2, outdir)
|
||||||
store_netID(tlib2, netw, netID)
|
store_netID(tlib2, netw, netID)
|
||||||
return netID
|
return netID
|
||||||
end
|
end
|
||||||
|
-- mark as "no network"
|
||||||
set_netID(pos, outdir, 0)
|
set_netID(pos, outdir, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Provide network with all node tables
|
-- Provide network with all node tables
|
||||||
function networks.get_network_table(pos, tlib2, outdir, force)
|
function networks.get_network_table(pos, tlib2, outdir)
|
||||||
assert(outdir)
|
assert(outdir)
|
||||||
local netID = get_netID(pos, outdir)
|
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||||
if netID then
|
if netID and netID > 0 then
|
||||||
return get_network(tlib2.tube_type, netID)
|
return get_network(tlib2.tube_type, netID)
|
||||||
end
|
end
|
||||||
if force then -- force the network load
|
|
||||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
|
||||||
if netID then
|
|
||||||
return get_network(tlib2.tube_type, netID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,6 +56,12 @@ local function print_power_network_data(pos, api, netw, netw_type)
|
||||||
local tlib2 = networks.registered_networks[api][netw_type]
|
local tlib2 = networks.registered_networks[api][netw_type]
|
||||||
local outdir = netw[netw_type].ntype == "junc" and 0 or nil
|
local outdir = netw[netw_type].ntype == "junc" and 0 or nil
|
||||||
local data = power.get_network_data(pos, tlib2, outdir)
|
local data = power.get_network_data(pos, tlib2, outdir)
|
||||||
|
if netw then
|
||||||
|
print("- Number of network nodes: " .. (netw.num_nodes or 0))
|
||||||
|
print("- Number of generators: " .. #(netw.gen or {}))
|
||||||
|
print("- Number of consumers: " .. #(netw.con or {}))
|
||||||
|
print("- Number of storage systems: " .. #(netw.sto or {}))
|
||||||
|
end
|
||||||
if data then
|
if data then
|
||||||
local s = string.format("- Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
local s = string.format("- Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
||||||
data.netw_num, round(data.provided),
|
data.netw_num, round(data.provided),
|
||||||
|
|
Loading…
Reference in New Issue