-
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
Add localUnits array and use that inside medical statemachines #4836
Changes from all commits
bb3869f
e15f0e6
54ac1bd
5ec6f54
dd6b603
c2c1c15
5ff36ae
310f91f
44fd1bf
c0bdd81
c98d605
85d4898
8af22f8
5535ca1
b30740c
4f9f471
a8b3915
4fca03c
04d03ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: dedmen | ||
* Gets localUnits array filtering out nullObjects. | ||
* If you can handle null objects you can use the array `ace_common_localUnits` directly. | ||
* Should be equivalent to `allUnits select {local _x}` | ||
* | ||
* Arguments: | ||
* Nothing | ||
* | ||
* Return Value: | ||
* Array of local Units <ARRAY> | ||
* | ||
* Example: | ||
* [] call ace_common_fnc_getLocalUnits | ||
* | ||
* Public: Yes | ||
*/ | ||
|
||
// Remove null objects | ||
GVAR(localUnits) = GVAR(localUnits) - [objNull]; | ||
|
||
GVAR(localUnits) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "script_component.hpp" | ||
/* | ||
* Author: dedmen | ||
* Adds the local unit event handlers. | ||
* Access with function `ace_common_fnc_getLocalUnits` or array `ace_common_localUnits` | ||
* | ||
* Arguments: | ||
* Nothing | ||
* | ||
* Return Value: | ||
* Nothing | ||
* | ||
* Example: | ||
* [] call ace_common_fnc_setupLocalUnitsHandler | ||
* | ||
* Public: No | ||
*/ | ||
|
||
GVAR(localUnits) = []; | ||
|
||
// Eventhandlers to maintain array of localUnits | ||
["CAManBase", "init", { | ||
params ["_unit"]; | ||
TRACE_2("unit init",_unit,local _unit); | ||
|
||
if (local _unit) then { | ||
if (!alive _unit) exitWith {}; | ||
GVAR(localUnits) pushBack _unit; | ||
}; | ||
}] call CBA_fnc_addClassEventHandler; | ||
|
||
["CAManBase", "respawn", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't "init" also fire for respawning units? Respawning in MP should be tested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Init does not fire for respawned objects. |
||
params ["_unit"]; | ||
TRACE_2("unit respawn",_unit,local _unit); | ||
|
||
if (local _unit) then { | ||
if (!alive _unit) exitWith {}; | ||
GVAR(localUnits) pushBack _unit; | ||
}; | ||
}] call CBA_fnc_addClassEventHandler; | ||
|
||
["CAManBase", "local", { | ||
params ["_unit", "_local"]; | ||
TRACE_2("unit local",_unit,_local); | ||
|
||
if (_local) then { | ||
if (!alive _unit) exitWith {}; | ||
GVAR(localUnits) pushBack _unit; | ||
} else { | ||
GVAR(localUnits) deleteAt (GVAR(localUnits) find _unit); | ||
}; | ||
}] call CBA_fnc_addClassEventHandler; | ||
|
||
["CAManBase", "deleted", { | ||
params ["_unit"]; | ||
TRACE_2("unit deleted",_unit,local _unit); | ||
|
||
if (local _unit) then { | ||
[{ | ||
params ["_unit"]; | ||
TRACE_3("unit deleted nextFrame",_unit,local _unit,isNull _unit); | ||
if (isNull _unit) then { // If it is not null then the deleted EH was Fake. | ||
GVAR(localUnits) = GVAR(localUnits) - [objNull]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I delete all objNull here as using |
||
}; | ||
}, [_unit]] call CBA_fnc_execNextFrame; | ||
}; | ||
}] call CBA_fnc_addClassEventHandler; | ||
|
||
["CAManBase", "killed", { | ||
params ["_unit"]; | ||
TRACE_2("unit killed",_unit,local _unit); | ||
|
||
if (local _unit) then { | ||
GVAR(localUnits) deleteAt (GVAR(localUnits) find _unit); | ||
}; | ||
}] call CBA_fnc_addClassEventHandler; |
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.
We can check diag_frameNo against a global variable so we only remove null objects once a frame to get us a little more perf.
But I'm not sure if
GVAR(localUnits) = GVAR(localUnits) - [objNull];
is really that expensive that it's worth it. Needs profiling with atleast a hundred local units.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.
Actually we only need to run this if there was a deletedEH in the last 2-3 frames. But I don't think it hurts.
Considering this will already be about a 100x improvement vs iterating through allUnits everytime.
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.
also to checking
diag_frameNo
objects are deleted in simulation cycle. Draw3D runs after that in the same frame. So that could cause Draw3D to still get null objects.