Dynamic Train Stops


Rename Train Stations based on Circuit Network Input

Content
8 years ago
0.13 - 0.14
10
Trains

i performance improvement

8 years ago
(updated 8 years ago)

You could significantly reduce update time with this on_tick method
(sorry for terrible formating)

script.on_event(defines.events.on_tick, function(event)
if dynamic_stations ~= nil then
for k, dynamic_station in pairs(dynamic_stations) do
if k % 60 == game.tick % 60 then
updateDynamicStation(dynamic_station)
end
end
end
end)

This will spread out updates evenly within 60ticks ~ 1s
I don't think trains would need a much faster update.

8 years ago

I have the stations updated every tick for a specific use case. Here's an example:

Train has a schedule of Dropoff, Holding, Pickup|Green

All of the Pickup| stations connected via circuit network back to the Holding stations. The departure condition of the train schedule at Holding is a circuit network condition for Green > 1. If the station name isn't updated in the same tick as the circuit condition is satisfied, the train will depart Holding and proceed directly to Dropoff as Pickup|Green does not yet exist.

Performance wise, I've tested up to about 200 Dynamic Stations and haven't noticed an impact from updating each tick.

8 years ago

Applying Optera's patch to this mod increased my UPS by about 15. It was fluctuating between 45-50 UPS now it never drops below 60.

8 years ago

First of all I love your mod, can't play without it anymore!

I did run into some performance issues as well, and I managed to reduce the tick time of this mod by about 30% for my map (from 2ms to 1.35ms). Your code cycles through the signals starting from Black and making its way up the priority list; I changed it to start at Red and stops checking lower priority signals once it has found an active signal.

With Optera's fix the update time is down to as low as 0.05ms per tick for me, but I understand why you might not want to use it for the specific scenario you described. My update changes the mods behavior in some very specific cases which I don't think will ever happen (If you have a red network with 1 Red, 1 Green, and a green network with -1 Red, the station will receive no color, while it would become Green with your code.)

Here's the code with my performance fix:
http://pastebin.com/gZrFhThN

New response