DayZ 1.29
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 AddLocation(loc);
66 }
67
69 {
70 BenchmarkLocation loc = new BenchmarkLocation("Teleport");
71 loc.SetDummyTeleport();
72 AddLocation(loc);
73 }
74
75 void AddWait()
76 {
77 BenchmarkLocation loc = new BenchmarkLocation("Wait");
78 loc.SetDummyWait();
79 AddLocation(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 m_StepDistance = vector.Distance(m_CurrentLocation.m_StartPos, target);
261 float camSpeedAdjust = m_CurrentLocation.m_CamSpeedMultiplier * 5 * m_TimeCounter * 1/m_StepDistance;
262 float distanceMulti = 1/Math.Max(0.001, m_StepDistance);
263
264 lerpX = Math.Lerp(m_CurrentLocation.m_StartPos[0], target[0], camSpeedAdjust);
265 lerpZ = Math.Lerp(m_CurrentLocation.m_StartPos[1], target[1], camSpeedAdjust);
266 lerpY = Math.Lerp(m_CurrentLocation.m_StartPos[2], target[2], camSpeedAdjust);
267
268 if (camSpeedAdjust >= 1 || m_NextLocation.m_IsDummyWait)
269 {
271 return;
272 }
273
274 FreeDebugCamera.GetInstance().SetPosition( Vector(lerpX, lerpZ, lerpY) );
275
276 target = m_NextLocation.m_StartLookAtPos;
277
278 lerpX = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[0], target[0], camSpeedAdjust);
279 //lerpZ = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[1], target[1], camSpeedAdjust); // ignored as it causes issues with lerping between look at points
280 lerpY = Math.Lerp(m_CurrentLocation.m_StartLookAtPos[2], target[2], camSpeedAdjust);
281 FreeDebugCamera.GetInstance().LookAt( Vector(lerpX, lerpZ, lerpY) );
282 }
283
284 protected void OnLocationSwitch()
285 {
286 if (m_LocIndex >= (m_Config.m_Locations.Count() - 1))
287 {
288 OnBenchmarkEnd("Test finished!");
289 return;
290 }
291
292 m_MeasureStepTimer = 1; // tick first measurement straight after preload
293 m_SumFPS = 0;
294 m_MeasuringStep = 0;
295 m_TimeCounter = 0;
297 m_NextLocation = m_Config.m_Locations[m_LocIndex+1];
298
299 if (!GetGame().GetPlayer())
300 {
301 CreatePlayer();
303 }
304
305 if (m_NextLocation.m_IsDummyTeleport) // flycam teleport
306 {
307 m_LocIndex += 2;
308 if (m_LocIndex >= (m_Config.m_Locations.Count() - 1))
309 {
310 OnBenchmarkEnd("Test finished!");
311 return;
312 }
313 else
314 {
316 m_NextLocation = m_Config.m_Locations[m_LocIndex+1];
319 }
320 }
321
322 if (m_NextLocation.m_IsDummyWait)
323 {
324 m_NextLocation.m_Name = m_CurrentLocation.m_Name + " Wait";
325 m_NextLocation.m_StartPos = m_CurrentLocation.m_StartPos;
326 m_NextLocation.m_StartLookAtPos = m_CurrentLocation.m_StartLookAtPos;
327 }
328
329 if (m_Config.m_DoDevPrints)
330 {
331 Print(string.Format("================"));
332 Print(string.Format("%1 test begin" , m_CurrentLocation.m_Name + " -> " + m_NextLocation.m_Name));
333 }
334 }
335
337 {
338 FreeDebugCamera.GetInstance().SetPosition(loc.m_StartPos);
339 vector lookAtPos = loc.m_StartLookAtPos;
340 lookAtPos[1] = loc.m_StartPos[1];
341 FreeDebugCamera.GetInstance().LookAt(lookAtPos);
342
343 GetGame().GetPlayer().SetPosition(m_CurrentLocation.m_StartPos - "0 2.5 0");
344 m_IsPreloading = true;
345 }
346
347 protected void OnBenchmarkEnd(string reason)
348 {
349 if (!m_Config.m_LogToRPT)
350 {
352
353 if (m_Config.m_DoDevPrints)
354 Print( "Benchmark CSV file closed" );
355 }
356
357 if (m_Config.m_DoDevPrints)
358 Print(string.Format("%1", reason));
359
360 FreeDebugCamera.GetInstance().SetActive(false);
361 GetGame().RequestExit( IDC_MAIN_QUIT ); // does not work on consoles ?
362 }
363
364 protected void CreatePlayer()
365 {
366 Entity playerEnt = GetGame().CreatePlayer(null, "SurvivorF_Eva", m_CurrentLocation.m_StartPos - "0 2.5 0", 0, "NONE");
367 PlayerBase player = PlayerBase.Cast(playerEnt);
368 GetGame().SelectPlayer(NULL, player);
369
370 player.GetStatWater().Set(3000);
371 player.GetStatEnergy().Set(3000);
372 player.SetModifiers(false);
373 player.SetAllowDamage(false);
374 player.SetCanBeDestroyed(false);
375 player.DisableSimulation(true);
376
377 FreeDebugCamera.GetInstance().SetFOV(0.72);
378 FreeDebugCamera.GetInstance().SetActive(true);
379 }
380
381 protected void CreateCSVLog()
382 {
383 string fileName = "benchmark";
384 if (m_Config.m_CSVName != string.Empty)
385 fileName = m_Config.m_CSVName;
386
387 m_CSVLog = OpenFile("$profile:" + fileName + ".csv", FileMode.WRITE);
388 if ( m_CSVLog == 0 )
389 OnBenchmarkEnd("Failed to create benchmark .csv");
390
391 if (m_Config.m_DoDevPrints)
392 Print("Benchmark .csv created");
393
394 FPrintln(m_CSVLog, "location,FPS,time");
395 }
396
397 protected void FPSLog( string position, float frames )
398 {
399 int year, month, day, hour, minute, second;
400 GetYearMonthDay(year, month, day);
401 GetHourMinuteSecondUTC(hour, minute, second);
402 string timestamp = string.Format( "%1-%2-%3-%4-%5-%6", year, month, day, hour, minute, second );
403
404 if (m_Config.m_LogToRPT)
405 PrintToRPT("Average FPS: " + frames);
406 else
407 FPrintln( m_CSVLog, position + "," + frames + "," + timestamp );
408 }
409}
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
Определения 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:284
float m_MeasureStepTimer
Определения MissionBenchmark.c:121
void FPSLog(string position, float frames)
Определения MissionBenchmark.c:397
void CreatePlayer()
Определения MissionBenchmark.c:364
void OnBenchmarkEnd(string reason)
Определения MissionBenchmark.c:347
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:381
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:336
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:119
DayZGame GetGame()
Определения gameplay.c:636
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 Max(float x, float y)
Returns bigger of two given values.
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/DayZ/constants.c:144