Ejemplo n.º 1
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        if (Input.inputString == "1")
        {
            timeScale = 1;
        }

        else if (Input.inputString == "0")
        {
            timeScale = 0;
        }

        else if (Input.inputString != "" && int.TryParse(Input.inputString, out int tempTimeScale) && tempTimeScale != 0)
        {
            timeScale = tempTimeScale * multiplier;
        }
        ;

        //time = new TimeData(World.Time.ElapsedTime, World.Time.DeltaTime * timeScale);
        //World.SetTime(time);
        if (UnityEngine.Time.timeScale != timeScale)
        {
            UnityEngine.Time.timeScale = timeScale;
            FixedRateUtils.EnableFixedRateWithCatchUp(simGroup, UnityEngine.Time.fixedDeltaTime);
        }

        return(inputDependencies);
    }
Ejemplo n.º 2
0
    protected override void OnCreate()
    {
        base.OnCreate();

        simGroup = World.GetOrCreateSystem <SimulationSystemGroup>();
        //FixedRateUtils.EnableFixedRateWithCatchUp(simGroup, UnityEngine.Time.fixedDeltaTime);
        FixedRateUtils.EnableFixedRateSimple(simGroup, UnityEngine.Time.fixedDeltaTime);
    }
Ejemplo n.º 3
0
        public void WorldSimulationFixedStep()
        {
            var world = new World("World A");
            var sim   = world.GetOrCreateSystem <SimulationSystemGroup>();
            var uc    = world.GetOrCreateSystem <UpdateCountSystem>();

            sim.AddSystemToUpdateList(uc);

            // Unity.Core.Hybrid.UpdateWorldTimeSystem
            var timeData = new TimeData();

            void AdvanceWorldTime(float amount)
            {
                uc.updateCount = 0;
                timeData       = new TimeData(timeData.ElapsedTime + amount, amount);
                world.SetTime(timeData);
            }

            FixedRateUtils.EnableFixedRateWithCatchUp(sim, 1.0f);

            // first frame will tick immediately
            AdvanceWorldTime(0.5f);
            world.Update();
            Assert.AreEqual(0.5, uc.lastUpdateTime, 0.001f);
            Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
            Assert.AreEqual(1, uc.updateCount);

            AdvanceWorldTime(1.1f);
            world.Update();
            Assert.AreEqual(1.5, uc.lastUpdateTime, 0.001f);
            Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
            Assert.AreEqual(1, uc.updateCount);

            // No update should happen because the time elapsed is less than the interval
            AdvanceWorldTime(0.1f);
            world.Update();
            Assert.AreEqual(1.5, uc.lastUpdateTime, 0.001f);
            Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
            Assert.AreEqual(0, uc.updateCount);

            AdvanceWorldTime(1.0f);
            world.Update();
            Assert.AreEqual(2.5, uc.lastUpdateTime, 0.001f);
            Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
            Assert.AreEqual(1, uc.updateCount);

            // If time jumps by a lot, we should tick the fixed rate systems
            // multiple times
            AdvanceWorldTime(2.0f);
            world.Update();
            Assert.AreEqual(4.5, uc.lastUpdateTime, 0.001f);
            Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
            Assert.AreEqual(2, uc.updateCount);

            world.Dispose();
        }
Ejemplo n.º 4
0
        public void WorldSimulation_FixedStep_CatchUp()
        {
            using (var world = new World("World A"))
            {
                var sim = world.GetOrCreateSystem <SimulationSystemGroup>();
                var uc  = world.GetOrCreateSystem <UpdateCountSystem>();
                sim.AddSystemToUpdateList(uc);

                // Unity.Core.Hybrid.UpdateWorldTimeSystem
                var timeData = new TimeData();

                void AdvanceWorldTime(float amount)
                {
                    uc.updateCount = 0;
                    timeData       = new TimeData(timeData.ElapsedTime + amount, amount);
                    world.SetTime(timeData);
                }

                FixedRateUtils.EnableFixedRateWithCatchUp(sim, 1.0f);

                // first frame will tick at elapsedTime=0
                AdvanceWorldTime(0.5f);
                world.Update();
                Assert.AreEqual(0.0, uc.lastUpdateTime, 0.001f);
                Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
                Assert.AreEqual(1, uc.updateCount);

                // Advance elapsed time to 1.6 seconds. the second tick should occur at 1.0
                AdvanceWorldTime(1.1f);
                world.Update();
                Assert.AreEqual(1.0, uc.lastUpdateTime, 0.001f);
                Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
                Assert.AreEqual(1, uc.updateCount);

                // Advance elapsed time to 1.7 seconds. No tick should occur.
                AdvanceWorldTime(0.1f);
                world.Update();
                Assert.AreEqual(1.0, uc.lastUpdateTime, 0.001f);
                Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
                Assert.AreEqual(0, uc.updateCount);

                // Advance elapsed time to 2.7 seconds. The third tick should occur at 2.0
                AdvanceWorldTime(1.0f);
                world.Update();
                Assert.AreEqual(2.0, uc.lastUpdateTime, 0.001f);
                Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
                Assert.AreEqual(1, uc.updateCount);

                // Advance elapsed time to 4.9 seconds. The fourth and fifth ticks should occur at 3.0 and 4.0.
                AdvanceWorldTime(2.2f);
                world.Update();
                Assert.AreEqual(4.0, uc.lastUpdateTime, 0.001f);
                Assert.AreEqual(1.0, uc.lastUpdateDeltaTime, 0.001f);
                Assert.AreEqual(2, uc.updateCount);
            }
        }
Ejemplo n.º 5
0
        public void FixedStepSimulationSystemGroup_DisableFixedTimestep_GroupUpdatesOnce()
        {
            var fixedSimGroup     = World.CreateSystem <FixedStepSimulationSystemGroup>();
            var updateTimesSystem = World.CreateSystem <RecordUpdateTimesSystem>();

            fixedSimGroup.AddSystemToUpdateList(updateTimesSystem);
            fixedSimGroup.SortSystems();

            fixedSimGroup.Timestep = 1.0f;
            FixedRateUtils.DisableFixedRate(fixedSimGroup);
            // Simulate a large elapsed time since the previous frame
            World.PushTime(new TimeData(8.5f, 0.01f));
            fixedSimGroup.Update();
            World.PopTime();
            // with fixed timestep disabled, the group should see the same elapsed/delta times as the World.
            CollectionAssert.AreEqual(updateTimesSystem.Updates,
                                      new[]
            {
                new TimeData(8.5f, 0.01f),
            });
        }
Ejemplo n.º 6
0
 private static void SetFixedUpdate()
 {
     FixedRateUtils.EnableFixedRateSimple(World.DefaultGameObjectInjectionWorld.GetExistingSystem <FixedUpdateGroup>(), UnityEngine.Time.fixedDeltaTime);
 }
Ejemplo n.º 7
0
        protected override void OnCreate()
        {
            base.OnCreate();

            FixedRateUtils.EnableFixedRateWithCatchUp(this, UnityEngine.Time.fixedDeltaTime);
        }