-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPopGuiRenderTimeline.js
More file actions
115 lines (94 loc) · 2.44 KB
/
PopGuiRenderTimeline.js
File metadata and controls
115 lines (94 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// dependencies
// Pop.Gui.Timeline
// Pop.FrameCounter
// Pop.WaitForFrame (PopWebApi atm)
// this is currently dependent on the API's in the web implementation, native needs to catchup with stats
Pop.Gui.RenderTimelineWindow = class
{
constructor(Name,Rect,GetData)
{
this.ReportFrequencyMs = 300;
this.Window = new Pop.Gui.Window(Name,Rect);
this.Window.EnableScrollbars(false,false);
this.Timeline = new Pop.Gui.Timeline(this.Window,[0,0,'100%','100%'],this.GetTimelineData.bind(this));
// 1 pixel for every report
this.Timeline.ViewTimeToPx = 10/this.ReportFrequencyMs;
this.Timeline.SmearData = true;
this.Timeline.TrackHeight = 30;
this.TimelineData = {};
this.TimelineData.GetDataColour = this.GetDataColour.bind(this);
this.Counters = {};
this.UpdateRenderCounterLoop();
}
async UpdateRenderCounterLoop()
{
while(this.Window)
{
await Pop.WaitForFrame();
if ( this.Window.IsMinimised() )
{
await Pop.Yield(2000);
continue;
}
// flush opengl stats
const Stats = Pop.Opengl.Stats;
for ( const Key in Stats )
{
// grab value, update counter, reset counter
const Value = Stats[Key];
this.UpdateCounter(Key,Value);
Stats[Key] = 0;
}
}
}
UpdateTimelineData(Name,Counter)
{
// round to nearest frequency
const Now = Math.floor(Pop.GetTimeNowMs()/this.ReportFrequencyMs) * this.ReportFrequencyMs;
if ( !this.TimelineData.hasOwnProperty(Now) )
this.TimelineData[Now] = {};
this.TimelineData[Now][Name] = Counter;
this.OnDataChanged();
}
UpdateCounter(Name,Add)
{
// filter counters here
if ( Name != 'Renders' )
return;
if ( !this.Counters.hasOwnProperty(Name) )
{
this.Counters[Name] = new FrameCounter(Name,this.ReportFrequencyMs);
// catch report
function Report(CountPerSec)
{
this.UpdateTimelineData(Name,CountPerSec);
}
this.Counters[Name].Report = Report.bind(this);
}
this.Counters[Name].Add(Add);
}
GetDataColour(Key,Value)
{
// scale data to 1sec
Value *= 1000 / this.ReportFrequencyMs;
// renders are out of 60
if ( Key == 'Renders' )
{
const Max = 60;
const SizeNormal = Math.min( 1, Value / Max );
const RgbHeight = Math.NormalToRedGreen(SizeNormal);
RgbHeight[3] = SizeNormal;
return RgbHeight;
}
}
GetTimelineData(MinTime,MaxTime)
{
return this.TimelineData;
}
OnDataChanged()
{
if ( this.Window.IsMinimised() )
return;
this.Timeline.OnDataChanged();
}
}