Board index FlightGear Development Canvas

777 EFB: initial feedback

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 1:50 am

Here are some suggestions on restructuring efb.nas a bit and down-stripping it in the process:

To see how io.include() is used, check out: https://gitorious.org/fg/canvas-hackers ... /GPSmap196
Specifically see the top of the file: https://gitorious.org/fg/canvas-hackers ... map196.nas

As you can see, we're including/using a separate mfd.nas file that contains helpers for "modes" & "pages", and yet another file that implements each page.

The point is not that this is the way this MUST be done, but just to demonstrate how a more flexible approach can be implemented.
In fact, the Avidyne code is much better here - but not as easily reusable.

Given the size of the efb.nas file and the compactness of the gpsmap196 in comparison, you may find that it's fairly straightforward to borrow ideas from it. Let me know if you have any questions or need specific examples/code snippets.

Obviously, understanding how classes and objects work in Nasal would be really useful, but we have fairly good Nasal/OO tutorials, if you disagree, just let us know what's missing, and I can edit the wiki accordingly.

Given your background, my suggested order of reading would be this:

http://wiki.flightgear.org/Howto:Unders ... nd_Methods
http://wiki.flightgear.org/Howto:Start_ ... mmended.29
http://wiki.flightgear.org/Object_orien ... g_in_Nasal
http://wiki.flightgear.org/Object_Orien ... with_Nasal
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: 777 EFB: initial feedback

Postby I-NEMO » Tue Jun 03, 2014 2:09 am

Hooray,

Ok. Will get back to you soon, once I've read the reccomended docs.

Thanks,

I-NEMO
I-NEMO
 
Posts: 102
Joined: Thu Sep 29, 2011 3:09 am
Location: Italy
Callsign: I-NEMO
Version: 2017.2.1
OS: Windows 7 64 bit

Re: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 2:11 am

no hurry please - take it slowly, and make sure that you are enjoying the work :D
If you are getting stuck somewhere, make sure to post a few questions here BEFORE the frustration kicks in !
OOP can be an intimidating concept at first, but we've really been trying to improve those docs recently, so any feedback telling us where we're still lacking would be greatly appreciated, even regardless of the EFB 8)

PS: Being able to use git/gitorious would be another obvious plus, so that you can easily undo/restore changes - otherwise, just keep some backups around
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: 777 EFB: initial feedback

Postby Philosopher » Tue Jun 03, 2014 2:17 am

My nickel saying here would be: variables are a necessary evil -- but don't overuse them! Exactly as Hooray said: vectors would simplify every bit of code that uses it. But animation code should be much much simpler in Canvas because it's so much smarter, and a Nasal block in XML shouldn't be very long at all, certainly not complex.

Thanks for getting in touch. roga multas rogationes! ;)
Philosopher
 
Posts: 1593
Joined: Sun Aug 12, 2012 7:29 pm

Re: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 2:19 am

regarding variables, in general, people want to avoid "global" variables and really use hashes or even classes, as per: http://wiki.flightgear.org/Howto:Coding ... _Framework
But exploring that makes really only sense once OOP is sufficiently understood - even the original ND/PFD code used global/"singleton" hashes here instead of members.
The Avidyne Entegra R9 is basically the only complex instrument that got this right immediately, by supporting an arbitrary number of instances without unnecessary global state ...
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: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 1:56 pm

regarding the comment on using vectors/arrays, and my earlier statement that we can help you reduce the code significantly, here's one such example: https://gitorious.org/fg/fgdata/source/ ... .nas#L1867

Once that is using vectors, the whole thing can be erased in a simple for/foreach loop, like this:
Code: Select all
foreach(var key; myKeys ) {
 key = "";
}


For now, I would ignore the fact that we are going to update the text handling at some point, even just simplifying such constructs will greatly help optimizing the code, and also allow us to get involved with patches. Currently, efb.nas is roughly 2500 lines - I think we can easily reduce it by about 50-60% without making it more complex, i.e. using just constructs that you are already using. Obviously, page handling is rather explicit and verbose at the moment, so I would consider also moving that to a separate file until we can optimize that. Having separate "entities" (files, functions, classes) is generally a good practice, because it helps others to collaborate with you, without inevitably introducing conflicting changes.
For instance, once the whole thing is split across 2-3 different files, I can provide some help to port things, while you can work on a completely different file.
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: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 2:33 pm

Here's another example that can be simplified: https://gitorious.org/fg/fgdata/source/ ... b.nas#L210
Code: Select all
var ChartSelection = ["NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL"];
var ChartName = ["NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL"];


You can simply use a foreach/forindex loop and then call append(ChartSelection, "NULL");
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: 777 EFB: initial feedback

Postby I-NEMO » Tue Jun 03, 2014 10:11 pm

Hallo Hooray,

I'm starting to 'modernize'...

Code: Select all
var ChartSelection_Size = 30;
var ChartSelection = [];
setsize(ChartSelection, ChartSelection_Size);

    forindex(var i; ChartSelection_Size - 1)
      ChartSelection[i] = "NULL";

I got an error: "foreach enumeration of non-vector"

Isn't ChartSelection properly set as a vector?

Regards,

I-NEMO
I-NEMO
 
Posts: 102
Joined: Thu Sep 29, 2011 3:09 am
Location: Italy
Callsign: I-NEMO
Version: 2017.2.1
OS: Windows 7 64 bit

Re: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 10:22 pm

you need to iterate using the VECTOR not the size of the vector:
Code: Select all
var ChartSelection_Size = 30;
var ChartSelection = [];
setsize(ChartSelection, ChartSelection_Size);

forindex(var i; ChartSelection)
 ChartSelection[i] = "NULL";


You can also directly use a foreach loop:
Code: Select all
var ChartSelection_Size = 30;
var ChartSelection = [];
setsize(ChartSelection, ChartSelection_Size);

foreach(var char; ChartSelection)
 char = "NULL";
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: 777 EFB: initial feedback

Postby I-NEMO » Tue Jun 03, 2014 10:31 pm

Hooray,

that's what I was thinking by reading theFGWiki: http://wiki.flightgear.org/Howto:Start_using_vectors_and_hashes_in_Nasal

Code: Select all
var waypoint = {number:1,altitude:2,distance:3,angle:4,length:5,ID:6,bearing:7};
var new_waypoint = func {return {parents:[waypoint] };}
 
var NUM_ELEMENTS = 5;
var waypoints = [];
setsize(waypoints, NUM_ELEMENTS);
 
forindex(var i; NUM_ELEMENTS-1)
    waypoints[i] = new_waypoint();

So, in the example, that NUM_ELEMENTS is NOT the size of the vector waypoints?

Regards,

I-NEMO
I-NEMO
 
Posts: 102
Joined: Thu Sep 29, 2011 3:09 am
Location: Italy
Callsign: I-NEMO
Version: 2017.2.1
OS: Windows 7 64 bit

Re: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 10:35 pm

thanks for pointing that out, will review the wiki article and test the code - it's possible that you found a bug in the docs
Otherwise, you can use a conventional FOR loop (not foreach/forindex, which operate on VECTORS)
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: 777 EFB: initial feedback

Postby I-NEMO » Tue Jun 03, 2014 10:42 pm

No problem.
Got that working with Vectors, now; no more that long silly line of "NULL" !!

Thanks,

I-NEMO
I-NEMO
 
Posts: 102
Joined: Thu Sep 29, 2011 3:09 am
Location: Italy
Callsign: I-NEMO
Version: 2017.2.1
OS: Windows 7 64 bit

Re: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 10:54 pm

good job, you will probably find more opportunities to adapt repetitive code using vectors - especially stuff like hist1..hist6, l0...l20 and r0..r20 is so called "code smell".
index(), update() and clearpage() are also low-hanging fruits.
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: 777 EFB: initial feedback

Postby I-NEMO » Tue Jun 03, 2014 11:12 pm

Already working on those "code smell"...

Thanks,

I-NEMO
I-NEMO
 
Posts: 102
Joined: Thu Sep 29, 2011 3:09 am
Location: Italy
Callsign: I-NEMO
Version: 2017.2.1
OS: Windows 7 64 bit

Re: 777 EFB: initial feedback

Postby Hooray » Tue Jun 03, 2014 11:30 pm

you will probably find that the file will become much smaller, and much easier to navigate, too. Moving certain stuff out of the file into separate Nasal files (via io.include) is also going to help with that. The chart list can be moved into something like "chartlist.db" (file extension doesn't matter!) and then use io.include("chartlist.db") at the top of the file.
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

Next

Return to Canvas

Who is online

Users browsing this forum: No registered users and 4 guests