diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas index 2c864a850..5e0511eba 100644 --- a/Nasal/canvas/api.nas +++ b/Nasal/canvas/api.nas @@ -319,16 +319,25 @@ var Group = { # type can be group, text createChild: func(type, id = nil) { - var factory = me._element_factories[type]; - + var factory = me._getFactory(type); if( factory == nil ) - { - debug.dump("canvas.Group.createChild(): unknown type (" ~ type ~ ")"); return nil; - } - + return factory([me._node, type], id); }, + # Create multiple children of given type + createChildren: func(type, count) + { + var factory = me._getFactory(type); + if( factory == nil ) + return []; + + var nodes = me._node.addChildren(type, count, 0, 0); + for(var i = 0; i < count; i += 1) + nodes[i] = factory(nodes[i], nil); # TODO id. Maybe -? + + return nodes; + }, # Get a vector of all child elements getChildren: func() { @@ -386,6 +395,15 @@ var Group = { { # Create element from existing node return me._element_factories[ node.getName() ](node, nil); + }, + _getFactory: func(type) + { + var factory = me._element_factories[type]; + + if( factory == nil ) + debug.dump("canvas.Group.createChild(): unknown type (" ~ type ~ ")"); + + return factory; } }; diff --git a/Nasal/canvas/map/taxiways.draw b/Nasal/canvas/map/taxiways.draw index 0980c064c..6cfaf337f 100644 --- a/Nasal/canvas/map/taxiways.draw +++ b/Nasal/canvas/map/taxiways.draw @@ -1,40 +1,41 @@ var draw_taxiways = func(group, apt, lod) { # TODO: the LOD arg isn't stricly needed here, # the layer is a conventional canvas group, so it can access its map # parent and just read the "range" property to do LOD handling - group.set("z-index",-100); # HACK: we need to encapsulate this + group.set("z-index",-100) # HACK: we need to encapsulate this + .set("stroke", "none"); # var group = group.createChild("group", "apt-"~apt.id); #FIXME: we don't need to use two nested groups for each taxiway - performance? # group = group.createChild("group", "taxiways"); # print("drawing taxiways for:", apt.id); # Taxiways drawn first so the runways and parking positions end up on top. - foreach(var taxi; apt.taxiways) - { - var clr = SURFACECOLORS[taxi.surface]; - if (clr == nil) { clr = SURFACECOLORS[0]}; - var icon_taxi = - group.createChild("path", "taxi") - .setStrokeLineWidth(0) - .setColor(clr.r, clr.g, clr.b) - .setColorFill(clr.r, clr.g, clr.b); + # Preallocate all paths at once to gain some speed + var taxi_paths = group.createChildren("path", size(apt.taxiways)); + var i = 0; + foreach(var taxi; apt.taxiways) + { + var clr = SURFACECOLORS[taxi.surface]; + if (clr == nil) { clr = SURFACECOLORS[0]}; - var txi = Runway.new(taxi); - var beg1 = txi.pointOffCenterline(0, 0.5 * taxi.width); - var beg2 = txi.pointOffCenterline(0, -0.5 * taxi.width); - var end1 = txi.pointOffCenterline(taxi.length, 0.5 * taxi.width); - var end2 = txi.pointOffCenterline(taxi.length, -0.5 * taxi.width); + var txi = Runway.new(taxi); + var beg1 = txi.pointOffCenterline(0, 0.5 * taxi.width); + var beg2 = txi.pointOffCenterline(0, -0.5 * taxi.width); + var end1 = txi.pointOffCenterline(taxi.length, 0.5 * taxi.width); + var end2 = txi.pointOffCenterline(taxi.length, -0.5 * taxi.width); - icon_taxi.setDataGeo - ( - [ canvas.Path.VG_MOVE_TO, - canvas.Path.VG_LINE_TO, - canvas.Path.VG_LINE_TO, - canvas.Path.VG_LINE_TO, - canvas.Path.VG_CLOSE_PATH ], - [ beg1[0], beg1[1], - beg2[0], beg2[1], - end2[0], end2[1], - end1[0], end1[1] ] - ); - } + taxi_paths[i].setColorFill(clr.r, clr.g, clr.b) + .setDataGeo + ( + [ canvas.Path.VG_MOVE_TO, + canvas.Path.VG_LINE_TO, + canvas.Path.VG_LINE_TO, + canvas.Path.VG_LINE_TO, + canvas.Path.VG_CLOSE_PATH ], + [ beg1[0], beg1[1], + beg2[0], beg2[1], + end2[0], end2[1], + end1[0], end1[1] ] + ); + i += 1; + } } diff --git a/Nasal/props.nas b/Nasal/props.nas index 5c8aea147..da8531f75 100644 --- a/Nasal/props.nas +++ b/Nasal/props.nas @@ -15,6 +15,7 @@ var Node = { getChild : func wrap(_getChild(me._g, arg)), getChildren : func wrap(_getChildren(me._g, arg)), addChild : func wrap(_addChild(me._g, arg)), + addChildren : func wrap(_addChildren(me._g, arg)), removeChild : func wrap(_removeChild(me._g, arg)), removeChildren : func wrap(_removeChildren(me._g, arg)), getAliasTarget : func wrap(_getAliasTarget(me._g, arg)),