Exemplo n.º 1
0
        /// <summary>
        /// Add and remove multiple component to an entity
        /// </summary>
        /// <param name="entityHandle"></param>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public void AddRemoveMultipleComponent(GameEntityHandle entityHandle, Span <ComponentType> addSpan, Span <ComponentType> removeSpan)
        {
            ThrowOnInvalidHandle(entityHandle);

            var updateArch = false;

            foreach (ref readonly var componentType in addSpan)
            {
                var componentBoard = GameWorldLL.GetComponentBoardBase(Boards.ComponentType, componentType);
                var cRef           = new ComponentReference(componentType, GameWorldLL.CreateComponent(componentBoard));

                updateArch |= GameWorldLL.AssignComponent(componentBoard, cRef, Boards.Entity, entityHandle);
                GameWorldLL.SetOwner(componentBoard, cRef, entityHandle);
            }

            foreach (ref readonly var componentType in removeSpan)
            {
                updateArch |= GameWorldLL.RemoveComponentReference(GameWorldLL.GetComponentBoardBase(Boards.ComponentType, componentType), componentType, Boards.Entity, entityHandle);
            }

            if (updateArch)
            {
                GameWorldLL.UpdateArchetype(Boards.Archetype, Boards.ComponentType, Boards.Entity, entityHandle);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove a component from an entity.
        /// </summary>
        /// <param name="entityHandle">The entity</param>
        /// <param name="componentType">The component type</param>
        /// <returns>True if the component was removed, false if it did not exist.</returns>
        public bool RemoveComponent(GameEntityHandle entityHandle, ComponentType componentType)
        {
            ThrowOnInvalidHandle(entityHandle);

            if (GameWorldLL.RemoveComponentReference(GameWorldLL.GetComponentBoardBase(Boards.ComponentType, componentType), componentType, Boards.Entity, entityHandle))
            {
                GameWorldLL.UpdateArchetype(Boards.Archetype, Boards.ComponentType, Boards.Entity, entityHandle);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove a component from an entity.
        /// </summary>
        /// <param name="entityHandle">The entity</param>
        /// <param name="componentType">The component type</param>
        /// <returns>True if the component was removed, false if it did not exist.</returns>
        public bool RemoveMultipleComponent(GameEntityHandle entityHandle, Span <ComponentType> componentTypeSpan)
        {
            ThrowOnInvalidHandle(entityHandle);

            var b = true;

            foreach (ref readonly var componentType in componentTypeSpan)
            {
                b &= GameWorldLL.RemoveComponentReference(GameWorldLL.GetComponentBoardBase(Boards.ComponentType, componentType), componentType, Boards.Entity, entityHandle);
            }

            if (b)
            {
                GameWorldLL.UpdateArchetype(Boards.Archetype, Boards.ComponentType, Boards.Entity, entityHandle);
            }

            return(b);
        }