Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
FPS_Autotest.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameLib/Scripted/Autotest", description:"FPS_autotest", dynamicBox: true)]
2class FPS_AutotestClass: GenericEntityClass
3{
4}
5
7{
8 [Attribute("ScriptCamera1", UIWidgets.EditBox, "Name of camera entity", "")]
9 private string m_cameraEntityName;
10
11 [Attribute("", UIWidgets.EditBox, "Name of a page", "")]
12 private string m_pageName;
13
14 [Attribute("300", UIWidgets.Slider, "Measurements step", "10 2000 10")]
15 private int m_step;
16
17 [Attribute("1", UIWidgets.Slider, "Wait time", "0 20 0.1")]
18 private float m_stepWaitTime;
19
20 [Attribute("80", UIWidgets.Slider, "Camera height", "10 300 10")]
21 private float m_cameraHeight;
22
23 [Attribute("10", UIWidgets.Slider, "Number of slowest points for lowest FPS graph", "10 50 1")]
24 private int m_lowFrameCount;
25
27 protected float m_timer; //< Used for counting how long camera stais on one place
28
29 private IEntity m_camera; //< Entity used as camera, this one is auto moved by autotest
30
31 private int m_x = 0; //< Next camera x position
32 private int m_z = 0; //< Next camera y position
33 private int m_worldSize; //< How big is world we are scanning
34
35 private float m_avgFPS = -1; //< Accumulated avarage FPS in current test
36 private int m_avgFpsIdx = 0; //< This is just persistent index of autotest for tracking long term changes in results
37
38 protected ref MeasurementFile m_heatmapfile; //< Test heatmap output file
39 protected ref MeasurementFile m_graphfile; //< Test long term graph output file
40
41 private ref set<int> m_lowestFPSs;
43
44
45 protected ref AutotestRegister m_register;
46
48 {
49 m_timer = 0.0;
51 SetFlags(EntityFlags.ACTIVE, true);
52 m_lowestFPSs = new set<int>();
53 }
54
56 {
57
58 }
59
60 override void EOnInit(IEntity owner)
61 {
63 m_camera = g_Game.FindEntity(m_cameraEntityName);
64 if(m_camera)
65 {
66 float groundY = m_camera.GetWorld().GetSurfaceY(m_x, m_z);
67 m_camera.SetOrigin(Vector(m_x, groundY + m_cameraHeight, m_z));
68 }
69
71 if(g_Game.GetWorldEntity())
72 {
73 vector min, max;
74 g_Game.GetWorldEntity().GetWorldBounds(min, max);
75 m_worldSize = Math.Max(max[0] - min[0], max[2] - min[2]);
76 }
77 }
78
79 override void EOnFrame(IEntity owner, float timeSlice)
80 {
81 g_Game.GetInputManager().ActivateContext("BlockInputContext");
82
83 if(m_timer > m_stepWaitTime) //< When camera was still long enough
84 {
85 m_timer = 0;
86 if(m_camera)
87 {
89 float groundY = m_camera.GetWorld().GetSurfaceY(m_x, m_z);
90 m_camera.SetOrigin(Vector(m_x, groundY + m_cameraHeight, m_z));
91 }
92
93
95 if(!m_register)
96 {
97 m_register = new AutotestRegister();
98 m_register.Init(m_pageName);
99 }
100
103 if(!m_heatmapfile)
104 {
105 ref MeasurementFile descrFile = m_register.OpenMeasurementFile("0_fps_test_descr", "", MeasurementType.HTML);
106 descrFile.AddData(string.Format("<h1>Test description</h1><p>Camera step: %1m<br/>Step wait time: %2s<br/>Camera height above ground: %3m<br/>Number of worst FPS places: %4</p>", m_step, m_stepWaitTime, m_cameraHeight, m_lowFrameCount));
107
108 m_heatmapfile = m_register.OpenMeasurementFile("1_fps_heatmap", "FPS heatmap", MeasurementType.HeatMap);
109
110 ref MeasurementFile fileUploadDescr = m_register.OpenMeasurementFile("1_fps_heatmap_sourcefile", "Heatmap source data", MeasurementType.File);
111 fileUploadDescr.AddData(m_heatmapfile.GetFilePath());
112
113 m_register.UploadLogFileWithResults();
114 }
115 if(!m_graphfile)
116 {
117 m_graphfile = m_register.OpenMeasurementFile("2_fps_graph", "FPS graph", MeasurementType.GraphLine, false);
118 m_graphfile.SetGraphHeader("Measurement date, Avarage FPS");
119
120
123 string idxLine = m_register.LoadPersistentData("2_fps_graph.idx");
124 if(idxLine.Length() == 0)
125 m_avgFpsIdx = 0;
126 else
127 m_avgFpsIdx = idxLine.ToInt() + 1;
128
129 m_register.SavePersistentData("2_fps_graph.idx", string.Format("%1", m_avgFpsIdx));
131 }
133
134 int fps = System.GetFPS();
135 if (m_avgFPS == -1) //< First simulation
136 m_avgFPS = fps;
137 else
138 m_avgFPS = (m_avgFPS + fps) / 2.0;
139
140 m_heatmapfile.AddData(string.Format("%1,%2,%3", m_x, m_z, fps)); //< output new data to heatmap
141
142 m_lowestFPSs.Insert(fps);
143 if(m_lowestFPSs.Count() > m_lowFrameCount)
144 m_lowestFPSs.Remove(m_lowestFPSs.Count() - 1);
145
146 if (m_x <= m_worldSize)
147 {
149 m_x = m_x + m_step;
150 }
151 else
152 {
153 m_x = 0;
154 if (m_z <= m_worldSize)
155 {
156 m_z = m_z + m_step;
157 }
158 else
159 {
161 string timeStamp = FormatTimestamp();
162 m_graphfile.AddData(string.Format("%1,%2", timeStamp, m_avgFPS)); //< output avarage FPS in this test
163
164 ref MeasurementFile lowFpsFile = m_register.OpenMeasurementFile("3_low_fps_graph", "Avg of worst FPS places", MeasurementType.GraphLine, false);
165 lowFpsFile.SetGraphHeader("Measurement date, Avarage FPS");
166
167 int lowestFpsSum = 0;
168 for(int i = 0; i < m_lowestFPSs.Count(); ++i)
169 lowestFpsSum += m_lowestFPSs[i];
170
171 lowFpsFile.AddData(string.Format("%1,%2", timeStamp, lowestFpsSum / m_lowestFPSs.Count()));
172
173 g_Game.RequestClose(); //< End mission
174 }
175 }
176 }
177 m_timer += timeSlice;
178 }
179
181 {
182 int year, month, day;
183 System.GetYearMonthDay(year, month, day);
184 string smonth, sday;
185 if(month < 10)
186 smonth = string.Format("0%1", month);
187 else
188 smonth = string.Format("%1", month);
189
190 if(day < 10)
191 sday = string.Format("0%1", day);
192 else
193 sday = string.Format("%1", day);
194
195 return string.Format("%1%2%3-%4", year, smonth, sday, m_avgFpsIdx);
196 }
197}
MeasurementType
void ~FPS_Autotest()
float m_timer
ref MeasurementFile m_graphfile
ref AutotestRegister m_register
void FPS_Autotest(IEntitySource src, IEntity parent)
string FormatTimestamp()
ref MeasurementFile m_heatmapfile
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
proto external EntityEvent SetEventMask(EntityEvent e)
void EOnInit(IEntity owner)
void EOnFrame(IEntity owner, float timeSlice)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
Definition Math.c:13
Game g_Game
Game singleton instance.
Definition gameLib.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
proto native vector Vector(float x, float y, float z)