Beispiel #1
0
        public void GetAndReleaseClearList()
        {
            var list = new List <int> {
                0, 1, 2, 3, 4, 5
            };
            List <int> hackerList;

            using (var pooled = list.ToPooledList())
            {
                hackerList = pooled.List;
                Assert.That(list, Is.EqualTo(pooled.List));
                Assert.That(list, Is.Not.SameAs(pooled.List));
            }
            Assert.That(hackerList.Count, Is.EqualTo(0));
            hackerList.AddRange(list);
            Assert.That(hackerList.Count, Is.EqualTo(list.Count));

            using (var pooled = Pooling.GetList <int>())
            {
                // This relies on the fact that we internally uses a stack, so getting a new one will re-use the last returned one.
                Assert.That(pooled.List, Is.SameAs(hackerList));
                Assert.That(hackerList.Count, Is.EqualTo(0));
            }
        }
Beispiel #2
0
        private void OnServersInit()
        {
            Components = new ShipDockComponentManager
            {
                FrameTimeInScene = (int)(UnityEngine.Time.deltaTime * 1000)
            };

            MethodUpdater updater = ShipDockComponentManagerSetting.isMergeUpdateMode ?
                                    new MethodUpdater
            {
                Update = MergeComponentUpdateMode
            } :
            new MethodUpdater
            {
                Update = SingleFrameComponentUpdateMode
            };
            UpdaterNotice notice = Pooling <UpdaterNotice> .From();

            notice.ParamValue = updater;
            ShipDockConsts.NOTICE_ADD_UPDATE.Broadcast(notice);
            Pooling <UpdaterNotice> .To(notice);

            ShipDockConsts.NOTICE_SCENE_UPDATE_READY.Add(OnSceneUpdateReady);
        }
Beispiel #3
0
    public void ToPool()
    {
#if SHIPDOCK_POOLING
        Pooling <JSONObjectReuse> .To(this);
#endif
    }
Beispiel #4
0
 public void ToPool()
 {
     Pooling <ScopeChecker> .To(this);
 }
Beispiel #5
0
 protected override IGameModel GetNewModel()
 {
     return(Pooling <DruggeryModel> .From());
 }
