Ejemplo n.º 1
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
     {
         m_physics = null;
     }
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
     {
         m_syncObject = null;
     }
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
     {
         m_gameLogic = null;
     }
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         PositionComp = new MyNullPositionComponent();
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
     {
         m_hierarchy = null;
     }
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         Render = new MyNullRenderComponent();
     }
 }
Ejemplo n.º 2
0
 void Components_ComponentAdded(Type t, Sandbox.Common.Components.MyComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
     {
         m_physics = c as MyPhysicsBody;
     }
     else if (t == typeof(MySyncComponentBase))
     {
         m_syncObject = c as MySyncComponentBase;
     }
     else if (t == typeof(MyGameLogicComponent))
     {
         m_gameLogic = c as MyGameLogicComponent;
     }
     else if (t == typeof(MyPositionComponentBase))
     {
         m_position = c as MyPositionComponentBase;
     }
     else if (t == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = c as MyHierarchyComponentBase;
     }
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
Ejemplo n.º 3
0
 void Components_ComponentRemoved(Type t, Sandbox.Common.Components.MyComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
     {
         m_physics = null;
     }
     else if (t == typeof(MySyncComponentBase))
     {
         m_syncObject = null;
     }
     else if (t == typeof(MyGameLogicComponent))
     {
         m_gameLogic = null;
     }
     else if (t == typeof(MyPositionComponentBase))
     {
         m_position = null;
     }
     else if (t == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = null;
     }
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = null;
     }
 }
Ejemplo n.º 4
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
     {
         m_physics = c as MyPhysicsBody;
     }
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
     {
         m_syncObject = c as MySyncComponentBase;
     }
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
     {
         m_gameLogic = c as MyGameLogicComponent;
     }
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         m_position = c as MyPositionComponentBase;
         if (m_position == null)
         {
             PositionComp = new MyNullPositionComponent();
         }
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
     {
         m_hierarchy = c as MyHierarchyComponentBase;
     }
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
         {
             Render = new MyNullRenderComponent();
         }
     }
 }
Ejemplo n.º 5
0
 public override void OnAddedToContainer(MyComponentContainer container)
 {
     base.OnAddedToContainer(container);
     m_syncObject              = container.Get <MySyncComponentBase>();
     m_physics                 = container.Get <MyPhysicsComponentBase>();
     m_hierarchy               = container.Get <MyHierarchyComponentBase>();
     container.ComponentAdded += container_ComponentAdded;
 }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_syncObject                = Container.Get <MySyncComponentBase>();
     m_physics                   = Container.Get <MyPhysicsComponentBase>();
     m_hierarchy                 = Container.Get <MyHierarchyComponentBase>();
     Container.ComponentAdded   += container_ComponentAdded;
     Container.ComponentRemoved += container_ComponentRemoved;
 }
 void container_ComponentRemoved(Type type, MyEntityComponentBase comp)
 {
     if (type == typeof(MySyncComponentBase))
         m_syncObject = null;
     else if (type == typeof(MyPhysicsComponentBase))
         m_physics = null;
     else if (type == typeof(MyHierarchyComponentBase))
         m_hierarchy = null;
 }
 void container_ComponentAdded(Type type, MyEntityComponentBase comp)
 {
     if (type == typeof(MySyncComponentBase))
         m_syncObject = comp as MySyncComponentBase;
     else if (type == typeof(MyPhysicsComponentBase))
         m_physics = comp as MyPhysicsComponentBase;
     else if (type == typeof(MyHierarchyComponentBase))
         m_hierarchy = comp as MyHierarchyComponentBase;
 }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_syncObject = Container.Get<MySyncComponentBase>();
     m_physics = Container.Get<MyPhysicsComponentBase>();
     m_hierarchy = Container.Get<MyHierarchyComponentBase>();
     Container.ComponentAdded += container_ComponentAdded;
     Container.ComponentRemoved += container_ComponentRemoved;
 }
Ejemplo n.º 10
0
 public void RemoveChildEntity(MyEntity child)
 {
     if (MyFakes.ENABLE_PLANET_HIERARCHY)
     {
         if (child.Parent == this)
         {
             MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>();
             m_sectors.RemoveProxy((int)childHierarchy.ChildId);
             Hierarchy.RemoveChild(child, true);
         }
     }
 }
