Canvas MapStructure: Difference between revisions

Jump to navigation Jump to search
m
Line 735: Line 735:
Under the hood, this is using some fancy meta-programming that Philosopher came up with last year - but all you need to know as a MapStructure/ND contributor is that styling and caching work in conjunction as long as you follow a few simple rules - which can easily translate into significant frame rate gains when compared to the old method. This section is intended to describe the basic method, as well as provide a few examples/pointers - we're hoping to grow this over time.
Under the hood, this is using some fancy meta-programming that Philosopher came up with last year - but all you need to know as a MapStructure/ND contributor is that styling and caching work in conjunction as long as you follow a few simple rules - which can easily translate into significant frame rate gains when compared to the old method. This section is intended to describe the basic method, as well as provide a few examples/pointers - we're hoping to grow this over time.


First of all, let's consider an existing example: VOR.symbol:
First of all, let's consider an existing layer/example already using caching properly: VOR.symbol:


<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
var drawVOR = func(group) {
var drawVOR = func(group) {
     group.createChild("path")
     return group.createChild("path")
         .moveTo(-15,0)
         .moveTo(-15,0)
         .lineTo(-7.5,12.5)
         .lineTo(-7.5,12.5)
Line 775: Line 775:
'''df_style''' is a new hash that contains styling defaults for this particular layer.
'''df_style''' is a new hash that contains styling defaults for this particular layer.


Otherwise, everything else in the drawVOR() function can be considered to be "hard-coded". The only other thing worth keeping in mind here is that  Nasal will implicitly return the last expression to the caller absent any explicit return statements - i.e. the group will be returned to the caller (for the sake of clarity, you could also add an explicit return statement here).
Otherwise, everything else in the drawVOR() function can be considered to be "hard-coded". When looking at other examples, the only other thing worth keeping in mind here is that  Nasal will implicitly return the last expression to the caller absent any explicit return statements - i.e. the group will be returned to the caller (for the sake of clarity, you could also add an explicit return statement, as is done in the snippet above).
 
However, the code snippet above is just a drawing routine that is still unknown to the system, so that needs to be done is to set up a corresponding cache entry, which can be seen below:
However, the code snippet above is just a drawing routine that is still unknown to the system, so that needs to be done is to set up a corresponding cache entry, which can be seen below:


Navigation menu