Board index FlightGear Development Nasal

Any way to run this Flightgear C method in Nasal?

Nasal is the scripting language of FlightGear.

Any way to run this Flightgear C method in Nasal?

Postby Necolatis » Mon Dec 05, 2016 8:22 pm

Pinto found this method in https://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scenery/scenery.cxx#l421:

get_cart_ground_intersection()

So is there any way to call it from Nasal? Sorta like what you would do with geodinfo()?
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Any way to run this Flightgear C method in Nasal?

Postby PINTO » Mon Dec 05, 2016 9:06 pm

I think we might have to write a new nasal function. I don't have access to grep at the moment but I don't think it's exposed to nasal as of yet.

This would be insanely handy for so many uses.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: Any way to run this Flightgear C method in Nasal?

Postby Hooray » Sat Dec 10, 2016 6:12 pm

It's really easy to do, see:

http://wiki.flightgear.org/Howto:Extend_Nasal
http://wiki.flightgear.org/Nasal/CppBind

Like you say, you could use a similar extension function as the template
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Any way to run this Flightgear C method in Nasal?

Postby Richard » Sun Dec 11, 2016 4:16 pm

I've already put together a binding for this method - available in the get_cart branch in my development repository. (ssh://r-harrison@git.code.sf.net/u/r-ha ... flightgear). Hopefully it'll all turn out good and we'll be able to merge this into the main source shortly.
Richard
 
Posts: 810
Joined: Sun Nov 02, 2014 11:17 pm
Version: Git
OS: Win10

Re: Any way to run this Flightgear C method in Nasal?

Postby Hooray » Sun Dec 11, 2016 4:20 pm

sooner or later, we may want to consider making thread-safety an explicit part of the extension function's name for the future - or even introducing a dedicated namespace with extension functions that are intended to be thread-safe - sooner or later this will become increasingly important, and some Nasal functions are already thread-safe, i.e. most restrictions are due to the underlying SG/FG code, not due to Nasal itself (e.g. the property tree)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Any way to run this Flightgear C method in Nasal?

Postby zakalawe » Sun Dec 11, 2016 6:25 pm

Can't you use cart-to-geod and geodinfo which already exist? Also I would be slightly worried about the performance implications of exposing this to Nasal, it's open to mis-use by inexperienced coders, because ground-cache queries can trigger scenery loading and unloading.
zakalawe
 
Posts: 1259
Joined: Sat Jul 19, 2008 5:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Any way to run this Flightgear C method in Nasal?

Postby Hooray » Sun Dec 11, 2016 6:42 pm

That's a good point, the corresponding APIs have previously been used to do all sorts of terrain sampling (local/advanced weather, but also for various VSD implementations), and they've been shown to cause bottlenecks - which is why Torsten ended up creating a hard-coded terrain pre-sampler (which seems however undocumented for the time being, i.e. is not too useful for people wanting to do similar things)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Any way to run this Flightgear C method in Nasal?

Postby Necolatis » Sun Dec 11, 2016 7:46 pm

Actually this method will improve performance on many planes I suspect.

Right now planes do alot of samples of ground in front of them to do terrain collision warning, terrain collision avoidance, radar terrain masking, terrain following etc. The calls would be very much reduced by this method. In case of the radar calls could be 1 per radar echo, which will in many planes greatly reduce calls to detect terrain between the radar and the echo.

This method would be so useful for lots of stuff.

Also isn't geodinfo overkill in many cases as it looks up all kinds of info about the terrain? (And it doesn't trigger loading of terrain, it just returns nil when no terrain is loaded where it is applied, would this new method not do just the same?)
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Any way to run this Flightgear C method in Nasal?

Postby Hooray » Sun Dec 11, 2016 7:50 pm

The comment on geodinfo often being overkill is actually valid, too - in many cases, that info isn't even needed at all - it would make sense to either come up with a more lightweight geodinfo() equivalent, or one where said info is only provided on an opt-in basis, i.e. optionally requested - but not looked up by default.

Depending on what people have in mind (you mentioned terrain sampling), it would actually make sense to come up with a vector-based equivalent of geodinfo(), which works on a vector of tuples and returns a vector, too - to avoid unnecessary Nasal/C marshalling overhead (as well as unnecessary property tree overhead due to going through the fgcommand/props layer to look up said info).
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Any way to run this Flightgear C method in Nasal?

Postby PINTO » Sun Dec 11, 2016 8:05 pm

zakalawe wrote in Sun Dec 11, 2016 6:25 pm:Can't you use cart-to-geod and geodinfo which already exist?


You can, but it's both prone to being moderately inaccurate and computationally very expensive for the use cases that this new function would solve.

Take, for instance, the radar-locked-ground mode of the MiG-21bis. It lockes the radar at -1.5 degrees pitch relative to the aircraft, and I need the coordinates at where the radar beam hits the ground. Currently, this can take anywhere from 7 (best case) to 25 or more (worst case) calls to geodinfo() for a feasibly accurate reading (within 3 meters). With this new function, I only will need 1 call, and it will be much more accurate.

Same logic goes with plane-to-plane radar. Currently we take a line between plane A and plane B, and sample parts of that line to see if one plane is visible to the other (15-25 samples, maybe more, if I recall correct). We can only sample so many times, and when you spread that sample out over 80nm, it's prone to being very inaccurate. Also it occurs where plane A can see plane B, but plane B cannot see plane A, causing issues with fairness. With this function, we'd only need 1 call and it will return with much better accuracy.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: Any way to run this Flightgear C method in Nasal?

Postby zakalawe » Sun Dec 11, 2016 10:04 pm

Ah, for these kind of uses a cartesian intersection would be ideal. My big fear is someone implementing the ND TERR mode by scanning all elevations in a grid. This will bring the tile-manager / ground-cache / terrasync to their knees as they try to load huge amounts of scenery.
zakalawe
 
Posts: 1259
Joined: Sat Jul 19, 2008 5:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Any way to run this Flightgear C method in Nasal?

Postby zakalawe » Sun Dec 11, 2016 10:06 pm

Richard wrote in Sun Dec 11, 2016 4:16 pm: available in the get_cart branch in my development repository. (ssh://r-harrison@git.code.sf.net/u/r-ha ... flightgear). Hopefully it'll all turn out good and we'll be able to merge this into the main source shortly.

Do you want to send me an email about this? I would always prefer to be able to give feedback on such changes at the earliest stage possible, to make the merging process smooth! Or can I look at some changes already? Are they in a suitable state for feedback?
zakalawe
 
Posts: 1259
Joined: Sat Jul 19, 2008 5:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Any way to run this Flightgear C method in Nasal?

Postby Necolatis » Thu Dec 22, 2016 11:50 pm

I just want to say I tested Richards exposure to Nasal, and it worked. Was a small fraction of a foot difference to getElevation() but that's probably due to one of them hitting the runway layer, the other going directly for underlying terrain. Hope it gets commited.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10


Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests