Canvas Map API: Difference between revisions

Jump to navigation Jump to search
2,400 bytes removed ,  30 January 2014
m
→‎Optimization: remove things addressed by Philosopher's MapStructure framework
m (→‎Optimization: remove things addressed by Philosopher's MapStructure framework)
Line 127: Line 127:


== Optimization ==
== Optimization ==
From an optimization point of view, having to call the .removeAllChildren(); method in each draw routine is probably not strictly necessary, given the sophisticated spatial queries that are now supported by NasalPositioned: if we could look up canvas groups/elements by a key (say VOR/FIX/DME identifier), we could only remove those that are actually out of range - I think the property tree code could be easily modified accordingly, and the NasalPositioned APIs could then be told to return the corresponding subset of "new" geographic positions, instead of having to redundant work.
Overall, we can work with the assumption that the aircraft is usually moving, so permanently updating its center/origin coordinates to selectively prune entries that are no longer in range should be more efficient than doing the whole thing in scripting space.
Overall, we can work with the assumption that the aircraft is usually moving, so permanently updating its center/origin coordinates to selectively prune entries that are no longer in range should be more efficient than doing the whole thing in scripting space.


Line 134: Line 132:


Regarding spatial queries, on the nav-cache side, delta queries would be complex to support. What the C++ NavDisplay does is keep a persistent list which is updated infrequently - only when a setting changes (range, view options config), or when the aircraft moves > 1nm. In C++, computing the delta of two arrays is fast, and that's what I would suggest to avoid the 'remove all children' logic, which is obviously unfriendly to the Canvas. What I'm not sure about, is if Nasal currently has a nice API to compute the difference (added / removed items) between two arrays, but if it's missing I am sure it can be added.
Regarding spatial queries, on the nav-cache side, delta queries would be complex to support. What the C++ NavDisplay does is keep a persistent list which is updated infrequently - only when a setting changes (range, view options config), or when the aircraft moves > 1nm. In C++, computing the delta of two arrays is fast, and that's what I would suggest to avoid the 'remove all children' logic, which is obviously unfriendly to the Canvas. What I'm not sure about, is if Nasal currently has a nice API to compute the difference (added / removed items) between two arrays, but if it's missing I am sure it can be added.
I don't think we have any real Nasal API for getting a delta of two vectors - but I think, we'll want to avoid Nasal-space overhead here (aka a foreach loop), and simply add a corresponding C/C++ extension function, that directly operates on pointers/NasalPositionedGhosts, and then just return the corresponding subset.


On the canvas side, it would obviously be useful to address elements/groups by ID rather than index, because we could then selectively remove entries that are no longer valid. But maybe Tom has a better idea ?
On the canvas side, it would obviously be useful to address elements/groups by ID rather than index, because we could then selectively remove entries that are no longer valid. But maybe Tom has a better idea ?
the whole removeAllChildren() method is unfriendly to the canvas, and should eventually be replaced with something more efficient.
Which is why I would prefer to encapsulate it in some form of helper method, which can later on be re-implemented by touching only a single place.
At the moment, these update() methods are all structured in the same fashion, i.e. calling removeAllChildren() first, and then proceeding with the redrawing stuff - I would prefer to introduce a helper method here, something like having a refresh() method that would hide the removeAllChildren() internals, which could later on by re-implemented by calling a dedicated Nasal extension function to determine the delta between two vectors (like Zakalawe mentioned) - basically something like:
<syntaxhighlight lang="nasal">
var vec1 = [1,2,3];
var vec2 = [0,1,2,4,5];
# return a 2-element vector with removed/added elements
var delta = vec_diff(vec1, vec2)
var removed = delta[0]; # removed now contains all elements that are no longer in the 2nd vector
var added = delta[1]; # contains all elements that are new, i.e. not in the first vector
</syntaxhighlight>
Which would allow us to look up removed elements/groups, and only remove those from the canvas subtree, while just adding new ones as required.
This could be added as a simple extension function, or to optimize things even further, as dedicated NasalPositioned methods, or possibly even as Nasal Ghosts that operate on Canvas pointers directly.


== Full Example: Creating dialogs with embedded Canvas Maps ==
== Full Example: Creating dialogs with embedded Canvas Maps ==

Navigation menu