Board index FlightGear Development Nasal

cockpit-view: from --config format to --addon format  Topic is solved

Nasal is the scripting language of FlightGear.

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 9:05 pm

AndersG wrote in Mon Aug 14, 2017 8:49 pm:You can also fetch my quick conversion from here: http://www.gidenstam.org/FlightGear/misc/ModelCockpitView-addon.tar.gz

FWIW: i did have a very quick conversion that didn't require any ""fancy"" stuff... that quick conversion was nothing more than your original code placed in config.xml and main.nas containing nothing more than
Code: Select all
var main = func( root ) {
    # empty main()
} # func main()

but i just didn't/don't like the raw nasal code in the property tree... so that's why i'm trying to use io.load_nasal() to load it...

AndersG wrote in Mon Aug 14, 2017 8:49 pm:However, it should probably be updated with a copy of the arrows from the normal Model View instead of the key binding - in particular as some aircraft uses q/Q for other things...

yeah, i know but then what happens with those keys? i'm guessing something like what SpokenATC is doing would be required so that those keys are only active when the mod is active when we've walked into it via the V/v keys... that can be done but i just wanna get it working properly like this before we step off that cliff ;) ;) ;)
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby AndersG » Mon Aug 14, 2017 9:25 pm

It seems you load the file containing the model_view_handler into a different namespace/hash (namely "model_cockpit_view")?
So it would be model_cockpit_view.model_view_handler in your main.nas file (which I suppose is in the odd ___addon[x]____ something namespace).
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2444
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 9:28 pm

ok, so i renamed "var model_view_handler = {" to "var model_view_handler_code = {" and changed "globals["model-cockpit-view"].model_view_handler = model_view_handler;" to "globals["model-cockpit-view"].model_view_handler = model_view_handler_code;" so i could tell exactly what the loader was crying about now...
Code: Select all
Initializing addon from /home/myuser/myflightgear/Addons/cockpit-view/main.nas in __addon[0]__
Cockpit View initializing...
  model_cockpit_view directory is /home/myuser/myflightgear/Addons/cockpit-view/
  attempting to load /home/myuser/myflightgear/Addons/cockpit-view/view_handler.nas
Nasal runtime error: undefined symbol: model_view_handler_code
  at /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 39
  called from: /home/myuser/myflightgear/Addons/cockpit-view/main.nas, line 51
  called from: /home/myuser/flightgear-dev/fgdata-ng/Nasal/addons.nas, line 26

this seems to tell me that now it is not finding the code loaded by io.load_nasal()... how can i tell if io.load_nasal() has an error loading the file or not? i mean, does it even get loaded before the globals[] line is executed?

i think i'm going to drop back and bring in one of my other playbooks... now that i have some more code examples to work with... i might really just have to go all the way back and load the raw nasal into the property tree like it was originally but i really really really don't want to do it that way...



oh! and when starting the sim clean to try the above code changes, i got a SIGSEV, of all things... nothing to do with this mod, though... we never even got to the --launcher... i didn't even try to backtrace it...
Code: Select all
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffcffff700 (LWP 22394)]
0x00007ffff3ceaf3d in simgear::ResourceManager::findPath (this=0x21fa2e0, aResource="Systems/views.xml", aContext=...)
    at /home/myuser/flightgear-dev/next/simgear/simgear/misc/ResourceManager.cxx:95
95            SGPath path = (*it)->resolve(aResource, aContext);
(gdb) quit
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 9:30 pm

AndersG wrote in Mon Aug 14, 2017 9:25 pm:It seems you load the file containing the model_view_handler into a different namespace/hash (namely "model_cockpit_view")?

yeah, as a way to try to force it into the globals[] space... isn't that the name that we're binding to in the keybindings??

AndersG wrote in Mon Aug 14, 2017 9:25 pm:So it would be model_cockpit_view.model_view_handler in your main.nas file (which I suppose is in the odd ___addon[x]____ something namespace).

ahhhhhhhooooooooohhhhhhhh! i think i see something... lemme look and try again...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby AndersG » Mon Aug 14, 2017 9:33 pm

I think you load the code you load with io.load_nasal() into a different namespace than that of your main.nas. Hence, you can't refer to things in this different namespace directly. Did you look in the archive I linked above?

