From 07aa682124e17f843f4917ed67266961378d1619 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 15:23:46 -0400 Subject: [PATCH 01/15] added caching to SE --- cybersyn/changelog.txt | 5 ++ cybersyn/info.lua | 2 +- cybersyn/scripts/factorio-api.lua | 130 +++++++++++++++++++++--------- cybersyn/scripts/global.lua | 6 ++ cybersyn/scripts/migrations.lua | 2 + 5 files changed, 107 insertions(+), 38 deletions(-) diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index 4f1170c..9ee597c 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 1.2.15 +Date: 2023-4-30 + Bugfixes: + - Fixed UPS spikes in Space Exploration related to expensive remote calls into their modding interface. +--------------------------------------------------------------------------------------------------- Version: 1.2.14 Date: 2023-4-30 Features: diff --git a/cybersyn/info.lua b/cybersyn/info.lua index 639a3a2..860f838 100644 --- a/cybersyn/info.lua +++ b/cybersyn/info.lua @@ -3,4 +3,4 @@ --- It is used in migrations.lua to determine if any migrations need to be run for beta testers. --- It is expected these are only meaningful between releases during beta testing. --- It should be set to nil for any release version. -return nil +return 1 diff --git a/cybersyn/scripts/factorio-api.lua b/cybersyn/scripts/factorio-api.lua index 1c060bc..7809154 100644 --- a/cybersyn/scripts/factorio-api.lua +++ b/cybersyn/scripts/factorio-api.lua @@ -33,19 +33,70 @@ function get_dist(entity0, entity1) end +---@param cache PerfCache ---@param surface LuaSurface -function se_get_space_elevator_name(surface) - --TODO: check how expensive the following is and potentially cache it's results - local entity = surface.find_entities_filtered({ - name = SE_ELEVATOR_STOP_PROTO_NAME, - type = "train-stop", - limit = 1, - })[1] - if entity and entity.valid then - return string.sub(entity.backer_name, 1, string.len(entity.backer_name) - SE_ELEVATOR_SUFFIX_LENGTH) +function se_get_space_elevator_name(cache, surface) + ---@type LuaEntity? + local entity = nil + ---@type string? + local name = nil + local cache_idx = 2*surface.index + if cache.se_get_space_elevator_name then + entity = cache.se_get_space_elevator_name[cache_idx - 1] + name = cache.se_get_space_elevator_name[cache_idx] + else + cache.se_get_space_elevator_name = {} end -end + if entity and entity.valid then + return name + else + --Chaching failed, default to expensive lookup + entity = surface.find_entities_filtered({ + name = SE_ELEVATOR_STOP_PROTO_NAME, + type = "train-stop", + limit = 1, + })[1] + + if entity then + name = string.sub(entity.backer_name, 1, string.len(entity.backer_name) - SE_ELEVATOR_SUFFIX_LENGTH) + cache.se_get_space_elevator_name[cache_idx - 1] = entity + cache.se_get_space_elevator_name[cache_idx] = name + return name + end + end + + return nil +end +---@param cache PerfCache +---@param surface_index uint +local function se_get_zone_from_surface_index(cache, surface_index) + ---@type uint? + local zone_index = nil + ---@type uint? + local zone_orbit_index = nil + local cache_idx = 2*surface_index + if cache.se_get_zone_from_surface_index then + zone_index = cache.se_get_zone_from_surface_index[cache_idx - 1]--[[@as uint]] + zone_orbit_index = cache.se_get_zone_from_surface_index[cache_idx]--[[@as uint]] + else + cache.se_get_zone_from_surface_index = {} + end + + if not zone_index then + zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = surface_index}) + + if type(zone.index) == "number" and type(zone.orbit_index) == "number" then + zone_index = zone.index--[[@as uint]] + zone_orbit_index = zone.orbit_index--[[@as uint]] + --NOTE: caching these indices could be a problem if SE is not deterministic in choosing them + cache.se_get_zone_from_surface_index[cache_idx - 1] = zone_index + cache.se_get_zone_from_surface_index[cache_idx] = zone_orbit_index + end + end + + return zone_index, zone_orbit_index +end ---@param train LuaTrain ---@return LuaEntity? @@ -249,12 +300,12 @@ function set_manifest_schedule(map_data, train, depot_stop, same_depot, p_stop, elseif IS_SE_PRESENT then local other_surface_i = (not is_p_on_t and p_surface_i) or (not is_r_on_t and r_surface_i) or d_surface_i if (is_p_on_t or p_surface_i == other_surface_i) and (is_r_on_t or r_surface_i == other_surface_i) and (is_d_on_t or d_surface_i == other_surface_i) then - local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})--[[@as {}]] - local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = other_surface_i})--[[@as {}]] - if t_zone and other_zone then - local is_train_in_orbit = other_zone.orbit_index == t_zone.index - if is_train_in_orbit or t_zone.orbit_index == other_zone.index then - local elevator_name = se_get_space_elevator_name(t_surface) + local t_zone_index, t_zone_orbit_index = se_get_zone_from_surface_index(map_data.perf_cache, t_surface_i) + local other_zone_index, other_zone_orbit_index = se_get_zone_from_surface_index(map_data.perf_cache, other_surface_i) + if t_zone_index and other_zone_index then + local is_train_in_orbit = other_zone_orbit_index == t_zone_index + if is_train_in_orbit or t_zone_orbit_index == other_zone_index then + local elevator_name = se_get_space_elevator_name(map_data.perf_cache, t_surface) if elevator_name then local records = {create_inactivity_order(depot_stop.backer_name)} if t_surface_i == p_surface_i then @@ -329,28 +380,32 @@ function add_refueler_schedule(map_data, train, stop) train.schedule = schedule return true elseif IS_SE_PRESENT then - local t_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = t_surface_i})--[[@as {}]] - local other_zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = f_surface_i})--[[@as {}]] - local is_train_in_orbit = other_zone.orbit_index == t_zone.index - if is_train_in_orbit or t_zone.orbit_index == other_zone.index then - local elevator_name = se_get_space_elevator_name(t_surface) - local cur_order = schedule.records[i] - local is_elevator_in_orders_already = cur_order and cur_order.station == elevator_name..(is_train_in_orbit and SE_ELEVATOR_ORBIT_SUFFIX or SE_ELEVATOR_PLANET_SUFFIX) - if not is_elevator_in_orders_already then - table_insert(schedule.records, i, se_create_elevator_order(elevator_name, is_train_in_orbit)) - end - i = i + 1 - is_train_in_orbit = not is_train_in_orbit - table_insert(schedule.records, i, create_inactivity_order(stop.backer_name)) - i = i + 1 - if not is_elevator_in_orders_already then - table_insert(schedule.records, i, se_create_elevator_order(elevator_name, is_train_in_orbit)) - i = i + 1 - is_train_in_orbit = not is_train_in_orbit - end + local t_zone_index, t_zone_orbit_index = se_get_zone_from_surface_index(map_data.perf_cache, t_surface_i) + local other_zone_index, other_zone_orbit_index = se_get_zone_from_surface_index(map_data.perf_cache, f_surface_i) + if t_zone_index and other_zone_index then + local is_train_in_orbit = other_zone_orbit_index == t_zone_index + if is_train_in_orbit or t_zone_orbit_index == other_zone_index then + local elevator_name = se_get_space_elevator_name(map_data.perf_cache, t_surface) + if elevator_name then + local cur_order = schedule.records[i] + local is_elevator_in_orders_already = cur_order and cur_order.station == elevator_name..(is_train_in_orbit and SE_ELEVATOR_ORBIT_SUFFIX or SE_ELEVATOR_PLANET_SUFFIX) + if not is_elevator_in_orders_already then + table_insert(schedule.records, i, se_create_elevator_order(elevator_name, is_train_in_orbit)) + end + i = i + 1 + is_train_in_orbit = not is_train_in_orbit + table_insert(schedule.records, i, create_inactivity_order(stop.backer_name)) + i = i + 1 + if not is_elevator_in_orders_already then + table_insert(schedule.records, i, se_create_elevator_order(elevator_name, is_train_in_orbit)) + i = i + 1 + is_train_in_orbit = not is_train_in_orbit + end - train.schedule = schedule - return true + train.schedule = schedule + return true + end + end end end --create an order that probably cannot be fulfilled and alert the player @@ -358,6 +413,7 @@ function add_refueler_schedule(map_data, train, stop) lock_train(train) train.schedule = schedule send_alert_cannot_path_between_surfaces(map_data, train) + return false end diff --git a/cybersyn/scripts/global.lua b/cybersyn/scripts/global.lua index 4e668bf..e50d3c9 100644 --- a/cybersyn/scripts/global.lua +++ b/cybersyn/scripts/global.lua @@ -24,6 +24,11 @@ ---@field public each_refuelers {[uint]: true} ---@field public active_alerts {[uint]: {[1]: LuaTrain, [2]: int}}? ---@field public manager Manager +---@field public perf_cache PerfCache -- This gets reset to an empty table on migration change + +---@class PerfCache +---@field public se_get_space_elevator_name {}? +---@field public se_get_zone_from_surface_index {}? ---@class Station ---@field public entity_stop LuaEntity @@ -161,6 +166,7 @@ function init_global() global.refuelers = {} global.to_refuelers = {} global.each_refuelers = {} + global.perf_cache = {} IS_SE_PRESENT = remote.interfaces["space-exploration"] ~= nil end diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index fe0786b..20506fe 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -326,6 +326,8 @@ local migrations_table = { function on_config_changed(data) global.tick_state = STATE_INIT global.tick_data = {} + global.perf_cache = {} + flib_migration.on_config_changed(data, migrations_table) for i, v in pairs(global.manager.players) do From 2d33b908dd717eac388bed834c5d7d6b3ccc0db2 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 15:39:32 -0400 Subject: [PATCH 02/15] bugfixed SE --- cybersyn/locale/en/base.cfg | 4 +++- cybersyn/scripts/factorio-api.lua | 11 ++++++----- cybersyn/scripts/gui/main.lua | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 42d7217..247a08c 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -12,7 +12,7 @@ cybersyn-warmup-time=Station warmup time (sec) cybersyn-stuck-train-time=Stuck train timeout (sec) cybersyn-allow-cargo-in-depot=Allow cargo in depots cybersyn-invert-sign=Invert combinator output (deprecated) -cybersyn-manager-enabled=Enable the Cybersyn GUI. +cybersyn-manager-enabled=Preview the Indev Cybersyn Manager. cybersyn-manager-update-rate=Manager refresh tick interval cybersyn-manager-result-limit=Max entities displayed on GUI pages. @@ -30,6 +30,8 @@ cybersyn-warmup-time=How many seconds a cybernetic combinator will wait before c cybersyn-stuck-train-time=After this many seconds from a train's dispatch, an alert will be sent to let you know a train is probably stuck and has not completed its delivery. The player will likely have to debug their network to get the train unstuck. cybersyn-allow-cargo-in-depot=If checked, trains will be allowed to have cargo in depots; no alerts will be generated and the train will not be held. In addition, trains with orders to visit requester stations with "Inactivity condition" checked will wait for inactivity instead of waiting for empty cargo. Useful for creating train systems where depots handle excess cargo. For advanced users only. cybersyn-invert-sign=Flip the sign of the output of cybernetic combinators to be the same as it is in LTN or in earlier versions of Project Cybersyn. +cybersyn-manager-enabled=Allows viewing of all trains and stations connected to the Cybersyn network. This GUI is currently in development and is likely to have many crash. +cybersyn-manager-update-rate=Controls how frequently the Cybersyn manager gui refreshes. The Cybersyn manager must be set to active for this setting to have an effect. cybersyn-manager-result-limit=Caps the number of matching enitities (e.g. stations, trains) to limit the amount of update time consumed when the list is refreshed.\n-1 means return all results. [item-name] diff --git a/cybersyn/scripts/factorio-api.lua b/cybersyn/scripts/factorio-api.lua index 7809154..b053e19 100644 --- a/cybersyn/scripts/factorio-api.lua +++ b/cybersyn/scripts/factorio-api.lua @@ -63,10 +63,10 @@ function se_get_space_elevator_name(cache, surface) cache.se_get_space_elevator_name[cache_idx - 1] = entity cache.se_get_space_elevator_name[cache_idx] = name return name + else + return nil end end - - return nil end ---@param cache PerfCache ---@param surface_index uint @@ -78,7 +78,8 @@ local function se_get_zone_from_surface_index(cache, surface_index) local cache_idx = 2*surface_index if cache.se_get_zone_from_surface_index then zone_index = cache.se_get_zone_from_surface_index[cache_idx - 1]--[[@as uint]] - zone_orbit_index = cache.se_get_zone_from_surface_index[cache_idx]--[[@as uint]] + --zones may not have an orbit_index + zone_orbit_index = cache.se_get_zone_from_surface_index[cache_idx]--[[@as uint?]] else cache.se_get_zone_from_surface_index = {} end @@ -86,9 +87,9 @@ local function se_get_zone_from_surface_index(cache, surface_index) if not zone_index then zone = remote.call("space-exploration", "get_zone_from_surface_index", {surface_index = surface_index}) - if type(zone.index) == "number" and type(zone.orbit_index) == "number" then + if zone and type(zone.index) == "number" then zone_index = zone.index--[[@as uint]] - zone_orbit_index = zone.orbit_index--[[@as uint]] + zone_orbit_index = zone.orbit_index--[[@as uint?]] --NOTE: caching these indices could be a problem if SE is not deterministic in choosing them cache.se_get_zone_from_surface_index[cache_idx - 1] = zone_index cache.se_get_zone_from_surface_index[cache_idx] = zone_orbit_index diff --git a/cybersyn/scripts/gui/main.lua b/cybersyn/scripts/gui/main.lua index ae7d033..78ffa0b 100644 --- a/cybersyn/scripts/gui/main.lua +++ b/cybersyn/scripts/gui/main.lua @@ -47,7 +47,7 @@ end local manager_gui = {} function manager_gui.on_lua_shortcut(e) - if e.prototype_name == "cybersyn-toggle-gui" or e.input_name == "cybersyn-toggle-gui" or e.element.name == "manager_window" then + if e.prototype_name == "cybersyn-toggle-gui" or e.input_name == "cybersyn-toggle-gui" or (e.element and e.element.name == "manager_window") then manager.wrapper(e, manager.handle.manager_toggle) end end From 230fe3a7328832ac85d8744f75be0cb0983ede1d Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 15:43:42 -0400 Subject: [PATCH 03/15] removed unused migration --- cybersyn/scripts/migrations.lua | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index 20506fe..94488ac 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -351,25 +351,4 @@ end ---NOTE 2: Everything in this section must be idempotent function on_debug_revision_change() local map_data = global - - if debug_revision == 1 then - for _, e in pairs(map_data.refuelers) do - if e.network_flag ~= nil then - e.network_mask = e.network_flag - e.network_flag = nil - end - end - for _, e in pairs(map_data.stations) do - if e.network_flag ~= nil then - e.network_mask = e.network_flag - e.network_flag = nil - end - end - for _, e in pairs(map_data.trains) do - if e.network_flag ~= nil then - e.network_mask = e.network_flag - e.network_flag = nil - end - end - end end From 03ba4aca49eadb2d07dbad160e0e94982cd7d150 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 15:54:51 -0400 Subject: [PATCH 04/15] fixed broken translation key --- cybersyn/locale/de/base.cfg | 2 +- cybersyn/locale/en/base.cfg | 4 ++-- cybersyn/locale/es/base.cfg | 2 +- cybersyn/locale/ru/base.cfg | 2 +- cybersyn/locale/zh-CN/base.cfg | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cybersyn/locale/de/base.cfg b/cybersyn/locale/de/base.cfg index e583157..715c861 100644 --- a/cybersyn/locale/de/base.cfg +++ b/cybersyn/locale/de/base.cfg @@ -13,7 +13,7 @@ cybersyn-stuck-train-time=Zeitüberschreitung bei festgefahrenem Zug in Sekunden cybersyn-allow-cargo-in-depot=Erlaube Züge mit Fracht in Depots cybersyn-invert-sign=Invertieren der Kombinatorausgabe (veraltet) #cybersyn-manager-enabled= -#cybersyn-manager-update-rate= +#cybersyn-manager-updates-per-second= #cybersyn-manager-result-limit= [mod-setting-description] diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 247a08c..997c640 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -13,7 +13,7 @@ cybersyn-stuck-train-time=Stuck train timeout (sec) cybersyn-allow-cargo-in-depot=Allow cargo in depots cybersyn-invert-sign=Invert combinator output (deprecated) cybersyn-manager-enabled=Preview the Indev Cybersyn Manager. -cybersyn-manager-update-rate=Manager refresh tick interval +cybersyn-manager-updates-per-second=Manager refresh tick interval cybersyn-manager-result-limit=Max entities displayed on GUI pages. [mod-setting-description] @@ -31,7 +31,7 @@ cybersyn-stuck-train-time=After this many seconds from a train's dispatch, an al cybersyn-allow-cargo-in-depot=If checked, trains will be allowed to have cargo in depots; no alerts will be generated and the train will not be held. In addition, trains with orders to visit requester stations with "Inactivity condition" checked will wait for inactivity instead of waiting for empty cargo. Useful for creating train systems where depots handle excess cargo. For advanced users only. cybersyn-invert-sign=Flip the sign of the output of cybernetic combinators to be the same as it is in LTN or in earlier versions of Project Cybersyn. cybersyn-manager-enabled=Allows viewing of all trains and stations connected to the Cybersyn network. This GUI is currently in development and is likely to have many crash. -cybersyn-manager-update-rate=Controls how frequently the Cybersyn manager gui refreshes. The Cybersyn manager must be set to active for this setting to have an effect. +cybersyn-manager-updates-per-second=Controls how frequently the Cybersyn manager gui refreshes. The Cybersyn manager must be set to active for this setting to have an effect. cybersyn-manager-result-limit=Caps the number of matching enitities (e.g. stations, trains) to limit the amount of update time consumed when the list is refreshed.\n-1 means return all results. [item-name] diff --git a/cybersyn/locale/es/base.cfg b/cybersyn/locale/es/base.cfg index 5bcb8b8..46b5c71 100644 --- a/cybersyn/locale/es/base.cfg +++ b/cybersyn/locale/es/base.cfg @@ -13,7 +13,7 @@ cybersyn-stuck-train-time=Tren atascado tiempo de espera (seg) cybersyn-allow-cargo-in-depot=Permitir carga en depositos cybersyn-invert-sign=Invertir salida del combinador (obsoleto) cybersyn-manager-enabled=Habilitar la GUI de Cybersyn. -cybersyn-manager-update-rate=Actualizar manager intervalo de tick +cybersyn-manager-updates-per-second=Actualizar manager intervalo de tick cybersyn-manager-result-limit=Máxima cantidad de entidades mostradas en las páginas GUI. [mod-setting-description] diff --git a/cybersyn/locale/ru/base.cfg b/cybersyn/locale/ru/base.cfg index 5b15be8..f44d4ca 100644 --- a/cybersyn/locale/ru/base.cfg +++ b/cybersyn/locale/ru/base.cfg @@ -13,7 +13,7 @@ cybersyn-stuck-train-time=Таймаут застревания поезда (с cybersyn-allow-cargo-in-depot=Разрешить поезда с грузом в депо cybersyn-invert-sign=Инвертировать вывод комбинатора (устаревший параметр) #cybersyn-manager-enabled= -#cybersyn-manager-update-rate= +#cybersyn-manager-updates-per-second= #cybersyn-manager-result-limit= [mod-setting-description] diff --git a/cybersyn/locale/zh-CN/base.cfg b/cybersyn/locale/zh-CN/base.cfg index bd78c0e..6ecc781 100644 --- a/cybersyn/locale/zh-CN/base.cfg +++ b/cybersyn/locale/zh-CN/base.cfg @@ -13,7 +13,7 @@ cybersyn-stuck-train-time=卡住火车超时(秒) cybersyn-allow-cargo-in-depot=允许仓库中的货物 cybersyn-invert-sign=反转组合器输出(已弃用) #cybersyn-manager-enabled= -#cybersyn-manager-update-rate= +#cybersyn-manager-updates-per-second= #cybersyn-manager-result-limit= [mod-setting-description] From 83fe0652620ad34ba58dcdce818740bfe785927c Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 15:55:43 -0400 Subject: [PATCH 05/15] updated changelog --- cybersyn/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index 9ee597c..b909d26 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -3,6 +3,7 @@ Version: 1.2.15 Date: 2023-4-30 Bugfixes: - Fixed UPS spikes in Space Exploration related to expensive remote calls into their modding interface. + - Fixed missing cybersyn manager translation key. --------------------------------------------------------------------------------------------------- Version: 1.2.14 Date: 2023-4-30 From ecea6f66f2407ffe1983b313c1c09e37c0a0ecc0 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 16:02:47 -0400 Subject: [PATCH 06/15] updated en locale --- cybersyn/locale/en/base.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 997c640..d7ec62c 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -12,9 +12,9 @@ cybersyn-warmup-time=Station warmup time (sec) cybersyn-stuck-train-time=Stuck train timeout (sec) cybersyn-allow-cargo-in-depot=Allow cargo in depots cybersyn-invert-sign=Invert combinator output (deprecated) -cybersyn-manager-enabled=Preview the Indev Cybersyn Manager. -cybersyn-manager-updates-per-second=Manager refresh tick interval -cybersyn-manager-result-limit=Max entities displayed on GUI pages. +cybersyn-manager-enabled=Preview the Indev Cybersyn Manager +cybersyn-manager-updates-per-second=Manager updates per second +cybersyn-manager-result-limit=Max entities displayed on GUI pages [mod-setting-description] cybersyn-enable-planner=Enable or disable the central planning algorithm. If disabled no new trains will be dispatched. @@ -30,7 +30,7 @@ cybersyn-warmup-time=How many seconds a cybernetic combinator will wait before c cybersyn-stuck-train-time=After this many seconds from a train's dispatch, an alert will be sent to let you know a train is probably stuck and has not completed its delivery. The player will likely have to debug their network to get the train unstuck. cybersyn-allow-cargo-in-depot=If checked, trains will be allowed to have cargo in depots; no alerts will be generated and the train will not be held. In addition, trains with orders to visit requester stations with "Inactivity condition" checked will wait for inactivity instead of waiting for empty cargo. Useful for creating train systems where depots handle excess cargo. For advanced users only. cybersyn-invert-sign=Flip the sign of the output of cybernetic combinators to be the same as it is in LTN or in earlier versions of Project Cybersyn. -cybersyn-manager-enabled=Allows viewing of all trains and stations connected to the Cybersyn network. This GUI is currently in development and is likely to have many crash. +cybersyn-manager-enabled=Allows viewing of all trains and stations connected to the Cybersyn network. This GUI is currently in development and is likely to have many crashes. cybersyn-manager-updates-per-second=Controls how frequently the Cybersyn manager gui refreshes. The Cybersyn manager must be set to active for this setting to have an effect. cybersyn-manager-result-limit=Caps the number of matching enitities (e.g. stations, trains) to limit the amount of update time consumed when the list is refreshed.\n-1 means return all results. From b7354024bc625a600bc0962ed572db4761633f0d Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 16:32:22 -0400 Subject: [PATCH 07/15] updated allow-list description --- cybersyn/locale/en/base.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index d7ec62c..687866f 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -87,7 +87,7 @@ switch-request-tooltip=Lock this station to only request items from the network. network=Network network-tooltip=A signal is used to identify which network this combinator is a member of. Trains will only be dispatched from depots to provider and requester stations if they are all identified with the same signal. allow-list-description=Automatic allow-list -allow-list-tooltip=When checked trains in the network are automatically added to the allow-list if every wagon of the train is able to be loaded or unloaded by this station. When unchecked the allow-list is not used and all trains are allowed to park here. +allow-list-tooltip=Normally when a delivery is requested, any train with a large enough cargo capacity may fulfill it. When this setting is checked trains must also be on this station's "allow-list". Trains are automatically added to the allow-list if each of its wagons are able to be loaded or unloaded by inserters or pumps along this station. is-stack-description=Stack thresholds is-stack-tooltip=When checked all request thresholds for this station are interpretted as a count of item stacks rather than a count of total items. Thresholds for fluids are unaffected. enable-inactive-description=Inactivity condition From 4908f8442220de6b3528d7df53426de3bea11e2a Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 16:32:47 -0400 Subject: [PATCH 08/15] fixed typo --- cybersyn/locale/en/base.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 687866f..dbba4ea 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -89,7 +89,7 @@ network-tooltip=A signal is used to identify which network this combinator is a allow-list-description=Automatic allow-list allow-list-tooltip=Normally when a delivery is requested, any train with a large enough cargo capacity may fulfill it. When this setting is checked trains must also be on this station's "allow-list". Trains are automatically added to the allow-list if each of its wagons are able to be loaded or unloaded by inserters or pumps along this station. is-stack-description=Stack thresholds -is-stack-tooltip=When checked all request thresholds for this station are interpretted as a count of item stacks rather than a count of total items. Thresholds for fluids are unaffected. +is-stack-tooltip=When checked all request thresholds for this station are interpreted as a count of item stacks rather than a count of total items. Thresholds for fluids are unaffected. enable-inactive-description=Inactivity condition enable-inactive-tooltip=When checked a train at a provider is required to wait for inactivity even if its order has been fulfilled. This is frequently useful for preventing inserters from getting items stuck in their hands. use-same-depot-description=Require same depot From 4470c15fd83814af2657d929d8e56f254d233924 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 18:05:57 -0400 Subject: [PATCH 09/15] fixed cache invalidation bug --- cybersyn/info.lua | 2 +- cybersyn/scripts/factorio-api.lua | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cybersyn/info.lua b/cybersyn/info.lua index 860f838..90cefac 100644 --- a/cybersyn/info.lua +++ b/cybersyn/info.lua @@ -3,4 +3,4 @@ --- It is used in migrations.lua to determine if any migrations need to be run for beta testers. --- It is expected these are only meaningful between releases during beta testing. --- It should be set to nil for any release version. -return 1 +return 2 diff --git a/cybersyn/scripts/factorio-api.lua b/cybersyn/scripts/factorio-api.lua index b053e19..a34109e 100644 --- a/cybersyn/scripts/factorio-api.lua +++ b/cybersyn/scripts/factorio-api.lua @@ -3,6 +3,8 @@ local get_distance = require("__flib__.position").distance local table_insert = table.insert local bit_extract = bit32.extract local bit_replace = bit32.replace +local string_sub = string.sub +local string_len = string.len local DEFINES_WORKING = defines.entity_status.working local DEFINES_LOW_POWER = defines.entity_status.low_power @@ -38,19 +40,14 @@ end function se_get_space_elevator_name(cache, surface) ---@type LuaEntity? local entity = nil - ---@type string? - local name = nil - local cache_idx = 2*surface.index + local cache_idx = surface.index if cache.se_get_space_elevator_name then - entity = cache.se_get_space_elevator_name[cache_idx - 1] - name = cache.se_get_space_elevator_name[cache_idx] + entity = cache.se_get_space_elevator_name[cache_idx] else cache.se_get_space_elevator_name = {} end - if entity and entity.valid then - return name - else + if not entity or not entity.valid then --Chaching failed, default to expensive lookup entity = surface.find_entities_filtered({ name = SE_ELEVATOR_STOP_PROTO_NAME, @@ -59,14 +56,15 @@ function se_get_space_elevator_name(cache, surface) })[1] if entity then - name = string.sub(entity.backer_name, 1, string.len(entity.backer_name) - SE_ELEVATOR_SUFFIX_LENGTH) - cache.se_get_space_elevator_name[cache_idx - 1] = entity - cache.se_get_space_elevator_name[cache_idx] = name - return name - else - return nil + cache.se_get_space_elevator_name[cache_idx] = entity end end + + if entity and entity.valid then + return string_sub(entity.backer_name, 1, string_len(entity.backer_name) - SE_ELEVATOR_SUFFIX_LENGTH) + else + return nil + end end ---@param cache PerfCache ---@param surface_index uint From e20ef82eb5d72be377213bec69f455edb973a2e8 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sun, 30 Apr 2023 21:00:50 -0400 Subject: [PATCH 10/15] added check for poisoned migrations --- cybersyn/scripts/migrations.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index 94488ac..90ed9df 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -297,7 +297,7 @@ local migrations_table = { end end, ["1.2.14"] = function() - ---@type MapData + ---@type MapData local map_data = global map_data.manager = { @@ -328,12 +328,21 @@ function on_config_changed(data) global.tick_data = {} global.perf_cache = {} - flib_migration.on_config_changed(data, migrations_table) - - for i, v in pairs(global.manager.players) do - manager_gui.reset_player(i, v) + if global.manager then + for i, v in pairs(global.manager.players) do + manager_gui.reset_player(i, v) + end + else + global.manager = { + players = {}, + } + for i, v in pairs(game.players) do + manager_gui.on_player_created({player_index = i}) + end end + flib_migration.on_config_changed(data, migrations_table) + IS_SE_PRESENT = remote.interfaces["space-exploration"] ~= nil if IS_SE_PRESENT and not global.se_tele_old_id then global.se_tele_old_id = {} From 59eb580eb562d36eeb1659fe3aa4831f99bf2f57 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Mon, 1 May 2023 06:26:20 -0400 Subject: [PATCH 11/15] moved migration logic into manager --- cybersyn/changelog.txt | 1 + cybersyn/info.lua | 2 +- cybersyn/scripts/gui/main.lua | 13 ++++++++++--- cybersyn/scripts/migrations.lua | 13 ------------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index b909d26..11e4a85 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -4,6 +4,7 @@ Date: 2023-4-30 Bugfixes: - Fixed UPS spikes in Space Exploration related to expensive remote calls into their modding interface. - Fixed missing cybersyn manager translation key. + - Added a fix for a crash related to using the beta branch of cybersyn --------------------------------------------------------------------------------------------------- Version: 1.2.14 Date: 2023-4-30 diff --git a/cybersyn/info.lua b/cybersyn/info.lua index 90cefac..639a3a2 100644 --- a/cybersyn/info.lua +++ b/cybersyn/info.lua @@ -3,4 +3,4 @@ --- It is used in migrations.lua to determine if any migrations need to be run for beta testers. --- It is expected these are only meaningful between releases during beta testing. --- It should be set to nil for any release version. -return 2 +return nil diff --git a/cybersyn/scripts/gui/main.lua b/cybersyn/scripts/gui/main.lua index 277810c..ac3df56 100644 --- a/cybersyn/scripts/gui/main.lua +++ b/cybersyn/scripts/gui/main.lua @@ -50,9 +50,9 @@ function manager_gui.on_lua_shortcut(e) if e.prototype_name == "cybersyn-toggle-gui" or e.input_name == "cybersyn-toggle-gui" or e.element then if e.element then if e.element.name == "manager_window" then - manager.wrapper(e, manager.handle.manager_toggle) + manager.wrapper(e, manager.handle.manager_toggle) end - else + else manager.wrapper(e, manager.handle.manager_toggle) end end @@ -147,7 +147,14 @@ end function manager_gui.on_migration() - init_items(global.manager) + if global.manager then + for i, v in pairs(global.manager.players) do + manager_gui.reset_player(i, v) + end + init_items(global.manager) + else + manager_gui.on_init() + end end function manager_gui.on_init() diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index 90ed9df..f004736 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -328,19 +328,6 @@ function on_config_changed(data) global.tick_data = {} global.perf_cache = {} - if global.manager then - for i, v in pairs(global.manager.players) do - manager_gui.reset_player(i, v) - end - else - global.manager = { - players = {}, - } - for i, v in pairs(game.players) do - manager_gui.on_player_created({player_index = i}) - end - end - flib_migration.on_config_changed(data, migrations_table) IS_SE_PRESENT = remote.interfaces["space-exploration"] ~= nil From f0d8c2e430c9e0d5e733c5fb23f82440643f4985 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Mon, 1 May 2023 06:35:42 -0400 Subject: [PATCH 12/15] added additional fixes to migrations --- cybersyn/scripts/gui/main.lua | 10 +++------- cybersyn/scripts/migrations.lua | 14 ++++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cybersyn/scripts/gui/main.lua b/cybersyn/scripts/gui/main.lua index ac3df56..7628c42 100644 --- a/cybersyn/scripts/gui/main.lua +++ b/cybersyn/scripts/gui/main.lua @@ -147,14 +147,10 @@ end function manager_gui.on_migration() - if global.manager then - for i, v in pairs(global.manager.players) do - manager_gui.reset_player(i, v) - end - init_items(global.manager) - else - manager_gui.on_init() + for i, v in pairs(global.manager.players) do + manager_gui.reset_player(i, v) end + init_items(global.manager) end function manager_gui.on_init() diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index f004736..ce39374 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -296,15 +296,17 @@ local migrations_table = { end end end, - ["1.2.14"] = function() + ["1.2.15"] = function() ---@type MapData local map_data = global - map_data.manager = { - players = {}, - } - for i, v in pairs(game.players) do - manager_gui.on_player_created({player_index = i}) + if not global.manager then + global.manager = { + players = {}, + } + for i, v in pairs(game.players) do + manager_gui.on_player_created({player_index = i}) + end end for _, e in pairs(map_data.refuelers) do From 7b57ffb276b85fed2d626d4f9eda01e305684adf Mon Sep 17 00:00:00 2001 From: mamoniot Date: Mon, 1 May 2023 06:38:15 -0400 Subject: [PATCH 13/15] improved migrations --- cybersyn/scripts/migrations.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index ce39374..51d406a 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -310,16 +310,22 @@ local migrations_table = { end for _, e in pairs(map_data.refuelers) do - e.network_mask = e.network_flag - e.network_flag = nil + if e.network_flag then + e.network_mask = e.network_flag + e.network_flag = nil + end end for _, e in pairs(map_data.stations) do - e.network_mask = e.network_flag - e.network_flag = nil + if e.network_flag then + e.network_mask = e.network_flag + e.network_flag = nil + end end for _, e in pairs(map_data.trains) do - e.network_mask = e.network_flag - e.network_flag = nil + if e.network_flag then + e.network_mask = e.network_flag + e.network_flag = nil + end end end, } From fc4dad06d920ce669573569b321a2300fe317210 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Mon, 1 May 2023 06:39:25 -0400 Subject: [PATCH 14/15] upped version number --- cybersyn/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cybersyn/info.json b/cybersyn/info.json index e1a036f..06ebe55 100644 --- a/cybersyn/info.json +++ b/cybersyn/info.json @@ -1,6 +1,6 @@ { "name": "cybersyn", - "version": "1.2.14", + "version": "1.2.15", "title": "Project Cybersyn", "author": "Mami", "factorio_version": "1.1", From 096163d0cb904e636fec10a19bf60c2d74c070ab Mon Sep 17 00:00:00 2001 From: mamoniot Date: Mon, 1 May 2023 06:43:43 -0400 Subject: [PATCH 15/15] added to changelog --- cybersyn/changelog.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index 11e4a85..6041ef7 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -3,8 +3,9 @@ Version: 1.2.15 Date: 2023-4-30 Bugfixes: - Fixed UPS spikes in Space Exploration related to expensive remote calls into their modding interface. - - Fixed missing cybersyn manager translation key. - Added a fix for a crash related to using the beta branch of cybersyn + - Fixed missing cybersyn manager translation key. + - Improved several tooltips --------------------------------------------------------------------------------------------------- Version: 1.2.14 Date: 2023-4-30