Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
debug.c
Go to the documentation of this file.
1 // TODO:
2 // 1. Alredy exist some key in array / map
3 // 2. Object is null (check object & log error)
4 // 3. Debug version only
5 // 4. Destructor of static classes
6 // 5. Debug Console Interface:
7 // - Clear Log
8 // - Filter
9 // - Log per frame
10 // 6. Per frame log ?
11 // 7. Zapis do fajlu
12 
13 class Debug
14 {
15  static private const string LOG_DEBUG = "Debug";
16  static private const string LOG_DEBUG_ACTION = "Action";
17  static private const string LOG_DEBUG_SYMPTOM = "Symptom";
18  static private const string LOG_DEBUG_INV_MOVE = "Inv Move";
19  static private const string LOG_DEBUG_INV_RESERVATION = "Inv Rrsv";
20  static private const string LOG_DEBUG_INV_HFSM = "HFSM";
21  static private const string LOG_DEBUG_QUICKBAR = "Quickbar";
22  static private const string LOG_DEBUG_BASEBUILDING = "Base Building";
23  static private const string LOG_DEBUG_BLEEDING_CHANCES = "Bleeding";
24  static private const string LOG_DEBUG_TRIGGER = "Trigger";
25  static private const string LOG_DEBUG_PARTICLE = "Particle";
26  static private const string LOG_DEBUG_TF = "TestFramework";
27  static private const string LOG_DEBUG_WEIGHT = "Weight";
28  static private const string LOG_DEBUG_MELEE = "Melee";
29  static private const string LOG_DEBUG_WEATHER = "Weather";
30 
31  static private const string LOG_INFO = "Info";
32  static private const string LOG_WARNING = "Warning";
33  static private const string LOG_ERROR = "Error";
34  static private const string LOG_DEFAULT = "n/a";
35 
36  static private ref array<Shape> m_DebugShapes;
37 
38  static Widget m_DebugLayoutCanvas;
39  static CanvasWidget m_CanvasDebug;
40 
41 
42 
43  static string GetDebugName(Managed entity)
44  {
45  if (!entity)
46  return "";
47 
48  Object obj;
49  if (CastTo(obj, entity))
50  return obj.GetDebugNameNative();
51 
52  return entity.GetDebugName();
53  }
54 
55  static void InitCanvas()
56  {
57  if (!m_DebugLayoutCanvas)
58  {
59  m_DebugLayoutCanvas = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_debugcanvas.layout");
60  m_CanvasDebug = CanvasWidget.Cast( m_DebugLayoutCanvas.FindAnyWidget( "CanvasWidget" ) );
61  }
62  }
63 
64  static void ClearCanvas()
65  {
66  if (m_CanvasDebug)
67  m_CanvasDebug.Clear();
68  }
69 
70  static void CanvasDrawLine(float x1, float y1, float x2, float y2, float width, int color)
71  {
72  InitCanvas();
73  m_CanvasDebug.DrawLine(x1, y1, x2, y2, width, color);
74  }
75 
87  static void CanvasDrawPoint(float x1, float y1, int color)
88  {
89  CanvasDrawLine(x1, y1, x1+1, y1, 1, color);
90  }
91 
92  static void Init()
93  {
94  m_DebugShapes = new array<Shape>;
95  }
96 
97  static void DestroyAllShapes()
98  {
99  for ( int i = 0; i < m_DebugShapes.Count(); ++i )
100  {
101  if ( m_DebugShapes.Get(i) )
102  {
103  m_DebugShapes.Get(i).Destroy();
104  }
105  }
106 
107  m_DebugShapes.Clear();
108  }
109 
110  static void RemoveShape(out Shape shape)
111  {
112  if (!shape) return;
113  for ( int i = 0; i < m_DebugShapes.Count(); i++ )
114  {
115  Shape found_shape = m_DebugShapes.Get(i);
116 
117  if ( found_shape && found_shape == shape )
118  {
119  found_shape.Destroy();
120  m_DebugShapes.Remove(i); // Mandatory! Otherwise the Destroy() function causes crash!
121  shape = null;
122  return;
123  }
124  }
125  }
136  static void Log(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
137  {
138  string res = LogMessage(LOG_DEBUG, plugin, entity, author, label, message);
139 
140 #ifdef LOG_TO_RPT
141  if (res.Length() > 0)
142  {
143  PrintToRPT("" + res);
144  }
145 #endif
146  }
147 
148  static void ActionLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
149  {
150  string res = LogMessage(LOG_DEBUG_ACTION, plugin, entity, author, label, message);
151 
152 #ifdef LOG_TO_RPT
153  if (res.Length() > 0)
154  {
155  PrintToRPT("" + res);
156  }
157 #endif
158  }
159 
160  static void SymptomLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
161  {
162  string res = LogMessage(LOG_DEBUG_SYMPTOM, plugin, entity, author, label, message);
163 
164 #ifdef LOG_TO_RPT
165  if (res.Length() > 0)
166  {
167  PrintToRPT("" + res);
168  }
169 #endif
170  }
171 
172  static void InventoryMoveLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
173  {
174  string res = LogMessage(LOG_DEBUG_INV_MOVE, plugin, entity, author, label, message);
175 
176 #ifdef LOG_TO_RPT
177  if (res.Length() > 0)
178  {
179  PrintToRPT("" + res);
180  }
181 #endif
182  }
183 
184  static void InventoryReservationLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
185  {
186  string res = LogMessage(LOG_DEBUG_INV_RESERVATION, plugin, entity, author, label, message);
187 
188 #ifdef LOG_TO_RPT
189  if (res.Length() > 0)
190  {
191  PrintToRPT("" + res);
192  }
193 #endif
194  }
195 
196  static void InventoryHFSMLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
197  {
198  string res = LogMessage(LOG_DEBUG_INV_HFSM, plugin, entity, author, label, message);
199 
200 #ifdef LOG_TO_RPT
201  if (res.Length() > 0)
202  {
203  PrintToRPT("" + res);
204  }
205 #endif
206  }
207 
208  static void QuickbarLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
209  {
210  string res = LogMessage(LOG_DEBUG_QUICKBAR, plugin, entity, author, label, message);
211 
212 #ifdef LOG_TO_RPT
213  if (res.Length() > 0)
214  {
215  PrintToRPT("" + res);
216  }
217 #endif
218  }
219 
220  static void BaseBuildingLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
221  {
222  string res = LogMessage(LOG_DEBUG_BASEBUILDING, plugin, entity, author, label, message);
223 
224 #ifdef LOG_TO_RPT
225  if (res.Length() > 0)
226  {
227  PrintToRPT("" + res);
228  }
229 #endif
230  }
231 
232  static void BleedingChancesLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
233  {
234  string res = LogMessage(LOG_DEBUG_BLEEDING_CHANCES, plugin, entity, author, label, message);
235 
236 #ifdef LOG_TO_RPT
237  if (res.Length() > 0)
238  {
239  PrintToRPT("" + res);
240  }
241 #endif
242  }
243 
244  static void TriggerLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
245  {
246  string res = LogMessage(LOG_DEBUG_TRIGGER, plugin, entity, author, label, message);
247 
248 #ifdef LOG_TO_RPT
249  if (res.Length() > 0)
250  {
251  PrintToRPT("" + res);
252  }
253 #endif
254  }
255 
256  static void ParticleLog(string message = LOG_DEFAULT, Managed caller = null, string function = "", Managed entity = null)
257  {
258  string res = LogMessage(LOG_DEBUG_PARTICLE, GetDebugName(caller), GetDebugName(entity), "", function, message);
259 
260 #ifdef LOG_TO_RPT
261  if (res.Length() > 0)
262  {
263  PrintToRPT("" + res);
264  }
265 #endif
266  }
267 
268  static void TFLog(string message = LOG_DEFAULT, TestFramework caller = null, string function = "")
269  {
270  string res = LogMessage(LOG_DEBUG_TF, GetDebugName(caller), "", "", function, message);
271 
272 #ifdef LOG_TO_RPT
273  if (res.Length() > 0)
274  {
275  PrintToRPT("" + res);
276  }
277 #endif
278  }
279 
280  static void WeightLog(string message = LOG_DEFAULT, Managed caller = null, string function = "", Managed entity = null)
281  {
282  /*
283  string res = LogMessage(LOG_DEBUG_WEIGHT, GetDebugName(caller), GetDebugName(entity), "", function, message);
284 
285 #ifdef LOG_TO_RPT
286  if (res.Length() > 0)
287  {
288  PrintToRPT("" + res);
289  }
290 #endif
291  */
292  }
293 
294  static void MeleeLog(Entity entity, string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT)
295  {
296  string logMessage = string.Format("%1: %2", entity.GetSimulationTimeStamp(), message);
297  string res = LogMessage(LOG_DEBUG_MELEE, plugin, GetDebugName(entity), author, label, logMessage);
298 
299 #ifdef LOG_TO_RPT
300  if (res.Length() > 0)
301  {
302  PrintToRPT("" + res);
303  }
304 #endif
305  }
306 
307  static void WeatherLog(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
308  {
309  if (!LogManager.IsWeatherLogEnabled())
310  {
311  return;
312  }
313 
314  string res = LogMessage(LOG_DEBUG_WEATHER, plugin, entity, author, label, message);
315 
316  #ifdef LOG_TO_RPT
317  if (res.Length() > 0)
318  {
319  PrintToRPT("" + res);
320  }
321  #endif
322  }
323 
334  static void LogInfo(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
335  {
336  string res = LogMessage(LOG_INFO, plugin, entity, author, label, message);
337 
338 #ifdef LOG_TO_RPT
339  if (res.Length() > 0)
340  {
341  PrintToRPT("" + res);
342  }
343 #endif
344  }
345 
356  static void LogWarning(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
357  {
358  string res = LogMessage(LOG_WARNING, plugin, entity, author, label, message);
359 
360 #ifdef LOG_TO_RPT
361  if (res.Length() > 0)
362  {
363  PrintToRPT("" + res);
364  }
365 #endif
366  }
367 
378  static void LogError(string message = LOG_DEFAULT, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
379  {
380  string res = LogMessage(LOG_ERROR, plugin, entity, author, label, message);
381 
382 #ifdef LOG_TO_RPT
383  if (res.Length() > 0)
384  {
385  PrintToRPT("" + res);
386  }
387 #endif
388  }
389 
390  static void LogArrayInt(array<int> arr = NULL, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
391  {
392  if (arr == null)
393  return;
394 
395  string res;
396 
397  for (int i = 0; i < arr.Count(); i++)
398  {
399  res += LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i).ToString());
400  }
401 
402 #ifdef LOG_TO_RPT
403  if (res.Length() > 0)
404  {
405  PrintToRPT("" + res);
406  }
407 #endif
408  }
409 
410  static void LogArrayString(array<string> arr = NULL, string plugin = LOG_DEFAULT, string author = LOG_DEFAULT, string label = LOG_DEFAULT, string entity = LOG_DEFAULT)
411  {
412  if (arr == null)
413  return;
414 
415  string res;
416 
417  for (int i = 0; i < arr.Count(); i++)
418  {
419  res += LogMessage(LOG_DEBUG, plugin, entity, author, label, arr.Get(i));
420  }
421 
422 #ifdef LOG_TO_RPT
423  if (res.Length() > 0)
424  {
425  PrintToRPT("" + res);
426  }
427 #endif
428  }
429 
430  static void ReceivedLogMessageFromServer(string message)
431  {
432  if (!LogManager.IsLogsEnable())
433  {
434  return;
435  }
436 
437  SaveLog(message);
438 
439 #ifdef LOG_TO_RPT
440  if (message.Length() > 0)
441  {
442  PrintToRPT("" + message);
443  }
444 #endif
445  }
446 
447  static void ClearScriptLogs()
448  {
449  ClearLogs();
450  }
451 
452  static Shape DrawBox(vector pos1, vector pos2, int color = 0x1fff7f7f)
453  {
454  return DrawBoxEx(pos1, pos2, color, ShapeFlags.TRANSP|ShapeFlags.NOZWRITE);
455  }
456 
457  static Shape DrawBoxEx(vector pos1, vector pos2, int color = 0x1fff7f7f, ShapeFlags flags = ShapeFlags.TRANSP|ShapeFlags.NOZWRITE)
458  {
459  Shape shape = Shape.Create(ShapeType.BBOX, color, flags, pos1, pos2);
460  if (( flags & ShapeFlags.ONCE ) == 0)
461  m_DebugShapes.Insert(shape);
462  return shape;
463  }
464 
465  static Shape DrawCube(vector pos, float size = 1, int color = 0x1fff7f7f)
466  {
467  vector min = pos;
468  vector max = pos;
469 
470  float size_h = size * 0.5;
471 
472  min[0] = min[0] - size_h;
473  min[1] = min[1] - size_h;
474  min[2] = min[2] - size_h;
475 
476  max[0] = max[0] + size_h;
477  max[1] = max[1] + size_h;
478  max[2] = max[2] + size_h;
479 
480  Shape shape = Shape.Create(ShapeType.DIAMOND, color, ShapeFlags.TRANSP|ShapeFlags.NOZWRITE, min, max);
481  m_DebugShapes.Insert(shape);
482  return shape;
483  }
484 
485  static Shape DrawSphere(vector pos, float size = 1, int color = 0x1fff7f7f, ShapeFlags flags = ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
486  {
487  Shape shape = Shape.CreateSphere(color, flags, pos, size);
488  if (( flags & ShapeFlags.ONCE ) == 0)
489  m_DebugShapes.Insert(shape);
490  return shape;
491  }
492 
493  static Shape DrawFrustum(float horizontalAngle, float verticalAngle, float length, int color = 0x1fff7f7f, ShapeFlags flags = ShapeFlags.TRANSP|ShapeFlags.WIREFRAME)
494  {
495  Shape shape = Shape.CreateFrustum(horizontalAngle, verticalAngle, length, color, flags);
496  if (( flags & ShapeFlags.ONCE ) == 0)
497  m_DebugShapes.Insert(shape);
498  return shape;
499  }
500 
501  static Shape DrawCylinder(vector pos, float radius, float height = 1, int color = 0x1fff7f7f, ShapeFlags flags = ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE )
502  {
503  Shape shape = Shape.CreateCylinder(color, flags, pos, radius, height);
504  if (( flags & ShapeFlags.ONCE ) == 0)
505  m_DebugShapes.Insert(shape);
506  return shape;
507  }
508 
509  static array<Shape> DrawCone(vector pos, float lenght, float halfAngle, float offsetAngle, int color = 0xFFFFFFFF, int flags = 0)
510  {
511  array<Shape> shapes = new array<Shape>;
512 
513  vector endL, endR;
514  Math3D.ConePoints(pos, lenght, halfAngle, offsetAngle, endL, endR);
515 
516  // Left side
517  shapes.Insert( Debug.DrawLine(pos, endL, color, flags) );
518  // Rigth side
519  shapes.Insert( Debug.DrawLine(pos, endR, color, flags) );
520  // Top side
521  shapes.Insert( Debug.DrawLine(endL, endR, color, flags) );
522  // Middle (height) line
523  shapes.Insert( Debug.DrawLine(pos, pos + Vector(Math.Cos(offsetAngle), 0, Math.Sin(offsetAngle)).Normalized() * lenght, color, flags) );
524 
525  return shapes;
526  }
527 
540  static Shape DrawLine(vector from, vector to, int color = 0xFFFFFFFF, int flags = 0)
541  {
542  vector pts[2]
543  pts[0] = from;
544  pts[1] = to;
545 
546  Shape shape = Shape.CreateLines(color, flags, pts, 2);
547  if (( flags & ShapeFlags.ONCE ) == 0)
548  m_DebugShapes.Insert(shape);
549  //m_DebugShapes.Debug();
550  return shape;
551  }
552 
553  static Shape DrawLines(vector[] positions, int count, int color = 0xFFFFFFFF, int flags = 0)
554  {
555 
556  Shape shape = Shape.CreateLines(color, flags, positions, count);
557  if (( flags & ShapeFlags.ONCE ) == 0)
558  m_DebugShapes.Insert(shape);
559  return shape;
560  }
561 
562  static Shape DrawArrow(vector from, vector to, float size = 0.5, int color = 0xFFFFFFFF, int flags = 0)
563  {
564  Shape shape = Shape.CreateArrow(from, to, size, color, flags);
565  m_DebugShapes.Insert(shape);
566  return shape;
567  }
568 
569 
570 
575  static void GetBaseConfigClasses( out TStringArray base_classes )
576  {
577  base_classes.Clear();
578  base_classes.Insert(CFG_VEHICLESPATH);
579  base_classes.Insert(CFG_WEAPONSPATH);
580  base_classes.Insert(CFG_MAGAZINESPATH);
581  base_classes.Insert(CFG_AMMO);
582  base_classes.Insert(CFG_WORLDS);
583  base_classes.Insert(CFG_SURFACES);
584  base_classes.Insert(CFG_SOUND_SETS);
585  base_classes.Insert(CFG_SOUND_SHADERS);
586  base_classes.Insert(CFG_NONAI_VEHICLES);
587  base_classes.Insert(CFG_SOUND_TABLES);
588  }
589 
596  static void GetFiltredConfigClasses( string search_string, out TStringArray filtered_classes, bool only_public = true )
597  {
598  TStringArray searching_in = new TStringArray;
599  GetBaseConfigClasses( searching_in );
600 
601  filtered_classes.Clear();
602 
603  search_string.ToLower();
604 
605  for ( int s = 0; s < searching_in.Count(); ++s )
606  {
607  string config_path = searching_in.Get(s);
608 
609  int objects_count = GetGame().ConfigGetChildrenCount(config_path);
610  for (int i = 0; i < objects_count; i++)
611  {
612  string childName;
613  GetGame().ConfigGetChildName(config_path, i, childName);
614 
615  if ( only_public )
616  {
617  int scope = GetGame().ConfigGetInt( config_path + " " + childName + " scope" );
618  if ( scope == 0 )
619  {
620  continue;
621  }
622  }
623 
624  string nchName = childName;
625  nchName.ToLower();
626 
627  if ( nchName.Contains(search_string) != -1)
628  {
629  filtered_classes.Insert(childName);
630  }
631  }
632  }
633  }
634 
635  //---------------------------------------------------------------
636  //-------private
637 
638  static private bool m_EnabledLogs;
639 
640  static private string LogMessage(string level, string plugin, string entity, string author, string label, string message)
641  {
642  if (GetGame() == null || !LogManager.IsLogsEnable())
643  return string.Empty;
644 
645  bool is_server_log = ( GetGame().IsServer() && GetGame().IsMultiplayer() );
646 
647 
648  // Formation output to external file
649  // %date{MM-dd HH:mm:ss} | %Enviroment | %Level | %Module | %Entity | %Author | %Label | %Message
650  string date = GetDate();
651  string env = "Client";
652  string msg = string.Empty;
653 
654  if ( is_server_log )
655  {
656  env = "Server";
657  }
658 
659  msg = string.Format("%1 | %2 | %3 | %4 | %5 | %6 | %7", date, env, level, plugin, entity, label, message);
660 
661  if ( is_server_log )
662  {
663  SaveLog(msg);
664  #ifdef DEVELOPER //not sendig log to clients on stable
665  Param1<string> msg_p = new Param1<string>(msg);
667  #endif
668  }
669  else
670  {
671  SaveLog(msg);
672  }
673 
674  return msg;
675  }
676 
677  static private void SaveLog(string log_message)
678  {
679  #ifndef SERVER
680  CachedObjectsParams.PARAM1_STRING.param1 = log_message;
681  GetDispatcher().CallMethod(CALL_ID_SCR_CNSL_ADD_PRINT, CachedObjectsParams.PARAM1_STRING);
682  #endif
683 
684  FileHandle fileHandle = OpenFile(GetFileName(), FileMode.APPEND);
685  if (fileHandle == 0)
686  return;
687 
688  FPrintln(fileHandle, log_message);
689  CloseFile(fileHandle);
690 
691  #ifndef LOG_TO_RPT
692  #ifdef DIAG_DEVELOPER
693  Print(string.Format("%1", log_message));
694  #endif
695  #endif
696  }
697 
698  static void ClearLogs()
699  {
700  if (FileExist(GetFileName()))
701  {
702  FileHandle fileHandle = OpenFile(GetFileName(), FileMode.WRITE);
703  if (fileHandle == 0)
704  return;
705 
706  FPrintln(fileHandle, "");
707  CloseFile(fileHandle);
708  }
709  }
710 
711  static string GetFileName()
712  {
714  }
715 
716  static private string GetDate()
717  {
718  int year;
719  int month;
720  int day;
721  int hour;
722  int minute;
723  int second;
724 
725  GetYearMonthDay(year, month, day);
726  GetHourMinuteSecond(hour, minute, second);
727 
728  string date = month.ToStringLen(2) + "-" + day.ToStringLen(2) + " " + hour.ToStringLen(2) + ":" + minute.ToStringLen(2) + ":" + second.ToStringLen(2);
729 
730  return date;
731  }
732 };
733 
735 {
736  static bool m_DoLogs;
737  static bool m_DoActionDebugLog;
738  static bool m_DoSymptomDebugLog;
739  static bool m_DoInventoryMoveLog;
740  static bool m_DoInventoryReservationLog;
741  static bool m_DoInventoryHFSMLog;
742  static bool m_DoSyncLog;
743  static bool m_DoQuickbarLog;
744  static bool m_DoBaseBuildingLog;
745  static bool m_DoWeaponLog;
746  static bool m_DoWeatherLog;
747  static bool m_DoBleedingChanceLog;
748 
749  static void Init()
750  {
751  #ifdef DIAG_DEVELOPER
752  m_DoLogs = true;
753  #else
754  m_DoLogs = IsCLIParam("doLogs");
755  #endif
756 
757  m_DoActionDebugLog = IsCLIParam("doActionLog");
758  m_DoSymptomDebugLog = IsCLIParam("doSymptomLog");
759  m_DoInventoryMoveLog = IsCLIParam("doInvMoveLog");
760  m_DoInventoryReservationLog = IsCLIParam("doInvReservLog");
761  m_DoInventoryHFSMLog = IsCLIParam("doInvHFSMLog");
762  m_DoSyncLog = IsCLIParam("doSyncLog");
763  m_DoQuickbarLog = IsCLIParam("doQuickbarLog");
764  m_DoBaseBuildingLog = IsCLIParam("doBaseBuildingLog");
765  m_DoWeaponLog = IsCLIParam("doWeaponLog");
766  m_DoWeatherLog = IsCLIParam("doWeatherLog");
767  }
768 
769  static bool IsLogsEnable()
770  {
771  return m_DoLogs;
772  }
773 
774  static void SetLogsEnabled(bool enable)
775  {
776  m_DoLogs = enable;
777  }
778 
779  static bool IsActionLogEnable()
780  {
781  return m_DoActionDebugLog;
782  }
783 
784  static void ActionLogEnable(bool enable)
785  {
786  m_DoActionDebugLog = enable;
787  }
788 
789  static bool IsInventoryMoveLogEnable()
790  {
791  return m_DoInventoryMoveLog;
792  }
793 
794  static void InventoryMoveLogEnable(bool enable)
795  {
796  m_DoInventoryMoveLog = enable;
797  }
798 
799  static bool IsInventoryReservationLogEnable()
800  {
801  return m_DoInventoryReservationLog;
802  }
803 
804  static void InventoryReservationLogEnable(bool enable)
805  {
806  m_DoInventoryReservationLog = enable;
807  }
808 
809  static bool IsInventoryHFSMLogEnable()
810  {
811  return m_DoInventoryHFSMLog;
812  }
813 
814  static void InventoryHFSMLogEnable(bool enable)
815  {
816  m_DoInventoryHFSMLog = enable;
817  }
818 
819  static bool IsSyncLogEnable()
820  {
821  return m_DoSyncLog;
822  }
823 
824  static void SyncLogEnable(bool enable)
825  {
826  m_DoSyncLog = enable;
827  }
828 
829  static bool IsQuickbarLogEnable()
830  {
831  return m_DoQuickbarLog;
832  }
833 
834  static void QuickbarLogEnable(bool enable)
835  {
836  m_DoQuickbarLog = enable;
837  }
838 
839  static bool IsBaseBuildingLogEnable()
840  {
841  return m_DoBaseBuildingLog;
842  }
843 
844  static void BaseBuildingLogEnable(bool enable)
845  {
846  m_DoBaseBuildingLog = enable;
847  }
848 
849  static bool IsSymptomLogEnable()
850  {
851  return m_DoSymptomDebugLog;
852  }
853 
854  static void SymptomLogEnable(bool enable)
855  {
856  m_DoSymptomDebugLog = enable;
857  }
858 
859  static bool IsWeaponLogEnable()
860  {
861  return m_DoWeaponLog;
862  }
863 
864  static void WeaponLogEnable(bool enable)
865  {
866  m_DoWeaponLog = enable;
867  }
868 
869  static bool IsWeatherLogEnabled()
870  {
871  return m_DoWeatherLog;
872  }
873 
874  static bool IsBleedingChancesLogEnable()
875  {
876  return m_DoBleedingChanceLog;
877  }
878 
879  static void BleedingChancesLogEnable(bool enable)
880  {
881  m_DoBleedingChanceLog = enable;
882  }
883 }
884 
885 enum WeightDebugType
886 {
887  NONE = 0,
888  RECALC_FORCED = 1,
889  RECALC_DIRTY = 2,
890  DUMP_STACK = 4,
891  SET_DIRTY_FLAG = 8,
892 }
893 
894 class WeightDebug
895 {
897  static WeightDebugType m_VerbosityFlags;
898 
899  //-------------------------------------------------------------
900  static WeightDebugData GetWeightDebug(EntityAI entity)
901  {
902  if (!m_WeightDebugData.Get(entity))
903  {
904  WeightDebugData data = new WeightDebugData(entity);
905  m_WeightDebugData.Insert(entity,data);
906  return data;
907  }
908  return m_WeightDebugData.Get(entity);
909  }
910  //-------------------------------------------------------------
911  static void ClearWeightDebug()
912  {
913  m_WeightDebugData.Clear();
914  }
915  //-------------------------------------------------------------
916  static void PrintAll(EntityAI entity)
917  {
918  GameInventory inv = entity.GetInventory();
919  if (!inv)
920  return;
921  array<EntityAI> items = new array<EntityAI>;
922  inv.EnumerateInventory(InventoryTraversalType.PREORDER, items);
923  for(int i = 0; i < items.Count(); i++)
924  {
925  EntityAI item = items.Get(i);
926  if (m_WeightDebugData.Get(item))
927  {
928  m_WeightDebugData.Get(item).Output();
929  }
930  }
931  }
932  //-------------------------------------------------------------
933  static void SetVerbosityFlags(WeightDebugType type)
934  {
935  m_VerbosityFlags = type;
936  }
937 }
938 
940 {
941  string m_Classname;
942  string m_Weight;
943  int m_InventoryDepth;
944  string m_CalcDetails;
945  //-------------------------------------------------------------
946  void WeightDebugData(EntityAI entity)
947  {
948  m_Classname = entity.GetType();
949  m_InventoryDepth = entity.GetHierarchyLevel();
950  }
951  //-------------------------------------------------------------
952  void SetWeight(float weight)
953  {
954  m_Weight = weight.ToString();
955  }
956  //-------------------------------------------------------------
957  void SetCalcDetails(string details)
958  {
959  m_CalcDetails = details;
960  }
961 
962  //-------------------------------------------------------------
963  void AddCalcDetails(string details)
964  {
965  m_CalcDetails += "+ "+details;
966  }
967  //-------------------------------------------------------------
968  void Output()
969  {
970  string spaces;
971  for(int i = 0; i < m_InventoryDepth;i++)
972  spaces+="--------";
973 
974  Print(spaces+">" + m_Classname + " Overall entity weight: "+ m_Weight + " Calculation details:" + m_CalcDetails);
975  }
976  //-------------------------------------------------------------
977 
978 }
FPrintln
proto void FPrintln(FileHandle file, void var)
Write to file and add new line.
GetGame
proto native CGame GetGame()
CloseFile
proto void CloseFile(FileHandle file)
Close the File.
IsCLIParam
proto native bool IsCLIParam(string param)
Returns if command line argument is present.
OpenFile
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
CFG_SURFACES
const string CFG_SURFACES
Definition: constants.c:214
CFG_NONAI_VEHICLES
const string CFG_NONAI_VEHICLES
Definition: constants.c:218
LogManager
Definition: debug.c:734
TStringArray
array< string > TStringArray
Definition: enscript.c:685
SET_DIRTY_FLAG
class LogManager SET_DIRTY_FLAG
WeightDebugData
Definition: debug.c:939
CFG_SOUND_SHADERS
const string CFG_SOUND_SHADERS
Definition: constants.c:216
CallMethod
Param CallMethod(CallID call_id, Param params)
Definition: dispatcher.c:36
RECALC_DIRTY
class LogManager RECALC_DIRTY
TestFramework
void TestFramework()
Definition: testframework.c:217
Managed
TODO doc.
Definition: enscript.c:117
FileExist
proto bool FileExist(string name)
Check existence of file.
Print
proto void Print(void var)
Prints content of variable to console/log.
DUMP_STACK
class LogManager DUMP_STACK
CachedObjectsParams
Definition: utilityclasses.c:9
CFG_SOUND_SETS
const string CFG_SOUND_SETS
Definition: constants.c:217
FileMode
FileMode
Definition: ensystem.c:382
m_WeightDebugData
class LogManager m_WeightDebugData
CFG_WORLDS
const string CFG_WORLDS
Definition: constants.c:213
CALL_ID_SEND_LOG
const CallID CALL_ID_SEND_LOG
Definition: dispatcher.c:3
GetYearMonthDay
proto void GetYearMonthDay(out int year, out int month, out int day)
Returns world date.
NONE
class LogManager NONE
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
GetHourMinuteSecond
proto void GetHourMinuteSecond(out int hour, out int minute, out int second)
Returns world time.
CFG_FILE_SCRIPT_LOG_EXT
const string CFG_FILE_SCRIPT_LOG_EXT
Definition: constants.c:237
CFG_VEHICLESPATH
const string CFG_VEHICLESPATH
Definition: constants.c:209
ShapeFlags
ShapeFlags
Definition: endebug.c:125
Object
Definition: objecttyped.c:1
PrintToRPT
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
CFG_SOUND_TABLES
const string CFG_SOUND_TABLES
Definition: constants.c:219
CFG_MAGAZINESPATH
const string CFG_MAGAZINESPATH
Definition: constants.c:211
CFG_WEAPONSPATH
const string CFG_WEAPONSPATH
Definition: constants.c:210
array< Shape >
CALL_ID_SCR_CNSL_ADD_PRINT
const CallID CALL_ID_SCR_CNSL_ADD_PRINT
Definition: dispatcher.c:6
Debug
Definition: debug.c:13
Entity
Definition: camera.c:1
InventoryTraversalType
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition: gameplay.c:5
GetDispatcher
Dispatcher GetDispatcher()
Definition: dispatcher.c:20
FileHandle
int[] FileHandle
Definition: ensystem.c:390
ShapeType
ShapeType
Definition: endebug.c:115
RECALC_FORCED
class LogManager RECALC_FORCED
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
CFG_AMMO
const string CFG_AMMO
Definition: constants.c:212
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
Math3D
Definition: enmath3d.c:27
Shape
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78