Exemplo n.º 1
0
        /// <summary>
        /// Add component for entity
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="data"></param>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TComponent"></typeparam>
        public TComponent AddComponent <TComponent>(Entity entity, TComponent data) where TComponent : class, IComponent
        {
            #if WORLD_STATE_CHECK
            if (this.HasStep(WorldStep.LogicTick) == false && this.HasResetState() == true)
            {
                OutOfStateException.ThrowWorldStateCheck();
            }
            #endif

            #if WORLD_THREAD_CHECK
            if (this.worldThread != System.Threading.Thread.CurrentThread)
            {
                WrongThreadException.Throw("AddComponent");
            }
            #endif

            this.currentState.components.Add(entity.id, data);
            if (this.currentState.filters.HasInFilters <TComponent>() == true)
            {
                this.currentState.storage.archetypes.Set <TComponent>(in entity);
            }
            this.AddComponentToFilter(entity);

            return(data);
        }
Exemplo n.º 2
0
        public bool AddMarker <TMarker>(TMarker markerData) where TMarker : struct, IMarker
        {
            #if WORLD_STATE_CHECK
            if (this.isActive == true && this.HasStep(WorldStep.LogicTick) == true)
            {
                OutOfStateException.ThrowWorldStateCheckVisual();
            }
            #endif

            ref var exists = ref World.MarkersDirectCache <TMarker> .exists;
Exemplo n.º 3
0
        /// <summary>
        /// Remove all components with type TComponent from all entities
        /// This method doesn't update any filter, you should call UpdateFilter manually
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        public void RemoveComponents <TComponent>() where TComponent : class, IComponent
        {
            #if WORLD_STATE_CHECK
            if (this.HasStep(WorldStep.LogicTick) == false && this.HasResetState() == true)
            {
                OutOfStateException.ThrowWorldStateCheck();
            }
            #endif

            if (this.currentState.components.RemoveAll <TComponent>() > 0)
            {
                this.currentState.storage.archetypes.RemoveAll <TComponent>();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Remove all components with type from certain entity by predicate
        /// </summary>
        /// <param name="entity"></param>
        public void RemoveComponentsPredicate <TComponent, TComponentPredicate>(Entity entity, TComponentPredicate predicate) where TComponent : class, IComponent where TComponentPredicate : IComponentPredicate <TComponent>
        {
            #if WORLD_STATE_CHECK
            if (this.HasStep(WorldStep.LogicTick) == false && this.HasResetState() == true)
            {
                OutOfStateException.ThrowWorldStateCheck();
            }
            #endif

            if (this.currentState.components.RemoveAllPredicate <TComponent, TComponentPredicate>(entity.id, predicate) > 0)
            {
                this.RemoveComponentFromFilter(in entity);
            }
        }
Exemplo n.º 5
0
        private void RemoveMarkers()
        {
            #if WORLD_STATE_CHECK
            if (this.isActive == true && this.HasStep(WorldStep.LogicTick) == true)
            {
                OutOfStateException.ThrowWorldStateCheckVisual();
            }
            #endif

            foreach (var item in this.allExistMarkers)
            {
                item.arr[this.id] = false;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add component for entity
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="data"></param>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TComponent"></typeparam>
        public TComponent AddComponent <TComponent>(Entity entity, TComponent data) where TComponent : class, IComponent
        {
            #if WORLD_STATE_CHECK
            if (this.HasStep(WorldStep.LogicTick) == false && this.HasResetState() == true)
            {
                OutOfStateException.ThrowWorldStateCheck();
            }
            #endif

            this.currentState.components.Add(entity.id, data);
            this.currentState.storage.archetypes.Set <TComponent>(in entity);
            this.AddComponentToFilter(entity);

            return(data);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Remove all components from certain entity
        /// </summary>
        /// <param name="entity"></param>
        public void RemoveComponents(Entity entity)
        {
            #if WORLD_STATE_CHECK
            if (this.HasStep(WorldStep.LogicTick) == false && this.HasResetState() == true)
            {
                OutOfStateException.ThrowWorldStateCheck();
            }
            #endif

            if (this.currentState.components.RemoveAll(entity.id) > 0)
            {
                this.currentState.storage.archetypes.RemoveAll(in entity);
                this.RemoveComponentFromFilter(in entity);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Remove all components with type TComponent from all entities
        /// This method doesn't update any filter, you should call UpdateFilter manually
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        public void RemoveComponents <TComponent>() where TComponent : class, IComponent
        {
            #if WORLD_STATE_CHECK
            if (this.HasStep(WorldStep.LogicTick) == false && this.HasResetState() == true)
            {
                OutOfStateException.ThrowWorldStateCheck();
            }
            #endif

            #if WORLD_THREAD_CHECK
            if (this.worldThread != System.Threading.Thread.CurrentThread)
            {
                WrongThreadException.Throw("RemoveComponents");
            }
            #endif

            if (this.currentState.components.RemoveAll <TComponent>() > 0)
            {
                this.currentState.storage.archetypes.RemoveAll <TComponent>();
            }
        }