Пример #1
0
        public static EntityAction <TComponent> Create(World world)
        {
            var instance = PoolClass <EntityAction <TComponent> > .Spawn();

            world.RegisterEntityAction(instance);
            return(instance);
        }
 public override void Recycle()
 {
     this.anchorPosition = default;
     this.rotation       = default;
     this.scale          = default;
     PoolClass <RectState> .Recycle(this);
 }
Пример #3
0
 public void Copy(Node from, ref Node to)
 {
     if (to == null)
     {
         to = PoolClass <GridNode> .Spawn();
     }
     to.CopyFrom(from);
 }
Пример #4
0
 public static void Release(ref FiltersStorage storage)
 {
     if (storage == null)
     {
         return;
     }
     PoolClass <FiltersStorage> .Recycle(ref storage);
 }
Пример #5
0
        public static TState CreateState <TState>() where TState : class, IStateBase, new()
        {
            var state = PoolClass <TState> .Spawn();

            state.entityId = default;
            state.tick     = default;
            return(state);
        }
Пример #6
0
        public static void ReleaseState <TState>(ref State state) where TState : State, new()
        {
            state.entityId    = default;
            state.tick        = default;
            state.randomState = default;
            PoolClass <TState> .Recycle((TState)state);

            state = null;
        }
Пример #7
0
        public override void RemoveNode(ref Node node, bool bruteForceConnections = false)
        {
            base.RemoveNode(ref node, bruteForceConnections);

            var g = (GridNode)node;

            PoolClass <GridNode> .Recycle(ref g);

            node = null;
        }
 public void Dispose()
 {
     this.internalCall      = default;
     this.animationComplete = default;
     this.hierarchyComplete = default;
     this.baseComplete      = default;
     this.instance          = null;
     this.parameters        = default;
     PoolClass <ShowHideClosureParametersClass> .Recycle(this);
 }
Пример #9
0
        public virtual T AddNode <T>() where T : Node, new()
        {
            var node = PoolClass <T> .Spawn();

            node.graph = this;
            node.index = this.nodes.Count;
            this.nodes.Add(node);

            return(node);
        }
Пример #10
0
        public static void CreateWorld <TState>(ref World <TState> worldRef, float tickTime, int forcedWorldId = 0) where TState : class, IState <TState>, new()
        {
            if (worldRef != null)
            {
                WorldUtilities.ReleaseWorld(ref worldRef);
            }
            worldRef = PoolClass <World <TState> > .Spawn();

            worldRef.SetId(forcedWorldId);
            ((IWorldBase)worldRef).SetTickTime(tickTime);
            Worlds <TState> .Register(worldRef);
        }
Пример #11
0
        /// <summary>
        /// Initializes the contents of the stack from an existing collection.
        /// </summary>
        /// <param name="collection">A collection from which to copy elements.</param>
        private void InitializeFromCollection(IEnumerable <T> collection)
        {
            // We just copy the contents of the collection to our stack.
            Node lastNode = null;

            foreach (T element in collection)
            {
                Node newNode = (this.usePool == true ? PoolClass <Node> .Spawn() : new Node());
                newNode.m_value = element;
                newNode.m_next  = lastNode;
                lastNode        = newNode;
            }

            m_head = lastNode;
        }
Пример #12
0
        public static string UnpackDirect(Packer packer)
        {
            var length = Int32Serializer.UnpackDirect(packer);
            var sb     = PoolClass <System.Text.StringBuilder> .Spawn();

            sb.Clear();
            sb.Capacity = length;
            for (int i = 0; i < length; ++i)
            {
                sb.Append(CharSerializer.UnpackDirect(packer));
            }
            var res = sb.ToString();

            PoolClass <System.Text.StringBuilder> .Recycle(ref sb);

            return(res);
        }
Пример #13
0
        /// <summary>
        /// Local helper function to Pop an item from the stack, slow path
        /// </summary>
        /// <param name="result">The popped item</param>
        /// <returns>True if succeeded, false otherwise</returns>
        private bool TryPopCore(out T result)
        {
            Node poppedNode;

            if (TryPopCore(1, out poppedNode) == 1)
            {
                result = poppedNode.m_value;
                if (this.usePool == true)
                {
                    PoolClass <Node> .Recycle(ref poppedNode);
                }
                return(true);
            }

            result = default(T);
            return(false);
        }
