Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
AIAutotest.c
Go to the documentation of this file.
1
[
EntityEditorProps
(
category
:
"GameLib/Scripted/Autotest"
, description:
"AIAutotest"
, dynamicBox:
true
)]
2
class
AIAutotestClass
: GenericEntityClass
3
{
4
};
5
6
class
AIAutotest
:
GenericEntity
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
32
protected
GenericEntity
m_FirstEnt
;
33
protected
GenericEntity
m_SecondEnt
;
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
49
void
AIAutotest
(
IEntitySource
src,
IEntity
parent)
50
{
51
SetEventMask
(
EntityEvent
.INIT |
EntityEvent
.FRAME);
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
73
if
(
m_FirstEnt
&&
m_SecondEnt
&&
m_entityDistanceTest
> 0)
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
94
void
InitTestResultFiles
()
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
119
string
FormatTimestamp
()
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
155
string
FormatAutotestInfo
()
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
)
191
InitTestResultFiles
();
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
MeasurementType
Definition
AutotestRegister.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
EntityEditorProps
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Definition
SCR_CompassComponent.c:10
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition
SCR_DestructionSynchronizationComponent.c:17
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
AIAutotestClass
Definition
AIAutotest.c:3
AIAutotest::m_FirstEnt
GenericEntity m_FirstEnt
Definition
AIAutotest.c:32
AIAutotest::m_SecondEnt
GenericEntity m_SecondEnt
Definition
AIAutotest.c:33
AIAutotest::m_entity2Name
string m_entity2Name
Definition
AIAutotest.c:18
AIAutotest::m_entity1Name
string m_entity1Name
Definition
AIAutotest.c:15
AIAutotest::m_ResultFile
ref MeasurementFile m_ResultFile
Definition
AIAutotest.c:42
AIAutotest::CreateGraph
void CreateGraph(string graphName)
Definition
AIAutotest.c:160
AIAutotest::FormatIndex
string FormatIndex(int index)
Definition
AIAutotest.c:143
AIAutotest::FormatAutotestInfo
string FormatAutotestInfo()
Definition
AIAutotest.c:155
AIAutotest::m_WorldName
string m_WorldName
Definition
AIAutotest.c:40
AIAutotest::m_timeout
float m_timeout
Definition
AIAutotest.c:24
AIAutotest::ShouldEnd
bool ShouldEnd()
Definition
AIAutotest.c:68
AIAutotest::m_entityDistanceTest
float m_entityDistanceTest
Definition
AIAutotest.c:21
AIAutotest::m_SpawnerName
string m_SpawnerName
Definition
AIAutotest.c:30
AIAutotest::m_register
ref AutotestRegister m_register
Definition
AIAutotest.c:45
AIAutotest::m_SpawnerGroup
AISpawnerGroup m_SpawnerGroup
Definition
AIAutotest.c:47
AIAutotest::m_graphfile
ref MeasurementFile m_graphfile
Definition
AIAutotest.c:43
AIAutotest::HasPassed
bool HasPassed()
Definition
AIAutotest.c:83
AIAutotest::FormatTimestamp
string FormatTimestamp()
Definition
AIAutotest.c:119
AIAutotest::m_Timer
float m_Timer
Definition
AIAutotest.c:38
AIAutotest::InitTestResultFiles
void InitTestResultFiles()
Definition
AIAutotest.c:94
AIAutotest::EOnInit
override void EOnInit(IEntity owner)
EntityEvent.INIT.
Definition
AIAutotest.c:57
AIAutotest::EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
EntityEvent.FRAME.
Definition
AIAutotest.c:167
AIAutotest::AIAutotest
void AIAutotest(IEntitySource src, IEntity parent)
Definition
AIAutotest.c:49
GenericEntity
Definition
GenericEntity.c:16
IEntity::IEntity
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
IEntity::SetEventMask
proto external EntityEvent SetEventMask(EntityEvent e)
IEntity::GetWorld
proto external BaseWorld GetWorld()
IEntity::SetFlags
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
IEntitySource
Definition
IEntitySource.c:13
System
Definition
System.c:13
UIWidgets
Definition
attributes.c:40
vector
Definition
vector.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EntityEvent
EntityEvent
Various entity events.
Definition
EntityEvent.c:14
EntityFlags
EntityFlags
Various entity flags.
Definition
EntityFlags.c:14
scripts
Game
AI
AIAutotest.c
Generated by
1.17.0