diff --git a/addons/diagnostics/$PBOPREFIX$ b/addons/diagnostics/$PBOPREFIX$ new file mode 100644 index 0000000..d6d982b --- /dev/null +++ b/addons/diagnostics/$PBOPREFIX$ @@ -0,0 +1 @@ +z\afm\addons\diagnostics \ No newline at end of file diff --git a/addons/diagnostics/CfgEventHandlers.hpp b/addons/diagnostics/CfgEventHandlers.hpp new file mode 100644 index 0000000..e90bed4 --- /dev/null +++ b/addons/diagnostics/CfgEventHandlers.hpp @@ -0,0 +1,15 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/diagnostics/XEH_PREP.hpp b/addons/diagnostics/XEH_PREP.hpp new file mode 100644 index 0000000..9e1822c --- /dev/null +++ b/addons/diagnostics/XEH_PREP.hpp @@ -0,0 +1,8 @@ +PREP(dlcOpen); +PREP(dlcRequest); +PREP(dlcRespond); +PREP(dlcUpdate); +PREP(fpsOpen); +PREP(fpsRequest); +PREP(fpsRespond); +PREP(fpsUpdate); diff --git a/addons/diagnostics/XEH_postInit.sqf b/addons/diagnostics/XEH_postInit.sqf new file mode 100644 index 0000000..84f2529 --- /dev/null +++ b/addons/diagnostics/XEH_postInit.sqf @@ -0,0 +1 @@ +#include "script_component.hpp" \ No newline at end of file diff --git a/addons/diagnostics/XEH_preInit.sqf b/addons/diagnostics/XEH_preInit.sqf new file mode 100644 index 0000000..133827d --- /dev/null +++ b/addons/diagnostics/XEH_preInit.sqf @@ -0,0 +1,64 @@ +#include "script_component.hpp" +ADDON = false; +#include "XEH_PREP.hpp" +ADDON = true; + +#include "initSettings.sqf" + +GVAR(dlcList) = [ + [288520, "Karts"], + [304380, "Helicopters"], + [332350, "Marksman"], + [395180, "Apex"], + [571710, "Laws of War"], + [601670, "Jets"], + [744950, "Tac Ops"], + [798390, "Tanks"], + [1021790, "Contact"], + [1042220, "GM"], + // TODO: IDs for remaining DLCs + [] +]; + +if (hasInterface) then { + ["DLC List", QGVAR(dlcListDialog)] call CBA_fnc_addPauseMenuOption; + ["FPS List", QGVAR(fpsListDialog)] call CBA_fnc_addPauseMenuOption; + + [QGVAR(dlcRequest), FUNC(dlcRespond)] call CBA_fnc_addEventHandler; + [QGVAR(dlcResponse), FUNC(dlcUpdate)] call CBA_fnc_addEventHandler; + + [QGVAR(fpsRequest), FUNC(fpsRespond)] call CBA_fnc_addEventHandler; + [QGVAR(fpsResponse), FUNC(fpsUpdate)] call CBA_fnc_addEventHandler; +}; + +if (!isServer) exitWith {}; + +if (!QGVAR(markersEnabled)) exitWith {}; + +// By default only server is an FPS diag target +GVAR(fpsTargets) = [2]; + +// Add headless clients to diag targets when they join +addMissionEventHandler ["PlayerConnected", { + params ["", "_uid", "", "", "_owner"]; + if ((_uid select [0,2] != "HC")) exitWith {}; + + GVAR(fpsTargets) pushBack _owner; +}]; + +// Cleanup headless client markers on disconnect +addMissionEventHandler ["PlayerDisconnected", { + params ["", "_uid", "", "", "_owner"]; + if ((_uid select [0,2] != "HC")) exitWith {}; + + GVAR(fpsTargets) = GVAR(fpsTargets) - [_owner]; + + private _fpsMarker = format ["%1_%2", QGVAR(fpsMarker), _owner]; + deleteMarker _fpsMarker; +}]; + +[{ + { + [_x, _forEachIndex] remoteExec [QFUNC(updateDiagnosticMarker), _x]; + } forEach GVAR(fpsTargets); +}, 15] call CBA_fnc_addPerFrameHandler; diff --git a/addons/diagnostics/XEH_preStart.sqf b/addons/diagnostics/XEH_preStart.sqf new file mode 100644 index 0000000..a51262a --- /dev/null +++ b/addons/diagnostics/XEH_preStart.sqf @@ -0,0 +1,2 @@ +#include "script_component.hpp" +#include "XEH_PREP.hpp" diff --git a/addons/diagnostics/config.cpp b/addons/diagnostics/config.cpp new file mode 100644 index 0000000..7fff1e1 --- /dev/null +++ b/addons/diagnostics/config.cpp @@ -0,0 +1,30 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = { + "afm_common" + }; + author = "ArmaForces"; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" + +// TODO: Move this somewhere appropriate +class GVAR(fpsListDialog) { + idd = -1; + movingEnable = 0; + onLoad = QUOTE(_this call FUNC(fpsOpen)); +}; + +class GVAR(dlcListDialog) { + idd = -1; + movingEnable = 0; + onLoad = QUOTE(_this call FUNC(dlcOpen)); +}; diff --git a/addons/diagnostics/functions/fn_dlc_open.sqf b/addons/diagnostics/functions/fn_dlc_open.sqf new file mode 100644 index 0000000..a28448e --- /dev/null +++ b/addons/diagnostics/functions/fn_dlc_open.sqf @@ -0,0 +1,92 @@ +/* + armaforces_diagnostics_fnc_dlc_open + + File: fn_dlc_open.sqf + Date: 2019-06-21 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle DLC List display open. + + Parameter(s): + _display - DLC List display [DISPLAY, defaults to displayNull] + + Returns: + NOTHING +*/ +params [ + ["_display", displayNull, [displayNull]] +]; + +if !([] call BIS_fnc_isDebugConsoleAllowed) exitWith { + ["No debug console access"] call CBA_fnc_notify; +}; + +private _width = safezoneW * 0.75; + +// Confirm +private _confirm = _display ctrlCreate ["RscButtonMenu", 10]; +uiNamespace setVariable [QGVAR(dlcConfirm), _confirm]; + +private _confirmHeight = safezoneH / 23; +private _confirmY = safezoneY + safezoneH/1.3 - 1.1 * _confirmHeight; + +_confirm ctrlSetPosition [ + 0.5 - _width/2 + _width*0.2, + _confirmY, + _width*0.8, _confirmHeight +]; +_confirm ctrlCommit 0; +_confirm ctrlSetText toUpper "REFRESH"; + +_confirm ctrlAddEventHandler ["MouseButtonDown", { + params ["_confirm", "_button"]; + if (_button != 0) exitWith {}; + _confirm ctrlEnable false; + [{_this ctrlEnable true}, _confirm, 2] call CBA_fnc_waitAndExecute; + + [] call FUNC(dlcRequest); +}]; + +private _close = _display ctrlCreate ["RscButtonMenu", 1]; +_close ctrlSetPosition [ + 0.5 - _width/2, + _confirmY, + _width*0.2, _confirmHeight +]; +_close ctrlCommit 0; +_close ctrlSetText "CLOSE"; + +// List +private _listHeight = safezoneH/2; + +private _listBg = _display ctrlCreate ["RscText", 2]; // centered RscListNBox +_listBg ctrlSetBackgroundColor [0,0,0,0.8]; + +private _list = _display ctrlCreate ["RscListNBox", 3]; // centered RscListNBox +uiNamespace setVariable [QGVAR(dlcListDialog), _list]; + +_list lnbAddRow (["Player"] + (GVAR(dlcList) apply {""})); + +private _listColOffsets = []; +{ + _x params ["", "_name"]; + + _listColOffsets pushBack 0.12 + ((1 - 0.12) / count GVAR(dlcList)) * _forEachIndex; +} forEach GVAR(dlcList); + +_list lnbSetColumnsPos ([0] + _listColOffsets); + +{ + _x ctrlSetPosition [ + 0.5 - _width / 2, + _confirmY - _listHeight - _confirmHeight/10 , + _width, _listHeight + ]; + _x ctrlCommit 0; +} forEach [_listBg, _list]; + +[] call FUNC(dlcRequest); + +nil diff --git a/addons/diagnostics/functions/fn_dlc_request.sqf b/addons/diagnostics/functions/fn_dlc_request.sqf new file mode 100644 index 0000000..9aac8e7 --- /dev/null +++ b/addons/diagnostics/functions/fn_dlc_request.sqf @@ -0,0 +1,28 @@ +/* + armaforces_diagnostics_fnc_dlc_request + + File: fn_dlc_request.sqf + Date: 2019-06-21 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Request DLC ownership from clients. + + Parameter(s): + NONE + + Returns: + NOTHING +*/ +private _list = uiNamespace getVariable [QGVAR(dlcListDialog), controlNull]; + +lnbClear _list; +_list lnbAddRow (["Player"] + (GVAR(dlcList) apply {"-"})); +_list lnbSetCurSelRow 1; + +[{ + [QGVAR(dlcRequest), player] call CBA_fnc_globalEvent; +}] call CBA_fnc_execNextFrame; + +nil diff --git a/addons/diagnostics/functions/fn_dlc_respond.sqf b/addons/diagnostics/functions/fn_dlc_respond.sqf new file mode 100644 index 0000000..9930eab --- /dev/null +++ b/addons/diagnostics/functions/fn_dlc_respond.sqf @@ -0,0 +1,37 @@ +/* + armaforces_diagnostics_fnc_dlc_respond + + File: fn_dlc_respond.sqf + Date: 2019-07-28 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Respond to DLC ownership request. + + Parameter(s): + _requester - Player that requested DLC list [OBJECT, defaults to objNull] + + Returns: + NOTHING +*/ +params [ + ["_requester", objNull, [objNull]] +]; + +private _ownedIds = getDLCs 1; + +private _DLCs = GVAR(dlcList); + +private _DLCsData = _DLCs apply { + _x params ["_id", "_name"]; + + [_name, _id in _ownedIds]; +}; + +[QGVAR(dlcResponse), + [name player, _DLCsData], + _requester +] call CBA_fnc_targetEvent; + +nil diff --git a/addons/diagnostics/functions/fn_dlc_update.sqf b/addons/diagnostics/functions/fn_dlc_update.sqf new file mode 100644 index 0000000..0a7c85c --- /dev/null +++ b/addons/diagnostics/functions/fn_dlc_update.sqf @@ -0,0 +1,33 @@ +/* + armaforces_diagnostics_fnc_dlc_update + + File: fn_dlc_update.sqf + Date: 2019-06-21 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Update DLC List display contents. + + Parameter(s): + NONE + + Returns: + NOTHING +*/ +params [ + ["_playerName", "", [""]], + ["_DLCsData", [], []] +]; + +private _list = uiNamespace getVariable [QGVAR(dlcListDialog), controlNull]; + +private _lastRow = _list lnbAddRow ([_playerName] + (_DLCsData apply {_x select 0})); + +private ["_color"]; +{ + _color = [[1,0,0,1], [0,1,0,1]] select _x; + _list lnbSetColor [[_lastRow, _forEachIndex+1], _color]; +} forEach (_DLCsData apply {_x select 1}) + + diff --git a/addons/diagnostics/functions/fn_fps_open.sqf b/addons/diagnostics/functions/fn_fps_open.sqf new file mode 100644 index 0000000..c429984 --- /dev/null +++ b/addons/diagnostics/functions/fn_fps_open.sqf @@ -0,0 +1,84 @@ +/* + armaforces_diagnostics_fnc_fps_open + + File: fn_fps_open.sqf + Date: 2019-06-21 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle FPS List display open. + + Parameter(s): + _display - FPS List display [DISPLAY, defaults to displayNull] + + Returns: + NOTHING +*/ +params [ + ["_display", displayNull, [displayNull]] +]; + +if !([] call BIS_fnc_isDebugConsoleAllowed) exitWith { + ["No debug console access"] call CBA_fnc_notify; +}; + +private _width = safezoneW * 0.3; + +// Confirm +private _confirm = _display ctrlCreate ["RscButtonMenu", 10]; +uiNamespace setVariable [QGVAR(fpsConfirm), _confirm]; + +private _confirmHeight = safezoneH / 23; +private _confirmY = safezoneY + safezoneH/1.3 - 1.1 * _confirmHeight; + +_confirm ctrlSetPosition [ + 0.5 - _width/2 + _width*0.2, + _confirmY, + _width*0.8, _confirmHeight +]; +_confirm ctrlCommit 0; +_confirm ctrlSetText toUpper "REFRESH"; + +_confirm ctrlAddEventHandler ["MouseButtonDown", { + params ["_confirm", "_button"]; + if (_button != 0) exitWith {}; + _confirm ctrlEnable false; + [{_this ctrlEnable true}, _confirm, 2] call CBA_fnc_waitAndExecute; + + [] call FUNC(fpsRequest); +}]; + +private _close = _display ctrlCreate ["RscButtonMenu", 1]; +_close ctrlSetPosition [ + 0.5 - _width/2, + _confirmY, + _width*0.2, _confirmHeight +]; +_close ctrlCommit 0; +_close ctrlSetText "CLOSE"; + +// List +private _listHeight = safezoneH/2; + +private _listBg = _display ctrlCreate ["RscText", 11]; // centered RscListNBox +_listBg ctrlSetBackgroundColor [0,0,0,0.8]; + +private _list = _display ctrlCreate ["RscListNBox", 12]; // centered RscListNBox +uiNamespace setVariable [QGVAR(fpsListDialog), _list]; +_list lnbSetColumnsPos [0.1,0.5,0.7]; +_list lnbAddRow ["Player", "FPS Avg ", "FPS Min"]; +_list lnbSetCurSelRow 1; + +{ + _x ctrlSetPosition [ + 0.5 - _width / 2, + _confirmY - _listHeight - _confirmHeight/10 , + _width, _listHeight + ]; + _x ctrlCommit 0; +} forEach [_listBg, _list]; + +[] call FUNC(fpsRequest); + +nil diff --git a/addons/diagnostics/functions/fn_fps_request.sqf b/addons/diagnostics/functions/fn_fps_request.sqf new file mode 100644 index 0000000..8f9c948 --- /dev/null +++ b/addons/diagnostics/functions/fn_fps_request.sqf @@ -0,0 +1,25 @@ +/* + armaforces_diagnostics_fnc_fps_request + + File: fn_fps_request.sqf + Date: 2019-06-21 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Request FPS values from clients. + + Parameter(s): + NONE + + Returns: + NOTHING +*/ +private _list = uiNamespace getVariable [QGVAR(fpsListDialog), controlNull]; + +lnbClear _list; +_list lnbAddRow ["Player", "FPS Avg ", "FPS Min"]; + +[QGVAR(fpsRequest), player] call CBA_fnc_globalEvent; + +nil diff --git a/addons/diagnostics/functions/fn_fps_respond.sqf b/addons/diagnostics/functions/fn_fps_respond.sqf new file mode 100644 index 0000000..5255b2f --- /dev/null +++ b/addons/diagnostics/functions/fn_fps_respond.sqf @@ -0,0 +1,27 @@ +/* + armaforces_diagnostics_fnc_fps_respond + + File: fn_fps_respond.sqf + Date: 2019-06-21 + Last Update: 2019-06-21 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Respond to FPS values request. + + Parameter(s): + _requester - Player that requested FPS list [OBJECT, defaults to objNull] + + Returns: + NOTHING +*/ +params [ + ["_requester", objNull, [objNull]] +]; + +["armaforces_fpsResponse", + [name player, diag_fps toFixed 2, diag_fpsMin toFixed 2], + _requester +] call CBA_fnc_targetEvent; + +nil diff --git a/addons/diagnostics/functions/fn_fps_update.sqf b/addons/diagnostics/functions/fn_fps_update.sqf new file mode 100644 index 0000000..08516c3 --- /dev/null +++ b/addons/diagnostics/functions/fn_fps_update.sqf @@ -0,0 +1,52 @@ +/* + armaforces_diagnostics_fnc_fps_update + + File: fn_fps_update.sqf + Date: 2019-06-21 + Last Update: 2019-07-29 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Update FPS List display contents. + + Parameter(s): + NONE + + Returns: + NOTHING +*/ +private _list = uiNamespace getVariable [QGVAR(fpsListDialog), controlNull]; + +_list lnbAddRow _this; + +// Colorize cells depending on fps value +private _lastRow = (lnbSize _list)#0 - 1; +params ["", "_fps", "_fpsMin"]; +// AVG FPS +switch (true) do { + case (parseNumber _fps < 20): { + _list lnbSetColor [[_lastRow, 1], [1,0,0,1]]; + }; + case (parseNumber _fps < 40): { + _list lnbSetColor [[_lastRow, 1], [1,1,0,1]]; + }; + default { + _list lnbSetColor [[_lastRow, 1], [0,1,0,1]]; + }; +}; +// MIN FPS +switch (true) do { + case (parseNumber _fpsMin < 20): { + _list lnbSetColor [[_lastRow, 2], [1,0,0,1]]; + }; + case (parseNumber _fpsMin < 40): { + _list lnbSetColor [[_lastRow, 2], [1,1,0,1]]; + }; + default { + _list lnbSetColor [[_lastRow, 2], [0,1,0,1]]; + }; +}; + +_list lnbSortByValue [0, false]; + +nil diff --git a/addons/diagnostics/functions/fn_updateDiagnosticMarker.sqf b/addons/diagnostics/functions/fn_updateDiagnosticMarker.sqf new file mode 100644 index 0000000..b584925 --- /dev/null +++ b/addons/diagnostics/functions/fn_updateDiagnosticMarker.sqf @@ -0,0 +1,45 @@ +/* + armaforces_diagnostics_fnc_update + + File: fnc_update.sqf + Date: 2019-06-01 + Last Update: 2019-06-01 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Creates or updates FPS marker. + + Parameter(s): + _id - ID of client that is updating fps marker [NUMBER] + _offset - Offset of the marker [NUMBER] + + Returns: + NOTHING +*/ +params ["_id", "_offset"]; + +private _fpsMarkerName = format ["%1_%2", QGVAR(fpsMarker), _id]; +private _pos = [0, -500 - (400 * _offset)]; + +private _fpsMarker = createMarker [_fpsMarkerName, _pos]; +_fpsMarker setMarkerPos _pos; + +_fpsMarker setMarkerType "mil_dot"; +_fpsMarker setMarkerSize [0.7, 0.7]; + +private _localgroups = {local _x} count allGroups; +private _localunits = {local _x} count allUnits; + +private _fps = diag_fps; +private _markerColor = switch true do { + case (_fps < 15): {"ColorRED"}; + case (_fps < 25): {"ColorORANGE"}; + case (_fps < 35): {"ColorYELLOW"}; + default {"ColorGREEN"}; +}; + +_fpsMarker setMarkerColor _markerColor; + +_fpsMarker setMarkerText format ["NetID %1: %2 fps, %3 local groups, %4 local units", _id, _fps toFixed 2, _localgroups, _localunits]; + +nil diff --git a/addons/diagnostics/functions/script_component.hpp b/addons/diagnostics/functions/script_component.hpp new file mode 100644 index 0000000..0331a67 --- /dev/null +++ b/addons/diagnostics/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\afm\addons\diagnostics\script_component.hpp" \ No newline at end of file diff --git a/addons/diagnostics/initSettings.sqf b/addons/diagnostics/initSettings.sqf new file mode 100644 index 0000000..732d796 --- /dev/null +++ b/addons/diagnostics/initSettings.sqf @@ -0,0 +1,10 @@ +[ + QGVAR(markersEnabled), + "CHECKBOX", + [LLSTRING(EnableMarkers), LLSTRING(EnableMarkers_Description)], + LSTRING(DisplayName), + true, + 2, + {}, + true +] call CBA_fnc_addSetting; diff --git a/addons/diagnostics/script_component.hpp b/addons/diagnostics/script_component.hpp new file mode 100644 index 0000000..8d47eec --- /dev/null +++ b/addons/diagnostics/script_component.hpp @@ -0,0 +1,14 @@ +#define COMPONENT diagnostics +#include "\z\afm\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE + +#ifdef DEBUG_ENABLED_DIAGNOSTICS + #define DEBUG_MODE_FULL +#endif + #ifdef DEBUG_SETTINGS_DIAGNOSTICS + #define DEBUG_SETTINGS DEBUG_SETTINGS_DIAGNOSTICS +#endif + +#include "\z\afm\addons\main\script_macros.hpp" diff --git a/addons/diagnostics/stringtable.xml b/addons/diagnostics/stringtable.xml new file mode 100644 index 0000000..c4f5f86 --- /dev/null +++ b/addons/diagnostics/stringtable.xml @@ -0,0 +1,17 @@ + + + + + ArmaForces - Diagnostics + ArmaForces - Diagnostyka + + + Enable diagnostic markers + Włącz markery diagnostyczne + + + Shows markers with server and headess client diagnostic information below map. + Pokazuje markery z danymi diagnostycznimi serwera i HC poniżej mapy. + + +