Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
AIAutotest.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameLib/Scripted/Autotest", description: "AIAutotest", dynamicBox: true)]
2class AIAutotestClass: GenericEntityClass
3{
4};
5
7{
8 [Attribute("AI Autotests", UIWidgets.EditBox, "Name of Confluence page", "")]
9 private string m_pageName;
10
11 [Attribute("Unnamed test", UIWidgets.EditBox, "Title of particular test", "")]
12 private string m_testName;
13
14 [Attribute("PlayerCharacter", UIWidgets.EditBox, "First entity to test completeness", "")]
15 protected string m_entity1Name;
16
17 [Attribute("", UIWidgets.EditBox, "Second entity to test completeness", "")]
18 protected string m_entity2Name;
19
20 [Attribute("-1", UIWidgets.EditBox, "Distance to test between entities", "")]
21 protected float m_entityDistanceTest;
22
23 [Attribute("-1", UIWidgets.EditBox, "Safety timeout, test will end after", "")]
24 protected float m_timeout;
25
26 [Attribute("false", UIWidgets.CheckBox, "If timeout is not failing test", "")]
27 private bool m_testSucceedsAlways;
28
29 [Attribute("", UIWidgets.EditBox, "AISpawnerGroup to check before starting measurement")]
30 protected string m_SpawnerName;
31
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;
39 private int m_Index;
40 protected string m_WorldName;
41
42 protected ref MeasurementFile m_ResultFile;
43 protected ref MeasurementFile m_graphfile;
44
45 protected ref AutotestRegister m_register;
46
47 protected AISpawnerGroup m_SpawnerGroup;
48
50 {
52 SetFlags(EntityFlags.ACTIVE, true);
53
54 m_WorldName = "";
55 }
56
57 override void EOnInit(IEntity owner)
58 {
59 m_FirstEnt = null;
60 m_SecondEnt = null;
61 m_avgFPS = 0;
62 m_lowFPS = 1000;
63 m_highFPS = -1;
64 m_Timer = -1;
65 m_Index = 1;
66 }
67
68 bool ShouldEnd()
69 {
70 if (m_timeout > 0 && m_Timer > m_timeout)
71 return true;
72
74 {
75 vector diff = (m_FirstEnt.GetOrigin() - m_SecondEnt.GetOrigin());
76 float dist = diff.Length();
77 if (dist < m_entityDistanceTest)
78 return true;
79 }
80 return false;
81 }
82
83 bool HasPassed()
84 {
85 if (m_testSucceedsAlways)
86 return true;
87
88 if (m_timeout > 0 && m_Timer < m_timeout)
89 return true;
90
91 return false;
92 }
93
95 {
96 if (GetGame())
97 {
98 m_WorldName = GetGame().GetWorldFile();
99 int lastslash = m_WorldName.LastIndexOf("/");
100 m_WorldName = m_WorldName.Substring(lastslash, m_WorldName.Length() - lastslash);
101 }
103 if(!m_register)
104 {
105 m_register = new AutotestRegister();
106 m_register.Init(m_pageName);
107 }
108 if (!m_ResultFile)
109 {
110 MeasurementFile descrFile = m_register.OpenMeasurementFile("000_ai_test_descr", "", MeasurementType.HTML);
111 descrFile.AddData("<h1>AI Autotests</h1>");
112
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);
116 }
117 }
118
120 {
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;
125 if(month < 10)
126 smonth = string.Format("0%1", month);
127 else
128 smonth = string.Format("%1", month);
129
130 if(day < 10)
131 sday = string.Format("0%1", day);
132 else
133 sday = string.Format("%1", day);
134
135 if (hour < 10)
136 shour = string.Format("0%1", hour);
137 else
138 shour = string.Format("%1", hour);
139
140 return string.Format("%1%2%3-%4", year, smonth, sday, shour);
141 }
142
143 string FormatIndex(int index)
144 {
145 string sindex;
146 if (index < 10)
147 sindex = string.Format("00%1", index);
148 else if (index < 100)
149 sindex = string.Format("0%1", index);
150 else
151 sindex = string.Format("%1", index);
152 return sindex;
153 }
154
156 {
157 return string.Format("avg %1 min %2 max %3", m_avgFPS, m_lowFPS, m_highFPS);
158 }
159
160 void CreateGraph(string graphName)
161 {
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));
165 }
166
167 override void EOnFrame(IEntity owner, float timeSlice)
168 {
169 if (timeSlice <= 0)
170 return;
171
172 if (m_SpawnerName.Length() > 0 && !m_SpawnerGroup)
173 {
174 m_SpawnerGroup = AISpawnerGroup.Cast(owner.GetWorld().FindEntityByName(m_SpawnerName));
175 return;
176 }
177 else if (m_SpawnerGroup)
178 {
179 if (!m_SpawnerGroup.IsSpawningFinished())
180 return;
181 }
182
183 if (m_Timer < 0)
184 m_Timer = 0;
185 else
186 {
187 m_Timer += timeSlice;
188 }
189
190 if (!m_ResultFile)
192
193 m_avgFPS = (m_avgFPS + (1 / timeSlice)) / 2.0;
194 float currFPS2 = System.GetFPS();
195 float currFPS = 1/timeSlice;
196
197 if (currFPS < m_lowFPS)
198 m_lowFPS = currFPS;
199 if (currFPS > m_highFPS)
200 m_highFPS = currFPS;
201
202 if (!m_FirstEnt && m_entity1Name.Length() > 0)
203 {
204 m_FirstEnt = GenericEntity.Cast(GetGame().FindEntity(m_entity1Name));
205 }
206 if (!m_SecondEnt && m_entity2Name.Length() > 0)
207 {
208 m_SecondEnt = GenericEntity.Cast(GetGame().FindEntity(m_entity2Name));
209 }
210
211 if (ShouldEnd())
212 {
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));
215
216 string result = "<span style='color: rgb(255,64,64);'>Fail</span>";
217 if (HasPassed())
218 result = "<span style='color: rgb(64,255,64);'>Success</span>";
219 if (m_ResultFile)
220 {
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>");
225 }
226 string graphName = string.Format("%1_test_graph", m_WorldName);
227 CreateGraph(graphName);
228
229 GetGame().RequestClose(); //< End mission
230 }
231 }
232};
MeasurementType
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
GenericEntity m_FirstEnt
Definition AIAutotest.c:32
GenericEntity m_SecondEnt
Definition AIAutotest.c:33
string m_entity2Name
Definition AIAutotest.c:18
string m_entity1Name
Definition AIAutotest.c:15
ref MeasurementFile m_ResultFile
Definition AIAutotest.c:42
void CreateGraph(string graphName)
Definition AIAutotest.c:160
string FormatIndex(int index)
Definition AIAutotest.c:143
string FormatAutotestInfo()
Definition AIAutotest.c:155
string m_WorldName
Definition AIAutotest.c:40
float m_timeout
Definition AIAutotest.c:24
bool ShouldEnd()
Definition AIAutotest.c:68
float m_entityDistanceTest
Definition AIAutotest.c:21
string m_SpawnerName
Definition AIAutotest.c:30
ref AutotestRegister m_register
Definition AIAutotest.c:45
AISpawnerGroup m_SpawnerGroup
Definition AIAutotest.c:47
ref MeasurementFile m_graphfile
Definition AIAutotest.c:43
bool HasPassed()
Definition AIAutotest.c:83
string FormatTimestamp()
Definition AIAutotest.c:119
float m_Timer
Definition AIAutotest.c:38
void InitTestResultFiles()
Definition AIAutotest.c:94
override void EOnInit(IEntity owner)
EntityEvent.INIT.
Definition AIAutotest.c:57
override void EOnFrame(IEntity owner, float timeSlice)
EntityEvent.FRAME.
Definition AIAutotest.c:167
void AIAutotest(IEntitySource src, IEntity parent)
Definition AIAutotest.c:49
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external BaseWorld GetWorld()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14