Пример #14
0
        public static void ReleaseWorld <TState>(ref World world) where TState : State, new()
        {
            if (world == null || world.isActive == false)
            {
                world = null;
                return;
            }

            Worlds.DeInitializeBegin();
            var w = world;

            world.RecycleResetState <TState>();
            PoolClass <World> .Recycle(ref w);

            world.RecycleStates <TState>();
            Worlds.UnRegister(world);
            Worlds.DeInitializeEnd();
        }
Пример #15
0
        /// <summary>
        /// Inserts an object at the top of the <see cref="ConcurrentStack{T}"/>.
        /// </summary>
        /// <param name="item">The object to push onto the <see cref="ConcurrentStack{T}"/>. The value can be
        /// a null reference (Nothing in Visual Basic) for reference types.
        /// </param>
        public void Push(T item)
        {
            // Pushes a node onto the front of the stack thread-safely. Internally, this simply
            // swaps the current head pointer using a (thread safe) CAS operation to accomplish
            // lock freedom. If the CAS fails, we add some back off to statistically decrease
            // contention at the head, and then go back around and retry.

            Node newNode = (this.usePool == true ? PoolClass <Node> .Spawn() : new Node());

            newNode.m_value = item;
            newNode.m_next  = m_head;
            if (Interlocked.CompareExchange(ref m_head, newNode, newNode.m_next) == newNode.m_next)
            {
                return;
            }

            // If we failed, go to the slow path and loop around until we succeed.
            PushCore(newNode, newNode);
        }
