11 private float m_TimeInterval;
13 void SimpleTimeSignal(
float timeInterval)
16 m_TimeInterval = timeInterval;
19 bool Update(
float currentTime)
36 void RestartAndSignal()
44 [
Attribute(
"Camera1", UIWidgets.EditBox,
"Name of camera entity",
"")]
45 private string m_cameraEntityName;
47 [
Attribute(
"60", UIWidgets.Slider,
"Which FPS is considered as minimal",
"0 240 1")]
48 private float m_FPSLimit;
50 [
Attribute(
"1.8", UIWidgets.Slider,
"Distance between surface and camera on y-axis",
"0 20 0.1")]
51 private float m_HeightAboveSurface;
53 [
Attribute(
"5", UIWidgets.Slider,
"Time in seconds to make a 360 degree rotation, to load all of the resources",
"1 100 1")]
54 private float m_FirstRotationTime;
56 [
Attribute(
"5", UIWidgets.Slider,
"Time in seconds to make a 360 degree rotation, to make the measurement",
"1 100 1")]
57 private float m_SecondRotationTime;
59 [
Attribute(
"1", UIWidgets.Slider,
"Time in seconds to start the autotest, n seconds after the initialization of this object",
"1 20 1")]
60 private float m_StartAfterInitTime;
62 [
Attribute(
"10", UIWidgets.Slider,
"Grid size on x axis",
"1 100 1")]
63 private float m_GridX;
65 [
Attribute(
"10", UIWidgets.Slider,
"Grid size on z axis",
"1 100 1")]
66 private float m_GridZ;
68 private int m_GridPosition;
71 private string m_directory;
73 private TextWidget m_FPSWidget;
75 protected float m_timeFromStart;
76 protected float m_timeLastStatsSnapshot;
78 private ref SimpleTimeSignal m_StartTtimeSignal;
79 private ref SimpleTimeSignal m_FirstRotationSignal;
80 private ref SimpleTimeSignal m_SecondRotationSignal;
87 private int m_CurrentRotation;
89 private ref Measurement m_MeasureFPS;
90 private ref Measurement m_MeasureMemory;
92 private ref array<ref Measurement> m_MeasurementMemory;
94 [
Attribute(
"MotionZone", UIWidgets.EditBox,
"Motion Zone Object Name",
"")]
95 private string m_MotionZone;
99 private float m_CurrentRotationT;
100 private float m_CurrentDuration;
102 void AutotestGrid(IEntitySource src,
IEntity parent)
106 m_MeasureFPS =
new Measurement();
107 m_MeasureMemory =
new Measurement();
108 m_MeasurementMemory =
new array<ref Measurement>();
109 int mc = MemoryStatsSnapshot.GetStatsCount();
110 for (
int i = 0; i < mc; i++)
112 m_MeasurementMemory.Insert(
new Measurement());
117 m_timeLastStatsSnapshot = 0;
118 m_CurrentRotation = -1;
119 m_CurrentRotationT = 0;
121 m_StartTtimeSignal =
new SimpleTimeSignal(m_StartAfterInitTime);
122 m_FirstRotationSignal =
new SimpleTimeSignal(m_FirstRotationTime);
123 m_SecondRotationSignal =
new SimpleTimeSignal(m_SecondRotationTime);
125 System.GetCLIParam(
"autotest-output-dir", m_directory);
127 if (m_directory.Length() == 0)
129 m_directory =
"$logs:" +
GetName();
132 AutotestBase.Reset();
133 AutotestBase.SetLastProcessingTime_Treshold(100/1000);
140 vector GridPositionToWorldPosition(
int gridPosition)
142 float dX = m_MotionZoneInstance.GetMax()[0] - m_MotionZoneInstance.GetMin()[0];
143 float dZ = m_MotionZoneInstance.GetMax()[2] - m_MotionZoneInstance.GetMin()[2];
145 float nX = dX / m_GridX;
146 float nZ = dZ / m_GridZ;
148 int t = Math.AbsInt(gridPosition / m_GridX);
150 int cZ = gridPosition - t * m_GridX;
152 vector ret =
Vector(m_MotionZoneInstance.GetMin()[0] + nX * cX + 0.5 * nX, 0, m_MotionZoneInstance.GetMin()[2] + nZ * cZ + 0.5 * nZ);
153 ret[1] = m_HeightAboveSurface + GetYDistance(ret[0], ret[2]);
158 void UpdateMeasurements()
160 int f = System.GetFPS();
162 m_MeasureFPS.AddValue(f);
163 m_MeasureMemory.AddValue(System.MemoryAllocationKB());
165 if (m_timeFromStart - m_timeLastStatsSnapshot > 2)
167 m_timeLastStatsSnapshot = m_timeFromStart;
169 auto snapshot =
new MemoryStatsSnapshot();
170 int count = snapshot.GetStatsCount();
171 for (
int i = 0; i < count; i++)
173 int value = snapshot.GetStatValue(i);
174 m_MeasurementMemory[i].AddValue(value);
179 override void EOnInit(
IEntity owner)
189 m_camera.SetOrigin(
Vector(1269.97, 32.95, 1156.55));
194 if (m_MotionZoneInstance != null)
196 m_MotionZoneInstance.Initialize();
199 m_FPSWidget = TextWidget.Cast(
g_Game.
GetWorkspace().CreateWidgetInWorkspace(
WidgetType.TextWidgetTypeID, 16, 16, 512, 128,
WidgetFlags.VISIBLE,
new Color(0.0, 0.0, 0.0, 1.0), 1024));
200 m_FPSWidget.SetExactFontSize(64);
211 private void MakeSummeryFile(
string filename)
213 FileHandle descrFile = FileIO.OpenFile(filename,
FileMode.WRITE);
219 descrFile.WriteLine(
string.Format(
"GRID AUTO TEST"));
220 descrFile.WriteLine(
string.Format(
"Resolution: %1 x %2 px", sizeX, sizeY));
222 descrFile.WriteLine(
string.Format(
"Entering playmode time: %1 s",
g_Game.
GetLoadTime() / 1000));
224 descrFile.WriteLine(
string.Format(
"Load time: %1 s",
g_Game.
GetLoadTime() / 1000));
226 descrFile.WriteLine(
string.Format(
"Duration: %1 s", m_timeFromStart));
228 descrFile.WriteLine(
string.Format(
"FPS average (s): %1", m_MeasureFPS.ComputeAverage()));
229 descrFile.WriteLine(
string.Format(
"FPS min (s): %1", m_MeasureFPS.m_Min));
230 descrFile.WriteLine(
string.Format(
"FPS max (s): %1", m_MeasureFPS.m_Max));
232 int count = MemoryStatsSnapshot.GetStatsCount();
233 for (
int i = 0; i < count; i++)
235 string name = MemoryStatsSnapshot.GetStatName(i);
236 descrFile.WriteLine(
string.Format(
"Measurement '%1' average: %2", name, (
int)m_MeasurementMemory[i].
ComputeAverage()));
237 descrFile.WriteLine(
string.Format(
"Measurement '%1' min: %2", name, (
int)m_MeasurementMemory[i].
m_Min));
238 descrFile.WriteLine(
string.Format(
"Measurement '%1' max: %2", name, (
int)m_MeasurementMemory[i].
m_Max));
242 Print(
"Summary file successfully saved into " + filename);
246 override void EOnFrame(
IEntity owner,
float timeSlice)
250 int fps = System.GetFPS();
251 m_FPSWidget.SetText(
"FPS " + fps);
252 if (fps < m_FPSLimit)
253 m_FPSWidget.SetColor(
new Color(1.0, 0.0, 0.0, 1.0));
255 m_FPSWidget.SetColor(
new Color(0.0, 1.0, 0.0, 1.0));
265 destination = output[0];
268 bool signal0 = m_StartTtimeSignal.Update(m_timeFromStart);
269 bool signal1 = m_FirstRotationSignal.Update(m_timeFromStart);
270 bool signal2 = m_SecondRotationSignal.Update(m_timeFromStart);
272 if (signal0 && m_CurrentRotation == -1)
274 m_CurrentRotation = 0;
275 m_FirstRotationSignal.RestartAndSignal();
277 vector p = GridPositionToWorldPosition(m_GridPosition);
278 m_camera.SetOrigin(p);
280 Print(
"-- init time done");
283 if (signal1 && m_CurrentRotation == 0)
286 m_CurrentRotation = 1;
287 m_CurrentRotationT = 0;
288 m_CurrentDuration = m_FirstRotationTime;
289 Print(
"-- start 1st rotation");
292 if (signal1 && m_CurrentRotation == 1)
295 m_CurrentRotation = 2;
296 m_CurrentDuration = 1;
297 Print(
"-- end 1st rotation");
298 m_SecondRotationSignal.RestartAndSignal();
301 if (signal2 && m_CurrentRotation == 2)
304 m_CurrentRotation = 3;
305 m_CurrentRotationT = 0;
306 m_CurrentDuration = m_SecondRotationTime;
307 Print(
"-- start 2nd rotation");
310 if (signal2 && m_CurrentRotation == 3)
313 if (m_GridPosition >= m_GridX * m_GridZ)
315 Print(
"-- END of test");
316 string summeryFilename =
string.Format(
"%1/%2", m_directory,
"summary_grid.txt");
317 Print(
"Autotest Finished; result in " + summeryFilename);
318 FileIO.MakeDirectory(m_directory);
319 MakeSummeryFile(summeryFilename);
324 m_CurrentRotation = 0;
325 m_CurrentDuration = 1;
327 vector p = GridPositionToWorldPosition(m_GridPosition);
328 m_camera.SetOrigin(p);
331 m_FirstRotationSignal.RestartAndSignal();
334 Print(
"-- end 2nd rotation a move to next grid point");
338 if (m_CurrentRotation > 0)
340 RotateCamera(timeSlice, m_CurrentDuration);
343 if (m_CurrentRotation == 3)
345 UpdateMeasurements();
348 if (AutotestBase.IsLastProcessingTime_Signal())
351 Print(
"!!! Warning Frame update too long");
353 AutotestBase.ResetLastProcessingTime_Signal();
356 m_timeFromStart += timeSlice;
359 private void RotateCamera(
float timeSlice,
float duration)
364 float d = duration / 4;
366 if (m_CurrentRotationT <= 1 * d)
368 Math3D.DirectionAndUpMatrix(vector.Forward, vector.Up, matF);
369 Math3D.DirectionAndUpMatrix(vector.Right, vector.Up, matB);
372 if (m_CurrentRotationT <= 2 * d)
374 Math3D.DirectionAndUpMatrix(vector.Right, vector.Up, matF);
375 Math3D.DirectionAndUpMatrix(-vector.Forward, vector.Up, matB);
378 if (m_CurrentRotationT <= 3 * d)
380 Math3D.DirectionAndUpMatrix(-vector.Forward, vector.Up, matF);
381 Math3D.DirectionAndUpMatrix(-vector.Right, vector.Up, matB);
385 Math3D.DirectionAndUpMatrix(-vector.Right, vector.Up, matF);
386 Math3D.DirectionAndUpMatrix(vector.Forward, vector.Up, matB);
390 Math3D.MatrixToQuat(matF, quatF);
393 Math3D.MatrixToQuat(matB, quatB);
397 float t = m_CurrentRotationT;
398 if (m_CurrentRotationT >= 3.0 * d)
400 t = (t - 3.0 * d) / d;
403 if (m_CurrentRotationT >= 2.0 * d)
405 t = (t - 2.0 * d) / d;
408 if (m_CurrentRotationT >= 1.0 * d)
410 t = (t - 1.0 * d) / d;
417 Math3D.QuatLerp(outQuat, quatF, quatB, t);
419 m_CurrentRotationT += timeSlice;
421 vector
angles = Math3D.QuatToAngles(outQuat);
423 m_camera.SetYawPitchRoll(
angles);
426 private string QuatToString(
float q[4])
428 return "(" + q[0] +
"," + q[1] +
"," + q[2] +
"," + q[3] +
")";
431 private float GetYDistance(
float x,
float z)
433 float wy =
GetWorld().GetSurfaceY(x, z);
437 oh =
GetWorld().GetOceanBaseHeight();
438 oh = Math.Ceil(Math.AbsFloat(oh));
AutotestGridClass m_LastTime
void MotionZone(IEntitySource src, IEntity parent)
MotionAutoTestClass m_Min
ref array< string > angles
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
proto external void RequestClose()
Setting request flag for engine to exit the game.
proto external bool IsPreloadFinished()
If preload (started with BeginPreload method) is finished, returns true.
proto external int GetLoadTime()
Returns load time in milliseconds for the lastly loaded world.
proto external bool BeginPreload(notnull BaseWorld world, vector pos, float radius, int maxTime_sec=60)
Begin preloading on given position with given radius. Call is non-blocking, to get status of preload ...
proto external IEntity FindEntity(string name)
sealed WorkspaceWidget GetWorkspace()
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 external string GetName()
Game g_Game
Game singleton instance.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
EntityFlags
Various entity flags.
FileMode
Mode for opening file. See FileSystem::Open.
proto native vector Vector(float x, float y, float z)
WidgetFlags
Widget flags. See enf::Widget::SetFlags().