Bocator wrote:Thanks for the help ! Just tried it and I can feel the game is smoother. Being curious, what lines have you changed ?
Most of the changes were around line 50. The base 5dim code did some processing for every train every 20 ticks, and my version just split the work so that 1/20th of the total number of trains was processed every tick. It is the same amount of work, but as you noted it is much smoother.
That doesn't solve the problem of 5dim processing most trains multiple times, however. That is what the code in this post is for.
The following patch contains the change I described earlier, a fix for multiple copies of the same train being added to global.wagonsData, a fix for the wrong train being removed from global.wagonsData sometimes, and a migration script so that any existing duplicate trains are removed from existing saves when they are first loaded.
Please note that this patch is for 5dim_trains version 3.1.0, and that you should not manually add the migration file (migrations/5dim_trains_3.1.0.lua). Problems could arise if you do this and my migration file differs from any official release.
Code: Select all
diff -Nru source/5dim_trains_3.1.0/control.lua modified/5dim_trains_3.1.0/control.lua
--- source/5dim_trains_3.1.0/control.lua 2016-04-27 12:25:00.579958800 -0500
+++ modified/5dim_trains_3.1.0/control.lua 2016-05-14 13:56:46.135331700 -0500
@@ -40,7 +40,7 @@
global.updateStaticProxies = nil
end
- if global.wagonsData~=nil and event.tick %20 == 3 then
+ if global.wagonsData~=nil then
global.wagonsData = updateWagons(global.wagonsData)
@@ -50,9 +50,21 @@
end)
+local next_wagon_update_index = 1
function updateWagons(wagonsData)
local removeList = {}
- for i,wagonData in pairs(wagonsData) do
+ local wagon_updates_remaining = math.ceil(#wagonsData/20)
+
+ while wagon_updates_remaining > 0 do
+ wagon_updates_remaining = wagon_updates_remaining - 1
+
+ if wagonsData[next_wagon_update_index] == nil then
+ next_wagon_update_index = 1
+ end
+
+ wagonData = wagonsData[next_wagon_update_index]
+ next_wagon_update_index = next_wagon_update_index + 1
+
--wagonCount = wagonCount + 1
if wagonData ~= nil and wagonData.wagon ~= nil and wagonData.wagon.valid then
wagonData = updateWagonPosition(wagonData)
@@ -62,9 +74,8 @@
wagonData = updateRequestSlots(wagonData)
-- wagonData = updateLiquid(wagonData)
wagonData = updateHealth(wagonData)
- else
- table.insert(removeList, 1, wagon)
-
+ elseif wagonData ~= nil then
+ table.insert(removeList, 1, wagonData.wagon)
end
end
for i, wagon in ipairs(removeList) do
@@ -223,7 +234,7 @@
wagonsData={}
end
- if wagon ~= nil and wagon.valid then
+ if wagon ~= nil and wagon.valid and findWagonInTable(wagonsData, wagon) <= 0 then
local newWagon = {}
newWagon["wagon"] = wagon
@@ -311,8 +322,8 @@
end
end
end
- table.remove(wagonsData, i)
- return wagons
+ table.remove(wagonsData, loc)
+ return wagonsData
end
function hasStaticProxies(entityName)
@@ -708,16 +719,18 @@
local wagonsData = {}
if wagons ~= nil then
for wagon,value in pairs(wagons) do
- local newWagon = {}
- newWagon["wagon"] = wagon
- newWagon["position"] = value.position
- newWagon["proxy"] = value.proxy
- newWagon["inventoryCount"] = value.inventoryCount
- newWagon["liquid"] = value.liquid
- newWagon["requestSlots"] = value.requestSlots
- newWagon["health"] = value.health
- newWagon["energy"] = value.energy
- table.insert(wagonsData,newWagon)
+ if findWagonInTable(wagonsData, wagon) <= 0 then
+ local newWagon = {}
+ newWagon["wagon"] = wagon
+ newWagon["position"] = value.position
+ newWagon["proxy"] = value.proxy
+ newWagon["inventoryCount"] = value.inventoryCount
+ newWagon["liquid"] = value.liquid
+ newWagon["requestSlots"] = value.requestSlots
+ newWagon["health"] = value.health
+ newWagon["energy"] = value.energy
+ table.insert(wagonsData,newWagon)
+ end
end
end
return wagonsData
@@ -731,7 +744,6 @@
local newValues = {}
if wagonData.wagon.valid then
-- debugLog("Wagon is valid " .. i)
- table.insert(newWagons,wagonData)
addWagonToTable(newWagons, wagonData.wagon, wagonData["energy"], wagonData["liquid"])
else
debugLog("Wagon is invalid. " .. i)
diff -Nru source/5dim_trains_3.1.0/migrations/5dim_trains_3.1.0.lua modified/5dim_trains_3.1.0/migrations/5dim_trains_3.1.0.lua
--- source/5dim_trains_3.1.0/migrations/5dim_trains_3.1.0.lua 1969-12-31 18:00:00.000000000 -0600
+++ modified/5dim_trains_3.1.0/migrations/5dim_trains_3.1.0.lua 2016-05-14 13:52:27.285526400 -0500
@@ -0,0 +1,23 @@
+do
+ if global.wagonsData ~= nil then
+ local remove_indices = {}
+ local remove_wagons = {}
+ local before = #global.wagonsData
+
+ for ia,a in ipairs(global.wagonsData) do
+ if not remove_indices[ia] then
+ for ib,b in ipairs(global.wagonsData) do
+ if ia < ib and a.wagon == b.wagon then
+ remove_indices[ib] = true
+ end
+ end
+ end
+ end
+ for k,v in pairs(remove_indices) do
+ table.insert(remove_wagons, global.wagonsData[k].wagon)
+ end
+ for i, wagon in ipairs(remove_wagons) do
+ removeWagonFromTable(global.wagonsData, wagon)
+ end
+ end
+end
\ No newline at end of file
xBlizzDevious wrote:Extra fast smart inserters aren't fully smart.
I can add a filter so they only take specific items, but I cannot connect a logistics wire or set circuit/logistic configurations.
I'm running 3.0.0 automatisation but according to its changelog, that doesn't exist:
viewtopic.php?f=81&t=13137#p95432 (it only goes up to 2.1.0).
The names of some of the items in 5Dim - the extra fast smart inserter included - show up as an unknown key or something along those lines too.
I wrote a patch to fix these two bugs as well, this one for 5dim_automation version 3.1.0. The problem was just a missing flag in the data files and a few translations which needed to be copied to another location.
Code: Select all
diff -Nru source/5dim_automatization_3.1.0/locale/en/locale.cfg modified/5dim_automatization_3.1.0/locale/en/locale.cfg
--- source/5dim_automatization_3.1.0/locale/en/locale.cfg 2015-08-21 08:28:13.952979200 -0500
+++ modified/5dim_automatization_3.1.0/locale/en/locale.cfg 2016-05-13 12:51:33.728757500 -0500
@@ -72,6 +72,11 @@
5d-inserter-speed3-range1-close = Extra speed inserter near
5d-inserter-speed3-range2-close = Extra speed long inserter near
5d-inserter-speed3-range3-close = Extra speed extra long inserter near
+5d-inserter-smart-speed2-range1-close = Smart inserter near
+5d-inserter-smart-speed3-range1 = Extra speed smart inserter
+5d-inserter-smart-speed3-range1-close = Extra speed smart inserter near
+5d-inserter-smart-speed2-range2 = Long smart inserter
+5d-inserter-smart-speed2-range2-close = Long smart inserter near
5d-fast-inserter-left-90d = Fast speed left inserter
5d-basic-inserter-left-90d = Left inserter
5d-fast-inserter-right-90d = Fast speed right inserter
diff -Nru source/5dim_automatization_3.1.0/locale/es-ES/locale.cfg modified/5dim_automatization_3.1.0/locale/es-ES/locale.cfg
--- source/5dim_automatization_3.1.0/locale/es-ES/locale.cfg 2015-08-21 08:28:32.328981000 -0500
+++ modified/5dim_automatization_3.1.0/locale/es-ES/locale.cfg 2016-05-13 12:52:43.952774100 -0500
@@ -78,6 +78,11 @@
5d-inserter-speed3-range1-close = Inserter velocidad extrema largo 1 corto
5d-inserter-speed3-range2-close = Inserter velocidad extrema largo 2 corto
5d-inserter-speed3-range3-close = Inserter velocidad extrema largo 3 corto
+5d-inserter-smart-speed2-range1-close = Inserter inteligente corto
+5d-inserter-smart-speed3-range1 = Inserter inteligente velocidad extrema corto
+5d-inserter-smart-speed3-range1-close = Inserter inteligente velocidad extrema corto
+5d-inserter-smart-speed2-range2 = Inserter inteligente largo
+5d-inserter-smart-speed2-range2-close = Inserter inteligente largo corto
5d-fast-inserter-left-90d = Inserter velocidad normal largo 1 izq.
5d-basic-inserter-left-90d = Inserter velocidad r?pida largo 1 izq.
5d-fast-inserter-right-90d = Inserter velocidad r?pida largo 1 der.
diff -Nru source/5dim_automatization_3.1.0/locale/pl/locale.cfg modified/5dim_automatization_3.1.0/locale/pl/locale.cfg
--- source/5dim_automatization_3.1.0/locale/pl/locale.cfg 2016-03-30 16:00:33.030060200 -0500
+++ modified/5dim_automatization_3.1.0/locale/pl/locale.cfg 2016-05-13 12:53:16.896658400 -0500
@@ -73,6 +73,11 @@
5d-inserter-speed3-range1-close = Superszybki podajnik bliski
5d-inserter-speed3-range2-close = Superszybki long podajnik bliski
5d-inserter-speed3-range3-close = Superszybki bardzo długi podajnik bliski
+5d-inserter-smart-speed2-range1-close = Podajnik sterowany bliski
+5d-inserter-smart-speed3-range1 = Superszybki sterowany podajnik
+5d-inserter-smart-speed3-range1-close = Superszybki sterowany podajnik bliski
+5d-inserter-smart-speed2-range2 = Długi sterowany podajnik
+5d-inserter-smart-speed2-range2-close = Długi sterowany podajnik bliski
5d-fast-inserter-left-90d = Szybki lewy podajnik
5d-basic-inserter-left-90d = Lewy podajnik
5d-fast-inserter-right-90d = Szybki prawy podajnik
diff -Nru source/5dim_automatization_3.1.0/locale/pt-BR/locale.cfg modified/5dim_automatization_3.1.0/locale/pt-BR/locale.cfg
--- source/5dim_automatization_3.1.0/locale/pt-BR/locale.cfg 2016-03-30 09:15:36.692792800 -0500
+++ modified/5dim_automatization_3.1.0/locale/pt-BR/locale.cfg 2016-05-13 12:53:45.712306600 -0500
@@ -72,6 +72,11 @@
5d-inserter-speed3-range1-close = Insersor básico longo de altíssima velocidade de proximidade
5d-inserter-speed3-range2-close = Insersor longo de altíssima velocidade de proximidade
5d-inserter-speed3-range3-close = Insersor extra-longo de altíssima velocidade de proximidade
+5d-inserter-smart-speed2-range1-close = Insersor inteligente de proximidade
+5d-inserter-smart-speed3-range1 = Insersor inteligente de alta velocidade
+5d-inserter-smart-speed3-range1-close = Insersor inteligente de proximidade de alta velocidade
+5d-inserter-smart-speed2-range2 = Insersor inteligente longo
+5d-inserter-smart-speed2-range2-close = Insersor inteligente longo de proximidade
5d-fast-inserter-left-90d = Insersor básico longo esquerdo de alta velocidade
5d-basic-inserter-left-90d = Insersor básico longo esquerdo de velocidade comum
5d-fast-inserter-right-90d = Insersor básico longo direito de alta velocidade
diff -Nru source/5dim_automatization_3.1.0/locale/ru/locale.cfg modified/5dim_automatization_3.1.0/locale/ru/locale.cfg
--- source/5dim_automatization_3.1.0/locale/ru/locale.cfg 2016-03-11 01:46:01.070336000 -0600
+++ modified/5dim_automatization_3.1.0/locale/ru/locale.cfg 2016-05-13 12:54:00.096129300 -0500
@@ -72,6 +72,11 @@
5d-inserter-speed3-range1-close = Сверхбыстрый ближний манипулятор
5d-inserter-speed3-range2-close = Сверхбыстрый длинный ближний манипулятор
5d-inserter-speed3-range3-close = Сверхбыстрый сверхдлинный ближний манипулятор
+5d-inserter-smart-speed2-range1-close = Умный ближний манипулятор
+5d-inserter-smart-speed3-range1 = Умный сверхбыстрый манипулятор
+5d-inserter-smart-speed3-range1-close = Умный сверхбыстрый ближний манипулятор
+5d-inserter-smart-speed2-range2 = Умный длинный манипулятор
+5d-inserter-smart-speed2-range2-close = Умный длинный ближний манипулятор
5d-fast-inserter-left-90d = Быстрый левый манипулятор
5d-basic-inserter-left-90d = Левый манипулятор
5d-fast-inserter-right-90d = Быстрый правый манипулятор
diff -Nru source/5dim_automatization_3.1.0/locale/uk/locale.cfg modified/5dim_automatization_3.1.0/locale/uk/locale.cfg
--- source/5dim_automatization_3.1.0/locale/uk/locale.cfg 2016-03-27 17:29:06.999587700 -0500
+++ modified/5dim_automatization_3.1.0/locale/uk/locale.cfg 2016-05-13 12:54:27.392690500 -0500
@@ -72,6 +72,11 @@
5d-inserter-speed3-range1-close = Надшвидкий ближній маніпулятор
5d-inserter-speed3-range2-close = Надшвидкий довгий ближній маніпулятор
5d-inserter-speed3-range3-close = Надшвидкий наддовгий ближній маніпулятор
+5d-inserter-smart-speed2-range1-close = Розумний ближній маніпулятор
+5d-inserter-smart-speed3-range1 = Розумний надшвидкий маніпулятор
+5d-inserter-smart-speed3-range1-close = Розумний надшвидкий ближній маніпулятор
+5d-inserter-smart-speed2-range2 = Розумний довгий маніпулятор
+5d-inserter-smart-speed2-range2-close = Розумний довгий ближній маніпулятор
5d-fast-inserter-left-90d = Швидкий лівий маніпулятор
5d-basic-inserter-left-90d = Лівий маніпулятор
5d-fast-inserter-right-90d = Швидкий правий маніпулятор
diff -Nru source/5dim_automatization_3.1.0/locale/zh-CN/locale.cfg modified/5dim_automatization_3.1.0/locale/zh-CN/locale.cfg
--- source/5dim_automatization_3.1.0/locale/zh-CN/locale.cfg 2016-03-23 23:12:55.230371800 -0500
+++ modified/5dim_automatization_3.1.0/locale/zh-CN/locale.cfg 2016-05-13 12:54:46.304772200 -0500
@@ -72,6 +72,11 @@
5d-inserter-speed3-range1-close = 机械臂(极速)-近
5d-inserter-speed3-range2-close = 机械臂(极速&加长)-近
5d-inserter-speed3-range3-close = 机械臂(极速&超长)-近
+5d-inserter-smart-speed2-range1-close = 智能机械臂-近
+5d-inserter-smart-speed3-range1 = 加速智能机械臂
+5d-inserter-smart-speed3-range1-close = 加速智能机械臂-近
+5d-inserter-smart-speed2-range2 = 加长智能机械臂
+5d-inserter-smart-speed2-range2-close = 加长智能机械臂-近
5d-fast-inserter-left-90d = 机械臂(快速)-左
5d-basic-inserter-left-90d = 机械臂-左
5d-fast-inserter-right-90d = 机械臂(快速)-右
diff -Nru source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1.lua modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1.lua
--- source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1.lua 2016-03-15 08:41:31.298835800 -0500
+++ modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1.lua 2016-05-13 12:47:25.840579100 -0500
@@ -126,6 +126,5 @@
green = {0, 0}
}
},
- circuit_wire_max_distance = 7.5
},
})
\ No newline at end of file
diff -Nru source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1-close.lua modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1-close.lua
--- source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1-close.lua 2016-03-15 08:41:31.302376800 -0500
+++ modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range1-close.lua 2016-05-13 12:46:40.623992900 -0500
@@ -42,6 +42,7 @@
},
max_health = 40,
corpse = "small-remnants",
+ programmable = true,
circuit_wire_max_distance = 7.5,
resistances =
{
@@ -141,6 +142,5 @@
height = 46,
}
},
- circuit_wire_max_distance = 7.5
},
})
\ No newline at end of file
diff -Nru source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2.lua modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2.lua
--- source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2.lua 2016-03-15 08:41:31.261551600 -0500
+++ modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2.lua 2016-05-13 12:46:36.288744900 -0500
@@ -45,6 +45,7 @@
max_health = 40,
corpse = "small-remnants",
filter_count = 5,
+ programmable = true,
circuit_wire_max_distance = 7.5,
resistances =
{
@@ -143,6 +144,5 @@
height = 46,
}
},
- circuit_wire_max_distance = 7.5
},
})
\ No newline at end of file
diff -Nru source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2-close.lua modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2-close.lua
--- source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2-close.lua 2016-03-15 08:41:31.271076800 -0500
+++ modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed2-range2-close.lua 2016-05-13 12:46:58.448012400 -0500
@@ -44,6 +44,7 @@
},
max_health = 40,
corpse = "small-remnants",
+ programmable = true,
circuit_wire_max_distance = 7.5,
resistances =
{
@@ -143,6 +144,5 @@
height = 46,
}
},
- circuit_wire_max_distance = 7.5
},
})
\ No newline at end of file
diff -Nru source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1.lua modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1.lua
--- source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1.lua 2016-03-15 08:41:31.287801500 -0500
+++ modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1.lua 2016-05-13 12:42:20.483113700 -0500
@@ -43,6 +43,7 @@
},
max_health = 40,
corpse = "small-remnants",
+ programmable = true,
circuit_wire_max_distance = 7.5,
resistances =
{
@@ -143,6 +144,5 @@
height = 46,
}
},
- circuit_wire_max_distance = 7.5
},
})
\ No newline at end of file
diff -Nru source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1-close.lua modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1-close.lua
--- source/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1-close.lua 2016-03-15 08:41:31.295321100 -0500
+++ modified/5dim_automatization_3.1.0/prototypes/inserter-smart-speed3-range1-close.lua 2016-05-13 12:47:10.432697900 -0500
@@ -64,6 +64,7 @@
},
extension_speed = 0.07,
fast_replaceable_group = "inserter",
+ programmable = true,
circuit_wire_max_distance = 7.5,
working_sound =
{
@@ -144,6 +145,5 @@
height = 46,
}
},
- circuit_wire_max_distance = 7.5
},
})
\ No newline at end of file
If there are any questions about these patches, please feel free to ask.