Skip to content

Commit e0c4f68

Browse files
authored
Merge pull request #1766 from BrettMayson/debug_watch
Diagnostics - Add button to monitor watch expressions
2 parents 8c97d73 + 13c4db3 commit e0c4f68

14 files changed

Lines changed: 280 additions & 5 deletions

addons/diagnostic/CfgEventHandlers.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ class Extended_DisplayLoad_EventHandlers {
1919
class RscDisplayInterrupt {
2020
GVAR(extendedDebug) = QUOTE(call (uiNamespace getVariable 'FUNC(initExtendedDebugConsole)'));
2121
GVAR(targetDebug) = QUOTE(call (uiNamespace getVariable 'FUNC(initTargetDebugConsole)'));
22+
GVAR(watchInput) = QUOTE([ARR_2('start',[])] call (uiNamespace getVariable 'FUNC(watchInput)'));
2223
};
2324
class RscDisplayMPInterrupt {
2425
GVAR(extendedDebug) = QUOTE(call (uiNamespace getVariable 'FUNC(initExtendedDebugConsole)'));
2526
GVAR(targetDebug) = QUOTE(call (uiNamespace getVariable 'FUNC(initTargetDebugConsole)'));
27+
GVAR(watchInput) = QUOTE([ARR_2('start',[])] call (uiNamespace getVariable 'FUNC(watchInput)'));
2628
};
2729
};

addons/diagnostic/XEH_PREP.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
PREP(projectileTracking_drawProjectilePaths);
22
PREP(projectileTracking_handleFired);
33
PREP(projectileTracking_trackProjectile);
4+
5+
PREP(watchStart);
6+
PREP(watchStop);
7+
PREP(watchUpdate);
8+
PREP(watchInput);

addons/diagnostic/XEH_preInit.sqf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ADDON = false;
88
#include "XEH_PREP.hpp"
99
#include "initSettings.inc.sqf"
1010

11+
1112
[QGVAR(debug), {_this call CBA_fnc_debug}] call CBA_fnc_addEventHandler;
1213

