public GameObject getPooledObject(string poolName)
    {
        if (!_pools.ContainsKey(poolName))
        {
            return(null);
        }

        pool currentPool = _pools[poolName];

        for (int count = 0; count < currentPool.pooledAmount; ++count)
        {
            if (!currentPool.objects[count].activeInHierarchy)
            {
                return(currentPool.objects[count]);
            }
        }

        if (currentPool.willGrow)
        {
            GameObject poolObject = Instantiate(currentPool.objectToPool) as GameObject;

            poolObject.SetActive(false);
            poolObject.transform.parent = currentPool.collector.transform;

            currentPool.objects.Add(poolObject);
            currentPool.pooledAmount++;
            currentPool.collector.name = "(" + poolName + " | " + currentPool.pooledAmount + ")";

            return(poolObject);
        }

        return(null);
    }
Example #2
0
            /// <summary>
            /// 获取成员位图内存池
            /// </summary>
            /// <param name="size">成员位图字节数量</param>
            /// <returns></returns>
            public static pool GetPool(int size)
            {
                int index = size >> 3;

                if (index < pools.Length)
                {
                    pool pool = pools[index];
                    if (pool != null)
                    {
                        return(pool);
                    }
                    interlocked.CompareSetYield(ref poolLock);
                    if ((pool = pools[index]) == null)
                    {
                        try
                        {
                            pools[index] = pool = new pool(size);
                        }
                        finally { poolLock = 0; }
                        return(pool);
                    }
                    poolLock = 0;
                    return(pool);
                }
                return(null);
            }
    public void AddPool(GameObject objectToPull, int size, string poolName, bool expand)
    {
        pool poolToAdd = new pool();

        poolToAdd.InitializePool(gameObject, size, poolName, expand, objectToPull);
        poolArray.Add(poolToAdd);
    }
Example #4
0
    public void createPool(string poolName, int amountToPool, bool willGrow, GameObject objectToPool)
    {
        if (_pools.ContainsKey(poolName))
        {
            return;
        }

        pool newPool = new pool();

        newPool.willGrow     = willGrow;
        newPool.pooledAmount = amountToPool;

        newPool.objectToPool = objectToPool;
        newPool.collector    = new GameObject("(" + poolName + " | " + newPool.pooledAmount + ")");
        newPool.collector.transform.parent = transform;
        newPool.objects = new List <GameObject>();

        _pools.Add(poolName, newPool);

        for (int count = 0; count < amountToPool; ++count)
        {
            GameObject poolObject = Instantiate(objectToPool) as GameObject;

            poolObject.SetActive(false);

            poolObject.transform.parent = newPool.collector.transform;

            newPool.objects.Add(poolObject);
        }
    }
Example #5
0
 /// <summary>
 /// 添加类型对象池
 /// </summary>
 /// <param name="type">对象类型</param>
 /// <param name="pool">类型对象池</param>
 internal static void Add(Type type, pool pool)
 {
     Monitor.Enter(poolLock);
     try
     {
         pools.Add(type, pool);
     }
     finally { Monitor.Exit(poolLock); }
 }
Example #6
0
 /// <summary>
 /// 成员位图类型信息
 /// </summary>
 /// <param name="type">类型</param>
 /// <param name="members">成员索引集合</param>
 /// <param name="fieldCount">字段成员数量</param>
 public type(Type type, fastCSharp.code.memberIndex[] members, int fieldCount)
 {
     Type       = type;
     FieldCount = fieldCount;
     if ((MemberCount = members.Length) < 64)
     {
         MemberMapSize = MemberCount < 32 ? 4 : 8;
     }
     else
     {
         MemberMapSize = ((MemberCount + 63) >> 6) << 3;
     }
     nameIndexSearcher = fastCSharp.stateSearcher.charsSearcher.Create(members.getArray(value => value.Member.Name), true);
     if (MemberCount >= 64)
     {
         Pool = pool.GetPool(MemberMapSize);
         FieldSerializeSize = ((fieldCount + 31) >> 5) << 2;
     }
 }
