コード例 #1
0
ファイル: GameCore.cs プロジェクト: LoamNet/Bubbles
    // Unlimited bubbles are positioned in a random orientation
    private void PopulateUnlimitedBubbles()
    {
        if (!internalStateCurrentHasInit)
        {
            DataGeneral readOnlyData = data.GetDataGeneral();
            int         seed         = readOnlyData.seed;
            int         level        = readOnlyData.level;

            rand = new Utils.WichmannRng(seed + level);
            bubbles.Clear();
            guideLines.Clear();

            float bubbleCountFloat = 12.0f * Mathf.Log10(((float)level) + 9.1f) - 9.9f;

            while (bubbles.Count < bubbleCountFloat)
            {
                double    x          = (rand.Next() - 0.5f) * 2;
                double    y          = (rand.Next() - 0.5f) * 2;
                DataPoint screenSize = inputManager.ScreenSizeWorld();
                DataPoint pos        = new DataPoint(x * (screenSize.X - bubbleRadiusStandard), y * (screenSize.Y - bubbleRadiusStandard * 2));
                bubbles.Add(new DataBubble(new DataPoint(pos)));
            }

            events.OnBubblesChange?.Invoke(bubbles);
            events.OnGuideLinesChange?.Invoke(guideLines);

            internalStateCurrentHasInit = true;
        }
    }
コード例 #2
0
 public Benchmark_Float(Utils.WichmannRng rand, string name) : base(rand, name)
 {
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        // General idle states
        case BenchmarkState.Idle:
            // This state intentionally left blank
            break;

        // Run once to set up the benchmark. NOTE: Avoiding const folding chance w/ system random to choose specific seeded random.
        case BenchmarkState.Begin:
            benchmarks = new List <Benchmark>();
            System.Random sysRand = new System.Random();     // Derived by default from system clock. Can be different per system, but it's effectively random.
            rand = new Utils.WichmannRng(BENCH_GENERAL_SEED);
            display.ClearAll();

            // Prevent const folding w/ sys rand, use wichmannRNG for controlled rand in testing
            double sysDouble = sysRand.NextDouble() * 2;
            Debug.Log($"Sys double: {sysDouble}");
            if (sysDouble >= 1)
            {
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
            }
            else
            {
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
            }


            currentBench     = benchmarks[currentBenchIndex];
            run.interactable = false;
            state            = BenchmarkState.Init;
            break;



        case BenchmarkState.Init:
            // Some casual resets. pre-calc/format as much as possible.
            state         = BenchmarkState.Execute;
            preformat     = $"%, {currentBenchIndex}/{benchmarks.Count}";
            progress.text = "";

            // Force a blocking clear for the GC to level the playing field
            System.GC.Collect(generation: 0, mode: GCCollectionMode.Forced, blocking: true);

            // Begin recording right before coroutine start. *nothing* after this but coroutine start.
            startTime = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            // At start of execute
            StartCoroutine(currentBench.Perform(
                               () =>
            {
                // End time before *anything* else.
                endTime = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                state   = BenchmarkState.Display;
            },
                               (percent) =>
            {
                // Preformatted for simple join. String.Join is fastest w/o string builder apparently(?) - minimize perf overhead
                // https://dotnetcoretutorials.com/2020/02/06/performance-of-string-concatenation-in-c/
                progress.text = String.Join("", percent, preformat);
            }
                               ));
            break;

        case BenchmarkState.Execute:
            // This state intentionally left blank
            break;

        case BenchmarkState.Display:
            long diff = endTime - startTime;
            display.AddItem(currentBench.Name, $"{diff}ms");
            progress.text = "";

            if (++currentBenchIndex < benchmarks.Count)
            {
                currentBench = benchmarks[currentBenchIndex];
                state        = BenchmarkState.Init;
            }
            else
            {
                state = BenchmarkState.Finished;
            }
            break;



        // General end state
        case BenchmarkState.Finished:
            run.interactable  = true;
            currentBench      = null;
            currentBenchIndex = 0;
            state             = BenchmarkState.Idle;
            break;
        }
    }
コード例 #4
0
 public Benchmark(Utils.WichmannRng rand, string name)
 {
     this.Name = name;
     this.rand = rand;
 }