1314
GVAR(projectileData) = [];
21.5 KB
Binary file not shown.
21.5 KB
Binary file not shown.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include "script_component.hpp"
2+
/* ----------------------------------------------------------------------------
3+
Internal Function: CBA_diagnostic_fnc_watchInput
4+
5+
Description:
6+
Handle events on the watch input controls
7+
8+
Parameters:
9+
_event - The event that triggered the function
10+
_args - The arguments passed to the event
11+
12+
Returns:
13+
nil
14+
15+
Examples:
16+
(begin example)
17+
[1] call CBA_diagnostic_fnc_watchInput;
18+
(end)
19+
20+
Author:
21+
Brett Mayson
22+
---------------------------------------------------------------------------- */
23+
24+
params ["_event", "_args"];
25+
26+
if (_event == "start") exitWith {
27+
if (isNil QGVAR(watchControls)) then {
28+
GVAR(watchControls) = [controlNull, controlNull, controlNull, controlNull];
29+
GVAR(watchStatements) = [[], [], [], []];
30+
addMissionEventHandler ["Draw2D", {call FUNC(watchUpdate)}];
31+
};
32+
};
33+
34+
_args params ["_ctrl"];
35+
36+
private _ctrlCheckbox = _ctrl;
37+
38+
private _idc = ctrlIDC _ctrl;
39+
if (_idc < 100000) then {
40+
_idc = _idc + 100000;
41+
} else {
42+
_ctrl = (ctrlParent _ctrl) displayCtrl (_idc - 100000);
43+
};
44+
private _index = switch (_idc) do {
45+
case IDC_DEBUGCONSOLE_WATCHINPUT_1: {
46+
0
47+
};
48+
case IDC_DEBUGCONSOLE_WATCHINPUT_2: {
49+
1
50+
};
51+
case IDC_DEBUGCONSOLE_WATCHINPUT_3: {
52+
2
53+
};
54+
case IDC_DEBUGCONSOLE_WATCHINPUT_4: {
55+
3
56+
};
57+
default {
58+
-1
59+
}
60+
};
61+
62+
if (_index < 0) exitWith {
63+
ERROR_1("Invalid control ID for watch toggle, control ID: %1",ctrlIDC _ctrl);
64+
};
65+
66+
if (_event == "loadCheckbox") exitWith {
67+
_ctrlCheckbox cbSetChecked (!isNull (GVAR(watchControls) select _index));
68+
};
69+
70+
if (_event != "load") then {
71+
private _statement = ctrlText _ctrl;
72+
GVAR(watchStatements) set [_index, [_statement, compile _statement]];
73+
};
74+
75+
switch (_event) do {
76+
case "killFocus": {
77+
_ctrl setVariable ['RscDebugConsole_watchPaused', false];
78+
};
79+
case "checked": {
80+
if ((_args select 1) == 1) then {
81+
[_index] call CBA_diagnostic_fnc_watchStart;
82+
} else {
83+
[_index] call CBA_diagnostic_fnc_watchStop;
84+
};
85+
}
86+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "script_component.hpp"
2+
/* ----------------------------------------------------------------------------
3+
Internal Function: CBA_diagnostic_fnc_watchStart
4+
5+
Description:
6+
Start watching an input
7+
8+
Parameters:
9+
_index - The index in the watch list
10+
11+
Returns:
12+
nil
13+
14+
Examples:
15+
(begin example)
16+
[1] call CBA_diagnostic_fnc_watchStart;
17+
(end)
18+
19+
Author:
20+
Brett Mayson
21+
---------------------------------------------------------------------------- */
22+
23+
params ["_index"];
24+
25+
diag_log format ["CBA_diagnostic: Starting watch for input %1", _index];
26+
27+
private _statement = GVAR(watchStatements) select _index;
28+
if (_statement isEqualTo "") exitWith {};
29+
30+
[_index] call CBA_diagnostic_fnc_watchStop;
31+
private _ctrl = findDisplay 46 ctrlCreate [QGVAR(watchedInput), 1000 + IDC_DEBUGCONSOLE_WATCHINPUT_1 + _index];
32+
_ctrl ctrlSetPosition [safeZoneX, (safeZoneH / 3) + (_index * (2.5 * GUI_GRID_H)), 1 / 3 * safeZoneW, 2 * GUI_GRID_H];
33+
_ctrl ctrlCommit 0;
34+
GVAR(watchControls) set [_index, _ctrl];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "script_component.hpp"
2+
/* ----------------------------------------------------------------------------
3+
Internal Function: CBA_diagnostic_fnc_watchStop
4+
5+
Description:
6+
Stop watching an input
7+
8+
Parameters:
9+
_index - The index in the watch list
10+
11+
Returns:
12+
nil
13+
14+
Examples:
15+
(begin example)
16+
[1] call CBA_diagnostic_fnc_watchStop;
17+
(end)
18+
19+
Author:
20+
Brett Mayson
21+
---------------------------------------------------------------------------- */
22+
23+
params ["_index"];
24+
25+
private _ctrl = GVAR(watchControls) param [_index, controlNull];
26+
if (!isNull _ctrl) then {
27+
ctrlDelete _ctrl;
28+
GVAR(watchControls) set [_index, controlNull];
29+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "script_component.hpp"
2+
/* ----------------------------------------------------------------------------
3+
Internal Function: CBA_diagnostic_fnc_watchStart
4+
5+
Description:
6+
Updates the currently displayed watch controls with the latest values.
7+
8+
Parameters:
9+
_index - The index in the watch list
10+
11+
Returns:
12+
nil
13+
14+
Examples:
15+
(begin example)
16+
[1] call CBA_diagnostic_fnc_watchStart;
17+
(end)
18+
19+
Author:
20+
Brett Mayson
21+
---------------------------------------------------------------------------- */
22+
23+
{
24+
if (isNull _x) then { continue; };
25+
private _statement = GVAR(watchStatements) select _forEachIndex;
26+
if (_statement isEqualTo [] || {_statement select 0 == ""}) then {
27+
[_forEachIndex] call CBA_diagnostic_fnc_watchStop;
28+
continue;
29+
};
30+
(allControls _x) params ["", "_ctrlExpression", "_ctrlResult"];
31+
_ctrlExpression ctrlSetText (_statement select 0);
32+
_ctrlResult ctrlSetText format ["%1", (0 call (_statement select 1))];
33+
} forEach (GVAR(watchControls));

addons/diagnostic/gui.hpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,83 @@ class GVAR(watchOutput): RscEdit {
4848
colorBackground[] = {0,0,0,0.75};
4949
sizeEx = QUOTE(0.7 * GUI_GRID_H);
5050
};
51+
52+
class RscCheckBox;
53+
class RscControlsGroup;
54+
class RscDebugConsole: RscControlsGroup {
55+
class controls {
56+
class WatchInput1: RscEdit {
57+
onKillFocus = QUOTE([ARR_2('killFocus',_this)] call FUNC(watchInput););
58+
onLoad = QUOTE([ARR_2('load',_this)] call FUNC(watchInput););
59+
};
60+
class WatchInput1View: RscCheckBox {
61+
idc = IDC_DEBUGCONSOLE_WATCHINPUT_1;
62+
onLoad = QUOTE([ARR_2('loadCheckbox',_this)] call FUNC(watchInput););
63+
y = QUOTE(11 * GUI_GRID_H);
64+
h = QUOTE(1 * GUI_GRID_H);
65+
w = QUOTE(1 * GUI_GRID_W);
66+
x = QUOTE(20 * GUI_GRID_W);
67+
resizeFlags = 1;
68+
alwaysVisible = 1;
69+
textureChecked = QPATHTOF(data\monitor_on_ca.paa);
70+
textureUnchecked = QPATHTOF(data\monitor_off_ca.paa);
71+
textureFocusedChecked = QPATHTOF(data\monitor_on_ca.paa);
72+
textureFocusedUnchecked = QPATHTOF(data\monitor_off_ca.paa);
73+
textureHoverChecked = QPATHTOF(data\monitor_on_ca.paa);
74+
textureHoverUnchecked = QPATHTOF(data\monitor_off_ca.paa);
75+
texturePressedChecked = QPATHTOF(data\monitor_on_ca.paa);
76+
texturePressedUnchecked = QPATHTOF(data\monitor_off_ca.paa);
77+
onCheckedChanged = QUOTE([ARR_2('checked',_this)] call FUNC(watchInput));
78+
};
79+
class WatchInputView2: WatchInput1View {
80+
idc = IDC_DEBUGCONSOLE_WATCHINPUT_2;
81+
checked = QUOTE(!isNull (GVAR(watchControls) select 1));
82+
y = QUOTE(13 * GUI_GRID_H);
83+
};
84+
class WatchInputView3: WatchInput1View {
85+
idc = IDC_DEBUGCONSOLE_WATCHINPUT_3;
86+
checked = QUOTE(!isNull (GVAR(watchControls) select 2));
87+
y = QUOTE(15 * GUI_GRID_H);
88+
};
89+
class WatchInputView4: WatchInput1View {
90+
idc = IDC_DEBUGCONSOLE_WATCHINPUT_4;
91+
checked = QUOTE(!isNull (GVAR(watchControls) select 3));
92+
y = QUOTE(17 * GUI_GRID_H);
93+
};
94+
};
95+
};
96+
97+
class RscText;
98+
class RscControlsGroupNoScrollbars;
99+
class GVAR(watchedInput): RscControlsGroupNoScrollbars {
100+
idc = -1;
101+
class controls {
102+
class Background: RscText {
103+
colorBackground[] = {0, 0, 0, 0.6};
104+
x = QUOTE(0.1 * GUI_GRID_W);
105+
y = QUOTE(0.1 * GUI_GRID_H);
106+
w = QUOTE(15 * GUI_GRID_W);
107+
h = QUOTE(1.8 * GUI_GRID_H);
108+
};
109+
class Expression: RscText {
110+
sizeEx = QUOTE(0.75 * GUI_GRID_H);
111+
font = "EtelkaMonospacePro";
112+
shadow = 1;
113+
colorText[] = {1, 1, 1, 1};
114+
colorBackground[] = {0, 0, 0, 0};
115+
text = "Expression";
116+
x = QUOTE(0.1 * GUI_GRID_W);
117+
y = QUOTE(0.1 * GUI_GRID_H);
118+
w = QUOTE(15 * GUI_GRID_W);
119+
h = QUOTE(0.8 * GUI_GRID_H);
120+
};
121+
class Result: Expression {
122+
style = 0;
123+
text = "Result";
124+
x = QUOTE(0.1 * GUI_GRID_W);
125+
y = QUOTE(0.9 * GUI_GRID_H);
126+
w = QUOTE(15 * GUI_GRID_W);
127+
h = QUOTE(1 * GUI_GRID_H);
128+
};
129+
};
130+
};

0 commit comments

Comments
 (0)