File size: 1,380 Bytes
00437a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Photon.Deterministic;

namespace Quantum
{
	public unsafe class BotSDKTimerSystem : SystemMainThread
	{
		public override void OnInit(Frame frame)
		{
			// We store the game's initial delta time so we can use it to further know
			// if the delta time was changed (i.e to create slowdown or speedups)
			frame.Global->BotSDKData.OriginalDeltaTime = FP._1 / frame.SessionConfig.UpdateFPS;
		}

		public override void Update(Frame frame)
		{
			BotSDKData* botSDKData = &frame.Global->BotSDKData;

			// If the delta time was not changed, this tick counts as 1
			if (botSDKData->OriginalDeltaTime == frame.DeltaTime)
			{
				botSDKData->ElapsedTicks += 1;
			}
			else
			{
				// If the delta time was changed, we accumulate it as a "partial tick" value
				// Once the partial tick value reaches at least 1 tick, we get the integer part of it
				// to add to actual elapsed ticks
				// Basically, if the simulation is running at half of the initial delta time, it will take double the time for one
				// elapsed tick to be counted
				botSDKData->ElapsedPartialTicks += frame.DeltaTime * frame.SessionConfig.UpdateFPS;
				if (botSDKData->ElapsedPartialTicks >= 1)
				{
					var integerPart = FPMath.FloorToInt(botSDKData->ElapsedPartialTicks);
					botSDKData->ElapsedTicks += integerPart;
					botSDKData->ElapsedPartialTicks -= integerPart;
				}
			}
		}
	}
}