Is there any reason whatever not to put all of the code in main.nas? It is not very much code anyway.

And if you must load it into its own namespace you could as well use the name the keyboard bindings expect: "model-cockpit-view" - then you wouldn't have to set up the alias.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2444
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 9:47 pm

stupid question: are the underlined items in the below supposed to be the same or no?

globals["model-cockpit-view"].model_view_handler = model_cockpit_view_handler_code;
view.manager.register("Model Cockpit View", model_view_handler);
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 10:00 pm

AndersG wrote in Mon Aug 14, 2017 9:33 pm:I think you load the code you load with io.load_nasal() into a different namespace than that of your main.nas.

yes, i'm trying to force it into globals[] so that it appears in the /nasal property tree branch...

AndersG wrote in Mon Aug 14, 2017 9:33 pm:Hence, you can't refer to things in this different namespace directly.

i think you are saying the following:
1. we're loading main.nas into __addon[0]__
2. then io.load_nasal() is loading the nasal code into __addon[0]__.model_cockpit_view_handler_code
3. but then i'm trying to reference it as model_cockpit_view_handler_code instead of __addon[0]__.model_cockpit_view_handler_code
is that right?

what i'm trying to do is let main.nas load into __addon[0]__ as the loader intends... then to force load the nasal code file into globals[model-cockpit-view] but i'm obviously not seeing the twisted path through the underbrush...

AndersG wrote in Mon Aug 14, 2017 9:33 pm:Did you look in the archive I linked above?

not yet but i suspect that i've already danced that dance... last night... just without your globals[] lines... but i will look shortly...

AndersG wrote in Mon Aug 14, 2017 9:33 pm:Is there any reason whatever not to put all of the code in main.nas? It is not very much code anyway.

i did have it that way at one time... then i tried using io.load_nasal to try to force it into the globals[] area...

AndersG wrote in Mon Aug 14, 2017 9:33 pm:And if you must load it into its own namespace you could as well use the name the keyboard bindings expect: "model-cockpit-view" - then you wouldn't have to set up the alias.

i've asked before if there was some automatic conversion from "_" to "-" when putting things into the property tree but no one answer that question :(
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Aug 14, 2017 11:09 pm

wkitty42 wrote in Mon Aug 14, 2017 9:28 pm:i think i'm going to drop back and bring in one of my other playbooks...

this is what i've done and yes, i had to use AndersG's globals[] code lines... it loads and runs, which is great!

but i'm still confused as to where the nasal code is going because i just do not see it in the property tree like i used to... the only things seen now are the /addons/addon[?] entry, the /sim/view[97000] entry and the /input/keyboard binding entries for the Q/q keys... i understand that the nasal code is in some namespace somewhere but i thought the whole purpose of AndersG's globals[] lines was to get it show up in /nasal like it used to do when loaded as a --config option... whatever...

hopefully it will be in FGAddon soon so that it is distributed automatically... for now, the link is here in my dropbox but it will stop working one day...

unzip it somewhere and use --addon=where/you/unzipped/it/cockpit-view on your flightgear command line to load it for use... you cannot add this line to the additional options box in the --launcher... it must be on the command line...

to use it, use the V/v keys to cycle through the views until you get to the "Model Cockpit View"... from there you can use the Q/q keys to switch between all the other models... yes, you can even view from the aircraft carriers ;)

this is an early version and it is expected that the keys will be changed or at least the code adjusted so that the keys are not bound until you're in the view... that way they won't conflict with the keys your craft may be using... we'll see what happens...

BTW: i still haven't looked at AnderG's code... i wanted to do this on my own... now that i have, i'm not sure if i will get that code or not... right now i can say that what i've done here was done effectively clean-room style with my only capabilities and the bit of help i received here in this topic... thanks to those who assisted!
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby Hooray » Sat Aug 19, 2017 6:37 pm

Like I tried to imply previously, you are over-thinking things here, because what you believe to be the case is actually not true: the stuff in the property tree is not required, it's just one way of loading Nasal scripts - so your assumption that scripts must be loaded into the tree is not correct, which is certainly what was confusing you.

AndersG's "globals" line is all about accessing the global namespace, then it using square brackets to look up sub-namespaces.
There are basically half a dozen of different ways to load Nasal code - one of which is PropertyList encoded XML files that are loaded in the global property tree, which in turn may have <nasal> section that are then loaded/executed (think -set.xml).

Ultimately, most of thehse ways tend to use different context specific "namespaces" to unclutter/better organize the global Nasal namespace (avoid conflicts) - but apart from that there is no exact relationship between stuff loaded into/via the tree vs other approaches (think keyboard/joystick bindings, GUI dialogs etc).

If you really want to learn more, I suggest to look at the articles in the wiki covering namespaces, e.g. starting with:

http://wiki.flightgear.org/Nasal_Namespaces
http://wiki.flightgear.org/index.php?ti ... edirect=no
http://wiki.flightgear.org/Nasal_Namespaces_in-depth

You will find that going through these articles in the given order provides for a very low barrier to entry, even for people without much of a coding background at all.
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: 11354
Joined: Tue Mar 25, 2008 8:40 am

Re: cockpit-view: from --config format to --addon format

Postby ThomasS » Mon Nov 27, 2017 6:59 am

I came across this thread while looking for exactly this type of addon as a viewing tool for my GroundServices addon. Is anyone of you the maintainer of this addon? I found a track to Anders' FlightGear collection where a release of the addon can be downloaded but couldn't find neither a Wiki article nor a source repositiory. Thats a pity. Maybe I can assist. And maybe we can add some additional features to this nice addon.
ThomasS
 
Posts: 94
Joined: Sun Sep 11, 2016 1:21 pm
Location: West of EDDK
Version: 2018.2.1
OS: Linux,MacOS,Windows

Re: cockpit-view: from --config format to --addon format

Postby AndersG » Mon Nov 27, 2017 9:42 am

The source files are in the archive. It is tiny, I don't think there is need for much source control for ~190 lines of configuration.

I wrote it (or rather adapted it from the standard model view that comes with FG) years ago. It is GPLv2+ so you can pick the parts you like from it (if your addon is GPLv2+ too).
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2444
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: cockpit-view: from --config format to --addon format

Postby Hooray » Mon Nov 27, 2017 12:11 pm

Actually, if people find it useful, why not get it committed, even if just to the addons directory ?
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: 11354
Joined: Tue Mar 25, 2008 8:40 am

Re: cockpit-view: from --config format to --addon format

Postby AndersG » Mon Nov 27, 2017 2:42 pm

Hooray wrote in Mon Nov 27, 2017 12:11 pm:Actually, if people find it useful, why not get it committed, even if just to the addons directory ?


Yes, that's another option, but the fact that the cockpit views starts at 0,0,0 is a bit of a usability problem - it works for someone that knows it is a bit of a hack but looks bad for anyone else.
And the model selection should be updated to use the same dialog as the model-view uses now. Might happen eventually, I suppose.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2444
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: cockpit-view: from --config format to --addon format

Postby wkitty42 » Mon Nov 27, 2017 5:40 pm

yeah, i just wanted to convert it over to the --addon format... i still haven't looked at anders' code...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5700
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: cockpit-view: from --config format to --addon format

Postby ThomasS » Tue Nov 28, 2017 12:05 pm

Aah, I also realized the cockpit origin (0,0,0) issue but thought it was a problem on my site. Well, if you don't mind I'll start creating a Wiki page as a home point for the plugin and will link to your archive for now. Depending on upcoming extensions we might decide later where to put the code.

Regarding the cockpit origin issue its my idea to introduce a <cockpit> section to AI model definitions, similar to an aircraft door definition. In combination with an additional property for each AI model (eg. /ai/models/*/modelfile) containing a link to the models XML file this might provide the opportunity for

* having a look from a carriers tower
* having a look from a ground service vehicle
* ground service vehicles attaching an aircrafts door
* maybe even a jetway attaching an AI aircraft (I don't know enough about how jetways work)
ThomasS
 
Posts: 94
Joined: Sun Sep 11, 2016 1:21 pm
Location: West of EDDK
Version: 2018.2.1
OS: Linux,MacOS,Windows

PreviousNext

Return to Nasal

Who is online

Users browsing this forum: No registered users and 0 guests

cron