Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update function header 'CBA_fnc_debug' #498

Merged
merged 2 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions addons/diagnostic/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +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;

[QGVAR(debug), {_this call CBA_fnc_debug}] call CBA_fnc_addEventHandler;

ADDON = true;
170 changes: 72 additions & 98 deletions addons/diagnostic/fnc_debug.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <STRING, ARRAY>
_title - Message title (optional, default: "cba_diagnostic") <STRING>
_type - Type of message <ARRAY>
0: _useChat - Write to chat (optional, default: true) <BOOLEAN>
1: _useLog - Log to arma.rpt (optional, default: true) <BOOLEAN>
2: _global - true: execute global (optional, default: false) <BOOLEAN>

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