big refactor, WIP!

This commit is contained in:
2024-02-06 01:52:25 -08:00
parent f588ffa4a0
commit 0a64d9e170
74 changed files with 1024 additions and 701 deletions

View File

@@ -0,0 +1,105 @@
#include "..\script_component.hpp"
//---------------------
// Server CPS
//---------------------
[
QGVAR(server_cps_enable),
"CHECKBOX",
"Server CPS Metrics Enabled",
["17th Battalion", "Server Metrics"],
true,
true,
{
params ["_value"];
[
QGVAR(cps_enable),
_value
] call EFUNC(common,logSettingChanged);
}
] call CBA_fnc_addSetting;
[QGVAR(cps_enable), true] call CBA_settings_fnc_set;
[
QGVAR(server_cps_interval),
"TIME",
"Server CPS Metrics Interval",
[QUOTE(SETTINGS_GROUP_NAME), QUOTE(COMPONENT_BEAUTIFIED)],
[60,300,120],
true,
{
if (!isServer) exitWith {};
params ["_value"];
[
QGVAR(cps_interval),
_value
] call EFUNC(common,logSettingChanged);
_cpsPFH = missionNamespace getVariable [QGVAR(server_cps_handler), ObjNull];
if (!isNull _cpsPFH) then {
_cpsPFH call CBA_fnc_deletePerFrameHandlerObject;
};
[] call FUNC(addServerStatsPFH);
}
] call CBA_fnc_addSetting;
//---------------------
// Client CPS
//---------------------
[
QGVAR(client_cps_enable),
"CHECKBOX",
"Client CPS Metrics Enabled",
[QUOTE(SETTINGS_GROUP_NAME), QUOTE(COMPONENT_BEAUTIFIED)],
true,
true,
{
params ["_value"];
[
QGVAR(client_cps_enable),
_value
] call EFUNC(common,logSettingChanged);
}
] call CBA_fnc_addSetting;
[QGVAR(client_cps_enable), true] call CBA_settings_fnc_set;
[
QGVAR(client_cps_interval),
"TIME",
"Client CPS Metrics Interval",
[QUOTE(SETTINGS_GROUP_NAME), QUOTE(COMPONENT_BEAUTIFIED)],
[60,300,120],
true,
{
if (!hasInterface) exitWith {};
params ["_value"];
[
QGVAR(client_cps_interval),
_value
] call EFUNC(common,logSettingChanged);
_cpsPFH = player getVariable [QGVAR(client_cps_handler), ObjNull];
if (!isNull _cpsPFH) then {
_cpsPFH call CBA_fnc_deletePerFrameHandlerObject;
};
[] call FUNC(addClientStatsPFH);
}
] call CBA_fnc_addSetting;
[
LEVEL_INFO,
QUOTE(COMPONENT),
"CREATED SETTINGS",
[]
] call EFUNC(common,log);

View File

@@ -0,0 +1,38 @@
#include "..\script_component.hpp"
if (!hasInterface) exitWith {};
[
LEVEL_INFO,
QUOTE(COMPONENT),
"Initializing client stats PFH",
[]
] call EFUNC(common,log);
_cpsPFH = [
{
[] call FUNC(calculateClientStats);
},
QGVAR(client_cps_interval) call CBA_settings_fnc_get,
[],
{
[
LEVEL_INFO,
QUOTE(COMPONENT),
"Client PFH loaded",
[["pfhInterval", QGVAR(client_cps_interval) call CBA_settings_fnc_get]]
] call EFUNC(common,log);
},
{ [
LEVEL_INFO,
QUOTE(COMPONENT),
"Client PFH unloaded",
[]
] call EFUNC(common,log);
},
{ QGVAR(client_cps_enable) call CBA_settings_fnc_get },
{ false },
[]
] call CBA_fnc_createPerFrameHandlerObject;
player setVariable [QGVAR(client_cps_handler), _cpsPFH];

View File

