Optimized transmission of data of dead units

Dead units only transmit basedata. Empty fields and empty units are removed from update packages.
This commit is contained in:
Pax1601
2023-05-10 16:13:55 +02:00
parent cf3cdcbd44
commit e69294b98c
6 changed files with 102 additions and 75 deletions

View File

@@ -72,8 +72,9 @@ export class UnitControlPanel extends Panel {
this.#advancedSettingsDialog = <HTMLElement> document.querySelector("#advanced-settings-dialog"); this.#advancedSettingsDialog = <HTMLElement> document.querySelector("#advanced-settings-dialog");
document.addEventListener("unitUpdated", (e: CustomEvent<Unit>) => { if (e.detail.getSelected()) this.update() }); window.setInterval(() => {this.update();}, 25);
document.addEventListener("unitsSelection", (e: CustomEvent<Unit[]>) => { this.show(); this.addButtons(); this.update()});
document.addEventListener("unitsSelection", (e: CustomEvent<Unit[]>) => { this.show(); this.addButtons();});
document.addEventListener("clearSelection", () => { this.hide() }); document.addEventListener("clearSelection", () => { this.hide() });
document.addEventListener("applyAdvancedSettings", () => {this.#applyAdvancedSettings();}) document.addEventListener("applyAdvancedSettings", () => {this.#applyAdvancedSettings();})
document.addEventListener("showAdvancedSettings", () => { document.addEventListener("showAdvancedSettings", () => {
@@ -94,45 +95,53 @@ export class UnitControlPanel extends Panel {
addButtons() { addButtons() {
var units = getUnitsManager().getSelectedUnits(); var units = getUnitsManager().getSelectedUnits();
this.getElement().querySelector("#selected-units-container")?.replaceChildren(...units.map((unit: Unit, index: number) => { if (units.length < 20) {
let database: UnitDatabase | null; this.getElement().querySelector("#selected-units-container")?.replaceChildren(...units.map((unit: Unit, index: number) => {
if (unit instanceof Aircraft) let database: UnitDatabase | null;
database = aircraftDatabase; if (unit instanceof Aircraft)
else if (unit instanceof GroundUnit) database = aircraftDatabase;
database = groundUnitsDatabase; else if (unit instanceof GroundUnit)
else database = groundUnitsDatabase;
database = null; // TODO add databases for other unit types else
database = null; // TODO add databases for other unit types
var button = document.createElement("button"); var button = document.createElement("button");
var callsign = unit.getBaseData().unitName || ""; var callsign = unit.getBaseData().unitName || "";
button.setAttribute("data-short-label", database?.getByName(unit.getBaseData().name)?.shortLabel || ""); button.setAttribute("data-short-label", database?.getByName(unit.getBaseData().name)?.shortLabel || unit.getBaseData().name);
button.setAttribute("data-callsign", callsign); button.setAttribute("data-callsign", callsign);
button.setAttribute("data-coalition", unit.getMissionData().coalition); button.setAttribute("data-coalition", unit.getMissionData().coalition);
button.classList.add("pill", "highlight-coalition") button.classList.add("pill", "highlight-coalition")
button.addEventListener("click", () => { button.addEventListener("click", () => {
getUnitsManager().deselectAllUnits(); getUnitsManager().deselectAllUnits();
getUnitsManager().selectUnit(unit.ID, true); getUnitsManager().selectUnit(unit.ID, true);
}); });
return (button); return (button);
})); }));
} else {
var el = document.createElement("div");
el.innerText = "Too many units selected"
this.getElement().querySelector("#selected-units-container")?.replaceChildren(el);
}
} }
update() { update() {
var units = getUnitsManager().getSelectedUnits(); if (this.getVisible()){
this.getElement().querySelector("#advanced-settings-div")?.classList.toggle("hide", units.length != 1); var units = getUnitsManager().getSelectedUnits();
if (this.getElement() != null && units.length > 0) { this.getElement().querySelector("#advanced-settings-div")?.classList.toggle("hide", units.length != 1);
this.#showFlightControlSliders(units); if (this.getElement() != null && units.length > 0) {
this.#showFlightControlSliders(units);
this.#optionButtons["ROE"].forEach((button: HTMLButtonElement) => { this.#optionButtons["ROE"].forEach((button: HTMLButtonElement) => {
button.classList.toggle("selected", units.every((unit: Unit) => unit.getOptionsData().ROE === button.value)) button.classList.toggle("selected", units.every((unit: Unit) => unit.getOptionsData().ROE === button.value))
}); });
this.#optionButtons["reactionToThreat"].forEach((button: HTMLButtonElement) => { this.#optionButtons["reactionToThreat"].forEach((button: HTMLButtonElement) => {
button.classList.toggle("selected", units.every((unit: Unit) => unit.getOptionsData().reactionToThreat === button.value)) button.classList.toggle("selected", units.every((unit: Unit) => unit.getOptionsData().reactionToThreat === button.value))
}); });
}
} }
} }

