12 private string m_sCameraLabel;
13 [
Attribute(
"-30 25 -30",
UIWidgets.EditBox,
"Camera position in world coordinates (metres)",
"")]
14 private vector m_vCameraPosition;
15 [
Attribute(
"0 45 0",
UIWidgets.EditBox,
"Camera rotation in world coordinates (degrees)",
"")]
16 private vector m_vCameraRotation;
17 [
Attribute(
"5",
UIWidgets.Slider,
"The interval before this camera is done.",
"0 100 1")]
18 private float m_fCameraDuration;
19 [
Attribute(
"false",
UIWidgets.CheckBox,
"Whether camera is set from the center of spawned objects, or in global coordinates.",
"")]
20 private bool m_bRelativeToObjectsCenter;
23 private ref array<float> m_aFramesPerSecond = null;
27 bool GetIsRelativeToCenter()
29 return m_bRelativeToObjectsCenter;
36 return m_sCameraLabel;
43 return m_vCameraPosition;
50 return m_vCameraRotation;
57 return m_fCameraDuration;
62 void LogFramesPerSecond(
float timeSlice)
64 if (!m_aFramesPerSecond)
65 m_aFramesPerSecond =
new array<float>();
67 m_aFramesPerSecond.Insert((
float)
System.GetFPS());
72 void ClearFramesPerSecond()
74 if (!m_aFramesPerSecond)
79 m_aFramesPerSecond.Clear();
86 bool GetFramesPerSecondsData(out
float minFps, out
float maxFps, out
float averageFps)
90 if (!m_aFramesPerSecond)
92 int fpsArrayLength = m_aFramesPerSecond.Count();
93 if (fpsArrayLength <= 0)
96 float min = 99999999.0;
97 float max = -99999999.0;
102 for (
int i = 0; i < fpsArrayLength; i++)
104 float currentFrame = m_aFramesPerSecond[i];
106 if (currentFrame > max)
109 if (currentFrame < min)
112 total += currentFrame;
115 avg = total / (
float)fpsArrayLength;
134 vector camRot = m_vCameraRotation;
135 vector eulerAngles =
Vector(camRot[1], camRot[0], camRot[2]);
137 Math3D.AnglesToMatrix(eulerAngles, rotMat);
140 camMat[0] = rotMat[0];
141 camMat[1] = rotMat[1];
142 camMat[2] = rotMat[2];
146 if (m_bRelativeToObjectsCenter)
148 centerOffset = center;
151 camMat[3] = m_vCameraPosition + centerOffset;
154 int cameraIndex = world.GetCurrentCameraId();
155 world.SetCameraEx(cameraIndex, camMat);
161 if (m_aFramesPerSecond)
163 m_aFramesPerSecond.Clear();
164 m_aFramesPerSecond = null;
174 [
Attribute(
"AR Models Autotest",
UIWidgets.EditBox,
"Target result page name in Confluence",
"")]
175 private string m_sConfluenceParentPageName;
178 private ref array<ref SCR_ModelAutotestCamera> m_aCameras;
181 private float m_fWarmupDelay = 2.5;
183 private float m_fTimePassed = 0.0;
186 private bool m_bWarmedUp =
false;
187 private bool m_bRespawningObjects =
false;
188 private bool m_bTestStarted =
false;
189 private bool m_bCameraSet =
false;
192 private int m_iCurrentObjectIndex = 0;
194 private int m_iCurrentCameraIndex = 0;
196 private int m_iCamerasCount = 0;
204 private ref AutotestRegister m_AutotestRegister = null;
205 private int m_iAutotestIndex = 0;
210 private string GetPersistentDataPath()
212 string indexFileName = m_sConfluenceParentPageName;
213 indexFileName.Replace(
" ",
"");
214 return string.Format(
"%1.idx", indexFileName);
219 private string GetFormattedTimestamp()
221 int year, month, day;
222 System.GetYearMonthDay(year, month, day);
225 smonth =
string.Format(
"0%1", month);
227 smonth =
string.Format(
"%1", month);
230 sday =
string.Format(
"0%1", day);
232 sday =
string.Format(
"%1", day);
234 m_AutotestRegister.SavePersistentData(GetPersistentDataPath(),
string.Format(
"%1", m_iAutotestIndex));
236 return string.Format(
"%1%2%3-%4", year, smonth, sday, m_iAutotestIndex);
242 private bool ValidateAutotestSettings()
245 if (!
GetGame().GetWorldEntity())
252 Print(
"No autotest cameras defined in ModelAutotestEntity! Returning to edit mode!",
LogLevel.ERROR);
257 if (m_aCameras.Count() <= 0)
259 Print(
"No autotest cameras defined in ModelAutotestEntity! Returning to edit mode!",
LogLevel.ERROR);
266 if (!m_CurrentAutotestCamera)
268 SetCamera(
GetGame().GetWorldEntity().
GetWorld(), 0, m_vCameraPositionCenter);
272 Print(
"Specified autotest camera was invalid! Returning to edit mode!",
LogLevel.ERROR);
278 if (!m_sConfluenceParentPageName || m_sConfluenceParentPageName ==
string.Empty)
280 Print(
"Specified target confluence page is invalid! Returning to edit mode!",
LogLevel.ERROR);
291 m_CurrentAutotestCamera = m_aCameras[
index];
292 m_CurrentAutotestCamera.SetAsCamera(world, center);
298 private void WriteMeasurementData()
301 ref MeasurementFile measurementFile = null;
304 int len = name.Length();
305 int lastBracket = name.IndexOf(
"}")+1;
307 string formattedName = name.Substring(lastBracket, len-lastBracket);
308 string fileName = formattedName;
310 fileName.Replace(
"/",
"#");
311 fileName.Replace(
"\\",
"#");
312 if (!measurementFile)
313 measurementFile = m_AutotestRegister.OpenMeasurementFile(fileName, formattedName,
MeasurementType.GraphLine,
false);
315 string header =
"date,";
316 for (
int i = 0; i < m_aCameras.Count(); i++)
318 if (i == m_aCameras.Count()-1)
319 header +=
"@"+m_aCameras[i].GetLabel();
321 header +=
"@"+m_aCameras[i].GetLabel()+
",";
325 string data = GetFormattedTimestamp()+
",";
326 for (
int i = 0; i < m_iCamerasCount; i++)
329 m_aCameras[i].GetFramesPerSecondsData(min, max, avg);
330 m_aCameras[i].ClearFramesPerSecond();
332 if (i == m_iCamerasCount - 1)
333 data += avg.ToString();
335 data += avg.ToString() +
",";
338 measurementFile.SetGraphHeader(header);
339 measurementFile.AddData(
data);
340 measurementFile = null;
348 Print(
string.Format(
"| Model Autotest | : Camera set to \"%1\"!", m_aCameras[cameraIndex].
GetLabel()));
356 string mdlName =
string.Empty;
358 mdlName = m_iCurrentObjectIndex.ToString();
359 Print(
string.Format(
"| Model Autotest | : Model set to \"%1\"!", mdlName));
381 if (m_iCurrentCameraIndex >= m_iCamerasCount)
385 WriteMeasurementData();
386 m_bTestStarted =
false;
387 m_iCurrentObjectIndex++;
388 m_iCurrentCameraIndex = 0;
389 m_bTestStarted =
false;
394 SetCamera(owner.
GetWorld(), m_iCurrentCameraIndex, m_vCameraPositionCenter);
400 if (!
Spawn(m_iCurrentObjectIndex, m_vCameraPositionCenter))
409 m_bTestStarted =
true;
420 m_fTimePassed += timeSlice;
421 if (m_fTimePassed <= m_fWarmupDelay)
427 int testNr = m_iCamerasCount*m_iCurrentObjectIndex + m_iCurrentCameraIndex+1;
428 Print(
string.Format(
"| Model Autotest | : Test number %1 started!", testNr));
434 float currentCameraTime = m_CurrentAutotestCamera.GetDuration();
436 if (m_fTimePassed < currentCameraTime)
438 m_CurrentAutotestCamera.LogFramesPerSecond(timeSlice);
439 m_fTimePassed+=timeSlice;
443 int testNr = m_iCamerasCount*m_iCurrentObjectIndex + m_iCurrentCameraIndex+1;
444 Print(
string.Format(
"| Model Autotest | : Test number %1 finished!", testNr));
447 m_aCameras[m_iCurrentCameraIndex].GetFramesPerSecondsData(min, max, avg);
448 Print(
string.Format(
"Test number %4 Results: Min FPS: %1 | Max FPS: %2 || Average FPS: %3", min, max, avg, testNr));
449 Print(
"-----------------------------------------------------------------");
452 m_bCameraSet =
false;
453 m_iCurrentCameraIndex++;
461 if (m_bTestStarted && m_bWarmedUp)
463 return m_fTimePassed;
472 if (!m_CurrentAutotestCamera)
475 return m_CurrentAutotestCamera.GetDuration();
481 super.EOnInit(owner);
483 if (!ValidateAutotestSettings())
487 m_iCamerasCount = m_aCameras.Count();
490 m_AutotestRegister =
new AutotestRegister();
491 m_AutotestRegister.Init(m_sConfluenceParentPageName);
494 string idxLine = m_AutotestRegister.LoadPersistentData(GetPersistentDataPath());
495 if(idxLine.Length() == 0)
496 m_iAutotestIndex = 0;
498 m_iAutotestIndex = idxLine.ToInt() + 1;
501 Print(
string.Format(
"| Model Autotest | : Starting in %1s", m_fWarmupDelay));
507 void ~SCR_ModelAutotestEntity()
509 for (
int i = 0; i < m_aCameras.Count(); i++)
511 m_aCameras[i] = null;