@@ -0,0 +1,89 @@
#include "..\script_component.hpp"
if ( !hasInterface ) exitWith {};
diag_log text "[MILSIM] (DNI) writing variable loop";
[] spawn {
while {true} do {
player setVariable ["DNI_PlayerFPS", floor diag_fps, true];
sleep 1
};
};
diag_log text "[MILSIM] (DNI) variable loop complete";
/////////////////////////////////////////////////////////
//Waits until curators are initalized in order to check//
//if player is zeus to run the fps scripts //
/////////////////////////////////////////////////////////
diag_log text "[MILSIM] (DNI) waiting for curators";
waitUntil {
private _hasCurators = (count allcurators) > 0;
private _hasInitializedCurators = (count (call BIS_fnc_listCuratorPlayers)) > 0;
private _curatorsInitialized = !_hasCurators || _hasInitializedCurators;
((time > 2) || _curatorsInitialized)
};
diag_log text "[MILSIM] (DNI) curator init complete";
/////////////////////////////////////////////////////////
//If player is a curator it will run the script and each/
//player will have their FPS appear beneath them //
/////////////////////////////////////////////////////////
if (player in (call bis_fnc_listcuratorplayers)) then {
diag_log text "[MILSIM] (DNI) player is in curator list, adding Draw3D handler";
addMissionEventHandler ["Draw3D", {
{
_distance = position curatorCamera distance _x;
//if zeus camera is farther than 1200 meters away from the targets the text will not display
if (_distance < 1200) then {
_playerFPS = _x getVariable ["DNI_PlayerFPS",50];
//if the FPS is below 20 it turns red and becomes more visible for zeus to see so they are aware
if (_playerFPS <20) then
{
drawIcon3D
[
"",//Path to image displayed near text
[1,0,0,0.7],//color of the text using RGBA
position _x,//position of the text _x referring to the player in 'allPlayers'
1,//Width
2,//height from position, below
0,//angle
format["%1 FPS: %2", name _x, str _playerFPS],//text to be displayed
0,//shadow on text, 0=none,1=shadow,2=outline
0.05,//text size
"PuristaMedium",//text font
"center"//align text left, right, or center
];
}
//if the FPS is above 20 text is smaller and less visible as to not conern zeus as much
else
{
drawIcon3D
[
"",//Path to image displayed near text
[1,1,1,0.3],//color of the text using RGBA
position _x,//position of the text _x referring to the player in 'allPlayers'
1,//Width
2,//height from position, below
0,//angle
format["%1 FPS: %2", name _x, str _playerFPS],//text to be displayed
0,//shadow on text, 0=none,1=shadow,2=outline
0.03,//text size
"PuristaMedium",//text font
"center"//align text left, right, or center
];
};
};
} forEach allPlayers;
//Here is the array of units you wish to display the FPS text for, it can be
//changed to be an array of specific units or players if you wish
}];
};
/////////////////////////////////////////////////////////
/////////////////////End FPS Script//////////////////////
/////////////////////////////////////////////////////////

View File

@@ -0,0 +1,70 @@
#include "..\script_component.hpp"
if (!isServer) exitWith {};
missionNamespace setVariable[QGVAR(raw_cps), 0];
missionNamespace setVariable[QGVAR(cps), 0];
publicVariable QGVAR(raw_cps);
publicVariable QGVAR(cps);
[
LEVEL_INFO,
QUOTE(COMPONENT),
"Initializing server stats PFH",
[]
] call EFUNC(common,log);
_serverCpsPFH = [
{
[] call FUNC(calculateServerStats);
},
QGVAR(server_cps_interval) call CBA_settings_fnc_get,
[],
{
[
LEVEL_INFO,
QUOTE(COMPONENT),
"Server PFH loaded",
[["pfhInterval", QGVAR(server_cps_interval) call CBA_settings_fnc_get]]
] call EFUNC(common,log);
},
{ [
LEVEL_INFO,
QUOTE(COMPONENT),
"Server PFH unloaded",
[]
] call EFUNC(common,log);
},
{ QGVAR(server_cps_enable) call CBA_settings_fnc_get },
{ false },
[]
] call CBA_fnc_createPerFrameHandlerObject;
missionNamespace setVariable [QGVAR(server_cps_handler), _serverCpsPFH];
_playerCpsPFH = [
{
diag_log text "[MILSIM] (server) ** Player Executions **";
{
diag_log ( format ["%1: ( %2, %3 )", name _x, _x getVariable ["milsim_player_raw_cps",-1], _x getVariable ["milsim_player_cps",-1] ] )
} forEach allPlayers;
diag_log text "[MILSIM] (server) ***********************";
},
"milsim_server_cps_interval" call CBA_settings_fnc_get,
[],
{ diag_log text format ["[MILSIM] (server) Player PFH loaded"] },
{ diag_log text format ["[MILSIM] (server) Player PFH unloaded"] },
{ "milsim_server_cps_enable" call CBA_settings_fnc_get },
{ false },
[]
] call CBA_fnc_createPerFrameHandlerObject;
missionNamespace setVariable ["milsim_player_cps_handler", _playerCpsPFH];
nil;

