Will too many asteroids kill the game?

Freeform discussion about anything related to modding Transcendence.
Post Reply
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Image
This is a tad bit overkill but yeah, just wondering.
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

I wonder if there is a spaceObj limit for each system.
Jay2Jay
Militia Commander
Militia Commander
Posts: 283
Joined: Fri Jan 11, 2013 12:57 am

Image
I made this for you
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

I haven't done any empirical tests, and perhaps someone can supply some numbers (how many asteroids do you need before the game starts slowing down?)

In general there are two performance issues:

1. Linear update time: The game updates every object in the system once per tick (1/30th of a second). That means we execute some amount of code for every object. For an asteroid, that code is minimal, but you will eventually get a slow down. The best way to mitigate this is to decrease the number of asteroids or decrease the time per asteroids update. The latter is probably already close to (but not exactly) zero. I could get it to zero by optimizing the case of objects that do nothing in their update.

2. N-squared collision detection: For each object we loop to see if it hit anything. This is a double loop and thus O(n^2). If there are lots of asteroids and lots of bullets, then this could get really ugly fast. There are a couple of optimizations for this. I can use a quad-tree to only search for objects in a particular spot on the map (I have something similar today, but I bet I can optimize it). And I can optimize the time for non-colliding objects to zero.
User avatar
Arisaya
Fleet Admiral
Fleet Admiral
Posts: 5535
Joined: Tue Feb 05, 2008 1:10 am
Location: At the VSS Shipyards in the frontier, designing new ships.

For updates, you can used a 'touch' based system, which in worst case is still O(N), but more likely will be much less than that.

Take a queue or a stack, your pick
If anything happens to an object, (such as a collision is detected, or a script is called on it) then put it in the queue/stack. At the end, when everything needs to be updated, iterate though only these objects and update them, instead of updating everything.

Of course, depending on how the system is implemented and what the updates are doing, it could be a bit more complex than that, but it should greatly improve performance because in most cases, its just iterating through things that do nothing.
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Wolfy wrote:For updates, you can used a 'touch' based system, which in worst case is still O(N), but more likely will be much less than that.

Take a queue or a stack, your pick
If anything happens to an object, (such as a collision is detected, or a script is called on it) then put it in the queue/stack. At the end, when everything needs to be updated, iterate though only these objects and update them, instead of updating everything.

Of course, depending on how the system is implemented and what the updates are doing, it could be a bit more complex than that, but it should greatly improve performance because in most cases, its just iterating through things that do nothing.
That may not work for objects with timers running on them.
Literally is the new Figuratively
User avatar
Arisaya
Fleet Admiral
Fleet Admiral
Posts: 5535
Joined: Tue Feb 05, 2008 1:10 am
Location: At the VSS Shipyards in the frontier, designing new ships.

Hm, depends on how the timers are implemented, but in the worst case, i think you could just have a minheap of all timers pointing to the objects they are timing-on or however you would say it (thus the items closest to the top are the ones that are due to be run)

Or something
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
Post Reply