Inheritance: IGameDataStructure
Esempio n. 1
0
        public bool AddDList(DListCommand command)
        {
            //Check if there exists a vertexcollection that could need it
            for (int i = 0; i < _vertices.Count; i++)
            {
                DListCollection coll = _dLists[i];

                if (coll.Contains(command.Offset))
                {
                    return(false);
                }

                else if (coll.IsAdjacentTo(command.Offset, command.Size))
                {
                    //Add to the collection
                    coll.DListCommands.Add(command);
                    if (coll.Offset > command.Offset)
                    {
                        coll.Offset -= command.Size;
                    }

                    //Do some kind of reverse checking on the collection to make sure it now isn't adacent to another collection
                    for (int j = 0; j < _dLists.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }

                        if (coll.IsAdjacentTo(_dLists[j].Offset, _dLists[j].Size))
                        {
                            int newOffset = Math.Min(coll.Offset, _dLists[j].Offset);
                            foreach (DListCommand comm in _dLists[j].DListCommands)
                            {
                                coll.DListCommands.Add(comm);
                            }
                            coll.Offset = newOffset;
                            _dLists.RemoveAt(j);

                            return(true);
                        }
                    }

                    return(true);
                }
            }

            //Create new VertexCollection
            DListCollection newColl = new DListCollection(command.Offset);

            newColl.DListCommands.Add(command);

            _dLists.Add(newColl);

            return(true);
        }
        public bool AddDList(DListCommand command)
        {
            //Check if there exists a vertexcollection that could need it
            for (int i = 0; i < _vertices.Count; i++)
            {
                DListCollection coll = _dLists[i];

                if (coll.Contains(command.Offset))
                    return false;

                else if (coll.IsAdjacentTo(command.Offset, command.Size))
                {
                    //Add to the collection
                    coll.DListCommands.Add(command);
                    if (coll.Offset > command.Offset)
                        coll.Offset -= command.Size;

                    //Do some kind of reverse checking on the collection to make sure it now isn't adacent to another collection
                    for (int j = 0; j < _dLists.Count; j++)
                    {
                        if (i == j)
                            continue;

                        if (coll.IsAdjacentTo(_dLists[j].Offset, _dLists[j].Size))
                        {
                            int newOffset = Math.Min(coll.Offset, _dLists[j].Offset);
                            foreach (DListCommand comm in _dLists[j].DListCommands)
                            {
                                coll.DListCommands.Add(comm);
                            }
                            coll.Offset = newOffset;
                            _dLists.RemoveAt(j);

                            return true;
                        }
                    }

                    return true;
                }
            }

            //Create new VertexCollection
            DListCollection newColl = new DListCollection(command.Offset);

            newColl.DListCommands.Add(command);

            _dLists.Add(newColl);

            return true;
        }