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