Skip to content

Commit 118d3d5

Browse files
authored
1.5.3
- fixed sensors didn't properly reset for vehicles and trains
1 parent b3d2bc0 commit 118d3d5

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.5.3
2+
- fixed sensors didn't properly reset for vehicles and trains
3+
14
1.5.2
25
- fixed possible integer overflow from mod settings
36

control.lua

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ function OnEntityRemoved(event)
102102
end
103103

104104

105+
-- grouped stepping by Optera
106+
-- 91307.27ms on 100k ticks
105107
function OnTick(event)
106108
global.tickCount = global.tickCount or 1
107109
global.SensorIndex = global.SensorIndex or 1
@@ -135,17 +137,17 @@ function OnTick(event)
135137
end
136138
end
137139

140+
-- stepping from tick modulo with stride by eradicator
141+
-- 93048.58ms on 100k ticks: 1.9% slower than grouped stepping
138142
-- function OnTick(event)
139-
-- local tick = game.tick
140-
-- for i=1, #global.ItemSensors do
141-
-- local itemSensor = global.ItemSensors[i]
142-
-- if not itemSensor.SkipEntityScanning and (i + tick) % ScanInterval == 0 then
143-
-- SetConnectedEntity(itemSensor)
144-
-- end
145-
-- if (i + tick) % UpdateInterval == 0 then
146-
-- UpdateSensor(itemSensor)
147-
-- end
148-
-- end
143+
-- local offset = event.tick % UpdateInterval
144+
-- for i=#global.ItemSensors - offset, 1, -1 * UpdateInterval do
145+
-- local itemSensor = global.ItemSensors[i]
146+
-- if not itemSensor.SkipEntityScanning and (event.tick - itemSensor.LastScanned) >= ScanInterval then
147+
-- SetConnectedEntity(itemSensor)
148+
-- end
149+
-- UpdateSensor(itemSensor)
150+
-- end
149151
-- end
150152

151153
---- LOGIC ----
@@ -204,14 +206,22 @@ function SetConnectedEntity(itemSensor)
204206
if connectedEntities then
205207
for i=1, #connectedEntities do
206208
local entity = connectedEntities[i]
207-
if entity.valid and SupportedTypes[entity.type] ~= nil and itemSensor.ConnectedEntity ~= entity then
209+
if entity.valid and SupportedTypes[entity.type] ~= nil then
210+
-- log("[IS] Sensor "..itemSensor.Sensor.unit_number.." found entity "..tostring(entity.type))
208211
itemSensor.ConnectedEntity = entity
209212
itemSensor.SkipEntityScanning = SupportedTypes[entity.type]
210-
SetInventories(itemSensor, entity)
213+
if itemSensor.ConnectedEntity ~= entity then
214+
SetInventories(itemSensor, entity)
215+
end
211216
return
212217
end
213218
end
214-
end
219+
end
220+
-- if no entity was found remove stored data
221+
-- log("[IS] Sensor "..itemSensor.Sensor.unit_number.." no entity found")
222+
itemSensor.ConnectedEntity = nil
223+
itemSensor.SkipEntityScanning = false
224+
itemSensor.Inventory = {}
215225
end
216226

217227
function UpdateSensor(itemSensor)

info.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "Inventory Sensor",
3-
"version": "1.5.2",
3+
"version": "1.5.3",
44
"title": "Inventory Sensor",
55
"author": "Optera",
66
"contact": "https://forums.factorio.com/memberlist.php?mode=viewprofile&u=21729",
77
"homepage": "https://forums.factorio.com/viewtopic.php?f=97&t=30454",
88
"description": "Adds a combinator that reads inventories of locomotives, wagons, cars, furnaces, assemblers, roboports, rocket silos and reactors.",
99
"factorio_version": "0.15",
10-
"dependencies": ["base >= 0.15.32"]
10+
"dependencies": ["base >= 0.15.37"]
1111
}

0 commit comments

Comments
 (0)