public void Activity()
 {
     if (mNodeNetwork != null)
     {
         mNodeNetwork.UpdateShapes();
     }
 }
Пример #2
0
        public static void Update()
        {
            mEditingLogic.Update();

            PerformKeyboardShortcuts();

            //PerformMouseCameraControl();

            mNodeNetwork.UpdateShapes();
        }
        public static void RemoveNodesForCollision(this NodeNetwork network, AxisAlignedRectangle collision)
        {
            var nodeCircle = new Circle {
                Radius = 20f
            };

            for (var i = network.Nodes.Count - 1; i >= 0; i--)
            {
                var node = network.Nodes[i];
                nodeCircle.Position = node.Position;

                if (collision.CollideAgainst(nodeCircle))
                {
                    network.Remove(node);
                }
            }
            network.UpdateShapes();
        }
Пример #4
0
        public NodeNetwork ToNodeNetwork(bool linkHorizontally, bool linkVertically, bool linkDiagonally, bool requireTile)
        {
            var toReturn = new NodeNetwork();


            int layercount = 0;

            foreach (MapLayer mapLayer in this.Layers)
            {
                if (!mapLayer.IsVisible)
                {
                    switch (mapLayer.VisibleBehavior)
                    {
                    case LayerVisibleBehavior.Ignore:
                        break;

                    case LayerVisibleBehavior.Skip:
                        continue;
                    }
                }
                var allNodes = new Dictionary <int, Dictionary <int, Dictionary <int, PositionedNode> > >();
                allNodes[layercount] = new Dictionary <int, Dictionary <int, PositionedNode> >();


                MapLayer mLayer      = mapLayer;
                int      mLayerCount = layercount;
                Parallel.For(0, mapLayer.data[0].tiles.Count, count =>
                {
                    uint gid = mLayer.data[0].tiles[count];

                    Tileset tileSet = GetTilesetForGid(gid);
                    if (tileSet != null || !requireTile)
                    {
                        var node = new PositionedNode();

                        //int tileWidth = requireTile ? tileSet.tilewidth : tilewidth;
                        //int tileHeight = requireTile ? tileSet.tileheight : tileheight;
                        int x = count % this.Width;
                        int y = count / this.Width;

                        float nodex;
                        float nodey;
                        float nodez;

                        CalculateWorldCoordinates(mLayerCount, count, tilewidth, tileheight, mLayer.width, out nodex, out nodey, out nodez);

                        node.X = nodex;
                        node.Y = nodey;
                        node.Z = nodez;

                        lock (allNodes)
                        {
                            if (!allNodes[mLayerCount].ContainsKey(x))
                            {
                                allNodes[mLayerCount][x] = new Dictionary <int, PositionedNode>();
                            }

                            allNodes[mLayerCount][x][y] = node;
                        }
                        node.Name = string.Format("Node {0}", count);
                        lock (toReturn)
                        {
                            toReturn.AddNode(node);
                        }
                    }
                });
                SetupNodeLinks(linkHorizontally, linkVertically, linkDiagonally, allNodes[layercount]);

                RemoveExcludedNodesViaPolygonLayer(toReturn, mapLayer, allNodes[layercount]);
                LowerNodesInNodesDownShapeCollection(mapLayer, allNodes[layercount]);
                RaiseNodesInNodesUpShapeCollection(mapLayer, allNodes[layercount]);

                ++layercount;
            }
            toReturn.UpdateShapes();

            return(toReturn);
        }