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.
|
||||
|
||||
**This library is heavily under development. API changes and crashes are likely!**
|
||||
|
||||
![networks](https://github.com/joe7575/networks/blob/main/screenshot.png)
|
||||
|
||||
|
||||
|
@ -116,5 +114,7 @@ Required: tubelib2
|
|||
- Add 'control' API
|
||||
|
||||
**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
|
||||
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)
|
||||
if netw then
|
||||
return netw[node_type] or {}
|
||||
end
|
||||
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||
if netw then
|
||||
return netw[node_type] or {}
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
|
8
init.lua
8
init.lua
|
@ -13,7 +13,7 @@
|
|||
networks = {}
|
||||
|
||||
-- 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
|
||||
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
|
||||
--dofile(MP .. "/test/test_liquid.lua")
|
||||
local Cable = dofile(MP .. "/test/test_power.lua")
|
||||
assert(loadfile(MP .. "/test/test_control.lua"))(Cable)
|
||||
dofile(MP .. "/test/test_tool.lua")
|
||||
--local Cable = dofile(MP .. "/test/test_power.lua")
|
||||
--assert(loadfile(MP .. "/test/test_control.lua"))(Cable)
|
||||
--dofile(MP .. "/test/test_tool.lua")
|
||||
|
|
|
@ -24,11 +24,9 @@ networks.registered_networks.liquid = {}
|
|||
|
||||
-- return list of nodes {pos = ..., indir = ...} of given 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)
|
||||
if netw then
|
||||
return netw[node_type] or {}
|
||||
end
|
||||
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||
if netw then
|
||||
return netw[node_type] or {}
|
||||
end
|
||||
return {}
|
||||
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.num_nodes = NumNodes
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -471,11 +471,9 @@ end
|
|||
function networks.determine_netID(pos, tlib2, outdir)
|
||||
assert(outdir)
|
||||
local netID = get_netID(pos, outdir)
|
||||
if netID then
|
||||
if netID > 0 then -- real netID
|
||||
get_network(tlib2.tube_type, netID)
|
||||
return netID
|
||||
end
|
||||
if netID and Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then
|
||||
return netID
|
||||
elseif netID == 0 then
|
||||
return -- no network available
|
||||
end
|
||||
|
||||
|
@ -485,20 +483,15 @@ function networks.determine_netID(pos, tlib2, outdir)
|
|||
store_netID(tlib2, netw, netID)
|
||||
return netID
|
||||
end
|
||||
-- mark as "no network"
|
||||
set_netID(pos, outdir, 0)
|
||||
end
|
||||
|
||||
-- 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)
|
||||
local netID = get_netID(pos, outdir)
|
||||
if netID then
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID and netID > 0 then
|
||||
return get_network(tlib2.tube_type, netID)
|
||||
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
|
||||
|
|
|
@ -56,6 +56,12 @@ local function print_power_network_data(pos, api, netw, netw_type)
|
|||
local tlib2 = networks.registered_networks[api][netw_type]
|
||||
local outdir = netw[netw_type].ntype == "junc" and 0 or nil
|
||||
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
|
||||
local s = string.format("- Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
||||
data.netw_num, round(data.provided),
|
||||
|
|
Loading…
Reference in New Issue