Skip to content

Conversation

@PabstMirror
Copy link
Contributor

@PabstMirror PabstMirror commented Oct 15, 2025

Skip running unit vital calculations and network activity for
AI units that have not been wounded or treated

The default values for things like heart rate are very close to the value they reach over time,
so I think this should not even be noticeable in most cases.
Possible edge case would be something like a AI unit with scripted reduce blood volume, HR/Pressure wouldn't update
But it's very easy to add a setVar to force the vital to always run

  • Doc GVAR to disable globally (if this causes problems with mods)

@PabstMirror PabstMirror added the kind/optimization Release Notes: **IMPROVED:** label Oct 15, 2025
if (!IS_MEDICAL_ACTIVITY(_unit)) then {
TRACE_2("activating medical for unit",_unit,typeOf _unit);
_unit setVariable [VAR_MEDICAL_ACTIVITY, true, true];
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vitals will go from never being run so the deltaT will max out at 10 seconds
so for example an AI would bleed 10seconds worth the first time they are hit
could fix with

Suggested change
};
if (_unit isNil QEGVAR(medical_vitals,lastTimeUpdated)) then {
_unit setVariable [QEGVAR(medical_vitals,lastTimeUpdated), CBA_missionTime - 1];
};
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you toggle QEGVAR(medical,medicalActivity)? As in, what is the impact if you do?

If it's meant to be toggled, you might want to add more checks regarding the update time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note that it should not be changed mid-mission

@PabstMirror PabstMirror added this to the 3.20.2 milestone Oct 22, 2025
@PabstMirror PabstMirror marked this pull request as ready for review October 22, 2025 19:39
@johnb432
Copy link
Contributor

johnb432 commented Oct 26, 2025

How well does this handle medical API functions? I imagine ace_medical_fnc_addDamageToUnit is fine, as it uses the QEGVAR(medical,woundReceived) event, but for ace_medical_fnc_adjustPainLevel and ace_medical_fnc_setUnconscious it's less clear to me.

}, _this] call CBA_fnc_addEventHandlerArgs;
};

if (!IS_MEDICAL_ACTIVITY(_unit)) then { [QGVAR(activateMedical), _unit] call CBA_fnc_localEvent; };
Copy link
Contributor

@LinkIsGrim LinkIsGrim Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe medical activity could only be enabled if state if the serialized state also had activity (check when serializing and output some magic value maybe)?

Thinking about a persistent mission with spawned but untouched AI in some far-off corner of the map, if they get serialized indiscriminately, this'd make them active after a restart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by adding ace_medical_engine_fnc_checkForMedicalActivity
this also handles manually scripted medical changes
like mission maker doing this setVariable ["ace_medical_bloodVolume", 4] to make a medical training dummy

@PabstMirror PabstMirror modified the milestones: 3.20.2, 3.20.3 Nov 30, 2025
@PabstMirror
Copy link
Contributor Author

ace_medical_vitals_fnc_handleUnitVitals takes ~0.1ms (on full loop)
So a server with 50 AI would be spending ~0.5% total time in vital loops doing nothing
But we also get to skip all the global setVariables, which should reduce traffic / jip queue

TRACE_1("checkForMedicalActivity",_unit);

if (!alive _unit || {!local _unit}) exitWith {};
if (_unit getVariable [QEGVAR(medical,medicalActivity), false]) exitWith {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it use EGVAR(medical,const_medicalActivity) as a default?

if (!IS_MEDICAL_ACTIVITY(_unit)) then {
TRACE_2("activating medical for unit",_unit,typeOf _unit);
_unit setVariable [VAR_MEDICAL_ACTIVITY, true, true];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you toggle QEGVAR(medical,medicalActivity)? As in, what is the impact if you do?

If it's meant to be toggled, you might want to add more checks regarding the update time.

Comment on lines +260 to +266
```sqf
// always run all vitals calculations on all AI (this should not be changed mid-mission)
ace_medical_const_medicalActivity = true;
// specific AI
unit setVariable ["ace_medical_medicalActivity", true]
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to make it even clearer:

Suggested change
```sqf
// always run all vitals calculations on all AI (this should not be changed mid-mission)
ace_medical_const_medicalActivity = true;
// specific AI
unit setVariable ["ace_medical_medicalActivity", true]
```
```sqf
// always run all vitals calculations on all AI
ace_medical_const_medicalActivity = true;
// specific AI
unit setVariable ["ace_medical_medicalActivity", true]
```
Once medical activity has been enabled, you can't disable it. In other words: if you execute `unit setVariable ["ace_medical_medicalActivity", true]`, you can't disable medical activity for that specific AI anymore. If you run `ace_medical_const_medicalActivity = true;`, you can no longer set it to `false` and all AI will have their medical activity enabled.

Is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/optimization Release Notes: **IMPROVED:**

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants