-
Notifications
You must be signed in to change notification settings - Fork 740
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
Medical Vitals - Extract update logic to separate functions #10566
Draft
LinkIsGrim
wants to merge
13
commits into
master
Choose a base branch
from
medical-refactor-vitals
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a63b97
Medical Vitals - Extract iv/medication consumption & state update
LinkIsGrim dee674b
headers/includes
LinkIsGrim d248f18
PREP
LinkIsGrim a2cae4e
fix undefined variables
LinkIsGrim 84b8b76
fix double IV consumption, missing arg
LinkIsGrim 2a16a5d
extract blood volume and pain update
LinkIsGrim 302a83c
fix tourniquet logic
LinkIsGrim 8cea489
refactor updateWoundBloodLoss
LinkIsGrim 77db3f6
Merge remote-tracking branch 'origin' into medical-refactor-vitals
LinkIsGrim c3119fe
Merge remote-tracking branch 'origin' into medical-refactor-vitals
LinkIsGrim ad79d95
add item back to IV array
LinkIsGrim a4c0ffd
Update addons/medical_vitals/functions/fnc_updatePain.sqf
LinkIsGrim 4e57482
fix hashmap key
LinkIsGrim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
addons/medical_status/functions/fnc_getBloodVolumeChange.sqf
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
PREP(consumeIVs); | ||
PREP(consumeMedications); | ||
PREP(handleUnitVitals); | ||
PREP(scanConfig); | ||
PREP(updateBloodPressure); | ||
PREP(updateBloodVolume); | ||
PREP(updateHeartRate); | ||
PREP(updateOxygen); | ||
PREP(updatePain); | ||
PREP(updatePainSuppress); | ||
PREP(updatePeripheralResistance); | ||
PREP(updateState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: Glowbal, LinkIsGrim | ||
* Calculates fluid intake and consumes unit's IVs. | ||
* | ||
* Arguments: | ||
* 0: The Unit <OBJECT> | ||
* 1: Time since last update <NUMBER> | ||
* 2: Global Sync Values (IVs) <BOOL> | ||
* | ||
* Return Value: | ||
* Blood volume change (liters per second) <NUMBER> | ||
* | ||
* Example: | ||
* [player, 1, true] call ace_medical_vitals_fnc_consumeIVs | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_unit", "_deltaT", "_syncValues"]; | ||
|
||
private _ivBags = _unit getVariable [QEGVAR(medical,ivBags), []]; | ||
|
||
if (_ivBags isEqualTo []) exitWith {0}; | ||
|
||
private _tourniquets = GET_TOURNIQUETS(_unit); | ||
private _bloodVolumeChange = 0; | ||
private _consumedIVs = []; | ||
|
||
{ | ||
_x params ["_bagVolumeRemaining", "_type", "_bodyPartIndex", "_treatment", "_rateCoef", "_item"]; | ||
|
||
if (_tourniquets select _bodyPartIndex > 0) then { | ||
continue | ||
}; | ||
|
||
private _bagChange = (_deltaT * EGVAR(medical,ivFlowRate) * IV_CHANGE_PER_SECOND * _rateCoef) min _bagVolumeRemaining; // absolute value of the change in miliLiters | ||
_bagVolumeRemaining = _bagVolumeRemaining - _bagChange; | ||
_consumedIVs pushBack [_type, _treatment, _bagChange]; | ||
|
||
if (_type in ["Blood", "Plasma", "Saline"]) then { | ||
_bloodVolumeChange = _bloodVolumeChange + (_bagChange / 1000); | ||
}; | ||
|
||
if (_bagVolumeRemaining >= 0.01) then { | ||
_x set [0, _bagVolumeRemaining]; | ||
} else { | ||
_ivBags deleteAt _forEachIndex; | ||
}; | ||
} forEachReversed _ivBags; | ||
|
||
(GVAR(deferredEvents) getOrDefault [_unit, [], true]) pushBack ([QEGVAR(medical,consumedIVs), [_unit, _consumedIVs]]); | ||
LinkIsGrim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (_ivBags isEqualTo []) then { | ||
_unit setVariable [QEGVAR(medical,ivBags), nil, true]; | ||
} else { | ||
_unit setVariable [QEGVAR(medical,ivBags), _ivBags, _syncValues]; | ||
}; | ||
|
||
_bloodVolumeChange // return |
61 changes: 61 additions & 0 deletions
61
addons/medical_vitals/functions/fnc_consumeMedications.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: Glowbal, LinkIsGrim | ||
* Consumes unit's medications and update relevant vitals | ||
* | ||
* Arguments: | ||
* 0: The Unit <OBJECT> | ||
* 1: Time since last update <NUMBER> | ||
* 2: Global Sync Values (medications) <BOOL> | ||
* | ||
* Return Value: | ||
* Values should be synced <BOOL> | ||
* | ||
* Example: | ||
* [player, 1, true] call ace_medical_vitals_fnc_consumeMedications | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_unit", "_deltaT", "_syncValues"]; | ||
|
||
private _medications = _unit getVariable [VAR_MEDICATIONS, []]; | ||
|
||
if (_medications isEqualTo []) exitWith { | ||
[0, 0, 0, false] | ||
}; | ||
|
||
private _hrTargetAdjustment = 0; | ||
private _painSupressAdjustment = 0; | ||
private _peripheralResistanceAdjustment = 0; | ||
private _consumedMedications = []; | ||
|
||
{ | ||
_x params ["_medication", "_timeAdded", "_timeTillMaxEffect", "_maxTimeInSystem", "_hrAdjust", "_painAdjust", "_flowAdjust"]; | ||
|
||
private _timeInSystem = CBA_missionTime - _timeAdded; | ||
if (_timeInSystem >= _maxTimeInSystem) then { | ||
_syncValues = true; | ||
_medications deleteAt _forEachIndex; | ||
} else { | ||
private _effectRatio = (((_timeInSystem / _timeTillMaxEffect) ^ 2) min 1) * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem; | ||
|
||
_consumedMedications pushBack [_medication, _effectRatio]; | ||
|
||
if (_hrAdjust != 0) then { _hrTargetAdjustment = _hrTargetAdjustment + _hrAdjust * _effectRatio; }; | ||
if (_painAdjust != 0) then { _painSupressAdjustment = _painSupressAdjustment + _painAdjust * _effectRatio; }; | ||
if (_flowAdjust != 0) then { _peripheralResistanceAdjustment = _peripheralResistanceAdjustment + _flowAdjust * _effectRatio; }; | ||
}; | ||
} forEachReversed _medications; | ||
|
||
(GVAR(deferredEvents) getOrDefault [_unit, [], true]) pushBack ([QEGVAR(medical,consumeMedications), [_unit, _consumedMedications]]); | ||
LinkIsGrim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (_syncValues) then { | ||
_unit setVariable [VAR_MEDICATIONS, _medications, true] | ||
}; | ||
|
||
[_unit, _hrTargetAdjustment, _deltaT, _syncValues] call FUNC(updateHeartRate); | ||
[_unit, _painSupressAdjustment, _deltaT, _syncValues] call FUNC(updatePainSuppress); | ||
[_unit, _peripheralResistanceAdjustment, _deltaT, _syncValues] call FUNC(updatePeripheralResistance); | ||
|
||
_syncValues // return |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key can't be an object, you need to use
hashValue
first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally not a huge fan of having a global hashmap for this kind of thing:
Why not use an object variable instead? Handles 1) and no longer requires
hashValue _unit
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hashmap is slightly faster (might not be with hashvalue), that was the only incentive. If we don't have to worry about keeping 3rd-party code out of the counter, I'd rather just raise the events outright.
locality change and deletion won't (shouldn't) happen mid-execution, deferred events are still executed on the same frame, so it'll be either before or after handleUnitVitals is executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do that then, makes more sense.