public void RenderTicksetsAreExecutedInOrderCreated(int ticksetCount) { // Create tick system with render ticksets CoreTickSystemConfigData coreTickConfigData = TickSystemConstructionUtility.BlankCoreTickSystemConfigData(); coreTickConfigData.renderTicksets = new TicksetConfigData[ticksetCount]; for (int i = 0; i < ticksetCount; i++) { coreTickConfigData.renderTicksets[i] = new TicksetConfigData { ticksetName = i.ToString() }; } new CoreTick(coreTickConfigData); // Create clients in order DemoOrderedRenderTickClient.tickOrderCounter = 0; DemoOrderedRenderTickClient[] clients = new DemoOrderedRenderTickClient[coreTickConfigData.renderTicksets.Length]; for (int i = 0; i < clients.Length; i++) { clients[i] = new DemoOrderedRenderTickClient(coreTickConfigData.renderTicksets[i], i); } // Tick Core.Tick.OnUpdate(0.0334f); // Client tick indices should match their tick keys foreach (var c in clients) { Assert.AreEqual(c.targetOrder, c.thisOrderedEntryResult, "Render ticksets are not executing in the order they were created."); } }
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; } } }
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."); }
public void SimulationTicksetsAreExecutedInOrderCreated(int ticks, int ticksetsPerTick) { // Tick data const float tRate = 0.035f; const float tMax = 0.05f; // Construct data with additional simulation ticks/ticksets CoreTickSystemConfigData coreTickConfigData = TickSystemConstructionUtility.BlankCoreTickSystemConfigData(); coreTickConfigData.simulationTicks = TickSystemConstructionUtility.SimulationTickDataGroup( ticks, ticksetsPerTick, tRate, tMax); new CoreTick(coreTickConfigData); // Create clients in order DemoOrderedSimulationTickClient.tickOrderCounter = 0; List <DemoOrderedSimulationTickClient> clients = new List <DemoOrderedSimulationTickClient>(); int count = 0; for (int i = 0; i < coreTickConfigData.simulationTicks.Length; i++) { for (int e = 0; e < coreTickConfigData.simulationTicks[i].ticksets.Length; e++) { clients.Add(new DemoOrderedSimulationTickClient( coreTickConfigData.simulationTicks[i].ticksets[e], count)); count++; } } // Tick; make sure the delta is long enough to tick simulation float diff = tMax - tRate; Core.Tick.OnUpdate(tMax - (diff / 2)); // Client tick indices should match their tick keys foreach (var c in clients) { Assert.AreEqual(c.targetOrder, c.thisOrderedEntryResult, "Simulation ticksets are not executing in the order they were created."); } }
public void SimulationTickClientsDoRegisterWithSimTicks(int clientCount) { // Create default tick core new CoreTick(TickSystemConstructionUtility.BlankCoreTickSystemConfigData()); // Create and regster clients for (int i = 0; i < clientCount; i++) { DemoSimulationTickClientInstanceRegistrationTest thisClient = new DemoSimulationTickClientInstanceRegistrationTest(); thisClient.RegisterTickClient(); } // Tick once to ready client additions Core.Tick.OnUpdate(TickSystemConstructionUtility.blankSimTickRate); Assert.AreEqual(GetTotalNumberOfSimulationTickSubscribers(), clientCount, "Subscriber count for simulation ticksets do not match number of registrants."); }
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!"); }
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!"); }
public void RenderTickClientsDoUnregisterCorrectly() { // Create default tick core new CoreTick(TickSystemConstructionUtility.BlankCoreTickSystemConfigData()); // Register clients Random r = new Random(); int subCount = r.Next(10, 20); List <DemoRenderTickClientInstanceRegistrationTest> clients = new List <DemoRenderTickClientInstanceRegistrationTest>(); for (int i = 0; i < subCount; i++) { DemoRenderTickClientInstanceRegistrationTest thisClient = new DemoRenderTickClientInstanceRegistrationTest(); thisClient.RegisterTickClient(); clients.Add(thisClient); } // Tick once to ready client additions Core.Tick.OnUpdate(0.01f); // Unrgister clients int remCount = r.Next(3, 8); for (int i = 0; i < remCount; i++) { clients[i].UnregisterTickClient(); } // Tick once to ready client subtractions Core.Tick.OnUpdate(0.01f); Assert.AreEqual(GetTotalNumberOfRenderTickSubscribers(), subCount - remCount, "Subscriber count for render ticksets do not match number of registrants."); }