Пример #1
0
        public void SimulationTicksDoFireAtCorrectIntervalsRelativeToRenderTick(float mockTickrate)
        {
            // Create new tick core system, override with custom simulation tick
            CoreTickSystemConfigData coreTickConfigData = TickSystemConstructionUtility.BlankCoreTickSystemConfigData();

            coreTickConfigData.simulationTicks =
                TickSystemConstructionUtility.SimulationTickDataGroup(
                    1,
                    1,
                    mockTickrate,
                    float.MaxValue);
            var _ = new CoreTick(coreTickConfigData);

            // Create simulation tick instance
            DemoSimulationTickClientIntervalsTest simTick = new DemoSimulationTickClientIntervalsTest();

            Core.Tick.Register(simTick);

            Random r = new Random();
            float  elapsedSinceLastTick = 0;

            for (int i = 0; i < 100; i++)
            {
                // Tick
                float mockDelta = (float)r.NextDouble();
                Core.Tick.OnUpdate(mockDelta);
                elapsedSinceLastTick += mockDelta;

                // Collect target ticks
                int   targetTicks        = 0;
                float mockSimAccumulator = elapsedSinceLastTick;
                while (mockSimAccumulator >= mockTickrate)
                {
                    mockSimAccumulator -= mockTickrate;
                    targetTicks++;
                }
                elapsedSinceLastTick = mockSimAccumulator;

                // Detect ticks
                if (simTick.ticksSinceLastCheck < targetTicks)
                {
                    Assert.Fail(
                        "Simulation tick client is not ticking enough based on render tickrate: "
                        + "TARGET: " + targetTicks
                        + " RESULT: " + simTick.ticksSinceLastCheck);
                }
                else if (simTick.ticksSinceLastCheck > targetTicks)
                {
                    Assert.Fail(
                        "Simulation tick client is ticking too frequently based on render tickrate: "
                        + "TARGET: " + targetTicks
                        + " RESULT: " + simTick.ticksSinceLastCheck);
                }
                else
                {
                    simTick.ticksSinceLastCheck = 0;
                }
            }
        }
Пример #2
0
 public void CoreTickSystemConfigDataWithNullSimulationTicksDoesFailValidation()
 {
     try
     {
         var _ = new CoreTick(TickSystemConstructionUtility.TickSystemDataWithNullSimulationTicks());
         Assert.Fail("Tick system with null simulation ticks data is passing validation.");
     }
     catch (NullReferenceException)
     {
         // We good, failure happened as expected.
     }
 }
Пример #3
0
 public void CoreTickSystemNullConfigDataDoesFailValidation()
 {
     try
     {
         var _ = new CoreTick(null);
         Assert.Fail("Tick system with null config data is passing validation.");
     }
     catch (NullReferenceException)
     {
         // We good, failure happened as expected.
     }
 }
 public void InvalidDeltaTickIntervalsDoFailValidation(float interval)
 {
     try
     {
         var _ = new CoreTick(TickSystemConstructionUtility.BlankCoreTickSystemConfigData());
         Core.Tick.OnUpdate(interval);
         Assert.Fail("Invalid tick delta intervals are passing validation.");
     }
     catch (ArgumentOutOfRangeException)
     {
         // We good, failure happened as expected.
     }
 }
        public void ElapsedTimeIsAccurateGivenValidConstantDeltaIntervals(float interval)
        {
            var       _         = new CoreTick(TickSystemConstructionUtility.BlankCoreTickSystemConfigData());
            const int tickCount = 50;

            for (int i = 0; i < tickCount; i++)
            {
                Core.Tick.OnUpdate(interval);
            }

            TimeSpan elapsed = TimeSpan.FromSeconds(tickCount * interval);
            float    round   = Math.Abs((float)Core.Tick.elapsedSinceSimStartup.TotalSeconds - (float)elapsed.TotalSeconds);

            Assert.LessOrEqual(round, 0.0001f,
                               "Elapsed time does not add up based on constant delta intervals.");
        }
Пример #6
0
        public void SimulationTicksDoInitializeWithCorrectNumberOfTicksets(int ticks, int ticksetsPerTick)
        {
            // Construct data with additional simulation ticks/ticksets
            CoreTickSystemConfigData coreTickConfigData = TickSystemConstructionUtility.BlankCoreTickSystemConfigData();

            coreTickConfigData.simulationTicks =
                TickSystemConstructionUtility.SimulationTickDataGroup(ticks, ticksetsPerTick);
            var _ = new CoreTick(coreTickConfigData);

            // Total simulation ticksets should be equal to ticks + ticksets per (simulation ticks have no defaults)
            int count = 0;

            foreach (var tick in Core.Tick.simulationTicks)
            {
                count += tick.ticksets.Count;
            }
            Assert.AreEqual(ticks * ticksetsPerTick, count,
                            "Simulation tickset count is not correct!");
        }
Пример #7
0
        public void RenderTickDoesInitializeWithCorrectNumberOfTicksets(int additionalTicksets)
        {
            // Construct data with additoinal render ticksets
            CoreTickSystemConfigData coreTickConfigData = TickSystemConstructionUtility.BlankCoreTickSystemConfigData();

            coreTickConfigData.renderTicksets = new TicksetConfigData[additionalTicksets];
            for (int i = 0; i < additionalTicksets; i++)
            {
                coreTickConfigData.renderTicksets[i] = new TicksetConfigData
                {
                    ticksetName = "testTick_" + i
                };
            }
            var _ = new CoreTick(coreTickConfigData);

            // Total render ticksets should be equal to addtional ticksets plus 1 (the default tickset)
            Assert.AreEqual(additionalTicksets + 1, Core.Tick.renderTick.ticksets.Count,
                            "Render tickset count is not correct!");
        }