Esempio n. 1
0
 public void Init(YndFile ynd, YndNode node1, YndNode node2, NodeLink link)
 {
     Ynd     = ynd;
     Node1   = node1;
     Node2   = node2;
     RawData = link;
 }
Esempio n. 2
0
        public void InitNodesFromDictionary()
        {
            if (NodeDictionary != null)
            {
                if (NodeDictionary.Nodes != null)
                {
                    var nodes = NodeDictionary.Nodes;
                    Nodes = new YndNode[nodes.Length];
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        var n = new YndNode();
                        n.Init(this, nodes[i]);
                        Nodes[i] = n;
                        if (n.NodeID != i)
                        {
                        }   //never hit here - nodeid's have to match the index!
                    }
                }
                if ((NodeDictionary.JunctionRefs != null) && (NodeDictionary.Junctions != null))
                {
                    var juncrefs = NodeDictionary.JunctionRefs;
                    var juncs    = NodeDictionary.Junctions;
                    Junctions = new YndJunction[juncrefs.Length];
                    for (int i = 0; i < juncrefs.Length; i++)
                    {
                        var juncref = juncrefs[i];
                        if (juncref.JunctionID >= juncs.Length)
                        {
                            continue;
                        }

                        var j = new YndJunction();
                        j.Init(this, juncs[juncref.JunctionID], juncref);
                        j.Heightmap  = new YndJunctionHeightmap(NodeDictionary.JunctionHeightmapBytes, j);
                        Junctions[i] = j;
                    }
                }
            }
        }
Esempio n. 3
0
        public void UpdateBvhForNode(YndNode node)
        {
            //this needs to be called when a node's position changes...
            //if it changes a lot, need to recalc the BVH for mouse intersection optimisation purposes.

            //if (BVH == null) return;
            //BVH.UpdateForNode(node);

            BuildBVH();

            //also updates the NodePositions for the visible vertex
            if (Nodes != null)
            {
                for (int i = 0; i < Nodes.Length; i++)
                {
                    if (Nodes[i] == node)
                    {
                        NodePositions[i] = new Vector4(node.Position, 1.0f);
                        break;
                    }
                }
            }
        }
Esempio n. 4
0
        public YndNode AddNode()
        {
            int     cnt = Nodes?.Length ?? 0;
            YndNode yn  = new YndNode();
            Node    n   = new Node();

            n.AreaID = (ushort)AreaID;
            n.NodeID = (ushort)cnt;
            yn.Init(this, n);

            int ncnt = cnt + 1;

            YndNode[] nnodes = new YndNode[ncnt];
            for (int i = 0; i < cnt; i++)
            {
                nnodes[i] = Nodes[i];
            }
            nnodes[cnt] = yn;
            Nodes       = nnodes;
            NodeDictionary.NodesCount = (uint)ncnt;

            return(yn);
        }
Esempio n. 5
0
        public YndLink AddLink(YndNode tonode = null)
        {
            YndLink l = new YndLink();

            l._RawData.AreaID = AreaID;
            l.Node1           = this;
            if (tonode != null)
            {
                l.Node2           = tonode;
                l._RawData.AreaID = tonode.AreaID;
                l._RawData.NodeID = tonode.NodeID;
            }
            else if ((Ynd.Nodes != null) && (Ynd.Nodes.Length > 0))
            {
                l.Node2 = Ynd.Nodes[0];
            }
            else
            {
                l.Node2           = this;
                l._RawData.NodeID = NodeID;
            }
            l.UpdateLength();

            int cnt  = Links?.Length ?? 0;
            int ncnt = cnt + 1;

            YndLink[] nlinks = new YndLink[ncnt];
            for (int i = 0; i < cnt; i++)
            {
                nlinks[i] = Links[i];
            }
            nlinks[cnt] = l;
            Links       = nlinks;
            LinkCount   = ncnt;

            return(l);
        }
