Beispiel #1
0
 public void ObjectPool_Constructor_NullFunction_ShouldThrowException()
 {
     //--------------Arrange------------------------------
     //--------------Act----------------------------------
     var result = new ObjectPoolFactory <TestClass>().New(null, null);
     //--------------Assert-------------------------------
 }
Beispiel #2
0
 public CourierClientFactoryImpl(GuidProxy guidProxy, IThreadingProxy threadingProxy, INetworkingProxy networkingProxy, ObjectPoolFactory objectPoolFactory, IPofSerializer pofSerializer)
 {
     this.guidProxy         = guidProxy;
     this.threadingProxy    = threadingProxy;
     this.networkingProxy   = networkingProxy;
     this.objectPoolFactory = objectPoolFactory;
     this.pofSerializer     = pofSerializer;
 }
Beispiel #3
0
        public void ObjectPool_AcquireReleaseObject_CheckWithParallelObjectCreation_ShouldReturnObject()
        {
            //--------------Arrange------------------------------
            TestClass expectedResult = new TestClass();
            var       objectPool     = new ObjectPoolFactory <TestClass>().New(() => expectedResult, (instance) => false);

            Parallel.For(0, 1000, (i, loopState) =>
            {
                //--------------Act----------------------------------
                TestClass actualResult = objectPool.AcquireObject();

                //--------------Assert-------------------------------
                Assert.AreEqual(expectedResult, actualResult);

                Assert.AreEqual(expectedResult.GetValue(i), actualResult.GetValue(i));

                objectPool.ReleaseObject(actualResult);
            });
        }
Beispiel #4
0
    //IEnumerator LoadAsyncScene()
    //{
    //    AsyncOperation asyncload = SceneManager.LoadSceneAsync("desert", LoadSceneMode.Additive);
    //    while (!asyncload.isDone)
    //    {
    //        yield return new WaitForEndOfFrame();
    //    }
    //}

    //private void onLoadingComplete(Scene scene, LoadSceneMode mode)
    //{
    //    Debug.Log("OnSceneLoaded: " + scene.name);
    //    Debug.Log(mode);
    //    SceneManager.sceneLoaded -= onLoadingComplete;

    //    //AppFacade.Instance.SendNotification(LoadingNotify.Open, true);

    //}


    public void InitObjectPools(SimpleJSON.JSONArray ids, string types)
    {
        if (ids == null || ids.Count == 0)
        {
            return;
        }

        var of = new ObjectPoolFactory();

        for (int i = 0; i < ids.Count; i++)
        {
            SimpleJSON.JSONNode p = ids[i];
            int kindId            = p.AsInt;

            string poolname = Utils.getPoolName(kindId, types);
            var    pool     = App.Inst.getObjectPoolManage().getPool(poolname);
            if (pool == null)
            {
                of.createPools(kindId, types);
            }
        }
    }
Beispiel #5
0
        public void ObjectPool_Dispose_ShouldClearObjectList()
        {
            //--------------Arrange------------------------------
            TestClass expectedResult = new TestClass();
            var       objectPool     = new ObjectPoolFactory <TestClass>().New(() => expectedResult, (instance) => false);

            Parallel.For(0, 1000, (i, loopState) =>
            {
                TestClass actualResult = objectPool.AcquireObject();

                Assert.AreEqual(expectedResult, actualResult);

                Assert.AreEqual(expectedResult.GetValue(i), actualResult.GetValue(i));

                objectPool.ReleaseObject(actualResult);
            });

            //--------------Act----------------------------------
            objectPool.Dispose();

            //--------------Assert-------------------------------
        }
 private void OnEnable()
 {
     PoolFactory = (ObjectPoolFactory)target;
 }
Beispiel #7
0
 internal ObjectPool(ObjectPoolFactory factory)
     : this(20, factory)
 {
 }
Beispiel #8
0
 internal ObjectPool(int size, ObjectPoolFactory factory)
 {
     _factory = factory;
     _queue   = new Queue <T>(size);
 }
Beispiel #9
0
 void Awake()
 {
     factory = this;
 }