Beispiel #6
0
        public override string Next()
        {
            // 0. validate parameters
            if ((learningRate == null) || (momentum == null))
            {
                throw new Exception();
            }

            // 3. configure randomizer...
            int[] batchRandomizer   = new int[batchImages.Count()];
            int[] dataSetRandomizer = new int[nofSet];
            log     += "\nTraining data...";
            imagLyrG = new GrayImage();
            imagLyrG.Configure(28, 28, -1.0, 1.0);
            imagLyrG.fData = batchImages[0].fData[0];

            convLyr       = new Convolution();
            convLyr.Input = imagLyrG.Output;
            convLyr.Configure("depth=8; activation=relu(void); kernel=convolution(size = 5, stride = 1, padding = 0, weightfieldsize = 3); outputfieldSize =2");

            convLyr1       = new Convolution();
            convLyr1.Input = convLyr.Output;
            convLyr1.Configure("depth=8; activation=relu(void); kernel=convolution(size = 5, stride = 1, padding = 0, weightfieldsize = 3); outputfieldSize =2");

            poolLyr       = new Pooling();
            poolLyr.Input = convLyr1.Output;
            poolLyr.Configure("kernel=maxpool(size=2, stride=2); outputfieldsize=2");

            concLyr       = new Concatenation();
            concLyr.Input = poolLyr.Output;
            concLyr.Configure("outputfieldsize=2");

            // 1. initialize connection layers
            hiddLyr       = new Connected();
            hiddLyr.Input = concLyr.Output;
            hiddLyr.Configure("neuron=hiddenperceptron; activation=relu(void); nodes=128; outputfieldsize=2(def:2)");;

            // 2. initialize connection layers
            outpLyr       = new Connected();
            outpLyr.Input = hiddLyr.Output;
            outpLyr.Configure("neuron=outputperceptron; activation=linear(void); nodes=10; outputfieldsize=2(def:2)");

            for (int i = 0; i < Epochs; i++)
            {
                //log += "\n\n////////// Epoch[" + i + "]... ///////////////////////////////////////////////////////";

                Global.NextIntArray(0, nofSet, dataSetRandomizer);
                Global.NextIntArray(0, batchImages.Count(), batchRandomizer);
                // single epoch
                for (int j = 0; j < 100; j++) //batch
                {
                    //DisplayWeights();
                    batchLoss = 0;
                    for (int k = 0; k < 6; k++)
                    {
                        imagLyrG.fData = batchImages[batchRandomizer[j]].fData[dataSetRandomizer[k]];
                        convLyr.Next(Propagate.Signal);
                        convLyr1.Next(Propagate.Signal);
                        poolLyr.Next(Propagate.Signal);
                        concLyr.Next(Propagate.Signal);
                        hiddLyr.Next(Propagate.Signal);
                        outpLyr.Next(Propagate.Signal);

                        Node node;
                        probs = new double[outpLyr.Output[0].Rows];
                        for (int l = 0; l < batchImages[batchRandomizer[j]].fData[dataSetRandomizer[k]].Label.Length; l++)
                        {
                            node     = outpLyr.Output[0].GetElement(l, 0);
                            probs[l] = (double)((double?[])node.Element)[Global.Sig];
                            ((double?[])node.Element)[Global.Err] = batchImages[batchRandomizer[j]].fData[dataSetRandomizer[k]].Label[l];
                        }

                        //Set softmax output
                        double[] softmaxOutput = Softmax(probs);
                        for (int l = 0; l < probs.Length; l++)
                        {
                            node = outpLyr.Output[0].GetElement(l, 0);
                            ((double?[])node.Element)[Global.Sig] = softmaxOutput[l];
                        }

                        singleLoss = lossfunc.GetLoss(softmaxOutput, batchImages[batchRandomizer[j]].fData[dataSetRandomizer[k]].Label);

                        // Calculate batch loss
                        batchLoss += singleLoss;

                        //4.4 propagate error and set new weights
                        outpLyr.Next(Propagate.Error);
                        hiddLyr.Next(Propagate.Error);
                        concLyr.Next(Propagate.Error);
                        poolLyr.Next(Propagate.Error);
                        convLyr1.Next(Propagate.Error);
                        convLyr.Next(Propagate.Error);

                        SaveError(outpLyr);
                        SaveError(hiddLyr);
                        SaveError(concLyr);
                        SaveError(convLyr1);
                        SaveError(convLyr);

                        //log += "\n" + Model.ToString();
                    }
                    // 4.5 adjust weights
                    AdjustWeights(outpLyr);
                    AdjustWeights(hiddLyr);
                    AdjustWeights(concLyr);
                    AdjustWeights(convLyr1);
                    AdjustWeights(convLyr);

                    //DisplayWeights();
                    ClearError(outpLyr);
                    ClearError(hiddLyr);
                    ClearError(concLyr);
                    ClearError(convLyr1);
                    ClearError(convLyr);

                    batchLoss = batchLoss / (double)batchSize;
                    //log += "\n" + Model.ToString();
                    Console.WriteLine("Epoch[" + i.ToString() + "]" + "Batch[" + j.ToString() + "]" + "Loss: " + batchLoss.ToString("e4"));
                    log += "\n\nEpoch[" + i.ToString() + "]" + "Batch[" + j.ToString() + "]" + "Loss: " + batchLoss.ToString("e4");
                }
            }
            return(log);
        }
Beispiel #7
0
 void Start()
 {
     mPools = GetComponent <Pooling>();
 }
Beispiel #8
0
 // Start is called before the first frame update
 void Awake()
 {
     c_PoolInstance = this;
 }
Beispiel #9
0
 /// <summary>
 /// Assigns a new weapon to use
 /// </summary>
 /// <param name="newWeapon"></param>
 private void AssignWeapon(GameObject newWeapon)
 {
     CurrentWeapon = Pooling.GetFromPool(newWeapon, BarrelEndTransform.position, transform.rotation).GetComponent <BaseTankWeapon>();
     CurrentWeapon.transform.SetParent(transform);
     CurrentWeapon.transform.localScale = Vector3.one;
 }
Beispiel #10
0
 public override void ToPool()
 {
     Pooling <UpdaterNotice> .To(this);
 }
Beispiel #11
0
 public override void ToPool()
 {
     Pooling <CardNotice> .To(this);
 }
Beispiel #12
0
 protected override IGameModel GetNewModel()
 {
     return(Pooling <BlueprintModel> .From());
 }
Beispiel #13
0
 public TransformSync(Pooling poo)
 {
     m_my = poo;
 }
Beispiel #14
0
 public void SetPool(Pooling <Bird> pooling)
 {
     pool = pooling;
 }
 public static Pooling Instance;//singleton
 private void Awake()
 {
     Instance = this;
 }
Beispiel #16
0
 public override void ToPool()
 {
     Pooling <ParamNotice <T> > .To(this);
 }
Beispiel #17
0
    private void Awake()
    {
        OpenButton.OnClickEvents += Open;

        iconPooling = new Pooling <ConstructIcon>(CreateIcon, 10);
    }
Beispiel #18
0
    //public GameObject backgroundObject;

    void Start()
    {
        PowerUpControl    = topLimitObject.GetComponent <PowerUp>();
        gameController    = topLimitObject.GetComponent <GameController>();
        poolingController = topLimitObject.GetComponent <Pooling>();
    }
