Author Topic: Orbital position calculations  (Read 5578 times)

0 Members and 1 Guest are viewing this topic.

Offline AbuDhabi (OP)

  • Sub-Lieutenant
  • ******
  • Posts: 104
  • Thanked: 2 times
Orbital position calculations
« on: October 09, 2013, 06:18:01 PM »
(Not sure if this goes here, Rules, the Academy or Bugs.)

During an inspection of the database file following fixing some erroneously null-ified fields, I've noticed that the system bodies appear to have their current X and Y listed right there. It seems as thought these values are periodically recalculated and saved there.

Why?
 

Offline Thiosk

  • Commodore
  • **********
  • Posts: 784
  • Thanked: 1 times
Re: Orbital position calculations
« Reply #1 on: October 10, 2013, 02:16:02 AM »
I suppose it does form the center coordinate for their satellites and gives a physical location for the body for a ship to fly towards?  They are shown on the map so the map needs to know where to put the dot.
 

Offline AbuDhabi (OP)

  • Sub-Lieutenant
  • ******
  • Posts: 104
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #2 on: October 10, 2013, 06:47:18 AM »
That would be the obvious explanation. I've checked the predefined Sol system coordinates with the coordinates a game - they are completely different, which lends credence to the this. But that's what's so weird!

Because you don't need to know the incrementally calculated position of the system body to know where it is. Since the orbits are perfect circles, you can use uniform circular motion formulas. Given the body's initial position, its speed, radius and amount of time passed we can determine where it is at any point in time without needing to calculate where it was at any previous point in time.

Indeed, I think these formulas are already being used. But why does the game need to save the current coordinates?
 

Offline Mel Vixen

  • Commander
  • *********
  • Posts: 315
  • Thanked: 1 times
Re: Orbital position calculations
« Reply #3 on: October 10, 2013, 12:05:04 PM »
In databases you have to consider (and  is know its BAD deisign!) lookuptimes vs. calculation times. If your lookup is even a little bit faster then calculating the position say for each ship then you should have it in the database for better performance.

It could be better for aurora thought if the positions would go into an struct or something like that instead of the database itself.
"Share and enjoy, journey to life with a plastic boy, or girl by your side, let your pal be your guide.  And when it brakes down or starts to annoy or grinds as it moves and gives you no joy cause its has eaten your hat and or had . . . "

- Damaged robot found on Sirius singing a flat 5th out of t
 

Offline AbuDhabi (OP)

  • Sub-Lieutenant
  • ******
  • Posts: 104
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #4 on: October 10, 2013, 01:39:34 PM »
In databases you have to consider (and  is know its BAD deisign!) lookuptimes vs. calculation times. If your lookup is even a little bit faster then calculating the position say for each ship then you should have it in the database for better performance.

It could be better for aurora thought if the positions would go into an struct or something like that instead of the database itself.

There is also another consideration.

The current system (as I imagine it working, judging the the database, gameplay and my extrapolations) requires that every position be recalculated at least every time the game is paused. Possibly every sub-pulse, too, because otherwise there might occur significant deviations in flight times for ships. And every time it is recalculated, it is saved to the database (again, if my understanding is correct).

This seems very inefficient.

