11
11
12
12
public class TestRE2Plugin {
13
13
static bool IsRunningRE2 => Environment . ProcessPath . Contains ( "re2" , StringComparison . CurrentCultureIgnoreCase ) ;
14
+ static System . Diagnostics . Stopwatch imguiStopwatch = new ( ) ;
14
15
15
16
[ REFrameworkNET . Attributes . PluginEntryPoint ]
16
17
public static void Main ( ) {
@@ -24,10 +25,38 @@ public static void Main() {
24
25
RE2HookBenchmark . InstallHook ( ) ;
25
26
26
27
ImGuiRender . Pre += ( ) => {
28
+ var deltaSeconds = imguiStopwatch . Elapsed . TotalMilliseconds / 1000.0 ;
29
+ imguiStopwatch . Restart ( ) ;
30
+
27
31
if ( ImGui . Begin ( "Test Window" ) ) {
28
32
ImGui . Text ( "RE2" ) ;
29
33
ImGui . Separator ( ) ;
30
34
35
+
36
+ if ( ImGui . TreeNode ( "Player" ) ) {
37
+ var playerManager = API . GetManagedSingletonT < app . ropeway . PlayerManager > ( ) ;
38
+ var player = playerManager . get_CurrentPlayer ( ) ;
39
+ if ( player != null ) {
40
+ ImGui . Text ( "Player is not null" ) ;
41
+ } else {
42
+ ImGui . Text ( "Player is null" ) ;
43
+ }
44
+ ImGui . TreePop ( ) ;
45
+ }
46
+
47
+ ImGui . End ( ) ;
48
+ }
49
+
50
+ // ROund the window
51
+ ImGui . PushStyleVar ( ImGuiStyleVar . WindowRounding , 10.0f ) ;
52
+
53
+ ImGui . SetNextWindowSize ( new System . Numerics . Vector2 ( 500 , 500 ) , ImGuiCond . FirstUseEver ) ;
54
+ if ( ImGui . Begin ( "RE2 Bench" ) ) {
55
+
56
+ ImGui . PushStyleColor ( ImGuiCol . Text , new System . Numerics . Vector4 ( 0.5f , 1f , 0.4f , 1.0f ) ) ;
57
+ ImGui . PlotLines ( "Overall Benchmark" , ref RE2HookBenchmark . BenchmarkData [ 0 ] , 1000 , RE2HookBenchmark . MeasureCount % 1000 , RE2HookBenchmark . RunningAvg . ToString ( "0.000" ) + " µs" , 0 , ( float ) RE2HookBenchmark . RunningAvg * 2.0f , new System . Numerics . Vector2 ( 0 , 40 ) ) ;
58
+ ImGui . PopStyleColor ( ) ;
59
+
31
60
System . Collections . Generic . List < long > threadRanks = new ( ) ;
32
61
33
62
foreach ( var tdata in RE2HookBenchmark . threadData ) {
@@ -43,34 +72,36 @@ public static void Main() {
43
72
44
73
var totalThreadRanks = threadRanks . Count ;
45
74
75
+ System . Collections . Generic . List < RE2HookBenchmark . ThreadData > threadData = new ( ) ;
76
+
46
77
foreach ( var tdata in RE2HookBenchmark . threadData ) {
47
- var rank = threadRanks . IndexOf ( tdata . Value . threadID ) + 1 ;
48
- var greenColor = 1.0f - ( float ) rank / ( float ) totalThreadRanks ;
49
- var redColor = ( float ) rank / ( float ) totalThreadRanks ;
78
+ threadData . Add ( tdata . Value ) ;
79
+ }
80
+
81
+ threadData . Sort ( ( a , b ) => {
82
+ return a . lerp . CompareTo ( b . lerp ) ;
83
+ } ) ;
84
+
85
+ foreach ( var tdata in threadData ) {
86
+ var rank = threadRanks . IndexOf ( tdata . threadID ) + 1 ;
87
+ var rankRatio = ( double ) rank / ( double ) totalThreadRanks ;
88
+ var towards = Math . Max ( 80.0 * rankRatio , 20.0 ) ;
89
+ tdata . lerp = towards * deltaSeconds + tdata . lerp * ( 1.0 - deltaSeconds ) ;
90
+ var lerpRatio = tdata . lerp / 80.0 ;
91
+
92
+ var greenColor = 1.0 - lerpRatio ;
93
+ var redColor = lerpRatio ;
50
94
51
95
//ImGui.Text("Thread ID: " + tdata.Value.threadID + " Avg: " + tdata.Value.runningAvg.ToString("0.000") + " µs");
52
- ImGui . PushStyleColor ( ImGuiCol . Text , new System . Numerics . Vector4 ( redColor , greenColor , 0f , 1.0f ) ) ;
53
- ImGui . PlotLines ( "Thread " + tdata . Value . threadID , ref tdata . Value . benchmarkData [ 0 ] , 1000 , tdata . Value . callCount % 1000 , tdata . Value . runningAvg . ToString ( "0.000" ) + " µs" , 0 , ( float ) tdata . Value . runningAvg * 2.0f , new System . Numerics . Vector2 ( 0 , 30 ) ) ;
96
+ ImGui . PushStyleColor ( ImGuiCol . Text , new System . Numerics . Vector4 ( ( float ) redColor , ( float ) greenColor , 0f , 1.0f ) ) ;
97
+ ImGui . PlotLines ( "Thread " + tdata . threadID , ref tdata . benchmarkData [ 0 ] , 1000 , tdata . callCount % 1000 , tdata . runningAvg . ToString ( "0.000" ) + " µs" , ( float ) tdata . runningAvg , ( float ) tdata . runningAvg * 2.0f , new System . Numerics . Vector2 ( 0 , ( int ) tdata . lerp ) ) ;
54
98
ImGui . PopStyleColor ( ) ;
55
99
}
56
100
57
- ImGui . PushStyleColor ( ImGuiCol . Text , new System . Numerics . Vector4 ( 0.5f , 1f , 0.4f , 1.0f ) ) ;
58
- ImGui . PlotLines ( "Overall Benchmark" , ref RE2HookBenchmark . BenchmarkData [ 0 ] , 1000 , RE2HookBenchmark . MeasureCount % 1000 , RE2HookBenchmark . RunningAvg . ToString ( "0.000" ) + " µs" , 0 , ( float ) RE2HookBenchmark . RunningAvg * 2.0f , new System . Numerics . Vector2 ( 0 , 40 ) ) ;
59
- ImGui . PopStyleColor ( ) ;
60
-
61
- if ( ImGui . TreeNode ( "Player" ) ) {
62
- var playerManager = API . GetManagedSingletonT < app . ropeway . PlayerManager > ( ) ;
63
- var player = playerManager . get_CurrentPlayer ( ) ;
64
- if ( player != null ) {
65
- ImGui . Text ( "Player is not null" ) ;
66
- } else {
67
- ImGui . Text ( "Player is null" ) ;
68
- }
69
- ImGui . TreePop ( ) ;
70
- }
71
-
72
101
ImGui . End ( ) ;
73
102
}
103
+
104
+ ImGui . PopStyleVar ( ) ;
74
105
} ;
75
106
76
107
// Benchmarking the effects of threading on invoking game code
@@ -160,6 +191,7 @@ internal class ThreadData {
160
191
internal double highestMicros ;
161
192
internal double runningAvg ;
162
193
internal float [ ] benchmarkData = new float [ 1000 ] ;
194
+ internal double lerp = 40.0 ;
163
195
} ;
164
196
165
197
internal static System . Collections . Concurrent . ConcurrentDictionary < long , ThreadData > threadData = new ( Environment . ProcessorCount * 2 , 8192 ) ;
0 commit comments