Calculate inserter arm positions only when the GPU or a mod wants them

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Calculate inserter arm positions only when the GPU or a mod wants them

Post by quyxkh »

Top lesson from the UPS Wars threads hasn't changed: inserter swings almost completely dominate production cost. I suspect it's because the engine updates the inserter arm position every tick, but why? There's no collision checks, arm position mid-swing is there for us humans to look at, right? So how about storing just the arrival tick and target point, plus swing and extension rates for each inserter swing?

Koub
Global Moderator
Global Moderator
Posts: 7175
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by Koub »

what if power is shut down during the swing ?
Koub - Please consider English is not my native language.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by quyxkh »

Power-out's already an exceptional condition, right? Worst case, in a brownout you have to fall back to per-tick inserter updates, I'd think it's just whenever the power supply changes that you have to recalculate the swing.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by quyxkh »

That 92% touch-count reduction kept my monkey chattering until it came up with this:

Swinging inserters go on a head-tail queue, simplest might be one for every connected-power-grids and delivered-joules-required combination. The list anchor has a what's-on-the-list summary and a count of how many joules have ever been delivered to every item on that list; queuing an inserter swing is just updating the summary and four pointers and power delivery is updating the summary then an unsigned-subtract-and-compare-until-done dequeue loop, no updating the list entries themselves required.

For example: a normal stack inserter swing is 13 ticks, 133kW max 1kW min, 1kW*13/60s is 216⅔J/tick drain, so the inserter needs 133000*13/60-216⅔*13/60=26000 delivered joules to complete its swing. Adding an inserter to the 26000J-swing queue means the list append, incrementing the count of inserters on that queue, adding the inserter's drain, and copying the current delivered-joules total plus 26000 to the target joules in the list entry. Power delivery means subtracting the list drain, dividing by the list count, adding to the delivery total, and dequeuing everything from the front that's been fully supplied, updating the list drain and count accordingly. Account for drain in 60ths of a joule and there's no rounding error; account for delivered and target joules as an unsigned and there's no overflow or resetting.

No-touch-until-done, unless the GPU or a mod needs the current position, then the current swing fraction is 1-(target-delivered)/required.

I've learned, when my monkey won't shut up there's something there. I promise, though, _I_ will. I'll just sign off with "have mercy on me".

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by ssilk »

Interesting idea. Worth trying an implementation.

It would be really, really useful, if we have a power sensor, which has a signal, that rises when power is not 100% satisfied. So we would have a chance to turn power off completely (switch) and save much cpu.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2632
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by steinio »

Leads to calculate animations only when anybody is watching.
Out of screen entities and smoke could be frozen.
Image

Transport Belt Repair Man

View unread Posts

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by Honktown »

There's a mod that disables inserter animations. Have you seen that? OP? I wonder if it only disables animations, or completely interferes with their position awareness.
I have mods! I guess!
Link

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by eradicator »

@quyxkh:

Inserters don't swing in a perfect arc though. They chase items on belts and sometimes wait for the source/target to become unstuck. Does that still work?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1027
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by quyxkh »

eradicator wrote:
Sat Nov 09, 2019 2:13 pm
@quyxkh:

Inserters don't swing in a perfect arc though. They chase items on belts and sometimes wait for the source/target to become unstuck. Does that still work?
Worst case this only works for container-to-container swings, but I don't think inserters recalculate their target mid-swing, I think if they get to their target and there's nothing there they try again with a newly-calculated target.

AngledLuffa
Fast Inserter
Fast Inserter
Posts: 187
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by AngledLuffa »

ssilk wrote:
Sat Nov 09, 2019 8:22 am
It would be really, really useful, if we have a power sensor, which has a signal, that rises when power is not 100% satisfied. So we would have a chance to turn power off completely (switch) and save much cpu.
This is actually quite easy to do. Have a counter circuit connected to a solar panel and accumulator which is separate from the rest of your power so that it is always fully powered. Then have another counter connected to your regular power source which might possibly have low power. If the power drops, the counter circuit will tick slower than the uninterrupted counter, and you can measure that difference. judos made a daytime detector based on this logic:

viewtopic.php?f=193&t=77046

I can think of two problems with the usage you suggested:

1) You need to prepare some other measurement for when to turn the power back on. Otherwise, your measurement device will flicker on and off. Perhaps you could make it like a circuit breaker, where it stays off until human intervention turns it back on.

2) Does this actually save CPU? My understanding was that unpowered devices can never sleep because they are constantly checking to see if power is back.

User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 513
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

Re: Calculate inserter arm positions only when the GPU or a mod wants them

Post by Mylon »

Koub wrote:
Tue Nov 05, 2019 10:31 pm
what if power is shut down during the swing ?
Make inserters work like laser turrets: Either they swing or they don't. They deduct the full power to complete their swing at their start.

Post Reply

Return to “Ideas and Suggestions”