@@ -99,6 +99,29 @@ function technic.remove_network(network_id)
99
99
technic .active_networks [network_id ] = nil
100
100
end
101
101
102
+ local function switch_index (pos , net )
103
+ for index , spos in ipairs (net .swpos ) do
104
+ if pos .x == spos .x and pos .y == spos .y and pos .z == spos .z then
105
+ return index
106
+ end
107
+ end
108
+ end
109
+
110
+ function technic .switch_insert (pos , net )
111
+ if not switch_index (pos , net ) then
112
+ table.insert (net .swpos , table .copy (pos ))
113
+ end
114
+ return # net .swpos
115
+ end
116
+
117
+ function technic .switch_remove (pos , net )
118
+ local swindex = switch_index (pos , net )
119
+ if swindex then
120
+ table.remove (net .swpos , swindex )
121
+ end
122
+ return # net .swpos
123
+ end
124
+
102
125
function technic .sw_pos2network (pos )
103
126
return technic_cables [poshash ({x = pos .x ,y = pos .y - 1 ,z = pos .z })]
104
127
end
@@ -514,8 +537,8 @@ function technic.build_network(network_id)
514
537
network = {
515
538
-- Build queue
516
539
queue = {},
517
- -- Basic network data and lookup table for attached nodes (no switching stations)
518
- id = network_id , tier = tier , all_nodes = {},
540
+ -- Basic network data and lookup table for attached nodes
541
+ id = network_id , tier = tier , all_nodes = {}, swpos = {},
519
542
-- Indexed arrays for iteration by machine type
520
543
PR_nodes = {}, RE_nodes = {}, BA_nodes = {},
521
544
-- Power generation, usage and capacity related variables
@@ -580,9 +603,6 @@ local function run_nodes(list, vm, run_stage, network)
580
603
end
581
604
end
582
605
583
- local mesecons_path = minetest .get_modpath (" mesecons" )
584
- local digilines_path = minetest .get_modpath (" digilines" )
585
-
586
606
function technic .network_run (network_id )
587
607
--
588
608
-- !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!
@@ -592,19 +612,16 @@ function technic.network_run(network_id)
592
612
-- should be removed and/or refactored.
593
613
--
594
614
595
- local pos = technic .network2sw_pos (network_id )
596
615
local t0 = minetest .get_us_time ()
597
616
598
617
local PR_nodes
599
618
local BA_nodes
600
619
local RE_nodes
601
620
602
- local tier = technic .sw_pos2tier (pos )
603
- local network
604
- if tier then
605
- PR_nodes , BA_nodes , RE_nodes = get_network (network_id , tier )
621
+ local network = networks [network_id ]
622
+ if network then
623
+ PR_nodes , BA_nodes , RE_nodes = get_network (network_id , network .tier )
606
624
if not PR_nodes or technic .is_overloaded (network_id ) then return end
607
- network = networks [network_id ]
608
625
else
609
626
-- dprint("Not connected to a network")
610
627
technic .network_infotext (network_id , S (" @1 Has No Network" , S (" Switching Station" )))
@@ -625,9 +642,9 @@ function technic.network_run(network_id)
625
642
run_nodes (BA_nodes , vm , technic .battery , network )
626
643
627
644
-- Strings for the meta data
628
- local eu_demand_str = tier .. " _EU_demand"
629
- local eu_input_str = tier .. " _EU_input"
630
- local eu_supply_str = tier .. " _EU_supply"
645
+ local eu_demand_str = network . tier .. " _EU_demand"
646
+ local eu_input_str = network . tier .. " _EU_input"
647
+ local eu_supply_str = network . tier .. " _EU_supply"
631
648
632
649
-- Distribute charge equally across multiple batteries.
633
650
local charge_distributed = math.floor (network .BA_charge_active / network .BA_count_active )
@@ -658,20 +675,6 @@ function technic.network_run(network_id)
658
675
S (" Switching Station" ), technic .EU_string (PR_eu_supply ),
659
676
technic .EU_string (RE_eu_demand )))
660
677
661
- -- If mesecon signal and power supply or demand changed then
662
- -- send them via digilines.
663
- if mesecons_path and digilines_path and mesecon .is_powered (pos ) then
664
- if PR_eu_supply ~= network .supply or
665
- RE_eu_demand ~= network .demand then
666
- local meta = minetest .get_meta (pos )
667
- local channel = meta :get_string (" channel" )
668
- digilines .receptor_send (pos , technic .digilines .rules , channel , {
669
- supply = PR_eu_supply ,
670
- demand = RE_eu_demand
671
- })
672
- end
673
- end
674
-
675
678
-- Data that will be used by the power monitor
676
679
network .supply = PR_eu_supply
677
680
network .demand = RE_eu_demand
@@ -703,7 +706,8 @@ function technic.network_run(network_id)
703
706
local t1 = minetest .get_us_time ()
704
707
local diff = t1 - t0
705
708
if diff > 50000 then
706
- minetest .log (" warning" , " [technic] [+supply] technic_run took " .. diff .. " us at " .. minetest .pos_to_string (pos ))
709
+ minetest .log (" warning" , " [technic] [+supply] technic_run took " .. diff .. " us at "
710
+ .. minetest .pos_to_string (hashpos (network_id )))
707
711
end
708
712
709
713
return
@@ -733,7 +737,8 @@ function technic.network_run(network_id)
733
737
local t1 = minetest .get_us_time ()
734
738
local diff = t1 - t0
735
739
if diff > 50000 then
736
- minetest .log (" warning" , " [technic] [-supply] technic_run took " .. diff .. " us at " .. minetest .pos_to_string (pos ))
740
+ minetest .log (" warning" , " [technic] [-supply] technic_run took " .. diff .. " us at "
741
+ .. minetest .pos_to_string (hashpos (network_id )))
737
742
end
738
743
739
744
return
@@ -757,7 +762,8 @@ function technic.network_run(network_id)
757
762
local t1 = minetest .get_us_time ()
758
763
local diff = t1 - t0
759
764
if diff > 50000 then
760
- minetest .log (" warning" , " [technic] technic_run took " .. diff .. " us at " .. minetest .pos_to_string (pos ))
765
+ minetest .log (" warning" , " [technic] technic_run took " .. diff .. " us at "
766
+ .. minetest .pos_to_string (hashpos (network_id )))
761
767
end
762
768
763
769
end
0 commit comments