Consider the case where calculation is done on an ad-hoc basis only - systems which are devoid of ships do not need to be calculated at all. Further, system bodies of no interest (such as those which aren't the destination of any ships and have no colonies on them) might not be required to be recalculated, either. The only time when uninteresting bodies' coordinates need to be calculated is when the player is looking at the system map.
 

Offline TheDeadlyShoe

  • Vice Admiral
  • **********
  • Posts: 1264
  • Thanked: 58 times
  • Dance Commander
Re: Orbital position calculations
« Reply #5 on: October 10, 2013, 06:32:50 PM »
Quote
The current system (as I imagine it working, judging the the database, gameplay and my extrapolations) requires that every position be recalculated at least every time the game is paused. Possibly every sub-pulse, too, because otherwise there might occur significant deviations in flight times for ships. And every time it is recalculated, it is saved to the database (again, if my understanding is correct).
no, body locations only needed to be re-saved every five days.
 

Offline AbuDhabi (OP)

  • Sub-Lieutenant
  • ******
  • Posts: 104
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #6 on: October 11, 2013, 02:49:57 AM »
no, body locations only needed to be re-saved every five days.

Because they are recalculated in 5-day increments, yes? (That's the way it seems from Steve's explanation of how turns work.) So what happens when a ship's travel is shorter than that? Do they simply use the stored information, which only changes every 5 days?
 

Offline TheDeadlyShoe

  • Vice Admiral
  • **********
  • Posts: 1264
  • Thanked: 58 times
  • Dance Commander
Re: Orbital position calculations
« Reply #7 on: October 11, 2013, 06:28:42 AM »
I can't speak as to the architecture.  The ship only needs to know where the body will be in the five day increment that it reaches it.

Hell, the stored data might only be for some obscure function anyway,  like displaying the X,Y on the system map.  It might not be used in pathing at all.
 

Offline Bgreman

  • Lt. Commander
  • ********
  • Posts: 213
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #8 on: October 11, 2013, 01:21:03 PM »
It should be noted that it is not necessarily every five days.  Orbital motion calculations are performed every production cycle (whatever you have that set to) and the body positions updated then.

The reason that the X/Y coordinates are stored is so that you can have one function that sets where a TG is moving (or a mineral packet / missile /etc is being sent).  That function just looks up the X/Y position of whatever target object (lots of tables in the game have an X/Y coord, and many also have a "last x" / "last Y" so that you can draw the movement trails as well).

As for the question about what happens if a planet / body moves when a ship is trying to go there, it depends on what order things happen during the production cycle.  If planets move first, there is no problem, as the X/Y for the body will be updated before the ship tries to figure out how to get there.  I would assume body motion comes first for this reason, but it's possible it may not.  Just watch a slow conventional engine freighter trying to catch up with a planet and you will see that they aren't doing any kind of predictive motion interpolation.  They just head directly for the body.

As for why to store X/Y for each object rather than calculate it on the fly each time, that should be obvious.  Performing a calculation is almost always going to be slower than a simple DB lookup.  When you compound this with potentially thousands of calcs/lookups every increment, it can get slow pretty quick.
 

Offline AbuDhabi (OP)

  • Sub-Lieutenant
  • ******
  • Posts: 104
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #9 on: October 11, 2013, 03:38:36 PM »
The reason that the X/Y coordinates are stored is so that you can have one function that sets where a TG is moving (or a mineral packet / missile /etc is being sent).  That function just looks up the X/Y position of whatever target object (lots of tables in the game have an X/Y coord, and many also have a "last x" / "last Y" so that you can draw the movement trails as well).

This can be done with on-the-fly calculations as well. Simply calculate positions for t1 and t2, and draw those. The last time increment is a known value.

As for the question about what happens if a planet / body moves when a ship is trying to go there, it depends on what order things happen during the production cycle.  If planets move first, there is no problem, as the X/Y for the body will be updated before the ship tries to figure out how to get there.  I would assume body motion comes first for this reason, but it's possible it may not.  Just watch a slow conventional engine freighter trying to catch up with a planet and you will see that they aren't doing any kind of predictive motion interpolation.  They just head directly for the body.

That's terrible.

As for why to store X/Y for each object rather than calculate it on the fly each time, that should be obvious.  Performing a calculation is almost always going to be slower than a simple DB lookup.  When you compound this with potentially thousands of calcs/lookups every increment, it can get slow pretty quick.

No.

Performing a cheap calculation (as is the case here) will almost always be faster than a "simple DB lookup". Trigonometry stopped being calculationally expensive more than a decade ago. Even with solid-state drives, it is unlikely that accessing disk-bound data would be faster.
 

Offline TheDeadlyShoe

  • Vice Admiral
  • **********
  • Posts: 1264
  • Thanked: 58 times
  • Dance Commander
Re: Orbital position calculations
« Reply #10 on: October 11, 2013, 08:11:03 PM »
Quote
it is unlikely that accessing disk-bound data would be faster.
I would think it's in memory. 
 

Offline Mel Vixen

  • Commander
  • *********
  • Posts: 315
  • Thanked: 1 times
Re: Orbital position calculations
« Reply #11 on: October 12, 2013, 03:18:21 AM »
yes memory and most likely relative stationary so issuing an GetAddress(x) is faster then on the fly calcs.
"Share and enjoy, journey to life with a plastic boy, or girl by your side, let your pal be your guide.  And when it brakes down or starts to annoy or grinds as it moves and gives you no joy cause its has eaten your hat and or had . . . "

- Damaged robot found on Sirius singing a flat 5th out of t
 

Offline AbuDhabi (OP)

  • Sub-Lieutenant
  • ******
  • Posts: 104
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #12 on: October 12, 2013, 06:43:38 AM »
So the database gets loaded into memory? That would be faster, yes.
 

Offline sloanjh

  • Global Moderator
  • Admiral of the Fleet
  • *****
  • Posts: 2805
  • Thanked: 112 times
  • 2020 Supporter 2020 Supporter : Donate for 2020
    2021 Supporter 2021 Supporter : Donate for 2021
Re: Orbital position calculations
« Reply #13 on: October 12, 2013, 10:30:51 AM »
So the database gets loaded into memory? That would be faster, yes.

The DB is loaded into memory objects at the start of a movement cycle, so that it is NOT accessing disk during each interval.  There should be a post from Steve in Mechanics that's 4-6 years old talking about this optimization when it was done.

John
 

Offline Bgreman

  • Lt. Commander
  • ********
  • Posts: 213
  • Thanked: 2 times
Re: Orbital position calculations
« Reply #14 on: October 14, 2013, 03:59:06 PM »
That's terrible.

This is extremely helpful.