-
Notifications
You must be signed in to change notification settings - Fork 44
VehSpawn: add queued status to mitigate duplicate spawns (race condition) #209
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
base: development
Are you sure you want to change the base?
Changes from 3 commits
3d059bc
e2c1563
d726aef
a8efa8e
22d4a15
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ if (isNil "_spawnPoint") exitWith { "" }; | |
| private _vehicle = _spawnPoint getOrDefault ["currentVehicle", objNull]; | ||
| private _vehicleType = typeOf _vehicle; | ||
| private _vehicleName = getText (configFile >> "CfgVehicles" >> _vehicleType >> "displayName"); | ||
| if (_vehicleName isEqualTo "") then {_vehicleName = "vehicle"}; | ||
|
|
||
| private _status = _spawnPoint getOrDefault ["status", createHashMap]; | ||
| private _state = _status getOrDefault ["state", "UNKNOWN"]; | ||
|
|
@@ -43,29 +44,13 @@ private _fnc_getTimeRemaining = { | |
| format ["%1 seconds", _seconds]; | ||
| }; | ||
|
|
||
| if (_state isEqualTo "IDLE") exitWith { | ||
| format ["%1 is currently deployed and not in use.", _vehicleName] | ||
| switch (_state) do { | ||
| case "IDLE": { format ["%1 is currently deployed and not in use.", _vehicleName] }; | ||
| case "QUEUED": { format ["The %1 is in the respawn queue and should be created within %2", _vehicleName, call _fnc_getTimeRemaining] }; | ||
| case "REPAIRING": { format ["The %1 is currently being repaired, and will be sent to the respawn queue in %2.", _vehicleName, call _fnc_getTimeRemaining] }; | ||
| case "RESPAWNING": { format ["The %1 is currently respawning, and will be sent to the respawn queue in %2.", _vehicleName, call _fnc_getTimeRemaining] }; | ||
| case "WRECKED": { format ["The %1 is currently wrecked. The wreck needs bringing to a wreck recovery point at the main base or a FOB.", _vehicleName] }; | ||
| case "DISABLED": { format ["The %1 is currently deployed. However, it's disabled and needs repairs from an engineer.", _vehicleName] }; | ||
| case "ACTIVE": { format ["The %1 is currently deployed and in use.", _vehicleName] }; | ||
| default { "The current state of this spawn point is unknown." }; | ||
|
Comment on lines
+47
to
+55
Contributor
Author
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. forgot that i refactored this as part of the change. i can extract this out into a different PR if needed |
||
| }; | ||
|
|
||
| if (_state isEqualTo "REPAIRING") exitWith { | ||
| format ["The vehicle is currently being repaired, and will be finished in %1.", call _fnc_getTimeRemaining]; | ||
| }; | ||
|
|
||
| if (_state isEqualTo "RESPAWNING") exitWith { | ||
| format ["The vehicle is currently respawning, and will be finished in %1.", call _fnc_getTimeRemaining]; | ||
| }; | ||
|
|
||
| if (_state isEqualTo "WRECKED") exitWith { | ||
| format ["The %1 is currently wrecked. The wreck needs bringing to a wreck recovery point at the main base or a FOB.", _vehicleName]; | ||
| }; | ||
|
|
||
| if (_state isEqualTo "DISABLED") exitWith { | ||
| format ["The %1 is currently deployed. However, it's disabled and needs repairs from an engineer.", _vehicleName]; | ||
| }; | ||
|
|
||
| if (_state isEqualTo "ACTIVE") exitWith { | ||
| format ["The %1 is currently deployed and in use.", _vehicleName]; | ||
| }; | ||
|
|
||
|
|
||
| "The current state of this spawn point is unknown." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ if(!alive _vehicle) then { | |
| }; | ||
|
|
||
| //Vehicle is dead, and hasn't be transitioned to a "DEAD" state. | ||
| if (!alive _vehicle && !((_spawnPoint get "status" get "state") in ["RESPAWNING", "REPAIRING", "WRECKED"])) then { | ||
| if (!alive _vehicle && !((_spawnPoint get "status" get "state") in ["RESPAWNING", "REPAIRING", "WRECKED", "QUEUED"])) then { | ||
|
Contributor
Author
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. ref comment in #210 about maybe refactoring these state exclusion lines in future #210 (comment) |
||
| if (_respawnType == "WRECK") exitWith { | ||
| [_spawnPoint] call vn_mf_fnc_veh_asset_set_wrecked; | ||
| }; | ||
|
|
@@ -155,14 +155,16 @@ if ((_spawnPoint get "status" get "state") == "IDLE") then { | |
| }; | ||
|
|
||
| //Update marker position if it exists, and it's been too long. | ||
| if (_doMarkerUpdate && !((_spawnPoint get "status" get "state") in ["RESPAWNING", "REPAIRING"])) then { | ||
| if (_doMarkerUpdate && !((_spawnPoint get "status" get "state") in ["RESPAWNING", "REPAIRING", "QUEUED"])) then { | ||
| [_spawnPoint] call vn_mf_fnc_veh_asset_marker_update_position; | ||
| }; | ||
|
|
||
| //Check if a vehicle should be respawned | ||
| //Check if a vehicle should be queued for respawning | ||
| // guarantee delivery exactly once to avoid attempting multiple vehicle spawns and lots of explosions. | ||
| if ( | ||
| (_spawnPoint get "status" get "state") in ["RESPAWNING", "REPAIRING"] && | ||
| {(_spawnPoint get "status" getOrDefault ["finishesAt", 0]) < serverTime} | ||
| ) then { | ||
| vn_mf_spawn_points_to_respawn pushBackUnique (_spawnPoint get "id"); | ||
| [_spawnPoint] call vn_mf_fnc_veh_asset_set_queued; | ||
|
Contributor
Author
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. @Spoffy will cause a merge conflict if Prio merges merged in order. not sure why -- might be newline end of file? minor conflict to fix. |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| File: fn_veh_asset_set_queued.sqf | ||
| Author: Savage Game Design | ||
| Public: No | ||
| Description: | ||
| Marks the spawn point into queued satus -- we're going to be respawning the vehicle shortly. | ||
| Parameter(s): | ||
| _spawnPoint - Spawn point whose vehicle should be set as queued [HashMap] | ||
| Returns: nothing | ||
| Example(s): none | ||
| */ | ||
|
|
||
| params ["_spawnPoint"]; | ||
|
|
||
| [_spawnPoint, "status", createHashMapFromArray [ | ||
| ["state", "QUEUED"], | ||
| ["finishesAt", serverTime + 2 + count vn_mf_spawn_points_to_respawn], | ||
| ["lastChanged", serverTime] | ||
| ]] call vn_mf_fnc_veh_asset_set_global_variable; | ||
|
|
||
| [_spawnPoint] call vn_mf_fnc_veh_asset_marker_delete; |
Uh oh!
There was an error while loading. Please reload this page.
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.
new status here. no guarantee on how long it will take to start respawn. depends on how quick the queue is being popped from