Пример #1
0
        public EPropQuadTreeDivisionResult ResolveDivision(EPropQuadTreeDivisionDecider decider)
        {
            var expectedNodeType = decider.WhatTypeShouldNodeBe(_rectangle.RealSpaceRectangle);
            var currentNodeType  = _node.NodeType;

            var idChanges    = new List <EPropIdChange>();
            var scopesToFree = new List <LocaleBufferScopeIndexType>();

            if (expectedNodeType == currentNodeType)
            {
                if (currentNodeType == EPropQuadTreeNodeType.Complex)
                {
                    var complexNode = _node as EPropQuadTreeComplex;
                    var complexNodeDivisionResult = complexNode.ResolveDivision(decider.ChildElementDecider());

                    idChanges.AddRange(complexNodeDivisionResult.IdChanges);
                    scopesToFree.AddRange(complexNodeDivisionResult.ScopesToFree);
                }
            }
            else
            {
                Dictionary <LocaleBufferScopeIndexType, EPropLocaleBufferScopeRegistry> scopes = _node.TakeAwayAllScopes();
                if (expectedNodeType == EPropQuadTreeNodeType.Leaf)
                {
                    var leafNode = new EPropQuadTreeLeaf(_rectangle, _localeBufferManager);
                    _node = leafNode;
                    leafNode.SetScopes(scopes);
                }
                else
                {
                    var flatPositionWithId = scopes.SelectMany(c =>
                    {
                        var allLocales = c.Value.RetriveAllLocales();
                        return(allLocales.Select(k => new EPropElevationIdWithFlatPosition()
                        {
                            FlatPosition = k.FlatPosition,
                            Id = new EPropElevationId()
                            {
                                InScopeIndex = k.InScopeIndex,
                                LocaleBufferScopeIndex = c.Key
                            }
                        }));
                    }).ToList();
                    var complexNode = new EPropQuadTreeComplex(_rectangle, _localeBufferManager);
                    var complexNodeDivisionResult = complexNode.ResolveDivision(decider.ChildElementDecider());

                    idChanges.AddRange(complexNodeDivisionResult.IdChanges);
                    scopesToFree.AddRange(complexNodeDivisionResult.ScopesToFree);

                    _node = complexNode;
                    idChanges.AddRange(flatPositionWithId.Select(c =>
                                                                 new EPropIdChange()
                    {
                        NewId = _node.RegisterProp(c.FlatPosition),
                        OldId = c.Id
                    }
                                                                 ));

                    scopesToFree.AddRange(scopes.Keys);
                }
            }

            return(new EPropQuadTreeDivisionResult()
            {
                IdChanges = idChanges,
                ScopesToFree = scopesToFree
            });
        }
Пример #2
0
 public EPropQuadTreeBaseNode(MyQuantRectangle rectangle, EPropLocaleBufferManager localeBufferManager)
 {
     _rectangle           = rectangle;
     _localeBufferManager = localeBufferManager;
     _node = new EPropQuadTreeLeaf(rectangle, localeBufferManager);
 }