Ejemplo n.º 11
0
        public override void Close()
        {
            ((IMyGameLogicComponent)this.GameLogic).Close();
            MyHierarchyComponent <MyEntity> hierarchy = this.m_entity.Hierarchy;

            while (true)
            {
                if (hierarchy != null)
                {
                    ListReader <MyHierarchyComponentBase> children = hierarchy.Children;
                    if (children.Count > 0)
                    {
                        MyHierarchyComponentBase childHierarchy = hierarchy.Children[hierarchy.Children.Count - 1];
                        childHierarchy.Container.Entity.Close();
                        hierarchy.RemoveByJN(childHierarchy);
                        continue;
                    }
                }
                this.CallAndClearOnClosing();
                MyEntities.RemoveName(this.m_entity);
                MyEntities.RemoveFromClosedEntities(this.m_entity);
                if (this.m_entity.Physics != null)
                {
                    this.m_entity.Physics.Close();
                    this.m_entity.Physics = null;
                    this.m_entity.RaisePhysicsChanged();
                }
                MyEntities.UnregisterForUpdate(this.m_entity, true);
                MyEntities.UnregisterForDraw(this.m_entity);
                if ((hierarchy == null) || (hierarchy.Parent == null))
                {
                    MyEntities.Remove(this.m_entity);
                }
                else
                {
                    this.m_entity.Parent.Hierarchy.RemoveByJN(hierarchy);
                    if (this.m_entity.Parent.InScene)
                    {
                        this.m_entity.OnRemovedFromScene(this.m_entity);
                    }
                    MyEntities.RaiseEntityRemove(this.m_entity);
                }
                if (this.m_entity.EntityId != 0)
                {
                    MyEntityIdentifier.RemoveEntity(this.m_entity.EntityId);
                }
                this.CallAndClearOnClose();
                base.Closed = true;
                return;
            }
        }
 void container_ComponentRemoved(Type type, MyEntityComponentBase comp)
 {
     if (type == typeof(MySyncComponentBase))
     {
         m_syncObject = null;
     }
     else if (type == typeof(MyPhysicsComponentBase))
     {
         m_physics = null;
     }
     else if (type == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = null;
     }
 }
 void container_ComponentAdded(Type type, MyEntityComponentBase comp)
 {
     if (type == typeof(MySyncComponentBase))
     {
         m_syncObject = comp as MySyncComponentBase;
     }
     else if (type == typeof(MyPhysicsComponentBase))
     {
         m_physics = comp as MyPhysicsComponentBase;
     }
     else if (type == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = comp as MyHierarchyComponentBase;
     }
 }
Ejemplo n.º 14
0
        public void AddChildEntity(MyEntity child)
        {
            if (MyFakes.ENABLE_PLANET_HIERARCHY)
            {
                var bbox = child.PositionComp.WorldAABB;

                ProfilerShort.Begin("Add sector to tree.");
                int proxyId = m_sectors.AddProxy(ref bbox, child, 0);
                ProfilerShort.BeginNextBlock("Add to child hierarchy.");
                Hierarchy.AddChild(child, true);
                ProfilerShort.End();

                MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>();
                childHierarchy.ChildId = proxyId;
            }
            else
            {
                MyEntities.Add(child);
            }
        }
Ejemplo n.º 15
0
        public override void Close()
        {
            GameLogic.Close();
            //doesnt work in parallel update
            //Debug.Assert(MySandboxGame.IsMainThread(), "Entity.Close() called not from Main Thread!");
            Debug.Assert(MyEntities.UpdateInProgress == false, "Do not close entities directly in Update*, use MarkForClose() instead");
            Debug.Assert(MyEntities.CloseAllowed == true, "Use MarkForClose()");
            //Debug.Assert(!Closed, "Close() called twice!");

            //Children has to be cleared after close notification is send
            while (m_entity.Hierarchy.Children.Count > 0)
            {
                MyHierarchyComponentBase compToRemove = m_entity.Hierarchy.Children[m_entity.Hierarchy.Children.Count - 1];
                Debug.Assert(compToRemove.Parent != null, "Entity has no parent but is part of children collection");

                compToRemove.Container.Entity.Close();

                m_entity.Hierarchy.Children.Remove(compToRemove);
            }

            //OnPositionChanged = null;

            CallAndClearOnClosing();

            MyEntities.RemoveName(m_entity);
            MyEntities.RemoveFromClosedEntities(m_entity);

            if (m_entity.Physics != null)
            {
                m_entity.Physics.Close();
                m_entity.Physics = null;

                m_entity.RaisePhysicsChanged();
            }

            MyEntities.UnregisterForUpdate(m_entity, true);


            if (m_entity.Hierarchy.Parent == null) //only root objects are in entities list
            {
                MyEntities.Remove(m_entity);
            }
            else
            {
                m_entity.Parent.Hierarchy.Children.Remove(m_entity.Hierarchy);

                //remove children first
                if (m_entity.Parent.InScene)
                {
                    m_entity.OnRemovedFromScene(m_entity);
                }

                MyEntities.RaiseEntityRemove(m_entity);
            }

            if (m_entity.EntityId != 0)
            {
                MyEntityIdentifier.RemoveEntity(m_entity.EntityId);
            }

            //this.EntityId = 0;
            Debug.Assert(m_entity.Hierarchy.Children.Count == 0);

            CallAndClearOnClose();

            Closed = true;
        }