Example #7
0
    GameObject PoolAddNewObj(GameManager.whichObject _name)
    {
        pool       _pool = pools.Find(x => x.pool_Name == _name);
        GameObject obj   = null;

        if (_pool.pool_Prefab.GetComponent <PhotonView>() == null)
        {
            obj = Instantiate(_pool.pool_Prefab);
            obj.SetActive(false);
            obj.transform.SetParent(this.transform);
        }
        else
        {
            obj = PhotonNetwork.Instantiate(_pool.filePath, Vector3.zero, Quaternion.identity, 0);
            obj.GetComponent <PhotonView>().RPC("SetActiveF", PhotonTargets.All);
        }

        obj.transform.SetParent(transform);
        return(obj);
    }
        // is for draw a some block domino to play
        protected void draw_pull(int howmanyblocks, pool where)
        {
            Random generator = new Random(DateTime.Now.Second); // set srand

            if (howmanyblocks < 2)
                howmanyblocks = 2;

            for (int i = 0; i < howmanyblocks; i++) //Generate block of domino in 'where'
            {
                int a = generator.Next(7);
                int b = generator.Next(7);

                switch (where)
                {
                    case pool.jackpot:
                        {
                            blockdomino_jackpot.Add(new BlockDomino(a, b));
                            break;
                        }
                    case pool.player1:
                        {
                            blockdomino_player1.Add(new BlockDomino(a, b));
                            break;
                        }
                    case pool.player2:
                        {
                            blockdomino_player2.Add(new BlockDomino(a, b));
                            break;
                        }
                    case pool.onboard:
                        {
                            blockdomino_onboard.Add(new BlockDomino(a, b));
                            break;
                        }
                }

            }
        }
 overlaps = new CompoundPairSweepOverlaps(pool, compoundA.ChildCount);
        //This is a most important function to sending blocks from anywhere to anywhere
        protected int transferdomino(pool from, pool to, int[] arrayindex, int howmuch, bool isend)
        {
            List<BlockDomino> temporary = new List<BlockDomino>(); //initializate a temporary list of blocks of domino

            for(int i =0; i < howmuch; i++)
            {
                int currentindex = arrayindex[howmuch - i -1];  // get index from end to begin

                switch (from)
                {
                    case pool.jackpot:
                        {
                            temporary.Add(blockdomino_jackpot[currentindex]);  //save domino to temporary list
                            blockdomino_jackpot.RemoveAt(currentindex);         //remove saved domino from list
                            break;
                        }
                    case pool.player1:
                        {
                            temporary.Add(blockdomino_player1[currentindex]);
                            blockdomino_player1.RemoveAt(currentindex);
                            break;
                        }
                    case pool.player2:
                        {
                            temporary.Add(blockdomino_player2[currentindex]);
                            blockdomino_player2.RemoveAt(currentindex);
                            break;
                        }
                    case pool.onboard:
                        {
                            temporary.Add(blockdomino_onboard[currentindex]);
                            blockdomino_onboard.RemoveAt(currentindex);
                            break;
                        }
                }
            }
            if (isend == true) //if block you have to send to END
            {
                switch (to)
                {
                    case pool.jackpot:
                        {
                            blockdomino_jackpot.AddRange(temporary);
                            break;
                        }
                    case pool.player1:
                        {
                            blockdomino_player1.AddRange(temporary);
                            break;
                        }
                    case pool.player2:
                        {
                            blockdomino_player2.AddRange(temporary);
                            break;
                        }
                    case pool.onboard:
                        {
                            blockdomino_onboard.AddRange(temporary);
                            break;
                        }
                }
            }
            else //if block you have to send to BEGIN
            {
                switch (to)
                {
                    case pool.jackpot:
                        {
                            blockdomino_jackpot.InsertRange(0, temporary);
                            break;
                        }
                    case pool.player1:
                        {
                            blockdomino_player1.InsertRange(0, temporary);
                            break;
                        }
                    case pool.player2:
                        {
                            blockdomino_player2.InsertRange(0, temporary);
                            break;
                        }
                    case pool.onboard:
                        {
                            blockdomino_onboard.InsertRange(0, temporary);
                            break;
                        }
                }

            }

            return 0;
        }
