mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
Code was changed so that time starts at tick zero, and all entities are initialized in the space between tick 0 to 1. This was a solution to the fact fromSequence was including entities with lastStateUpdate tick one less than the actual sequence number. This is purely an issue about when exactly the game does its logic relative to the tick signals, ie positive or negative edge of the tick. Right now the game is set up to run the game logic on the positive edge of a Tick (enforced by GameLoop). The second big part is that an empty collection takes 5ish bytes more than a null collection in the NetSerializer, even though they are conceptually the same thing in a game state. This PR puts null checks around everything and allows GameStates to have whole sections of itself null. This reduced the payload size of an empty game state from 49B to 15B. This PR also fixes the bug where the physics system marks every movable entity as dirty every tick.
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Interfaces.Timing;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Robust.UnitTesting.Shared.Timing
|
|
{
|
|
[TestFixture]
|
|
[TestOf(typeof(GameLoop))]
|
|
class GameLoop_Test : RobustUnitTest
|
|
{
|
|
/// <summary>
|
|
/// With single step enabled, the game loop should run 1 tick and then pause again.
|
|
/// </summary>
|
|
[Test]
|
|
[Timeout(1000)] // comment this out if you want to debug
|
|
public void SingleStepTest()
|
|
{
|
|
// Arrange
|
|
var elapsedVal = TimeSpan.FromSeconds(Math.PI);
|
|
var newStopwatch = new Mock<IStopwatch>();
|
|
newStopwatch.SetupGet(p => p.Elapsed).Returns(elapsedVal);
|
|
var gameTiming = GameTimingFactory(newStopwatch.Object);
|
|
var loop = new GameLoop(gameTiming);
|
|
|
|
var callCount = 0;
|
|
loop.Tick += (sender, args) => callCount++;
|
|
loop.Render += (sender, args) => loop.Running = false; // break the endless loop for testing
|
|
|
|
// Act
|
|
loop.SingleStep = true;
|
|
loop.Run();
|
|
|
|
// Assert
|
|
Assert.That(callCount, Is.EqualTo(1));
|
|
Assert.That(gameTiming.CurTick, Is.EqualTo(new GameTick(2)));
|
|
Assert.That(gameTiming.Paused, Is.True); // it will pause itself after running each tick
|
|
Assert.That(loop.SingleStep, Is.True); // still true
|
|
}
|
|
|
|
private static IGameTiming GameTimingFactory(IStopwatch stopwatch)
|
|
{
|
|
var timing = new GameTiming();
|
|
|
|
var field = typeof(GameTiming).GetField("_realTimer", BindingFlags.Static | BindingFlags.NonPublic);
|
|
field.SetValue(null, stopwatch);
|
|
|
|
return timing;
|
|
}
|
|
}
|
|
}
|