8 [
Attribute(
"AI Autotests", UIWidgets.EditBox,
"Name of Confluence page",
"")]
9 private string m_pageName;
11 [
Attribute(
"Unnamed test", UIWidgets.EditBox,
"Title of particular test",
"")]
12 private string m_testName;
14 [
Attribute(
"PlayerCharacter", UIWidgets.EditBox,
"First entity to test completeness",
"")]
15 protected string m_entity1Name;
17 [
Attribute(
"", UIWidgets.EditBox,
"Second entity to test completeness",
"")]
18 protected string m_entity2Name;
20 [
Attribute(
"-1", UIWidgets.EditBox,
"Distance to test between entities",
"")]
21 protected float m_entityDistanceTest;
23 [
Attribute(
"-1", UIWidgets.EditBox,
"Safety timeout, test will end after",
"")]
24 protected float m_timeout;
26 [
Attribute(
"false", UIWidgets.CheckBox,
"If timeout is not failing test",
"")]
27 private bool m_testSucceedsAlways;
29 [
Attribute(
"", UIWidgets.EditBox,
"AISpawnerGroup to check before starting measurement")]
30 protected string m_SpawnerName;
34 private float m_avgFPS;
35 private float m_lowFPS;
36 private float m_highFPS;
37 private string m_worldFilePath;
38 protected float m_Timer;
40 protected string m_WorldName;
42 protected ref MeasurementFile m_ResultFile;
43 protected ref MeasurementFile m_graphfile;
45 protected ref AutotestRegister m_register;
47 protected AISpawnerGroup m_SpawnerGroup;
49 void AIAutotest(IEntitySource src, IEntity parent)
51 SetEventMask(EntityEvent.INIT | EntityEvent.FRAME);
52 SetFlags(EntityFlags.ACTIVE,
true);
57 override void EOnInit(IEntity owner)
70 if (m_timeout > 0 && m_Timer > m_timeout)
73 if (m_FirstEnt && m_SecondEnt && m_entityDistanceTest > 0)
75 vector diff = (m_FirstEnt.GetOrigin() - m_SecondEnt.GetOrigin());
76 float dist = diff.Length();
77 if (dist < m_entityDistanceTest)
85 if (m_testSucceedsAlways)
88 if (m_timeout > 0 && m_Timer < m_timeout)
94 void InitTestResultFiles()
98 m_WorldName =
GetGame().GetWorldFile();
99 int lastslash = m_WorldName.LastIndexOf(
"/");
100 m_WorldName = m_WorldName.Substring(lastslash, m_WorldName.Length() - lastslash);
105 m_register =
new AutotestRegister();
106 m_register.Init(m_pageName);
110 MeasurementFile descrFile = m_register.OpenMeasurementFile(
"000_ai_test_descr",
"", MeasurementType.HTML);
111 descrFile.AddData(
"<h1>AI Autotests</h1>");
113 m_Index = m_register.GetTestIndex() + 1;
114 string name =
string.Format(
"%1_test", m_WorldName);
115 m_ResultFile = m_register.OpenMeasurementFile(name,
"", MeasurementType.HTML,
true);
119 string FormatTimestamp()
121 int year, month, day, hour, minute, sec;
122 System.GetYearMonthDay(year, month, day);
123 System.GetHourMinuteSecond(hour, minute, sec);
124 string smonth, sday, shour;
126 smonth =
string.Format(
"0%1", month);
128 smonth =
string.Format(
"%1", month);
131 sday =
string.Format(
"0%1", day);
133 sday =
string.Format(
"%1", day);
136 shour =
string.Format(
"0%1", hour);
138 shour =
string.Format(
"%1", hour);
140 return string.Format(
"%1%2%3-%4", year, smonth, sday, shour);
143 string FormatIndex(
int index)
147 sindex =
string.Format(
"00%1",
index);
148 else if (
index < 100)
149 sindex =
string.Format(
"0%1",
index);
151 sindex =
string.Format(
"%1",
index);
155 string FormatAutotestInfo()
157 return string.Format(
"avg %1 min %2 max %3", m_avgFPS, m_lowFPS, m_highFPS);
160 void CreateGraph(
string graphName)
162 m_graphfile = m_register.OpenMeasurementFile(graphName,
"", MeasurementType.GraphLine,
false);
163 m_graphfile.SetGraphHeader(
"Measurement index, Average FPS");
164 m_graphfile.AddData(
string.Format(
"%1,%2", FormatTimestamp(), m_avgFPS));
167 override void EOnFrame(IEntity owner,
float timeSlice)
172 if (m_SpawnerName.Length() > 0 && !m_SpawnerGroup)
174 m_SpawnerGroup = AISpawnerGroup.Cast(owner.GetWorld().FindEntityByName(m_SpawnerName));
177 else if (m_SpawnerGroup)
179 if (!m_SpawnerGroup.IsSpawningFinished())
187 m_Timer += timeSlice;
191 InitTestResultFiles();
193 m_avgFPS = (m_avgFPS + (1 / timeSlice)) / 2.0;
194 float currFPS2 = System.GetFPS();
195 float currFPS = 1/timeSlice;
197 if (currFPS < m_lowFPS)
199 if (currFPS > m_highFPS)
202 if (!m_FirstEnt && m_entity1Name.Length() > 0)
206 if (!m_SecondEnt && m_entity2Name.Length() > 0)
213 Print(
string.Format(
"FPS: avg %1 min %2 max %3", m_avgFPS, m_lowFPS, m_highFPS));
214 Print(
string.Format(
"Time spent: %1 s", m_Timer));
216 string result =
"<span style='color: rgb(255,64,64);'>Fail</span>";
218 result =
"<span style='color: rgb(64,255,64);'>Success</span>";
221 m_ResultFile.AddData(
"<table><tr><th>Test</th><th>Result</th><th>FPS</th><th>Time Spent</th></tr>");
222 m_ResultFile.AddData(
string.Format(
"<tr><td>%1</td><td>%2</td><td>%3</td><td>%4s</td></tr>",
223 m_testName, result, FormatAutotestInfo(), m_Timer));
224 m_ResultFile.AddData(
"</table>");
226 string graphName =
string.Format(
"%1_test_graph", m_WorldName);
227 CreateGraph(graphName);