Made sure division is done to double values instead of ints.

This commit is contained in:
Harrison Deng 2020-05-27 11:20:18 -05:00
parent 9ecfd079b2
commit e6230c013b

View File

@ -19,7 +19,7 @@ namespace SlatedGameToolkit.Framework {
private static Thread thread;
private static volatile bool exit = false, stopped = true;
private static volatile bool deltaChanged;
private static TimeSpan updateDeltaTime = TimeSpan.FromSeconds(1/200), frameDeltaTime = TimeSpan.FromSeconds(1/60);
private static TimeSpan updateDeltaTime = TimeSpan.FromSeconds(1d/200d), frameDeltaTime = TimeSpan.FromSeconds(1d/60d);
/// <summary>
/// The amount of updates per second.
@ -29,14 +29,14 @@ namespace SlatedGameToolkit.Framework {
/// <value>The updates per second.</value>
public static double UpdatesPerSecond {
get {
return 1 / updateDeltaTime.TotalSeconds;
return 1d / updateDeltaTime.TotalSeconds;
}
set {
lock (deltaUpdateLock) {
if (1 / value < 0.005) {
updateDeltaTime = TimeSpan.FromSeconds(1/200);
updateDeltaTime = TimeSpan.FromSeconds(1d/200d);
} else {
updateDeltaTime = TimeSpan.FromSeconds(1/value);
updateDeltaTime = TimeSpan.FromSeconds(1d/value);
}
}
deltaChanged = true;
@ -59,7 +59,7 @@ namespace SlatedGameToolkit.Framework {
if (value == 0) {
frameDeltaTime = TimeSpan.FromSeconds(0);
} else {
frameDeltaTime = TimeSpan.FromSeconds(1/value);
frameDeltaTime = TimeSpan.FromSeconds(1d/value);
}
}
deltaChanged = true;
@ -89,6 +89,7 @@ namespace SlatedGameToolkit.Framework {
lock (deltaUpdateLock) {
updateDeltaTime = GameEngine.updateDeltaTime;
frameDeltaTime = GameEngine.frameDeltaTime;
logger.Information(String.Format("Deltas were set. Update Delta: {0}, Render Delta: {1}", updateDeltaTime.TotalSeconds, frameDeltaTime.TotalSeconds));
}
deltaChanged = false;
}