Esempio n. 6
0
        public bool RemoveNode(YndNode node)
        {
            List <YndNode> newnodes = new List <YndNode>();
            int            cnt      = Nodes?.Length ?? 0;
            bool           r        = false;
            int            ri       = -1;

            for (int i = 0; i < cnt; i++)
            {
                var tn = Nodes[i];
                if (tn != node)
                {
                    newnodes.Add(tn);
                }
                else
                {
                    r  = true;
                    ri = i;
                }
            }
            Nodes = newnodes.ToArray();
            NodeDictionary.NodesCount        = (uint)newnodes.Count;
            NodeDictionary.NodesCountVehicle = Math.Min(NodeDictionary.NodesCountVehicle, NodeDictionary.NodesCount);
            NodeDictionary.NodesCountPed     = Math.Min(NodeDictionary.NodesCountPed, NodeDictionary.NodesCount);

            //remap node ID's...
            List <YndLink> remlinks = new List <YndLink>();

            if (ri >= 0)
            {
                for (int i = 0; i < Nodes.Length; i++)
                {
                    var n = Nodes[i];
                    if (n.NodeID != i)
                    {
                        n.NodeID = (ushort)i;


                        //update nodeid's in links...
                        for (int j = 0; j < Nodes.Length; j++)
                        {
                            var tn = Nodes[j];
                            if ((tn != null) && (tn.Links != null))
                            {
                                for (int bl = 0; bl < tn.Links.Length; bl++)
                                {
                                    var backlink = tn.Links[bl];
                                    if (backlink.Node2 == n)
                                    {
                                        backlink._RawData.NodeID = (ushort)i;
                                    }
                                }
                            }
                        }
                    }

                    //remove any links referencing the node.
                    remlinks.Clear();
                    if (n.Links != null)
                    {
                        for (int l = 0; l < n.Links.Length; l++)
                        {
                            var nlink = n.Links[l];
                            if (nlink.Node2 == node)
                            {
                                remlinks.Add(nlink);
                            }
                        }
                        for (int l = 0; l < remlinks.Count; l++)
                        {
                            n.RemoveLink(remlinks[l]);
                        }
                    }
                }
            }

            UpdateAllNodePositions();

            return(r);
        }
Esempio n. 7
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            Name         = entry.Name;
            RpfFileEntry = entry;

            RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;

            if (resentry == null)
            {
                throw new Exception("File entry wasn't a resource! (is it binary data?)");
            }

            ResourceDataReader rd = new ResourceDataReader(resentry, data);


            NodeDictionary = rd.ReadBlock <NodeDictionary>();

            if (NodeDictionary != null)
            {
                if (NodeDictionary.Nodes != null)
                {
                    var nodes = NodeDictionary.Nodes;
                    Nodes = new YndNode[nodes.Length];
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        var n = new YndNode();
                        n.Init(this, nodes[i]);
                        Nodes[i] = n;
                        if (n.NodeID != i)
                        {
                        }   //never hit here - nodeid's have to match the index!
                    }
                }
                if ((NodeDictionary.JunctionRefs != null) && (NodeDictionary.Junctions != null))
                {
                    var juncrefs = NodeDictionary.JunctionRefs;
                    var juncs    = NodeDictionary.Junctions;
                    Junctions = new YndJunction[juncrefs.Length];
                    for (int i = 0; i < juncrefs.Length; i++)
                    {
                        var juncref = NodeDictionary.JunctionRefs[i];
                        if (juncref.JunctionID >= juncs.Length)
                        {
                            continue;
                        }

                        var j = new YndJunction();
                        j.Init(this, juncs[juncref.JunctionID], juncref);
                        j.Heightmap  = new YndJunctionHeightmap(NodeDictionary.JunctionHeightmapBytes, j);
                        Junctions[i] = j;
                    }
                }
            }

            UpdateAllNodePositions();

            //links will be populated by the space... maybe move that code here?



            string areaidstr = Name.ToLower().Replace("nodes", "").Replace(".ynd", "");
            int    areaid    = 0;

            int.TryParse(areaidstr, out areaid);
            AreaID = areaid;

            UpdateBoundingBox();


            BuildBVH();


            Loaded     = true;
            LoadQueued = true;
        }