Optimise spectator loops (#6021)

* Optimise spectator loops

`count` is only quicker than `forEach` when the final command returns a
boolean or nil. `forEach` is quicker if the final command returns any
other data type.

* Use `forEach` instead of `count`
This commit is contained in:
SilentSpike 2018-01-06 00:30:15 +00:00 committed by jonpas
parent 4eb7868f1a
commit dbe6a04e8a
5 changed files with 12 additions and 28 deletions

View File

@ -12,7 +12,7 @@
* 3: Respawn Delay <NUMBER> * 3: Respawn Delay <NUMBER>
* *
* Return Value: * Return Value:
* None <NIL> * None
* *
* Example: * Example:
* [bob, kevin, 3, 6] call ace_spectator_fnc_respawnTemplate * [bob, kevin, 3, 6] call ace_spectator_fnc_respawnTemplate

View File

@ -72,9 +72,7 @@ if !(GVAR(uiMapVisible)) then {
// Draw icon // Draw icon
drawIcon3D _icon; drawIcon3D _icon;
} forEach GVAR(iconsToDraw);
nil // Speed loop
} count GVAR(iconsToDraw);
END_COUNTER(drawTags); END_COUNTER(drawTags);
}; };
@ -119,13 +117,9 @@ if !(GVAR(uiMapVisible)) then {
drawLine3D [_oldLoc, _locNew, _colorNew]; drawLine3D [_oldLoc, _locNew, _colorNew];
}; };
_oldLoc = _locNew; _oldLoc = _locNew;
} forEach _segments;
nil // Speed loop
} count _segments;
}; };
} forEach GVAR(projectilesToDraw);
nil // Speed loop
} count GVAR(projectilesToDraw);
GVAR(projectilesToDraw) = _projectilesNew; GVAR(projectilesToDraw) = _projectilesNew;
{ {
@ -138,9 +132,7 @@ if !(GVAR(uiMapVisible)) then {
// Store grenade for next frame // Store grenade for next frame
_grenadesNew pushBack _x; _grenadesNew pushBack _x;
}; };
} forEach GVAR(grenadesToDraw);
nil // Speed loop
} count GVAR(grenadesToDraw);
GVAR(grenadesToDraw) = _grenadesNew; GVAR(grenadesToDraw) = _grenadesNew;
END_COUNTER(drawTracers); END_COUNTER(drawTracers);

View File

@ -64,8 +64,7 @@ private _handledVehicles = [];
_map drawIcon [_vehicleTexture, _sideColor, getPosASLVisual _vehicle, 24, 24, getDirVisual _vehicle, _text, 1, 0.04, "TahomaB", "right"]; _map drawIcon [_vehicleTexture, _sideColor, getPosASLVisual _vehicle, 24, 24, getDirVisual _vehicle, _text, 1, 0.04, "TahomaB", "right"];
}; };
nil // Speed loop } forEach ([] call FUNC(getTargetEntities));
} count ([] call FUNC(getTargetEntities));
// Set highlighted unit // Set highlighted unit
private _text = if (isNull _nearestEntity) then { private _text = if (isNull _nearestEntity) then {

View File

@ -139,9 +139,7 @@ private _camPos = AGLToASL positionCameraToWorld [0,0,0];
SETVAR(_vehicle,GVAR(firedEH),_vehicle addEventHandler [ARR_2("Fired",{_this call FUNC(handleFired)})]); SETVAR(_vehicle,GVAR(firedEH),_vehicle addEventHandler [ARR_2("Fired",{_this call FUNC(handleFired)})]);
}; };
}; };
} forEach ([] call FUNC(getTargetEntities));
nil // Speed loop
} count ([] call FUNC(getTargetEntities));
GVAR(iconsToDraw) = _iconsToDraw; GVAR(iconsToDraw) = _iconsToDraw;
GVAR(entitiesToDraw) = _entitiesToDraw; GVAR(entitiesToDraw) = _entitiesToDraw;

View File

@ -51,8 +51,7 @@ private _entities = [true] call FUNC(getTargetEntities);
alive _x && { NEEDS_REVIVE(_x) }, alive _x && { NEEDS_REVIVE(_x) },
_name _name
]; ];
nil // Speed loop } forEach _entitiesGroup;
} count _entitiesGroup;
// Cache the info of the group itself // Cache the info of the group itself
private _groupTexture = [_group] call FUNC(getGroupIcon); private _groupTexture = [_group] call FUNC(getGroupIcon);
@ -80,8 +79,7 @@ private _entities = [true] call FUNC(getTargetEntities);
((_newList select _sideIndex) select 4) pushBack [_groupInfo, _unitsInfo]; ((_newList select _sideIndex) select 4) pushBack [_groupInfo, _unitsInfo];
}; };
}; };
nil // Speed loop } forEach allGroups;
} count allGroups;
// Whether an update to the list is required (really only if something changed) // Whether an update to the list is required (really only if something changed)
if !(GVAR(curList) isEqualTo _newList) then { if !(GVAR(curList) isEqualTo _newList) then {
@ -207,12 +205,9 @@ if !(GVAR(curList) isEqualTo _newList) then {
_ctrl tvSetPictureColor [_path, _sideColor]; _ctrl tvSetPictureColor [_path, _sideColor];
_ctrl tvSetTooltip [_path, _tooltip]; _ctrl tvSetTooltip [_path, _tooltip];
}; };
nil // Speed loop } forEach _nestedUnitData;
} count _nestedUnitData; } forEach _nestedGroupData;
nil // Speed loop } forEach _newList;
} count _nestedGroupData;
nil // Speed loop
} count _newList;
// Store the new list as the current list // Store the new list as the current list
GVAR(curList) = _newList; GVAR(curList) = _newList;