Example #11
0
 var(resultBuf, result, actualBufferLength) = InvokeWithLength(pool, initialBufLength, func, handle);
Example #12
0
    public GameObject RequestToPool(string poolName, Vector3 pos, Vector3 rotation)
    {
        pool poolToRequest = SearchPoolForName(poolName);

        return(poolToRequest.PoolRequest(pos, rotation));
    }
    public GameObject RequestToPool(int poolPos, Vector3 pos, Quaternion rotation)
    {
        pool poolToRequest = poolArray[poolPos];

        return(poolToRequest.PoolRequest(pos, rotation));
    }
 // set  rotate in correct place
 private void set_rotate(pool pool, int index, rotate rotate)
 {
     switch(pool)
     {
         case pool.jackpot:
             {
                 // blockdomino_jackpot[index].Rotate = rotate;
                 break;
             }
         case pool.player1:
             {
                 blockdomino_player1[index].Rotate = rotate;
                 break;
             }
         case pool.player2:
             {
                 blockdomino_player2[index].Rotate = rotate;
                 break;
             }
         case pool.onboard:
             {
                 blockdomino_onboard[index].Rotate = rotate;
                 break;
             }
     }
 }
        public int send_block(int index, int side)
        {
            Console.WriteLine(change);
            if (change == true)
                return -1;
            change = true; //You can not do now anything
            pool pool = new pool();
            pool = get_who_play();

            BlockDomino temporary = new BlockDomino();
            if (pool == pool.player1)
            {
                if (index < 0 || index >= blockdomino_player1.Count)
                    return -1;
                temporary = blockdomino_player1[index];
            }
            else
            {
                if (index < 0 || index >= blockdomino_player2.Count)
                    return -1;
                temporary = blockdomino_player2[index];
            }

            bool no_move_error = true;

            if (left_value == -1)
            {
                if (temporary.Value_Up == temporary.Value_Down)
                {
                    set_rotate(pool, index, rotate.vertical);
                    left_vertical = false;
                    left_value = right_value = temporary.Value_Down;
                }
                else
                {
                    set_rotate(pool, index, rotate.horizonta_left);
                    left_vertical = false;
                    left_value = temporary.Value_Up;
                    right_value = temporary.Value_Down;
                }
                transferdomino(pool, pool.onboard, new int[] { index }, 1, false);
                no_move_error = false;
            }

            if (no_move_error == true)
            {
                if (side == 0)
                {
                    if (left_value == temporary.Value_Down || left_value == temporary.Value_Up)
                    {
                        if (temporary.Value_Down == temporary.Value_Up)
                        {
                            set_rotate(pool, index, rotate.vertical);
                            left_value = temporary.Value_Down;
                            left_vertical = true;
                        }
                        else if (left_value == temporary.Value_Down)
                        {
                            set_rotate(pool, index, rotate.horizonta_left);
                            left_value = temporary.Value_Up;
                            left_vertical = false;
                        }
                        else
                        {
                            set_rotate(pool, index, rotate.horizontal_right);
                            left_value = temporary.Value_Down;
                            left_vertical = false;
                        }
                        transferdomino(pool, pool.onboard, new int[] { index }, 1, false);
                        no_move_error = false;
                    }
                }
                else
                {
                    if (right_value == temporary.Value_Down || right_value == temporary.Value_Up)
                    {
                        if (temporary.Value_Down == temporary.Value_Up)
                        {
                            set_rotate(pool, index, rotate.vertical);
                            right_value = temporary.Value_Down;
                            right_vertical = true;
                        }
                        else if (right_value == temporary.Value_Down)
                        {
                            set_rotate(pool, index, rotate.horizontal_right);
                            right_value = temporary.Value_Up;
                            right_vertical = false;
                        }
                        else
                        {
                            set_rotate(pool, index, rotate.horizonta_left);
                            right_value = temporary.Value_Down;
                            right_vertical = false;
                        }
                        transferdomino(pool, pool.onboard, new int[] { index }, 1, true);
                        no_move_error = false;
                    }
                }
            }

            if (no_move_error == false)
            {
                return 0;
            }
            else
            {
                change = false;
                return -2;
            }
        }