mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-13 12:12:41 -06:00
fixed duplicate registry bug
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 1.3.0
|
||||||
|
Date: 2022-1-7
|
||||||
|
Bugfixes:
|
||||||
|
- Fixed a bug where it was possible for a single station to be updated twice per dispatch cycle, which could cause a crash
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 1.2.9
|
Version: 1.2.9
|
||||||
Date: 2022-1-7
|
Date: 2022-1-7
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cybersyn",
|
"name": "cybersyn",
|
||||||
"version": "1.2.9",
|
"version": "1.3.0",
|
||||||
"title": "Project Cybersyn",
|
"title": "Project Cybersyn",
|
||||||
"author": "Mami",
|
"author": "Mami",
|
||||||
"factorio_version": "1.1",
|
"factorio_version": "1.1",
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ local function tick_poll_station(map_data, mod_settings)
|
|||||||
end
|
end
|
||||||
station_id = map_data.active_station_ids[tick_data.i]
|
station_id = map_data.active_station_ids[tick_data.i]
|
||||||
station = map_data.stations[station_id]
|
station = map_data.stations[station_id]
|
||||||
if station then
|
if station and not station.is_warming_up then
|
||||||
if station.network_name then
|
if station.network_name then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -725,12 +725,19 @@ function tick_init(map_data, mod_settings)
|
|||||||
map_data.economy.all_r_stations = {}
|
map_data.economy.all_r_stations = {}
|
||||||
map_data.economy.all_names = {}
|
map_data.economy.all_names = {}
|
||||||
|
|
||||||
for i, id in pairs(map_data.warmup_station_ids) do
|
local i = 1
|
||||||
|
while i <= #map_data.warmup_station_ids do
|
||||||
|
local id = map_data.warmup_station_ids[i]
|
||||||
local station = map_data.stations[id]
|
local station = map_data.stations[id]
|
||||||
if station then
|
if station then
|
||||||
|
local cycles = map_data.warmup_station_cycles[id]
|
||||||
|
--force a station to wait at least 1 cycle so we can be sure active_station_ids was flushed of duplicates
|
||||||
|
if cycles > 0 then
|
||||||
if station.last_delivery_tick + mod_settings.warmup_time*mod_settings.tps < map_data.total_ticks then
|
if station.last_delivery_tick + mod_settings.warmup_time*mod_settings.tps < map_data.total_ticks then
|
||||||
|
station.is_warming_up = nil
|
||||||
map_data.active_station_ids[#map_data.active_station_ids + 1] = id
|
map_data.active_station_ids[#map_data.active_station_ids + 1] = id
|
||||||
map_data.warmup_station_ids[i] = nil
|
map_data.warmup_station_ids[i] = nil
|
||||||
|
map_data.warmup_station_cycles[id] = nil
|
||||||
if station.entity_comb1.valid then
|
if station.entity_comb1.valid then
|
||||||
combinator_update(map_data, station.entity_comb1)
|
combinator_update(map_data, station.entity_comb1)
|
||||||
else
|
else
|
||||||
@@ -738,9 +745,15 @@ function tick_init(map_data, mod_settings)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
map_data.warmup_station_ids[i] = nil
|
map_data.warmup_station_cycles[id] = cycles + 1
|
||||||
|
end
|
||||||
|
i = i + 1
|
||||||
|
else
|
||||||
|
table_remove(map_data.warmup_station_ids, i)
|
||||||
|
map_data.warmup_station_cycles[id] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if map_data.queue_station_update then
|
if map_data.queue_station_update then
|
||||||
for id, _ in pairs(map_data.queue_station_update) do
|
for id, _ in pairs(map_data.queue_station_update) do
|
||||||
local station = map_data.stations[id]
|
local station = map_data.stations[id]
|
||||||
@@ -787,7 +800,7 @@ function tick(map_data, mod_settings)
|
|||||||
end
|
end
|
||||||
elseif map_data.tick_state == STATE_DISPATCH then
|
elseif map_data.tick_state == STATE_DISPATCH then
|
||||||
for i = 1, mod_settings.update_rate do
|
for i = 1, mod_settings.update_rate do
|
||||||
tick_dispatch(map_data, mod_settings)
|
if tick_dispatch(map_data, mod_settings) then break end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
---@field public stations {[uint]: Station}
|
---@field public stations {[uint]: Station}
|
||||||
---@field public active_station_ids uint[]
|
---@field public active_station_ids uint[]
|
||||||
---@field public warmup_station_ids uint[]
|
---@field public warmup_station_ids uint[]
|
||||||
|
---@field public warmup_station_cycles {[uint]: int}
|
||||||
---@field public queue_station_update {[uint]: true?}?
|
---@field public queue_station_update {[uint]: true?}?
|
||||||
---@field public depots {[uint]: Depot}
|
---@field public depots {[uint]: Depot}
|
||||||
---@field public refuelers {[uint]: Refueler}
|
---@field public refuelers {[uint]: Refueler}
|
||||||
@@ -49,6 +50,7 @@
|
|||||||
---@field public item_p_counts {[string]: int} --transient
|
---@field public item_p_counts {[string]: int} --transient
|
||||||
---@field public item_thresholds {[string]: int}? --transient
|
---@field public item_thresholds {[string]: int}? --transient
|
||||||
---@field public display_state int
|
---@field public display_state int
|
||||||
|
---@field public is_warming_up true?
|
||||||
|
|
||||||
---@class Depot
|
---@class Depot
|
||||||
---@field public entity_stop LuaEntity
|
---@field public entity_stop LuaEntity
|
||||||
@@ -146,6 +148,7 @@ function init_global()
|
|||||||
global.stations = {}
|
global.stations = {}
|
||||||
global.active_station_ids = {}
|
global.active_station_ids = {}
|
||||||
global.warmup_station_ids = {}
|
global.warmup_station_ids = {}
|
||||||
|
global.warmup_station_cycles = {}
|
||||||
global.depots = {}
|
global.depots = {}
|
||||||
global.trains = {}
|
global.trains = {}
|
||||||
global.available_trains = {}
|
global.available_trains = {}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
--By Mami
|
--By Mami
|
||||||
local ceil = math.ceil
|
local ceil = math.ceil
|
||||||
local table_insert = table.insert
|
local table_insert = table.insert
|
||||||
|
local table_remove = table.remove
|
||||||
|
|
||||||
|
|
||||||
---@param map_data MapData
|
---@param map_data MapData
|
||||||
@@ -138,10 +139,25 @@ local function on_station_built(map_data, stop, comb1, comb2)
|
|||||||
item_p_counts = {},
|
item_p_counts = {},
|
||||||
item_thresholds = nil,
|
item_thresholds = nil,
|
||||||
display_state = 0,
|
display_state = 0,
|
||||||
|
is_warming_up = true,
|
||||||
}
|
}
|
||||||
local id = stop.unit_number--[[@as uint]]
|
local id = stop.unit_number--[[@as uint]]
|
||||||
|
|
||||||
map_data.stations[id] = station
|
map_data.stations[id] = station
|
||||||
|
|
||||||
|
--prevent the same station from warming up multiple times
|
||||||
|
if map_data.warmup_station_cycles[id] then
|
||||||
|
--enforce FIFO
|
||||||
|
for i, v in ipairs(map_data.warmup_station_ids) do
|
||||||
|
if v == id then
|
||||||
|
table_remove(map_data.warmup_station_ids, i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
map_data.warmup_station_ids[#map_data.warmup_station_ids + 1] = id
|
map_data.warmup_station_ids[#map_data.warmup_station_ids + 1] = id
|
||||||
|
map_data.warmup_station_cycles[id] = 0
|
||||||
|
|
||||||
if not map_data.queue_station_update then
|
if not map_data.queue_station_update then
|
||||||
map_data.queue_station_update = {}
|
map_data.queue_station_update = {}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -267,6 +267,32 @@ local migrations_table = {
|
|||||||
train.use_any_depot = true
|
train.use_any_depot = true
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
["1.3.0"] = function()
|
||||||
|
---@type MapData
|
||||||
|
local map_data = global
|
||||||
|
map_data.warmup_station_cycles = {}
|
||||||
|
|
||||||
|
local is_registered = {}
|
||||||
|
|
||||||
|
for i = #map_data.warmup_station_ids, 1, -1 do
|
||||||
|
local id = map_data.warmup_station_ids[i]
|
||||||
|
if is_registered[id] then
|
||||||
|
table.remove(map_data.warmup_station_ids, i)
|
||||||
|
else
|
||||||
|
is_registered[id] = true
|
||||||
|
map_data.warmup_station_cycles[id] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = #map_data.active_station_ids, 1, -1 do
|
||||||
|
local id = map_data.active_station_ids[i]
|
||||||
|
if is_registered[id] then
|
||||||
|
table.remove(map_data.active_station_ids, i)
|
||||||
|
else
|
||||||
|
is_registered[id] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
--STATUS_R_TO_D = 5
|
--STATUS_R_TO_D = 5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user