SDK Question Vessel detect other vessel within radius

Buzz313th

New member
Joined
Jan 1, 2010
Messages
92
Reaction score
0
Points
0
Quick SDK question....

Anyone know of a method to allow a vessel to detect a specific vessel within a given radius?

More specifically. A vessel to detect UMMU's within a certain radius.

I looked through the API reference and didn't find anything that was obvious, but then again I am extremely new to C++

JB
 

Juanelm

Addon Developer
Addon Developer
Donator
Joined
Nov 15, 2008
Messages
229
Reaction score
0
Points
16
Quick SDK question....

Anyone know of a method to allow a vessel to detect a specific vessel within a given radius?

More specifically. A vessel to detect UMMU's within a certain radius.

I looked through the API reference and didn't find anything that was obvious, but then again I am extremely new to C++

JB


And btw, thanks to Computerex. Your tutorial on setting up VC++ is excellent, and it helped me make my first addon.
 

Buzz313th

New member
Joined
Jan 1, 2010
Messages
92
Reaction score
0
Points
0
Thanks Jaunelm

Looking now..

JB

---------- Post added at 12:36 AM ---------- Previous post was at 12:26 AM ----------

Ok, I think I understand...

So you wanna identify every vessel in orbiter, then for each one get it's position or perameters and compare it with a constant position, identifying just the UMMU's within a certain range.

Is this correct?

If so, isn't this a large performance hit, considering it is being done every frame?

JB
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Checking each vessel at every frame would indeed be a very bad idea, because it doesn't scale well with increasing vessel numbers (think massively parallel multiplayer environment). If each vessel checks every other vessel each frame, this introduces an operation of complexity O(n^2) (n=number of vessels).

A slightly better method is to check only a limited number of vessels per frame. The disadvantage is that for a large number of vessels the checking period may become too large. For example, if you are checking for radio contact, then a period of 10-100 seconds may be sufficient. If you check 10 vessels per frame, and assuming a framerate of 100fps, this could accommodate up to 100,000 vessels. The complexity of this method is of order O(n).

Better still would be to build a priority list with individual checking periods. For example, if a vessel is 20AU from your current position, it's a good bet that it won't be within radio range for the forseeable future, so the next check could be delayed for a long time. A vessel right on the detection edge should be rechecked much sooner.

Hope this gives some ideas.
 

Buzz313th

New member
Joined
Jan 1, 2010
Messages
92
Reaction score
0
Points
0
Wow... Yeah it does... Now understand I just picked up my first C++ book a week ago, but I am able to struggle through reading code and I can write a bit from scratch.

So just to recap. You would get all the vessels info in orbiter, then prioritize the more frequent checks based on the search criteria specified by the ultimate goal? This would mean that the large check that gets all the vessels would be done once a day. Then the higher priority checks might be done once an hour, then the highest priority at once per second. That makes sense.

Since my goal is to check distance from a global position to only UMMU class vessels, then my first check would be done, lets say once per hour looking for all the vessels in orbiter. Then I would create variable that contains just the UMMU's outa that first check. Use this UMMU variable to find just the UMMU's on the planet. Then the last list of UMMU's on the planet can be checked every second to compare distance from the global position.

Am I on the same page?

The hardest part for me, is getting my brain trained to associate all these variables and functions to mechanical logic.

It's difficult stuff but I am trying.

Thanks for the tips... LOL, now all I gotta do is claw my way through writing that code..

JB
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
That's about the idea. Just remember that by the time you re-check the vessels in your list, things can have changed. Some vessels may have been deleted, others created. So your list of vessel handles may no longer be up to date (it is not safe to store a vessel handle and assume that it is still valid at some later time). You can use the oapiIsVessel function to check if a handle is still valid (although this function itself has complexity O(n), since Orbiter needs to scan its list of vessels).
 

Buzz313th

New member
Joined
Jan 1, 2010
Messages
92
Reaction score
0
Points
0
Thanks Martin...

For some reason I thought you were located in England, not Jamaica.

Have a good eve.

JB
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
For some reason I thought you were located in England, not Jamaica.
I'm usually located in orbit (virtually, anyway), so the choice of flag is rather coincidental. I picked the location of my favourite bobsled team.

Edit:

So just to recap. You would get all the vessels info in orbiter, then prioritize the more frequent checks based on the search criteria specified by the ultimate goal? This would mean that the large check that gets all the vessels would be done once a day. Then the higher priority checks might be done once an hour, then the highest priority at once per second. That makes sense.
Just to refine this algorithm a bit: The "large check" of all vessels should not be done in a single chunk, because that could lead to a stutter at that frame. Rather, the low-priority check of all vessels should be spread over a long period of time. It could look like this:

The low-priority group (i.e. all vessels) is checked at a rate of one vessel per frame. Whenever a "candidate" vessel is found, given a particular set of critera, it is entered into a second mid-priority group. Each member of this group is also checked at a rate of one per frame. Since this group is smaller, the check frequency for this group is much higher. Any vessels in the second group determined to be critical are moved into a third high-priority group, which is fully checked at each frame. This last group must be small (e.g. limited to 10 vessels max.)

You can add more intermediate stages to fine-tune the performance.
 

Buzz313th

New member
Joined
Jan 1, 2010
Messages
92
Reaction score
0
Points
0
Ok... That really ties it all together now. It's getting a bit clearer now how all this relates to performance. It's really the overhead on the system per frame. Just thinking of how to try and put this together makes my head spin around.


Oh, and by the way, good choice on the Bobsled team. ;)

Good eve.

JB

:)
 
Top