View File

@@ -0,0 +1,40 @@
#include "..\script_component.hpp"
[] spawn {
// warning: while loop without suspension executes multiple times per frame
private _counter = 0;
private _endTime = diag_tickTime + 5;
private _frameNo = diag_frameNo;
while { diag_tickTime < _endTime } do
{
_counter = _counter + 1;
};
// in an empty mission, the _counter may go well over 2000 times per frame!
[
LEVEL_INFO,
QUOTE(COMPONENT),
format ["Average Execution: %1 times per frame", _counter / (diag_frameNo - _frameNo)],
[["playerRawCPS", _counter / (diag_frameNo - _frameNo)]]
] call EFUNC(common,log);
player setVariable [QGVAR(player_raw_cps), _counter / (diag_frameNo - _frameNo), true];
// with suspension
private _counter = 0;
private _endTime = diag_tickTime + 5;
private _frameNo = diag_frameNo;
while { diag_tickTime < _endTime } do
{
_counter = _counter + 1;
uiSleep 0.001; // waits at least 1 frame
};
// _counter says one per frame, as expected
[
LEVEL_INFO,
QUOTE(COMPONENT),
format ["Average Execution: %1 times per frame", _counter / (diag_frameNo - _frameNo)],
[["playerCPS", _counter / (diag_frameNo - _frameNo)]]
] call EFUNC(common,log);
player setVariable [QGVAR(player_cps), _counter / (diag_frameNo - _frameNo), true];
};
nil;

View File

@@ -0,0 +1,34 @@
[] spawn {
// warning: while loop without suspension executes multiple times per frame
private _counter = 0;
private _endTime = diag_tickTime + 5;
private _frameNo = diag_frameNo;
while { diag_tickTime < _endTime } do
{
_counter = _counter + 1;
};
diag_log text format ["[MILSIM] (server) Average Server Execution: %1 times per frame", _counter / (diag_frameNo - _frameNo)];
missionNamespace setVariable ["milsim_raw_cps", _counter / (diag_frameNo - _frameNo)];
publicVariable "milsim_raw_cps";
// with suspension
private _counter = 0;
private _endTime = diag_tickTime + 5;
private _frameNo = diag_frameNo;
while { diag_tickTime < _endTime } do
{
_counter = _counter + 1;
uiSleep 0.001; // waits at least 1 frame
};
diag_log text format ["[MILSIM] (server) Average Server Execution: %1 times per frame", _counter / (diag_frameNo - _frameNo)];
missionNamespace setVariable ["milsim_cps", _counter / (diag_frameNo - _frameNo)];
publicVariable "milsim_cps";
["milsim_serverEfficiency", [ [ ["float", "milsim_raw_cps", missionNamespace getVariable ["milsim_raw_cps", -1]], ["float", "milsim_cps", missionNamespace getVariable ["milsim_cps", -1]] ] ] ] call CBA_fnc_localEvent;
};
nil;

View File

@@ -0,0 +1,3 @@
#define COMPONENT performance
#define COMPONENT_BEAUTIFIED Performance Monitoring
#include "../script_mod.hpp"