Пример #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);
        }
Пример #2
0
 public static void ThreadCheck(World world)
 {
     #if WORLD_THREAD_CHECK
     if (world.worldThread != System.Threading.Thread.CurrentThread)
     {
         WrongThreadException.Throw("Random", "this could cause sync problems");
     }
     #endif
 }
Пример #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 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>();
            }
        }
Пример #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 WORLD_THREAD_CHECK
            if (this.worldThread != System.Threading.Thread.CurrentThread)
            {
                WrongThreadException.Throw("RemoveComponentsPredicate");
            }
            #endif

            if (this.currentState.components.RemoveAllPredicate <TComponent, TComponentPredicate>(entity.id, predicate) > 0)
            {
                this.RemoveComponentFromFilter(in entity);
            }
        }
Пример #5
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 WORLD_THREAD_CHECK
            if (this.worldThread != System.Threading.Thread.CurrentThread)
            {
                WrongThreadException.Throw("RemoveComponents");
            }
            #endif

            if (this.currentState.components.RemoveAll(entity.id) > 0)
            {
                this.currentState.storage.archetypes.RemoveAll(in entity);
                this.RemoveComponentFromFilter(in entity);
            }
        }