Beispiel #19
0
 protected virtual IGameModel GetNewModel()
 {
     return(Pooling <GameModel> .From() as IGameModel);
 }
        public void PlayHitEffect(HitInfo hit, Vector3 effectsOffset = default(Vector3))
        {
            if (!firedOnCurrentFrame)
            {
                firedOnCurrentFrame = true;

                var audio = WeaverAudio.PlayAtPoint(DamageSound, transform.position, channel: AudioChannel.Sound);
                audio.AudioSource.pitch = UnityEngine.Random.Range(audioPitchMin, audioPitchMax);

                //DamageFlashPool.Instantiate(transform.position + effectsOffset, Quaternion.identity);
                Pooling.Instantiate(DamageFlash, transform.position + effectsOffset, Quaternion.identity);

                if (doFlashEffects)
                {
                    flasher.flashInfected();
                }

                switch (DirectionUtilities.DegreesToDirection(hit.Direction))
                {
                case CardinalDirection.Up:
                    if (doBlood)
                    {
                        Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Up);
                    }
                    //HitPuffPool.Instantiate(transform.position, Quaternion.Euler(270f, 90f, 270f));
                    Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(270f, 90f, 270f));
                    break;

                case CardinalDirection.Down:
                    if (doBlood)
                    {
                        Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Down);
                    }
                    Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(-72.5f, -180f, -180f));
                    break;

                case CardinalDirection.Left:
                    if (doBlood)
                    {
                        Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Left);
                    }
                    Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(180f, 90f, 270f));
                    break;

                case CardinalDirection.Right:
                    if (doBlood)
                    {
                        Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Right);
                    }
                    Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(0f, 90f, 270f));
                    break;
                }

                //GameObject hitParticles = Instantiate(Assets.EffectAssets.UninfectedHitPrefab, transform.position + effectsOffset, Quaternion.identity);
                //GameObject hitParticles = InfectedHitPool.Instantiate(transform.position + effectsOffset, Quaternion.identity);

                /*var direction = DirectionUtilities.DegreesToDirection(hit.Direction);
                 *
                 * switch (direction)
                 * {
                 *      case CardinalDirection.Up:
                 *              SetRotation2D(hitParticles.transform, 45f);
                 *              break;
                 *      case CardinalDirection.Down:
                 *              SetRotation2D(hitParticles.transform, 225f);
                 *              break;
                 *      case CardinalDirection.Left:
                 *              SetRotation2D(hitParticles.transform, -225f);
                 *              break;
                 *      case CardinalDirection.Right:
                 *              SetRotation2D(hitParticles.transform, -45f);
                 *              break;
                 * }
                 *
                 * Flings.SpawnFlings(NormalFlings, transform.position + effectsOffset, direction);*/
            }
        }
Beispiel #21
0
 private void DespawnThis()
 {
     ResetValues();
     UpdateHealthBar();
     Pooling.Despawn(gameObject);
 }
Beispiel #22
0
    IEnumerator DestroyCoroutine()
    {
        yield return(new WaitForSeconds(lifeTime));

        Pooling.Release(gameObject);
    }
Beispiel #23
0
    IEnumerator HitRoutine(HitInfo hit)
    {
        //WeaverLog.Log("NAIL TINK ATTACK DIRECTION = " + hit.Direction);
        WeaverGameManager.FreezeGameTime(WeaverGameManager.TimeFreezePreset.Preset3);
        Player.Player1.EnterParryState();
        CameraShaker.Instance.Shake(WeaverCore.Enums.ShakeType.EnemyKillShake);

        //PLAY AUDIO
        WeaverAudio.PlayAtPoint(TinkSound, transform.position);

        var attackDirection = hit.Direction;

        CardinalDirection direction = CardinalDirection.Right;

        if (attackDirection < 360f && attackDirection > 225f)
        {
            direction = CardinalDirection.Down;
        }
        else if (attackDirection <= 225f && attackDirection > 135f)
        {
            direction = CardinalDirection.Left;
        }
        else if (attackDirection <= 135 && attackDirection > 45f)
        {
            direction = CardinalDirection.Up;
        }
        else
        {
            direction = CardinalDirection.Right;
        }

        //WeaverLog.Log("TINK DIRECTION = " + direction);

        switch (direction)
        {
        case CardinalDirection.Up:
            Player.Player1.Recoil(CardinalDirection.Down);
            Pooling.Instantiate(TinkEffectPrefab, Player.Player1.transform.position + new Vector3(0f, 1.5f, 0f), Quaternion.identity);
            break;

        case CardinalDirection.Down:
            Player.Player1.Recoil(CardinalDirection.Up);
            Pooling.Instantiate(TinkEffectPrefab, Player.Player1.transform.position + new Vector3(0f, -1.5f, 0f), Quaternion.identity);
            break;

        case CardinalDirection.Left:
            Player.Player1.Recoil(CardinalDirection.Right);
            Pooling.Instantiate(TinkEffectPrefab, Player.Player1.transform.position + new Vector3(-1.5f, 0f, 0f), Quaternion.identity);
            break;

        case CardinalDirection.Right:
            Player.Player1.Recoil(CardinalDirection.Left);
            Pooling.Instantiate(TinkEffectPrefab, Player.Player1.transform.position + new Vector3(1.5f, 0f, 0f), Quaternion.identity);
            break;
        }

        yield return(null);


        Player.Player1.RecoverFromParry();


        if (enemy != null)
        {
            enemy.OnParry(this, hit);
        }


        yield return(null);

        yield return(new WaitForSeconds(0.15f));
    }
