Skip to content

Commit 511ec13

Browse files
committed
Improve FPS display
1 parent 436e216 commit 511ec13

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed

Components/LiveSplit.OriWotW.dll

512 Bytes
Binary file not shown.

Components/Updates.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<updates>
3+
<update version="1.1.8">
4+
<files>
5+
<file path="Components/LiveSplit.OriWotW.dll" status="changed"/>
6+
</files>
7+
<changelog>
8+
<change> Improved FPS display output </change>
9+
</changelog>
10+
</update>
311
<update version="1.1.7">
412
<files>
513
<file path="Components/LiveSplit.OriWotW.dll" status="changed"/>

Memory/FPSTimer.cs

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,88 @@
11
using System.Diagnostics;
22
namespace LiveSplit.OriWotW {
33
public class FPSTimer {
4-
private const long AveTimeTicks = 10000000;
5-
private const long ShortTimeTicks = 1000000;
6-
public float FPS = 0;
7-
public float FPSShort = 0;
4+
private TimeCalculation averageTime;
5+
private TimeCalculation shortTime;
86
private Stopwatch frameTimer;
97
private int lastFrameCount = 0;
10-
private int lastFrameShort = 0;
118
private long lastTicks = 0;
12-
private long lastTicksShort = 0;
13-
public FPSTimer() {
9+
private long updateDisplay;
10+
private float cacheFPS;
11+
public float FPS {
12+
get {
13+
if (updateDisplay > 2500000) {
14+
updateDisplay = 0;
15+
cacheFPS = averageTime.FPS;
16+
}
17+
return cacheFPS;
18+
}
19+
}
20+
public float FPSShort { get { return shortTime.FPS; } }
21+
public FPSTimer(int aveSamples, int shortSamples) {
1422
frameTimer = new Stopwatch();
1523
frameTimer.Start();
24+
averageTime = new TimeCalculation(aveSamples);
25+
shortTime = new TimeCalculation(shortSamples);
1626
}
1727
public void Reset() {
18-
lastTicksShort = 0;
1928
lastTicks = 0;
2029
lastFrameCount = 0;
21-
lastFrameShort = 0;
30+
averageTime.Reset();
31+
shortTime.Reset();
2232
}
2333
public void Update(int frameCount) {
2434
long ticks = frameTimer.ElapsedTicks;
25-
if (ticks >= lastTicks) {
26-
if (lastFrameCount > 0) {
27-
FPS = (float)((double)10000000 * (double)(frameCount - lastFrameCount) / (double)(ticks - lastTicks + AveTimeTicks));
28-
}
29-
lastFrameCount = frameCount;
30-
lastTicks = ticks + AveTimeTicks;
35+
long ticksDifference = ticks - lastTicks;
36+
int frameDifference = frameCount - lastFrameCount;
37+
if (lastFrameCount > 0) {
38+
updateDisplay += ticksDifference;
39+
averageTime.AddSample(ticksDifference, frameDifference);
40+
shortTime.AddSample(ticksDifference, frameDifference);
3141
}
32-
if (ticks >= lastTicksShort) {
33-
if (lastFrameShort > 0) {
34-
FPSShort = (float)((double)10000000 * (double)(frameCount - lastFrameShort) / (double)(ticks - lastTicksShort + ShortTimeTicks));
35-
}
36-
lastFrameShort = frameCount;
37-
lastTicksShort = ticks + ShortTimeTicks;
42+
lastTicks = ticks;
43+
lastFrameCount = frameCount;
44+
}
45+
}
46+
public class TimeCalculation {
47+
private TimeSlice[] samples;
48+
private long totalTime;
49+
private int totalFrames;
50+
private int index;
51+
52+
public TimeCalculation(int sampleCount) {
53+
samples = new TimeSlice[sampleCount];
54+
}
55+
public void Reset() {
56+
totalTime = 0;
57+
totalFrames = 0;
58+
for (int i = 0; i < samples.Length; i++) {
59+
samples[i] = default(TimeSlice);
60+
}
61+
}
62+
public void AddSample(long ticks, int frames) {
63+
TimeSlice slice = samples[index];
64+
totalTime += ticks - slice.Ticks;
65+
totalFrames += frames - slice.Frames;
66+
slice.Ticks = ticks;
67+
slice.Frames = frames;
68+
samples[index++] = slice;
69+
if (index >= samples.Length) {
70+
index = 0;
3871
}
3972
}
73+
public float FPS {
74+
get { return (float)((double)10000000 * (double)totalFrames / (double)totalTime); }
75+
}
76+
public override string ToString() {
77+
return FPS.ToString("0.0");
78+
}
79+
}
80+
public struct TimeSlice {
81+
public long Ticks;
82+
public int Frames;
83+
84+
public override string ToString() {
85+
return $"{Ticks}-{Frames}";
86+
}
4087
}
4188
}

Memory/MemoryManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public partial class MemoryManager {
6262
public DateTime LastHooked { get; set; }
6363
private bool? noPausePatched = null;
6464
private bool? targetFrameRatePatched = null;
65-
private FPSTimer fpsTimer = new FPSTimer();
65+
private FPSTimer fpsTimer = new FPSTimer(200, 15);
6666

6767
public MemoryManager() {
6868
LastHooked = DateTime.MinValue;

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
[assembly: AssemblyCulture("")]
1515
[assembly: ComVisible(false)]
1616
[assembly: Guid("b3294e28-2bd4-4e39-92fa-e04a620c737f")]
17-
[assembly: AssemblyVersion("1.1.7.0")]
18-
[assembly: AssemblyFileVersion("1.1.7.0")]
17+
[assembly: AssemblyVersion("1.1.8.0")]
18+
[assembly: AssemblyFileVersion("1.1.8.0")]
1919
[assembly: ComponentFactory(typeof(Factory))]

0 commit comments

Comments
 (0)