Skip to content
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

Vehicle GPS support #31

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Vehicle GPS support #31

wants to merge 10 commits into from

Conversation

veteran29
Copy link
Member

When merged this pull request will:

  • vehicles with GPS allow tracking of its crew
  • vehicles with GPS allow tracking other units to its crew

Closes #28

@veteran29 veteran29 added the feature New feature or request label Oct 30, 2020
@veteran29 veteran29 added this to the v1.2.0 milestone Oct 30, 2020
@veteran29 veteran29 requested a review from a team as a code owner October 30, 2020 02:05
@veteran29 veteran29 requested review from 3Mydlo3 and removed request for a team October 30, 2020 02:05
Copy link
Member

@3Mydlo3 3Mydlo3 left a comment

Choose a reason for hiding this comment

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

Good job.


if (!GVAR(GPSVehicle)) exitWith {false};

getNumber (configOf _vehicle >> "enableGPS") == 1 // return
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to limit this only to configured vehicles? No support for custom variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wasn't there a support to explicitly add certain object into tracker? It will have different color if I recall tho. 🤔 And also it would be shown when empty, not sure if it's necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also I wonder if adding caching here would improve performance.

Copy link
Member

Choose a reason for hiding this comment

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

Caching would be nice indeed.

Yep, there is support for adding tracker to objects but it's a bit different behaviour. But I guess we can leave it for now and maybe add this later if needed.

Copy link
Member

Choose a reason for hiding this comment

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

I've implemented caching and added ability to override config with afft_friendly_tracker_enabledGps variable on vehicle.

@veteran29 veteran29 self-assigned this Jan 21, 2021
Copy link
Member Author

@veteran29 veteran29 left a comment

Choose a reason for hiding this comment

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

@3Mydlo3
Caching does not give any performance advantage in such simple config lookup, always benchmark never assume.

Also, CBA hashmaps should not be used anymore unless you need objects as keys. I do not understand why you've used them as they're the slowest implementation that you could use.

Benchmark:

Test code: player call fnc_getSide

Implementations:

No caching

fnc_getSide = {
	private _side = _this getVariable ["side", ""];
	
	if (_side isEqualType 0) exitWith {_side};
	
	getNumber (configOf _this >> "side")
};

Execution Time: 0.0020 ms | Cycles: 10000/10000 | Total Time: 20 ms

Native HashMap

hash = createHashMap;

fnc_getSide = {
	private _side = _this getVariable ["side", ""];
	
	if (_side isEqualType 0) exitWith {_side};
	
	private _config = configOf _this;
	private _side = hash getOrDefault [_config, ""];
	
	if (_side isEqualTo "") then {
		_side = getNumber (_config >> "side");
		hash set [_config, _side];
	};
	
	_side
	
};

Execution Time: 0.0026 ms | Cycles: 10000/10000 | Total Time: 26 ms

Object/Location namespace

hash = call CBA_fnc_createNamespace;

fnc_getSide = {
	private _side = _this getVariable ["side", ""];
	
	if (_side isEqualType 0) exitWith {_side};
	
	private _config = configOf _this;
	private _configName = configName _config;
	private _side = hash getVariable [_configName, ""];
	
	if (_side isEqualTo "") then {
		_side = getNumber (_config >> "side");
		hash setVariable [_configName, _side];
	};
	
	_side
	
};

Execution Time: 0.0029 ms | Cycles: 10000/10000 | Total Time: 29 ms

CBA Hash

(your implementation is even slower as you're using configName but you can use configs as keys)

hash = call CBA_fnc_hashCreate;

fnc_getSide = {
	private _side = _this getVariable ["side", ""];
	
	if (_side isEqualType 0) exitWith {_side};
	
	private _config = configOf _this;
	private _side = [hash, _config, ""] call CBA_fnc_hashGet;
	
	if (_side isEqualTo "") then {
		_side = getNumber (_config >> "side");
		[hash, _config, _side] call CBA_fnc_hashSet;
	};
	
	_side
	
};

Execution Time: 0.0046 ms | Cycles: 10000/10000 | Total Time: 46 ms

Comment on lines +14 to +15
GVAR(vehicleGpsCache) = call CBA_fnc_hashCreate;

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
GVAR(vehicleGpsCache) = call CBA_fnc_hashCreate;

Comment on lines +22 to +37
private _enabledGps = _vehicle getVariable [QGVAR(enabledGps), ""];

if (_enabledGps isEqualType true) exitWith {_enabledGps};

private _vehicleConfig = configOf _vehicle;
private _vehicleConfigName = configName _vehicleConfig;

_enabledGps = [GVAR(vehicleGpsCache), _vehicleConfigName, ""] call CBA_fnc_hashGet;

if (_enabledGps isEqualTo "") then {
_enabledGps = getNumber (_vehicleConfig >> "enableGPS") == 1;
[GVAR(vehicleGpsCache), _vehicleConfigName, _enabledGps] call CBA_fnc_hashSet;
};

// Return
_enabledGps
Copy link
Member Author

Choose a reason for hiding this comment

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

// Execution Time: 0.0021 ms  |  Cycles: 10000/10000  |  Total Time: 21 ms
fnc_test1 = {
	private _enabledGps = _this getVariable "test";
	if (!isNil "_enabledGps") exitWith {
		_enabledGps // return
	};
	getNumber (configOf _this >> "side") == 1 // return
};

// Execution Time: 0.0022 ms  |  Cycles: 10000/10000  |  Total Time: 22 ms
fnc_test2 = {
	private _enabledGps = _this getVariable ["test", ""];
	if (_enabledGps isEqualType true) exitWith {
		_enabledGps // return
	};
	getNumber (configOf _this >> "side") == 1 // return
};


// Execution Time: 0.0017 ms  |  Cycles: 10000/10000  |  Total Time: 17 ms
fnc_test3 = {
	_this getVariable ["test", getNumber (configOf _this >> "side") == 1] // return
};
Suggested change
private _enabledGps = _vehicle getVariable [QGVAR(enabledGps), ""];
if (_enabledGps isEqualType true) exitWith {_enabledGps};
private _vehicleConfig = configOf _vehicle;
private _vehicleConfigName = configName _vehicleConfig;
_enabledGps = [GVAR(vehicleGpsCache), _vehicleConfigName, ""] call CBA_fnc_hashGet;
if (_enabledGps isEqualTo "") then {
_enabledGps = getNumber (_vehicleConfig >> "enableGPS") == 1;
[GVAR(vehicleGpsCache), _vehicleConfigName, _enabledGps] call CBA_fnc_hashSet;
};
// Return
_enabledGps
_vehicle getVariable [
QGVAR(enabledGps),
getNumber (configOf _vehicle >> "enableGPS") == 1
] // return

@3Mydlo3
Copy link
Member

3Mydlo3 commented Dec 6, 2021

I'll just stick to mission making.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vehicles with built-in GPS should provide same functionality as inventory one
2 participants