DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
MissionBenchmark.c
См. документацию.
1// Struct for individual benchmark locations
3{
7 string m_Name;
10
12 {
13 m_Name = name;
14 }
15
16 void SetPosition(vector start)
17 {
18 m_StartPos = start + "0 2.5 0"; // raise to head level
19 }
20
21 // note that vector[1] (height) is ignored during interpolation and setting it has no effect
23 {
24 m_StartLookAtPos = start;
25 }
26
27 void SetCameraSpeedMultiplier(float multiplier)
28 {
29 m_CamSpeedMultiplier = multiplier;
30 }
31
33 {
34 m_IsDummyTeleport = true;
35 }
36
38 {
39 m_IsDummyWait = true;
40 }
41}
42
43// Global settings of benchmark
44class BenchmarkConfig
45{
50 string m_CSVName;
51
53
55 {
56 m_Locations.Insert(loc);
57 }
58
59 void AddQuickLocation(string name, vector pos, vector lookAtPos)
60 {
62 loc.SetPosition(pos);
63 loc.SetLookAtPosition(lookAtPos);
64
65 m_Locations.Insert(loc);
66 }
67
69 {
70 BenchmarkLocation loc = new BenchmarkLocation("Teleport");
71 loc.SetDummyTeleport();
72 m_Locations.Insert(loc);
73 }
74
75 void AddWait()
76 {
77 BenchmarkLocation loc = new BenchmarkLocation("Wait");
78 loc.SetDummyWait();
79 m_Locations.Insert(loc);
80 }
81
82 // false = csv, true = rpt
83 void LogToRPT(bool logRPT)
84 {
85 m_LogToRPT = logRPT;
86 }
87
88 void DoDevPrints(bool doPrints)
89 {
90 m_DoDevPrints = doPrints;
91 }
92
93 // Preload time of individual locations after teleport
94 void SetPreloadLengthTime(int seconds)
95 {
96 m_PreloadLength = seconds;
97 }
98
99 // Time multiplier for quickly testing flypath
100 void SetTestTimeMultiplier(float multiplier)
101 {
102 m_TimeMultiplier = multiplier;
103 }
104
105 void SetCSVName(string name)
106 {
107 m_CSVName = name;
108 }
109}
110
111class MissionBenchmark : MissionGameplay
112{
113 protected const int INITIAL_PRELOAD = 5; // seconds, extra preload seconds to compensate for the game launching
114 protected const float STEP_INTERVAL = 1; // seconds, how much time passes between steps (fps measurements)
115
116 protected bool m_InitialLoadDone; // extra time is added to first preload to make up for intial loading of the game
117 protected bool m_IsPreloading; // preload time between location measurements
118 protected bool m_LocationDone; // finished measuring current location
119 protected int m_LocIndex;
120 protected int m_MeasuringStep;
121 protected float m_MeasureStepTimer = 1;
122 protected float m_SumFPS;
123 protected float m_TimeCounter;
124 protected float m_MeasureLength;
125 protected float m_StepDistance;
126
130
131 protected ref BenchmarkConfig m_Config;
132
133 protected static MissionBenchmark m_Instance;
134
136 {
137 m_Instance = this;
138 }
139
141 {
142 m_Instance = null;
143 }
144
146 {
147 return m_Instance;
148 }
149
150 BenchmarkConfig GetConfig()
151 {
152 if (!m_Config)
153 m_Config = new BenchmarkConfig();
154
155 return m_Config;
156 }
157
158 void Start()
159 {
160 if (!m_Config || m_Config.m_Locations.Count() <= 1)
161 {
162 OnBenchmarkEnd("Not enough locations defined");
163 return;
164 }
165
166 if (!m_Config.m_LogToRPT)
167 CreateCSVLog();
168
169 m_IsPreloading = true;
170
172 }
173
174 override void OnUpdate(float timeslice)
175 {
176 super.OnUpdate(timeslice);
177
178 m_TimeCounter += timeslice * m_Config.m_TimeMultiplier;
179
181 return;
182 else if (m_IsPreloading)
184 else
185 MeasureUpdate(timeslice);
186 }
187
188 // Update logic which runs when location is being preloaded
189 protected void PreloadUpdate()
190 {
192 {
193 if (m_TimeCounter >= (m_Config.m_PreloadLength + INITIAL_PRELOAD)) // end preload
194 m_InitialLoadDone = true;
195 }
196 else if (m_TimeCounter >= m_Config.m_PreloadLength * (1 / m_Config.m_TimeMultiplier)) // end preload
197 {
198 m_TimeCounter = 0;
199 m_IsPreloading = false;
200 }
201 }
202
203 // Update logic which runs when measurement is in progress
204 protected void MeasureUpdate(float timeSlice)
205 {
206 m_MeasureStepTimer += timeSlice;
208 {
209 float avgFps = GetGame().GetFps();
210
211 if (m_Config.m_DoDevPrints)
212 Print( string.Format("Measure step: %1 | FPS: %2" , m_MeasuringStep + 1, 1/avgFps) );
213
214 /*if (m_MeasuringStep >= m_MeasureLength) // end of steps
215 { }
216 else*/ // next step
217
219 m_SumFPS += ( 1/avgFps );
221 GetGame().GetPlayer().SetPosition(FreeDebugCamera.GetInstance().GetPosition() - "0 2.5 0");
222 }
223
224 LerpCamera();
225 }
226
227 protected void AdvanceLocation()
228 {
229 if (m_NextLocation.m_IsDummyWait && m_MeasuringStep < 5)
230 return;
231
232 string locationName = m_NextLocation.m_Name;
233 FPSLog(locationName, m_SumFPS/m_MeasuringStep);
234
235 if (m_Config.m_DoDevPrints)
236 Print( string.Format("%1 | Measurements: %2 | Average FPS: %3 | Elapsed time: %4 seconds" ,locationName, m_MeasuringStep, m_SumFPS/m_MeasuringStep ,m_TimeCounter) );
237
238 m_LocIndex++;
240 }
241
242 // logic for interpolating camera between location points
243 protected void LerpCamera()
244 {
245 float lerpX, lerpZ, lerpY;
246
247 vector target = m_NextLocation.m_StartPos;
248 float camSpeedAdjust = m_CurrentLocation.m_CamSpeedMultiplier * 5 * m_TimeCounter * 1/m_StepDistance;
249
250 lerpX = Math.Lerp(m_CurrentLocation.m_StartPos[0], target[0], camSpeedAdjust);
251 lerpZ = Math.Lerp(m_CurrentLocation.m_StartPos[1], target[1], camSpeedAdjust);
252 lerpY = Math.Lerp(m_CurrentLocation.m_StartPos[2], target[2], camSpeedAdjust);
253
254 if (camSpeedAdjust >= 1 || m_NextLocation.m_IsDummyWait)
255 {
257 return;
258 }
259
260 FreeDebugCamera.GetInstance().SetPosition( Vector(lerpX, lerpZ, lerpY) );
261
262 target = m_NextLocation.m_StartLookAtPos;
263
264 lerpX = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[0], target[0], camSpeedAdjust);
265 //lerpZ = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[1], target[1], camSpeedAdjust); // ignored as it causes issues with lerping between look at points
266 lerpY = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[2], target[2], camSpeedAdjust);
267 FreeDebugCamera.GetInstance().LookAt( Vector(lerpX, lerpZ, lerpY) );
268 }
269
270 protected void OnLocationSwitch()
271 {
272 if (m_LocIndex >= (m_Config.m_Locations.Count() - 1))
273 {
274 OnBenchmarkEnd("Test finished!");
275 return;
276 }
277
278 m_MeasureStepTimer = 1; // tick first measurement straight after preload
279 m_SumFPS = 0;
280 m_MeasuringStep = 0;
281 m_TimeCounter = 0;
283 m_NextLocation = m_Config.m_Locations[m_LocIndex+1];
285
286 if (!GetGame().GetPlayer())
287 {
288 CreatePlayer();
290 }
291
292 if (m_NextLocation.m_IsDummyTeleport) // flycam teleport
293 {
294 m_LocIndex += 2;
295 if (m_LocIndex >= (m_Config.m_Locations.Count() - 1))
296 {
297 OnBenchmarkEnd("Test finished!");
298 return;
299 }
300 else
301 {
303 m_NextLocation = m_Config.m_Locations[m_LocIndex+1];
306 }
307 }
308
309 if (m_NextLocation.m_IsDummyWait)
310 {
311 m_NextLocation.m_Name = m_CurrentLocation.m_Name + " Wait";
312 m_NextLocation.m_StartPos = m_CurrentLocation.m_StartPos;
313 m_NextLocation.m_StartLookAtPos = m_CurrentLocation.m_StartLookAtPos;
314 }
315
316 if (m_Config.m_DoDevPrints)
317 {
318 Print(string.Format("================"));
319 Print(string.Format("%1 test begin" , m_CurrentLocation.m_Name + " -> " + m_NextLocation.m_Name));
320 }
321 }
322
324 {
325 FreeDebugCamera.GetInstance().SetPosition(loc.m_StartPos);
326 vector lookAtPos = loc.m_StartLookAtPos;
327 lookAtPos[1] = loc.m_StartPos[1];
328 FreeDebugCamera.GetInstance().LookAt(lookAtPos);
329
330 GetGame().GetPlayer().SetPosition(m_CurrentLocation.m_StartPos - "0 2.5 0");
331 m_IsPreloading = true;
332 }
333
334 protected void OnBenchmarkEnd(string reason)
335 {
336 if (!m_Config.m_LogToRPT)
337 {
339
340 if (m_Config.m_DoDevPrints)
341 Print( "Benchmark CSV file closed" );
342 }
343
344 if (m_Config.m_DoDevPrints)
345 Print(string.Format("%1", reason));
346
347 FreeDebugCamera.GetInstance().SetActive(false);
348 GetGame().RequestExit( IDC_MAIN_QUIT ); // does not work on consoles ?
349 }
350
351 protected void CreatePlayer()
352 {
353 Entity playerEnt = GetGame().CreatePlayer(NULL, "SurvivorF_Eva", m_CurrentLocation.m_StartPos - "0 2.5 0", 0, "NONE");
354 PlayerBase player = PlayerBase.Cast(playerEnt);
355 GetGame().SelectPlayer(NULL, player);
356
357 player.GetStatWater().Set(3000);
358 player.GetStatEnergy().Set(3000);
359 player.SetAllowDamage(false);
360 player.SetCanBeDestroyed(false);
361
362 FreeDebugCamera.GetInstance().SetFOV(0.72);
363 FreeDebugCamera.GetInstance().SetActive(true);
364 }
365
366 protected void CreateCSVLog()
367 {
368 string fileName = "benchmark";
369 if (m_Config.m_CSVName != string.Empty)
370 fileName = m_Config.m_CSVName;
371
372 m_CSVLog = OpenFile("$profile:" + fileName + ".csv", FileMode.WRITE);
373 if ( m_CSVLog == 0 )
374 OnBenchmarkEnd("Failed to create benchmark .csv");
375
376 if (m_Config.m_DoDevPrints)
377 Print("Benchmark .csv created");
378
379 FPrintln(m_CSVLog, "Location,FPS,Time");
380 }
381
382 protected void FPSLog( string position, float frames )
383 {
384 int year, month, day, hour, minute, second;
385 GetYearMonthDay(year, month, day);
386 GetHourMinuteSecondUTC(hour, minute, second);
387 string timestamp = string.Format( "%1-%2-%3-%4-%5-%6", year, month, day, hour, minute, second );
388
389 if (m_Config.m_LogToRPT)
390 PrintToRPT("Average FPS: " + frames);
391 else
392 FPrintln( m_CSVLog, position + "," + frames + "," + timestamp );
393 }
394}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
void AddTeleport()
Определения MissionBenchmark.c:68
void DoDevPrints(bool doPrints)
Определения MissionBenchmark.c:88
string m_CSVName
Определения MissionBenchmark.c:50
void AddLocation(notnull BenchmarkLocation loc)
Определения MissionBenchmark.c:54
ref array< ref BenchmarkLocation > m_Locations
Определения MissionBenchmark.c:52
int m_PreloadLength
Определения MissionBenchmark.c:48
void SetPreloadLengthTime(int seconds)
Определения MissionBenchmark.c:94
void AddQuickLocation(string name, vector pos, vector lookAtPos)
Определения MissionBenchmark.c:59
class BenchmarkLocation m_LogToRPT
void AddWait()
Определения MissionBenchmark.c:75
void SetTestTimeMultiplier(float multiplier)
Определения MissionBenchmark.c:100
float m_TimeMultiplier
Определения MissionBenchmark.c:49
void SetCSVName(string name)
Определения MissionBenchmark.c:105
bool m_DoDevPrints
Определения MissionBenchmark.c:47
void LogToRPT(bool logRPT)
Определения MissionBenchmark.c:83
PlayerBase GetPlayer()
Определения ModifierBase.c:51
void SetLookAtPosition(vector start)
Определения MissionBenchmark.c:22
void SetDummyTeleport()
Определения MissionBenchmark.c:32
void SetCameraSpeedMultiplier(float multiplier)
Определения MissionBenchmark.c:27
void BenchmarkLocation(string name)
Определения MissionBenchmark.c:11
void SetDummyWait()
Определения MissionBenchmark.c:37
vector m_StartPos
Определения MissionBenchmark.c:8
vector m_StartLookAtPos
Определения MissionBenchmark.c:9
bool m_IsDummyWait
Определения MissionBenchmark.c:5
string m_Name
Определения MissionBenchmark.c:7
void SetPosition(vector start)
Определения MissionBenchmark.c:16
bool m_IsDummyTeleport
Определения MissionBenchmark.c:4
float m_CamSpeedMultiplier
Определения MissionBenchmark.c:6
proto native void SelectPlayer(PlayerIdentity identity, Object player)
Selects player's controlled object.
proto native Entity CreatePlayer(PlayerIdentity identity, string name, vector pos, float radius, string spec)
Assign player entity to client (in multiplayer)
proto native void RequestExit(int code)
Sets exit code and quits in the right moment.
proto native float GetFps()
Returns average FPS of last 16 frames.
proto native DayZPlayer GetPlayer()
Определения Camera.c:2
Определения EnMath.c:7
const float STEP_INTERVAL
Определения MissionBenchmark.c:114
void ~MissionBenchmark()
Определения MissionBenchmark.c:140
void AdvanceLocation()
Определения MissionBenchmark.c:227
static MissionBenchmark m_Instance
Определения MissionBenchmark.c:133
void Start()
Определения MissionBenchmark.c:158
bool m_LocationDone
Определения MissionBenchmark.c:118
void MeasureUpdate(float timeSlice)
Определения MissionBenchmark.c:204
void OnLocationSwitch()
Определения MissionBenchmark.c:270
float m_MeasureStepTimer
Определения MissionBenchmark.c:121
void FPSLog(string position, float frames)
Определения MissionBenchmark.c:382
void CreatePlayer()
Определения MissionBenchmark.c:351
void OnBenchmarkEnd(string reason)
Определения MissionBenchmark.c:334
bool m_InitialLoadDone
Определения MissionBenchmark.c:116
BenchmarkLocation m_CurrentLocation
Определения MissionBenchmark.c:128
const int INITIAL_PRELOAD
Определения MissionBenchmark.c:113
float m_MeasureLength
Определения MissionBenchmark.c:124
void LerpCamera()
Определения MissionBenchmark.c:243
void MissionBenchmark()
Определения MissionBenchmark.c:135
ref BenchmarkConfig m_Config
Определения MissionBenchmark.c:131
float m_TimeCounter
Определения MissionBenchmark.c:123
float m_SumFPS
Определения MissionBenchmark.c:122
override void OnUpdate(float timeslice)
Определения MissionBenchmark.c:174
float m_StepDistance
Определения MissionBenchmark.c:125
void CreateCSVLog()
Определения MissionBenchmark.c:366
int m_MeasuringStep
Определения MissionBenchmark.c:120
BenchmarkLocation m_NextLocation
Определения MissionBenchmark.c:129
void PreloadUpdate()
Определения MissionBenchmark.c:189
BenchmarkConfig GetConfig()
Определения MissionBenchmark.c:150
static MissionBenchmark GetInstance()
Определения MissionBenchmark.c:145
void TeleportToPos(BenchmarkLocation loc)
Определения MissionBenchmark.c:323
int m_LocIndex
Определения MissionBenchmark.c:119
FileHandle m_CSVLog
Определения MissionBenchmark.c:127
bool m_IsPreloading
Определения MissionBenchmark.c:117
Определения PlayerBaseClient.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
Определения EnConvert.c:106
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
FileMode
Определения EnSystem.c:383
proto void CloseFile(FileHandle file)
Close the File.
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
int[] FileHandle
Определения EnSystem.c:390
proto void FPrintln(FileHandle file, void var)
Write to file and add new line.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
proto void GetYearMonthDay(out int year, out int month, out int day)
Returns system date.
proto void GetHourMinuteSecondUTC(out int hour, out int minute, out int second)
Returns UTC system time.
const int IDC_MAIN_QUIT
Определения constants.c:144