From 933567ec599ee5a1f22b763d1aa097c56d294825 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 24 Aug 2016 20:30:41 +0200 Subject: [PATCH] update function header 'CBA_fnc_debug' --- addons/diagnostic/XEH_preInit.sqf | 9 +- addons/diagnostic/fnc_debug.sqf | 170 +++++++++++++----------------- 2 files changed, 77 insertions(+), 102 deletions(-) diff --git a/addons/diagnostic/XEH_preInit.sqf b/addons/diagnostic/XEH_preInit.sqf index 2b2e99f0f..28356dbbc 100644 --- a/addons/diagnostic/XEH_preInit.sqf +++ b/addons/diagnostic/XEH_preInit.sqf @@ -1,9 +1,10 @@ -// Any registered functions used in the PreINIT phase must use the uiNamespace copies of the variable. -// So uiNamespace getVariable "CBA_fnc_hashCreate" instead of just CBA_fnc_hashCreate -VM #include "script_component.hpp" +SCRIPT(XEH_preInit); LOG(MSG_INIT); -[QUOTE(GVAR(debug)), { _this call (uiNamespace getVariable "CBA_fnc_debug") }] call (uiNamespace getVariable "CBA_fnc_addEventHandler"); +ADDON = false; -PREP(perf_loop); +[QGVAR(debug), {_this call CBA_fnc_debug}] call CBA_fnc_addEventHandler; + +ADDON = true; diff --git a/addons/diagnostic/fnc_debug.sqf b/addons/diagnostic/fnc_debug.sqf index eb35d4941..7b8705285 100644 --- a/addons/diagnostic/fnc_debug.sqf +++ b/addons/diagnostic/fnc_debug.sqf @@ -4,129 +4,103 @@ Function: CBA_fnc_debug Description: General Purpose Debug Message Writer - Handles very long messages without losing text or crashing the game. + Handles very long messages without losing text. Parameters: - _message - Message to write or data structure to dump [String or Array]. - _component - component [String, defaults to "CBA_DIAGNOSTIC"] - _typeOfDebug - Type of message [3-element Array, as described below...] - ... _useGlobalChat - Write to global chat [Boolean, defaults to true]. - ... _local - Log to local arma.rpt [Boolean, defaults to true] - ... _global - Log to local and remote arma.rpt [Boolean, defaults to false] + _message - Message to write + _title - Message title (optional, default: "cba_diagnostic") + _type - Type of message + 0: _useChat - Write to chat (optional, default: true) + 1: _useLog - Log to arma.rpt (optional, default: true) + 2: _global - true: execute global (optional, default: false) Returns: nil Examples: (begin example) - // Write the debug message in chat-log of local computer, and in - // local and remote arma.rpt. - [ "New Player Joined the Server!", "cba_network", [true, false, true] ] call CBA_fnc_debug; + // Write the debug message in chat-log of every client + ["New Player Joined the Server!", "cba_network", [true, false, true]] call CBA_fnc_debug; (end) Author: - Sickboy + Sickboy, commy2 ---------------------------------------------------------------------------- */ - #include "script_component.hpp" -if (isNil QUOTE(ADDON)) then -{ - CREATELOGICLOCAL; - // GVAR(debug) = []; // TODO: Evaluate if this is useful... Logging to rpt and using a tail reader seems okay too! -}; +// function to split lines into multiple lines with a maxium length +#define MAX_LINE_LENGTH 120 -_ar2msg = { - private ["_ar", "_str", "_msg", "_orig", "_total", "_i"]; - _ar = []; - if (typeName (_this select 0) == "ARRAY") then - { - _orig = _this select 0; - _str = format["%1 [", _this select 1]; - } else { - _orig = _this; - _str = "["; - }; - { _ar pushBack (toArray _x) } forEach _orig; - _msg = []; - _total = 0; _i = 0; - { - _c = count _x; - if (_total + _c < 178) then - { - _total = _total + _c; - if (_i > 0) then { _str = _str + ", " }; - _str = _str + toString(_x); - } else { - _msg pushBack _str; - _total = _c; - _str = toString(_x); - }; - _i = _i + 1; - } forEach _ar; - _str = _str + "]"; - _msg pushBack _str; - _msg -}; +private _fnc_splitLines = { + private _return = []; -_str2msg = { - private ["_ar", "_i", "_nar", "_msg"]; - _ar = toArray _this; - if (count _ar < 180) exitWith { [_this] }; - _i = 0; _nar = []; _msg = []; { - if (_i < 180) then - { - _nar pushBack _x; - _i = _i + 1; - } else { - _msg pushBack (toString(_nar)); - _nar = [_x]; - _i = 1; + private _string = _x; + + while {count _string > 0} do { + _return pushBack (_string select [0, MAX_LINE_LENGTH]); + _string = _string select [MAX_LINE_LENGTH]; }; - } forEach _ar; - if (count _nar > 0) then { _msg pushBack (toString(_nar)) }; - _msg + } forEach _this; + + _return }; -_format = { - private ["_msg"]; - _msg = []; - switch (typeName _this) do - { - case "ARRAY": { { { _msg pushBack _x } forEach (_x call _str2msg) } forEach _this }; - case "STRING": { _msg = _this call _str2msg }; - default { _msg = format["%1", _this] call _str2msg }; - }; - _msg +// create a logic than can use the chat +if (isNil QGVAR(logic)) then { + GVAR(logic) = "Logic" createVehicleLocal [0,0,0]; }; -private ["_c", "_type", "_component", "_message", "_msg", "_ar2", "_i", "_msgAr"]; -_c = count _this; -_type = [true, true, false]; -_component = QUOTE(ADDON); -_message = _this select 0; -if (_c > 1) then -{ - _component = _this select 1; - if (_c > 2) then - { - _type = _this select 2; - }; +// input +params [["_message", "", ["", []]], ["_title", 'ADDON', [""]], ["_type", [], [[]]]]; + +_type params [ + ["_useChat", true, [false]], + ["_useLog", true, [false]], + ["_global", false, [false]] +]; + +// forward to remote machines +if (_global) then { + [QGVAR(debug), [_message, _title, [_useChat, _useLog, false]]] call CBA_fnc_remoteEvent; }; -if (_type select 2) exitWith -{ - [QGVAR(debug), [_message, _component, [_type select 0,_type select 1,false]]] call CBA_fnc_globalEvent; +// if string, split into seperate lines marked by "\n" +if (_message isEqualType "") then { + _message = [_message, "\n"] call CBA_fnc_split; }; -_msgAr = []; -switch (typeName _message) do -{ - case "ARRAY": { _msgAr = [format["%3 (%2) %1 -", _component, [time, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime, [diag_tickTime, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime]]; { _msgAr pushBack _x } forEach (_message call _ar2msg) }; - default { _msgAr = (format["%4 (%3) %1 - %2", _component, _message, [time, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime, [diag_tickTime, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime] call _format) }; +// format the first line to include title and time stamp +_message set [0, format [ + "(%3) %1 - %2", + _title, + _message select 0, + [CBA_missionTime, "H:MM:SS"] call CBA_fnc_formatElapsedTime +]]; + +_message = _message call _fnc_splitLines; + +// print in chat +if (_useChat) then { + // fix for chat-log being reset after the loading screen + if (time < 1) then { + _message spawn { + uiSleep 1; + + { + GVAR(logic) globalChat _x; + } forEach _this; + }; + } else { + { + GVAR(logic) globalChat _x; + } forEach _message; + }; }; -if (_type select 0) then { if (SLX_XEH_MACHINE select 0) then { { ADDON globalChat _x } forEach _msgAr } }; -if (_type select 1) then { { if (_x != "") then { diag_log text _x } } forEach _msgAr }; -//GVAR(debug) pushBack _msgAr; // TODO: Evaluate cleanup system? +// print in rpt-log +if (_useLog) then { + { + diag_log text _x; + } forEach _message; +};