Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Godot;
- using System;
- using System.Diagnostics;
- public class TickMaster : Godot.Node
- {
- int CurrTick = 0;
- int SupposedTickInt = 0;
- double SupposedTickDecims = 0f;
- bool NextPause = false;
- ulong WatchLastTime = 0;
- bool First = true;
- public override void _PhysicsProcess(float delta)
- {
- ++CurrTick;
- if(NextPause)
- {
- Wait(1000);
- NextPause = false;
- GD.Print("Paused.");
- }
- if(Input.IsActionJustPressed("Test_Key_2"))
- {
- NextPause = true;
- GD.Print("Pausing!");
- }
- if(CurrTick % 60 != 0) return;
- if(First)
- {
- First = false;
- SupposedTickInt = CurrTick;
- }
- GD.Print($"Current tick is {CurrTick}, based on time, it's supposed to be {SupposedTickInt}.{(int)(SupposedTickDecims * 1000)}! {SupposedTickInt - CurrTick} difference!");
- //GD.Print($"Current tick is {SupposedTick}, it's supposed to be {SupposedTickDecims}!");
- }
- long SupposedThreasold = 0;
- public override void _Process(float delta)
- {
- ulong now = OS.GetTicksUsec();
- SupposedTickDecims += ((double)(now - WatchLastTime) / 1000000) * 60;
- WatchLastTime = now;
- while(SupposedTickDecims >= 1f)
- {
- SupposedTickDecims -= 1f;
- ++SupposedTickInt;
- }
- /*if(SupposedThreasold <= SupposedTickInt)
- {
- GD.Print($"Current tick should be {SupposedTickInt}.{(int)(SupposedTickDecims * 1000)}!");
- SupposedThreasold += 60;
- }*/
- }
- void Wait(uint millis)
- {
- ulong now = OS.GetTicksUsec();
- ulong then = now + millis * 1000;
- while(now < then)
- {
- now = OS.GetTicksUsec();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement