DayZ 1.28
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 {
161
162 if (!m_Config || m_Config.m_Locations.Count() <= 1)
163 {
164 OnBenchmarkEnd("Not enough locations defined");
165 return;
166 }
167
168 if (!m_Config.m_LogToRPT)
169 CreateCSVLog();
170
171 m_IsPreloading = true;
172
174 }
175
176 override void OnUpdate(float timeslice)
177 {
178 super.OnUpdate(timeslice);
179
180 m_TimeCounter += timeslice * m_Config.m_TimeMultiplier;
181
183 return;
184 else if (m_IsPreloading)
186 else
187 MeasureUpdate(timeslice);
188 }
189
190 // Update logic which runs when location is being preloaded
191 protected void PreloadUpdate()
192 {
194 {
195 if (m_TimeCounter >= (m_Config.m_PreloadLength + INITIAL_PRELOAD)) // end preload
196 m_InitialLoadDone = true;
197 }
198 else if (m_TimeCounter >= m_Config.m_PreloadLength * (1 / m_Config.m_TimeMultiplier)) // end preload
199 {
200 m_TimeCounter = 0;
201 m_IsPreloading = false;
202 }
203 }
204
205 // Update logic which runs when measurement is in progress
206 protected void MeasureUpdate(float timeSlice)
207 {
208 m_MeasureStepTimer += timeSlice;
210 {
211 float avgFps = GetGame().GetFps();
212
213 if (m_Config.m_DoDevPrints)
214 Print( string.Format("Measure step: %1 | FPS: %2" , m_MeasuringStep + 1, 1/avgFps) );
215
216 /*if (m_MeasuringStep >= m_MeasureLength) // end of steps
217 { }
218 else*/ // next step
219
221 m_SumFPS += ( 1/avgFps );
223 GetGame().GetPlayer().SetPosition(FreeDebugCamera.GetInstance().GetPosition() - "0 2.5 0");
224 }
225
226 LerpCamera();
227 }
228
229 protected void DisableWeatherChange()
230 {
231 Weather weather = GetGame().GetWeather();
232 weather.SetDynVolFogHeightBias(0,0);
233 weather.SetDynVolFogHeightDensity(0,0);
234 weather.SetDynVolFogDistanceDensity(0,0);
235
236 weather.SetWeatherUpdateFreeze(true);
237 }
238
239 protected void AdvanceLocation()
240 {
241 if (m_NextLocation.m_IsDummyWait && m_MeasuringStep < 5)
242 return;
243
244 string locationName = m_NextLocation.m_Name;
245 FPSLog(locationName, m_SumFPS/m_MeasuringStep);
246
247 if (m_Config.m_DoDevPrints)
248 Print( string.Format("%1 | Measurements: %2 | Average FPS: %3 | Elapsed time: %4 seconds" ,locationName, m_MeasuringStep, m_SumFPS/m_MeasuringStep ,m_TimeCounter) );
249
250 m_LocIndex++;
252 }
253
254 // logic for interpolating camera between location points
255 protected void LerpCamera()
256 {
257 float lerpX, lerpZ, lerpY;
258
259 vector target = m_NextLocation.m_StartPos;
260 float camSpeedAdjust = m_CurrentLocation.m_CamSpeedMultiplier * 5 * m_TimeCounter * 1/m_StepDistance;
261
262 lerpX = Math.Lerp(m_CurrentLocation.m_StartPos[0], target[0], camSpeedAdjust);
263 lerpZ = Math.Lerp(m_CurrentLocation.m_StartPos[1], target[1], camSpeedAdjust);
264 lerpY = Math.Lerp(m_CurrentLocation.m_StartPos[2], target[2], camSpeedAdjust);
265
266 if (camSpeedAdjust >= 1 || m_NextLocation.m_IsDummyWait)
267 {
269 return;
270 }
271
272 FreeDebugCamera.GetInstance().SetPosition( Vector(lerpX, lerpZ, lerpY) );
273
274 target = m_NextLocation.m_StartLookAtPos;
275
276 lerpX = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[0], target[0], camSpeedAdjust);
277 //lerpZ = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[1], target[1], camSpeedAdjust); // ignored as it causes issues with lerping between look at points
278 lerpY = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[2], target[2], camSpeedAdjust);
279 FreeDebugCamera.GetInstance().LookAt( Vector(lerpX, lerpZ, lerpY) );
280 }
281
282 protected void OnLocationSwitch()
283 {
284 if (m_LocIndex >= (m_Config.m_Locations.Count() - 1))
285 {
286 OnBenchmarkEnd("Test finished!");
287 return;
288 }
289
290 m_MeasureStepTimer = 1; // tick first measurement straight after preload
291 m_SumFPS = 0;
292 m_MeasuringStep = 0;
293 m_TimeCounter = 0;
295 m_NextLocation = m_Config.m_Locations[m_LocIndex+1];
297
298 if (!GetGame().GetPlayer())
299 {
300 CreatePlayer();
302 }
303
304 if (m_NextLocation.m_IsDummyTeleport) // flycam teleport
305 {
306 m_LocIndex += 2;
307 if (m_LocIndex >= (m_Config.m_Locations.Count() - 1))
308 {
309 OnBenchmarkEnd("Test finished!");
310 return;
311 }
312 else
313 {
315 m_NextLocation = m_Config.m_Locations[m_LocIndex+1];
318 }
319 }
320
321 if (m_NextLocation.m_IsDummyWait)
322 {
323 m_NextLocation.m_Name = m_CurrentLocation.m_Name + " Wait";
324 m_NextLocation.m_StartPos = m_CurrentLocation.m_StartPos;
325 m_NextLocation.m_StartLookAtPos = m_CurrentLocation.m_StartLookAtPos;
326 }
327
328 if (m_Config.m_DoDevPrints)
329 {
330 Print(string.Format("================"));
331 Print(string.Format("%1 test begin" , m_CurrentLocation.m_Name + " -> " + m_NextLocation.m_Name));
332 }
333 }
334
336 {
337 FreeDebugCamera.GetInstance().SetPosition(loc.m_StartPos);
338 vector lookAtPos = loc.m_StartLookAtPos;
339 lookAtPos[1] = loc.m_StartPos[1];
340 FreeDebugCamera.GetInstance().LookAt(lookAtPos);
341
342 GetGame().GetPlayer().SetPosition(m_CurrentLocation.m_StartPos - "0 2.5 0");
343 m_IsPreloading = true;
344 }
345
346 protected void OnBenchmarkEnd(string reason)
347 {
348 if (!m_Config.m_LogToRPT)
349 {
351
352 if (m_Config.m_DoDevPrints)
353 Print( "Benchmark CSV file closed" );
354 }
355
356 if (m_Config.m_DoDevPrints)
357 Print(string.Format("%1", reason));
358
359 FreeDebugCamera.GetInstance().SetActive(false);
360 GetGame().RequestExit( IDC_MAIN_QUIT ); // does not work on consoles ?
361 }
362
363 protected void CreatePlayer()
364 {
365 Entity playerEnt = GetGame().CreatePlayer(NULL, "SurvivorF_Eva", m_CurrentLocation.m_StartPos - "0 2.5 0", 0, "NONE");
366 PlayerBase player = PlayerBase.Cast(playerEnt);
367 GetGame().SelectPlayer(NULL, player);
368
369 player.GetStatWater().Set(3000);
370 player.GetStatEnergy().Set(3000);
371 player.SetAllowDamage(false);
372 player.SetCanBeDestroyed(false);
373 player.DisableSimulation(true);
374
375 FreeDebugCamera.GetInstance().SetFOV(0.72);
376 FreeDebugCamera.GetInstance().SetActive(true);
377 }
378
379 protected void CreateCSVLog()
380 {
381 string fileName = "benchmark";
382 if (m_Config.m_CSVName != string.Empty)
383 fileName = m_Config.m_CSVName;
384
385 m_CSVLog = OpenFile("$profile:" + fileName + ".csv", FileMode.WRITE);
386 if ( m_CSVLog == 0 )
387 OnBenchmarkEnd("Failed to create benchmark .csv");
388
389 if (m_Config.m_DoDevPrints)
390 Print("Benchmark .csv created");
391
392 FPrintln(m_CSVLog, "Location,FPS,Time");
393 }
394
395 protected void FPSLog( string position, float frames )
396 {
397 int year, month, day, hour, minute, second;
398 GetYearMonthDay(year, month, day);
399 GetHourMinuteSecondUTC(hour, minute, second);
400 string timestamp = string.Format( "%1-%2-%3-%4-%5-%6", year, month, day, hour, minute, second );
401
402 if (m_Config.m_LogToRPT)
403 PrintToRPT("Average FPS: " + frames);
404 else
405 FPrintln( m_CSVLog, position + "," + frames + "," + timestamp );
406 }
407}
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()
proto native Weather GetWeather()
Returns weather controller object.
Определения Camera.c:2
Определения EnMath.c:7
const float STEP_INTERVAL
Определения MissionBenchmark.c:114
void ~MissionBenchmark()
Определения MissionBenchmark.c:140
void AdvanceLocation()
Определения MissionBenchmark.c:239
static MissionBenchmark m_Instance
Определения MissionBenchmark.c:133
void Start()
Определения MissionBenchmark.c:158
bool m_LocationDone
Определения MissionBenchmark.c:118
void MeasureUpdate(float timeSlice)
Определения MissionBenchmark.c:206
void OnLocationSwitch()
Определения MissionBenchmark.c:282
float m_MeasureStepTimer
Определения MissionBenchmark.c:121
void FPSLog(string position, float frames)
Определения MissionBenchmark.c:395
void CreatePlayer()
Определения MissionBenchmark.c:363
void OnBenchmarkEnd(string reason)
Определения MissionBenchmark.c:346
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:255
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:176
float m_StepDistance
Определения MissionBenchmark.c:125
void CreateCSVLog()
Определения MissionBenchmark.c:379
int m_MeasuringStep
Определения MissionBenchmark.c:120
BenchmarkLocation m_NextLocation
Определения MissionBenchmark.c:129
void PreloadUpdate()
Определения MissionBenchmark.c:191
BenchmarkConfig GetConfig()
Определения MissionBenchmark.c:150
static MissionBenchmark GetInstance()
Определения MissionBenchmark.c:145
void TeleportToPos(BenchmarkLocation loc)
Определения MissionBenchmark.c:335
int m_LocIndex
Определения MissionBenchmark.c:119
FileHandle m_CSVLog
Определения MissionBenchmark.c:127
void DisableWeatherChange()
Определения MissionBenchmark.c:229
bool m_IsPreloading
Определения MissionBenchmark.c:117
Определения PlayerBaseClient.c:2
proto native void SetDynVolFogHeightBias(float value, float time=0)
Sets the 'dynamic' volumetric height bias. Takes effect only if enabled via world config.
proto native void SetDynVolFogDistanceDensity(float value, float time=0)
Sets the dynamic volumetric fog distance density. Only takes effect if dynamic volumetric fog is enab...
proto native void SetDynVolFogHeightDensity(float value, float time=0)
Sets the dynamic volumetric fog height density. Only takes effect if dynamic volumetric fog is enable...
void SetWeatherUpdateFreeze(bool state)
Определения Weather.c:393
Определения Weather.c:168
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
Определения 3_Game/constants.c:144