Beispiel #1
0
 internal bool RemoveComponent(QuadTreeGameComponent component)
 {
     if (_gameComponents.Contains(component))
     {
         _gameComponents.Remove(component);
         component.qNode = null;
         return true;
     }
     return false;
 }
Beispiel #2
0
        /// <summary>
        /// Removes a QuadTreeGameComponent derived object from the QuadTree
        /// </summary>
        /// <param name="component">A QuadTreeGameComponent object previously added to the QuadTree</param>
        public void RemoveComponent(QuadTreeGameComponent component)
        {
            if (component != null) {
                if (component.quadTree != this) {
                    return; // wrong quadTree or never added
                }

                if (component.qNode != null) {
                    component.qNode.RemoveComponent(component);
                }
                component.qNode = null;

                if (_gameComponents.Contains(component)) {
                    _gameComponents.Remove(component);
                }
                component.quadTree = null;
            }
        }
Beispiel #3
0
        internal bool AddComponent(QuadTreeGameComponent component)
        {
            if (_gameComponents == null) {
                return false;
            }

            if (!IsInThisNode(component.Position)) {
                return false;
            }

            if (children != null) {
                for (int i = 0; i < 4; i++) {
                    if (children[i] != null) {
                        if (children[i].AddComponent(component))
                            return true;
                    }
                }
            }

            // up to us to store it
            if (component.position.Y == 0) {
                component.position.Y = GetHeightAt(component.Position.X, component.Position.Z);
            }
            component.qNode = this;
            _gameComponents.Add(component);
            return true;
        }
Beispiel #4
0
        public bool AddComponent(QuadTreeGameComponent component)
        {
            if (!_gameComponents.Contains(component))
                _gameComponents.Add(component);

            if (component.qNode != null && component.quadTree == this)
                component.qNode.RemoveComponent(component);
            component.qNode = null;

            component.quadTree = this;

            if (_valid && _root != null)
                _root.AddComponent(component);

            return true;
        }