Beispiel #24
0
 /// <summary>
 /// Spanws the player at the spawn location
 /// </summary>
 private void InstantiatePlayer()
 {
     mActivePlayer = Pooling.GetFromPool(PlayerPrefab, PlayerSpawnPoint.position, Quaternion.identity);
 }
Beispiel #25
0
 public override void ToPool()
 {
     Pooling <ProcessingNotice> .To(this);
 }
Beispiel #26
0
 public void Awake()
 {
     Instance      = this;
     particlesList = new List <ParticleSystem>();
 }
Beispiel #27
0
 public void Dispose()
 {
     Pooling <ScopeChecker> .To(this);
 }
Beispiel #28
0
        private void Pooling_Tick(object sender, EventArgs e)
        {
            if (needPooling)
            {
                try
                {
                    Ipaybox.Bill.Pooling();

                    if (InsSumm != Ipaybox.Bill.Amount)
                    {
                        // Обработка денег
                        textBox1.Text += Ipaybox.Bill.LastResult.ToString().Trim() + "\r\n";
                        Decimal bill = Ipaybox.Bill.Amount - InsSumm;
                        InsSumm        = Ipaybox.Bill.Amount;
                        label1.Text    = Ipaybox.Bill.BillCount.ToString();
                        textBox1.Text += "Внесена купюра " + bill.ToString() + "\r\n";
                    }

                    // Обработка ошибок
                    if (Ipaybox.Bill.Error)
                    {
                        Match m = Regex.Match(Ipaybox.Bill.ErrorMsg, @"HEXERR[:](?<val>.*?)");

                        string err = string.Empty;

                        if (m.Success)
                        {
                            err = m.Groups["val"].Value.ToString().Trim();
                        }

                        if (Ipaybox.Bill.ErrorMsg.IndexOf("2 3 7 82 2 2E 23") >= 0)
                        {
                            textBox1.AppendText("Внесена купюра 10. Возврат.\r\n");
                        }
                        else
                        if (Ipaybox.Bill.ErrorMsg.IndexOf("2 3 7 82 3 A7 32") >= 0)
                        {
                            textBox1.AppendText("Внесена купюра 50. Возврат.\r\n");
                        }
                        else
                        if (Ipaybox.Bill.ErrorMsg.IndexOf("2 3 7 82 4 18 46") >= 0)
                        {
                            textBox1.AppendText("Внесена купюра 100. Возврат.\r\n");
                        }
                        else
                        if (Ipaybox.Bill.ErrorMsg.IndexOf("2 3 7 82 5 91 57") >= 0 && Ipaybox.Bill.ErrorMsg.IndexOf("DROP_CASSETTE_REMOVED") < 0)
                        {
                            textBox1.AppendText("Внесена купюра 500. Возврат.\r\n");
                        }
                        else
                        if (Ipaybox.Bill.ErrorMsg.IndexOf("2 3 7 82 6 A 65") >= 0)
                        {
                            textBox1.AppendText("Внесена купюра 1000. Возврат.\r\n");
                        }
                        else
                        {
                            Pooling.Enabled = false;
                            Pooling.Stop();
                            Ipaybox.AddToLog(Ipaybox.Logs.Main, "Ошибка купюроприемника при тестировании в СМ\r\n" + Ipaybox.Bill.ErrorMsg);
                            textBox1.AppendText(Ipaybox.Bill.ErrorMsg + "\r\nОпрос остановлен. Для продолжения нажмите `Сброс` ");

                            Ipaybox.Bill.BillAcceptorActivity = false;
                        }
                    }
                    else
                    {
                        textBox1.AppendText("OK\r\n");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Не удалось обнаружить купюроприемник! " + ex.Message);
                    needPooling = false;
                }
            }
        }
Beispiel #29
0
 public virtual void ToPool()
 {
     Pooling <Notice> .To(this);
 }
Beispiel #30
0
 /// <summary>
 /// Called when the level starts
 /// </summary>
 public void OnLevelStart()
 {
     // Spawn the trophy
     Pooling.GetFromPool(BaseTrophy, SpawnPoint.position, Quaternion.identity);
 }