MotV => MotionBase, FPS -> FpsCounter

This commit is contained in:
2026-06-14 01:00:43 +02:00
parent 892132e1af
commit cd8ba47564
13 changed files with 80 additions and 80 deletions

View File

@@ -0,0 +1,37 @@
using System;
using System.Diagnostics;
namespace _2DGAMELIB
{
public class FpsCounter
{
public Stopwatch sw = new Stopwatch();
private long last_frame;
public double Value;
private double ticks_per_frame;
public FpsCounter(double FPS)
{
Value = FPS;
ticks_per_frame = (double)Stopwatch.Frequency / FPS;
sw.Start();
last_frame = sw.ElapsedTicks;
}
public void FPSFixed(Action Action)
{
long current_time = sw.ElapsedTicks;
if (current_time - last_frame >= ticks_per_frame)
{
Action();
Value = (9 * Value + ((double)Stopwatch.Frequency / (sw.ElapsedTicks - last_frame)))/10;
last_frame = current_time;
}
}
}
}