Ejemplo n.º 16
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = c as MyPhysicsBody;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = c as MySyncComponentBase;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = c as MyGameLogicComponent;
     else if (t == typeof(MyPositionComponentBase))
         m_position = c as MyPositionComponentBase;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
Ejemplo n.º 17
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
         m_physics = null;
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
         m_syncObject = null;
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
         m_gameLogic = null;
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
         PositionComp = new MyNullPositionComponent();
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
         m_hierarchy = null;
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         Render = new MyNullRenderComponent();
     }
 }
Ejemplo n.º 18
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
         m_physics = c as MyPhysicsBody;
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
         m_syncObject = c as MySyncComponentBase;
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
         m_gameLogic = c as MyGameLogicComponent;
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         m_position = c as MyPositionComponentBase;
         if (m_position == null)
             PositionComp = new MyNullPositionComponent();
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
             Render = new MyNullRenderComponent();
     }
 }
Ejemplo n.º 19
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = null;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = null;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = null;
     else if (t == typeof(MyPositionComponentBase))
         m_position = null;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = null;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = null;
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Every object must have this method, but not every phys object must necessarily have something to cleanup
        /// <remarks>
        /// </remarks>
        /// </summary>
        public void Delete()
        {
            Close();
            BeforeDelete();
            GameLogic.Close();
            //doesnt work in parallel update
            //Debug.Assert(MySandboxGame.IsMainThread(), "Entity.Close() called not from Main Thread!");
            Debug.Assert(MyEntities.UpdateInProgress == false, "Do not close entities directly in Update*, use MarkForClose() instead");
            Debug.Assert(MyEntities.CloseAllowed == true, "Use MarkForClose()");
            Debug.Assert(!Closed, "Close() called twice!");

            //Children has to be cleared after close notification is send
            while (Hierarchy.Children.Count > 0)
            {
                MyHierarchyComponentBase compToRemove = Hierarchy.Children[Hierarchy.Children.Count - 1];
                Debug.Assert(compToRemove.Parent != null, "Entity has no parent but is part of children collection");

                compToRemove.Container.Entity.Delete();

                Hierarchy.Children.Remove(compToRemove);
            }

            //OnPositionChanged = null;

            CallAndClearOnClosing();

            MyDecals.RemoveModelDecals(this);
            MyEntities.RemoveName(this);
            MyEntities.RemoveFromClosedEntities(this);

            if (m_physics != null)
            {
                m_physics.Close();
                Physics = null;

                RaisePhysicsChanged();
            }

            MyEntities.UnregisterForUpdate(this, true);


            if (Parent == null) //only root objects are in entities list
            {
                // Commented out - causes assertion when pasting grids
                //Debug.Assert(MyEntities.Exist(this), "Entity does not have parent and is not in MyEntities");
                MyEntities.Remove(this);
            }
            else
            {
                Parent.Hierarchy.Children.Remove(this.Hierarchy);

                //remove children first
                if (Parent.InScene)
                {
                    OnRemovedFromScene(this);
                }

                MyEntities.RaiseEntityRemove(this);
            }

            if (this.EntityId != 0)
            {
                MyEntityIdentifier.RemoveEntity(this.EntityId);
            }

            //this.EntityId = 0;
            Debug.Assert(this.Hierarchy.Children.Count == 0);

            CallAndClearOnClose();

            Components.Clear();

            ClearDebugRenderComponents();

            Closed = true;
        }