View File

@@ -54,7 +54,7 @@ export class UnitInfoPanel extends Panel {
const baseData = unit.getBaseData(); const baseData = unit.getBaseData();
/* Set the unit info */ /* Set the unit info */
this.#unitLabel.innerText = aircraftDatabase.getByName(baseData.name)?.label || ""; this.#unitLabel.innerText = aircraftDatabase.getByName(baseData.name)?.label || baseData.name;
this.#unitName.innerText = baseData.unitName; this.#unitName.innerText = baseData.unitName;
this.#unitControl.innerText = ( ( baseData.AI ) ? "AI" : "Human" ) + " controlled"; this.#unitControl.innerText = ( ( baseData.AI ) ? "AI" : "Human" ) + " controlled";
// this.#groupName.innerText = baseData.groupName; // this.#groupName.innerText = baseData.groupName;

View File

@@ -141,9 +141,9 @@ export class Unit extends Marker {
setData(data: UpdateData) { setData(data: UpdateData) {
/* Check if data has changed comparing new values to old values */ /* Check if data has changed comparing new values to old values */
const positionChanged = (data.flightData.latitude != undefined && data.flightData.longitude != undefined && (this.getFlightData().latitude != data.flightData.latitude || this.getFlightData().longitude != data.flightData.longitude)); const positionChanged = (data.flightData != undefined && data.flightData.latitude != undefined && data.flightData.longitude != undefined && (this.getFlightData().latitude != data.flightData.latitude || this.getFlightData().longitude != data.flightData.longitude));
const headingChanged = (data.flightData.heading != undefined && this.getFlightData().heading != data.flightData.heading); const headingChanged = (data.flightData != undefined && data.flightData.heading != undefined && this.getFlightData().heading != data.flightData.heading);
const aliveChanged = (data.baseData.alive != undefined && this.getBaseData().alive != data.baseData.alive); const aliveChanged = (data.baseData != undefined && data.baseData.alive != undefined && this.getBaseData().alive != data.baseData.alive);
var updateMarker = (positionChanged || headingChanged || aliveChanged || !getMap().hasLayer(this)) var updateMarker = (positionChanged || headingChanged || aliveChanged || !getMap().hasLayer(this))
if (data.baseData != undefined) if (data.baseData != undefined)

View File

@@ -48,9 +48,11 @@ end
function Olympus.getCountryIDByCoalition(coalition) function Olympus.getCountryIDByCoalition(coalition)
local countryID = 0 local countryID = 0
if coalition == 'red' then if coalition == 'red' then
countryID = country.id.RUSSIA countryID = country.id.CJTF_RED
elseif coalition == 'blue' then
countryID = country.id.CJTF_BLUE
else else
countryID = country.id.USA countryID = country.id.UN_PEACEKEEPERS
end end
return countryID return countryID
end end

View File

@@ -29,8 +29,8 @@ Unit::Unit(json::value json, int ID) :
addMeasure(L"radioCallsign", json::value(radioCallsign)); addMeasure(L"radioCallsign", json::value(radioCallsign));
addMeasure(L"radioCallsignNumber", json::value(radioCallsignNumber)); addMeasure(L"radioCallsignNumber", json::value(radioCallsignNumber));
setROE(L"Designated"); addMeasure(L"ROE", json::value(L"Designated"));
setReactionToThreat(L"Evade"); addMeasure(L"reactionToThreat", json::value(L"Evade"));
} }
Unit::~Unit() Unit::~Unit()
@@ -119,45 +119,59 @@ json::value Unit::getData(long long time)
if (measures.find(key) != measures.end() && measures[key]->getTime() > time) if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
json[L"baseData"][key] = measures[key]->getValue(); json[L"baseData"][key] = measures[key]->getValue();
} }
if (json[L"baseData"].size() == 0)
json.erase(L"baseData");
/********** Flight data **********/ if (alive) {
json[L"flightData"] = json::value::object(); /********** Flight data **********/
for (auto key : { L"latitude", L"longitude", L"altitude", L"speed", L"heading"}) json[L"flightData"] = json::value::object();
{ for (auto key : { L"latitude", L"longitude", L"altitude", L"speed", L"heading" })
if (measures.find(key) != measures.end() && measures[key]->getTime() > time) {
json[L"flightData"][key] = measures[key]->getValue(); if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
} json[L"flightData"][key] = measures[key]->getValue();
}
if (json[L"flightData"].size() == 0)
json.erase(L"flightData");
/********** Mission data **********/ /********** Mission data **********/
json[L"missionData"] = json::value::object(); json[L"missionData"] = json::value::object();
for (auto key : { L"fuel", L"ammo", L"targets", L"hasTask", L"coalition", L"flags"}) for (auto key : { L"fuel", L"ammo", L"targets", L"hasTask", L"coalition", L"flags" })
{ {
if (measures.find(key) != measures.end() && measures[key]->getTime() > time) if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
json[L"missionData"][key] = measures[key]->getValue(); json[L"missionData"][key] = measures[key]->getValue();
} }
if (json[L"missionData"].size() == 0)
json.erase(L"missionData");
/********** Formation data **********/ /********** Formation data **********/
json[L"formationData"] = json::value::object(); json[L"formationData"] = json::value::object();
for (auto key : { L"leaderID" }) for (auto key : { L"leaderID" })
{ {
if (measures.find(key) != measures.end() && measures[key]->getTime() > time) if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
json[L"formationData"][key] = measures[key]->getValue(); json[L"formationData"][key] = measures[key]->getValue();
} }
if (json[L"formationData"].size() == 0)
json.erase(L"formationData");
/********** Task data **********/ /********** Task data **********/
json[L"taskData"] = json::value::object(); json[L"taskData"] = json::value::object();
for (auto key : { L"currentState", L"currentTask", L"targetSpeed", L"targetAltitude", L"activePath", L"isTanker", L"isAWACS", L"TACANChannel", L"TACANXY", L"TACANCallsign", L"radioFrequency", L"radioCallsign", L"radioCallsignNumber"}) for (auto key : { L"currentState", L"currentTask", L"targetSpeed", L"targetAltitude", L"activePath", L"isTanker", L"isAWACS", L"TACANChannel", L"TACANXY", L"TACANCallsign", L"radioFrequency", L"radioCallsign", L"radioCallsignNumber" })
{ {
if (measures.find(key) != measures.end() && measures[key]->getTime() > time) if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
json[L"taskData"][key] = measures[key]->getValue(); json[L"taskData"][key] = measures[key]->getValue();
} }
if (json[L"taskData"].size() == 0)
json.erase(L"taskData");
/********** Options data **********/ /********** Options data **********/
json[L"optionsData"] = json::value::object(); json[L"optionsData"] = json::value::object();
for (auto key : { L"ROE", L"reactionToThreat" }) for (auto key : { L"ROE", L"reactionToThreat" })
{ {
if (measures.find(key) != measures.end() && measures[key]->getTime() > time) if (measures.find(key) != measures.end() && measures[key]->getTime() > time)
json[L"optionsData"][key] = measures[key]->getValue(); json[L"optionsData"][key] = measures[key]->getValue();
}
if (json[L"optionsData"].size() == 0)
json.erase(L"optionsData");
} }
return json; return json;

View File

@@ -97,7 +97,9 @@ void UnitsManager::getData(json::value& answer, long long time)
auto unitsJson = json::value::object(); auto unitsJson = json::value::object();
for (auto const& p : units) for (auto const& p : units)
{ {
unitsJson[to_wstring(p.first)] = p.second->getData(time); auto unitJson = p.second->getData(time);
if (unitJson.size() > 0)
unitsJson[to_wstring(p.first)] = p.second->getData(time);
} }
answer[L"units"] = unitsJson; answer[L"units"] = unitsJson;
} }