Initial Commit
This commit is contained in:
38
2DGAMELIB/_2DGAMELIB/FPS.cs
Normal file
38
2DGAMELIB/_2DGAMELIB/FPS.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace _2DGAMELIB;
|
||||
|
||||
public class FPS
|
||||
{
|
||||
public Stopwatch sw = new Stopwatch();
|
||||
|
||||
private long last_frame;
|
||||
public double Value;
|
||||
|
||||
private int count;
|
||||
|
||||
private double ticks_per_frame;
|
||||
public FPS(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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user