diff --git a/src/addon/config.cpp b/src/addon/config.cpp index 01facc6..cadc77f 100644 --- a/src/addon/config.cpp +++ b/src/addon/config.cpp @@ -35,11 +35,13 @@ class CfgFunctions class addUnitEventHandlers {}; class addVehicleEventHandlers {}; class init {}; + class reportMarkerPositions {}; class reportUnitPositions {}; class reportVehiclePositions {}; class sendEvent {}; class sendJson {}; class serializeJson {}; + class serializeMarker {}; class serializeMission {}; class serializePlayer {}; class serializePosition {}; diff --git a/src/addon/functions/fn_init.sqf b/src/addon/functions/fn_init.sqf index d54e00d..85841e9 100644 --- a/src/addon/functions/fn_init.sqf +++ b/src/addon/functions/fn_init.sqf @@ -67,6 +67,10 @@ if (isMultiplayer) then { /* Periodically send unit positions */ if (anrop_aar_position_reporting > 0) then { + [] spawn { + anrop_aar_position_reporting call anrop_aar_fnc_reportMarkerPositions; + }; + [] spawn { anrop_aar_position_reporting call anrop_aar_fnc_reportUnitPositions; }; diff --git a/src/addon/functions/fn_reportMarkerPositions.sqf b/src/addon/functions/fn_reportMarkerPositions.sqf new file mode 100644 index 0000000..3d3551a --- /dev/null +++ b/src/addon/functions/fn_reportMarkerPositions.sqf @@ -0,0 +1,42 @@ +private _markerHash = [[], ""] call CBA_fnc_hashCreate; +private _currentMarkers = []; + +private _reportMarker = { + params ["_event", "_marker"]; + + private _serializedMarker = _marker call anrop_aar_fnc_serializeMarker; + + private _obj = ["object", + ["type", ["string", _event]], + ["marker", _serializedMarker] + ]; + + private _cached = [_markerHash, _marker] call CBA_fnc_hashGet; + + private _serialized = _obj call anrop_aar_fnc_serializeJson; + if (_serialized != _cached) then { + [_markerHash, _marker, _serialized] call CBA_fnc_hashSet; + _serialized call anrop_aar_fnc_sendJson; + }; +}; + +while { true } do { + private _allMarkers = allMapMarkers; + private _newMarkers = _allMarkers - _currentMarkers; + private _updatedMarkers = _allMarkers - _newMarkers; + private _removedMarkers = _currentMarkers - _allMarkers; + + { + ["MarkerCreated", _x] call _reportMarker; + } forEach _newMarkers; + + { + ["MarkerPosition", _x] call _reportMarker; + } forEach _updatedMarkers; + + { + ["MarkerDeleted", _x] call _reportMarker; + } forEach _removedMarkers; + + sleep _this; +}; diff --git a/src/addon/functions/fn_serializeMarker.sqf b/src/addon/functions/fn_serializeMarker.sqf new file mode 100644 index 0000000..7cf00cb --- /dev/null +++ b/src/addon/functions/fn_serializeMarker.sqf @@ -0,0 +1,26 @@ +params ["_marker"]; + +private _id = _marker; +private _alpha = markerAlpha _marker; +private _brush = markerBrush _marker; +private _color = markerColor _marker; +private _position = ([markerPos _marker, markerDir _marker] call anrop_aar_fnc_serializePosition); +private _shape = markerShape _marker; +private _size = markerSize _marker; +private _text = markerText _marker; +private _type = markerType _marker; + +["object", + ["id", ["string", _id]], + ["alpha", ["number", _alpha]], + ["brush", ["string", _brush]], + ["color", ["string", _color]], + ["position", _position], + ["shape", ["string", _shape]], + ["size", ["object", + ["width", ["number", _size select 0]], + ["height", ["number", _size select 1]] + ]], + ["text", ["string", _text]], + ["type", ["string", _type]] +];