Esempio n. 1
0
 void Awake(){
     if(useAsSingleton) Instance = this;
     if(poolDictionary == null) poolDictionary = new Dictionary<string, PoolQueue<GameObject>>();
     else return;
     
     for(int i = 0; i < pools.Count; i++)
     {
         Pool pool = pools[i];
         PoolQueue<GameObject> objectPool = new PoolQueue<GameObject>();
         
         for(int j = 0;j<pool.size; j++)
         {
             GameObject obj = Instantiate(pool.prefab, gameObject.transform);
             obj.SetActive(false);
             
             MonoBehaviourPooledObject PooledObjectScript = obj.GetComponent<MonoBehaviourPooledObject>();
             
             if(PooledObjectScript != null) {
                 PooledObjectScript.SetQueue(objectPool);
             }
             
             objectPool.Enqueue(obj);
         }
         
         poolDictionary.Add(pool.tag, objectPool);
         objectPool.poolParent = pool;
     }
     
 }
Esempio n. 2
0
    void Awake()
    {
        if (poolQueue == null)
        {
            poolQueue = new PoolQueue <GameObject>();
        }
        else
        {
            return;
        }

        for (int j = 0; j < pool.size; j++)
        {
            GameObject obj = Instantiate(pool.prefab, gameObject.transform);
            obj.SetActive(false);

            MonoBehaviourPooledObject PooledObjectScript = obj.GetComponent <MonoBehaviourPooledObject>();

            if (PooledObjectScript != null)
            {
                PooledObjectScript.SetQueue(poolQueue);
            }

            poolQueue.Enqueue(obj);
        }

        poolQueue.poolParent = pool;
    }
Esempio n. 3
0
        private void DoTestLoad(Taste.Recommender.Recommender recommender, int allowedTimeSec)
        {
            // TODO: how to specify number of threads
            PoolQueue queue = new PoolQueue(new DefaultThreadPool(), new CommandExecutor());

            Command cmd = delegate
            {
                for (int i = 0; i < NUM_USERS; i++)
                {
                    string id = random.Next(NUM_USERS).ToString();
                    recommender.Recommend(id, 10);
                    if (i % 100 == 50)
                    {
                        recommender.Refresh();
                    }
                }
            };

            long start = DateTime.Now.Ticks;

            for (int i = 0; i < NUM_THREADS; i++)
            {
                queue.Enqueue(cmd);
            }
            long end = DateTime.Now.Ticks;

            double timeMS = TimeSpan.FromTicks(end - start).TotalMilliseconds;

            log.Info("Load test completed in " + timeMS + "ms");
            Assert.IsTrue(timeMS < 1000L * (long)allowedTimeSec);
        }
Esempio n. 4
0
        //操作完成后
        private void verTask_OnCompleted(VerifyProcess sender, VerifyResult arg)
        {
            evtHandlers.Enqueue(sender);
            maxAccepted.Release();

            if (tmpRequest.ContainsKey(arg.Key))
            {
                try
                {
                    Action <VerifyResult> callback = tmpRequest[arg.Key];
                    if (callback != null)
                    {
                        callback(arg);
                    }
                    else
                    {
                        if (OnVerifyCompleted != null)
                        {
                            OnVerifyCompleted(arg);
                        }
                    }
                }
                catch (Exception exp)
                {
                    Logger.AddLog(this.GetType(), "VerifyCenter.Part1", exp.Message);
                }
                finally
                {
                    tmpRequest.Remove(arg.Key);
                }
            }
            else
            {
                try
                {
                    if (OnVerifyCompleted != null)
                    {
                        OnVerifyCompleted(arg);
                    }
                }
                catch (Exception exp)
                {
                    Logger.AddLog(this.GetType(), "VerifyCenter.Part2", exp.Message);
                }
            }
        }
    public void WithdrawToPool()
    {
        gameObject.SetActive(false);

        if (queueBelongsTo != null)
        {
            queueBelongsTo.Enqueue(gameObject);
        }
        else
        {
            Debug.LogWarning("WithdrawToPool unsuccessful: queueBelongsTo is null");
            return;
        }

        if (cachedSpriteRenderer != null)
        {
            cachedSpriteRenderer.flipX = false;
            cachedSpriteRenderer.flipY = false;
        }
    }
Esempio n. 6
0
        private VerifyCenter(int maxTask)
        {
            try
            {
                MaxThreads = maxTask;

                this.maxAccepted = new Semaphore(MaxThreads, MaxThreads);

                tmpRequest = new Dictionary <string, Action <VerifyResult> >();

                evtHandlers = new PoolQueue <VerifyProcess>(MaxThreads + 2);
                for (int i = 0; i < MaxThreads; i++)
                {
                    VerifyProcess verTask = new VerifyProcess();
                    verTask.OnCompleted += verTask_OnCompleted;
                    evtHandlers.Enqueue(verTask);
                }
            }
            catch (Exception exp)
            {
                Logger.AddLog(this.GetType(), "VerifyCenter", exp.Message);
            }
        }
Esempio n. 7
0
        private void DoTestLoad(Taste.Recommender.Recommender recommender, int allowedTimeSec)
	    {
           
            // TODO: how to specify number of threads
            PoolQueue queue = new PoolQueue(new DefaultThreadPool(), new CommandExecutor());
  		   
            Command cmd = delegate
            {
                for (int i = 0; i < NUM_USERS; i++)
                {
                    string id = random.Next(NUM_USERS).ToString();
                    recommender.Recommend(id, 10);
                    if (i % 100 == 50)
                    {
                        recommender.Refresh();
                    }
                }
            };

		    long start = DateTime.Now.Ticks;
		    for (int i = 0; i < NUM_THREADS; i++) 
		    {
                queue.Enqueue(cmd);			    
		    }
		    long end = DateTime.Now.Ticks;	

		    double timeMS = TimeSpan.FromTicks(end - start).TotalMilliseconds;
		    log.Info("Load test completed in " + timeMS + "ms");
		    Assert.IsTrue(timeMS < 1000L * (long) allowedTimeSec);
	    }