Пример #16
0
        /// <summary>
        /// Removes all objects from the <see cref="ConcurrentStack{T}"/>.
        /// </summary>
        public void Clear()
        {
            // Clear the list by setting the head to null. We don't need to use an atomic
            // operation for this: anybody who is mutating the head by pushing or popping
            // will need to use an atomic operation to guarantee they serialize and don't
            // overwrite our setting of the head to null.
            var current = this.m_head;

            this.m_head = null;

            if (this.usePool == true)
            {
                while (current != null)
                {
                    PoolClass <Node> .Recycle(ref current);

                    current = current.m_next;
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Notifies that resource was deactivated.
        /// </summary>
        /// <remarks>
        /// This function should call direct only owner/manager of this resource.
        /// </remarks>
        /// <param name="source">The source of deactivation.</param>
        public virtual void NotifyDeactivated(object source)
        {
            using (var ob = PoolClass <HashSet <MyResource> > .Acquire())
            {
                HashSet <MyResource> collectedResources = ob;
                collectedResources.Clear();

                CollectResources(collectedResources, false);

                foreach (var collectedResource in collectedResources)
                {
                    collectedResource.NotifyDeactivated(this);
                }
            }

            // removed, it's "Storkovina"
            //this.IsActivated = false;

            OnDeactivated(source);
        }
Пример #18
0
        public static void CreateWorld <TState>(ref World worldRef, float tickTime, int forcedWorldId = 0, uint seed = 1u) where TState : State, new()
        {
            if (seed <= 0u)
            {
                seed = 1u;
            }

            if (worldRef != null)
            {
                WorldUtilities.ReleaseWorld <TState>(ref worldRef);
            }
            worldRef = PoolClass <World> .Spawn();

            worldRef.SetId(forcedWorldId);
            var worldInt = worldRef;

            worldInt.SetSeed(seed);
            worldInt.SetTickTime(tickTime);
            Worlds.Register(worldRef);
        }
Пример #19
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            Debug.Log(SingletonDebug.GetPtr().text());
        } // Q Down

        if (Input.GetKeyDown(KeyCode.W))
        {
            Debug.Log(MonoBehaviourSingletonDebug.GetPtr().text());
        } // Q Down

        if (Input.GetKeyDown(KeyCode.E))
        {
            new DataFromCSV("/Excels/buildings.csv");
        } // Q Down

        if (Input.GetKeyDown(KeyCode.A))
        {
            PoolClass pool = new PoolClass();
            pool.InitPoolType <DebugInput>(1);

            var temp2 = pool.GetObject <pepe>();
            var temp3 = pool.GetObject <pepe>();

            pool.FreeObject <pepe>(temp2);
            temp3 = pool.GetObject <pepe>();
        } // Q Down

        if (Input.GetKeyDown(KeyCode.S))
        {
            PoolGameObject pool = new PoolGameObject();
            pool.InitPoolGameObject(gameObject, "DebugInput", 1);

            var temp2 = pool.GetGameObject("DebugInput");
            var temp3 = pool.GetGameObject("DebugInput");

            pool.FreeGameObject("DebugInput", temp2);
        } // Q Down
    }
Пример #20
0
        /// <summary>
        /// Attempts to pop and return the object at the top of the <see cref="ConcurrentStack{T}"/>.
        /// </summary>
        /// <param name="result">
        /// When this method returns, if the operation was successful, <paramref name="result"/> contains the
        /// object removed. If no object was available to be removed, the value is unspecified.
        /// </param>
        /// <returns>true if an element was removed and returned from the top of the <see
        /// cref="ConcurrentStack{T}"/>
        /// succesfully; otherwise, false.</returns>
        public bool TryPop(out T result)
        {
            Node head = m_head;

            //stack is empty
            if (head == null)
            {
                result = default(T);
                return(false);
            }
            if (Interlocked.CompareExchange(ref m_head, head.m_next, head) == head)
            {
                result = head.m_value;
                if (this.usePool == true)
                {
                    PoolClass <Node> .Recycle(ref head);
                }
                return(true);
            }

            // Fall through to the slow path.
            return(TryPopCore(out result));
        }
Пример #21
0
        public override void OnRecycle()
        {
            this.size                 = default;
            this.nodeSize             = default;
            this.initialPenalty       = default;
            this.diagonalCostFactor   = default;
            this.connectionsType      = default;
            this.agentHeight          = default;
            this.checkMask            = default;
            this.collisionMask        = default;
            this.collisionCheckRadius = default;

            if (this.nodes != null)
            {
                Debug.Log("Recycle: " + this.nodes.Count);
                for (int i = 0; i < this.nodes.Count; ++i)
                {
                    var node = (GridNode)this.nodes[i];
                    PoolClass <GridNode> .Recycle(ref node);
                }

                this.nodes.Clear();
            }
        }
Пример #22
0
 public static void ReleaseState <TState>(ref TState state) where TState : class, IStateBase, new()
 {
     state.entityId = default;
     state.tick     = default;
     PoolClass <TState> .Recycle(ref state);
 }
Пример #23
0
 public static void Release(ref FiltersStorage storage)
 {
     PoolClass <FiltersStorage> .Recycle(ref storage);
 }
Пример #24
0
 public static void Release(ref Storage storage)
 {
     PoolClass <Storage> .Recycle(ref storage);
 }
Пример #25
0
        public static void ReleaseWorld <TState>(ref World <TState> world) where TState : class, IState <TState>, new()
        {
            Worlds <TState> .UnRegister(world);

            PoolClass <World <TState> > .Recycle(ref world);
        }
Пример #26
0
 public IViewsProvider <TEntity> Create()
 {
     return(PoolClass <UnityGameObjectProvider <TEntity> > .Spawn());
 }
Пример #27
0
 public static void Release <T>(ref Storage <T> storage) where T : struct, IEntity
 {
     PoolClass <Storage <T> > .Recycle(ref storage);
 }
Пример #28
0
 public static void Release(ref Components components)
 {
     PoolClass <Components> .Recycle(ref components);
 }
Пример #29
0
 public static void Release <TEntity, TState>(ref Components <TEntity, TState> components) where TState : class, IState <TState>, new() where TEntity : struct, IEntity
 {
     PoolClass <Components <TEntity, TState> > .Recycle(ref components);
 }
Пример #30
0
 public void Destroy(IViewsProvider <TEntity> instance)
 {
     PoolClass <UnityGameObjectProvider <TEntity> > .Recycle((UnityGameObjectProvider <TEntity>) instance);
 }