mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Started transition to binary data on client side
This commit is contained in:
2
client/src/@types/server.d.ts
vendored
2
client/src/@types/server.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
interface UnitsData {
|
||||
units: {[key: string]: UnitData},
|
||||
units: string,
|
||||
sessionHash: string
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { UnitDatabase } from "../units/unitdatabase";
|
||||
import { aircraftDatabase } from "../units/aircraftdatabase";
|
||||
import { helicopterDatabase } from "../units/helicopterdatabase";
|
||||
import { groundUnitsDatabase } from "../units/groundunitsdatabase";
|
||||
import { Buffer } from "buffer";
|
||||
|
||||
export function bearing(lat1: number, lon1: number, lat2: number, lon2: number) {
|
||||
const φ1 = deg2rad(lat1); // φ, λ in radians
|
||||
@@ -247,4 +248,8 @@ export function getUnitDatabaseByCategory(category: string) {
|
||||
return groundUnitsDatabase;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function base64ToBytes(base64: string) {
|
||||
return Buffer.from(base64, 'base64').buffer;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ export function startUpdate() {
|
||||
getAirbases((data: AirbasesData) => getMissionData()?.update(data));
|
||||
getBullseye((data: BullseyesData) => getMissionData()?.update(data));
|
||||
getMission((data: any) => { getMissionData()?.update(data) });
|
||||
getUnits((data: UnitsData) => getUnitsManager()?.update(data), true /* Does a full refresh */);
|
||||
getUnits((data: UnitsData) => getUnitsManager()?.update(data.units), true /* Does a full refresh */);
|
||||
|
||||
requestUpdate();
|
||||
requestRefresh();
|
||||
@@ -310,7 +310,7 @@ export function requestUpdate() {
|
||||
/* Main update rate = 250ms is minimum time, equal to server update time. */
|
||||
getUnits((data: UnitsData) => {
|
||||
if (!getPaused()) {
|
||||
getUnitsManager()?.update(data);
|
||||
getUnitsManager()?.update(data.units);
|
||||
checkSessionHash(data.sessionHash);
|
||||
}
|
||||
}, false);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { LatLng, LatLngBounds } from "leaflet";
|
||||
import { getHotgroupPanel, getInfoPopup, getMap, getMissionHandler, getUnitDataTable } from "..";
|
||||
import { getHotgroupPanel, getInfoPopup, getMap, getMissionHandler } from "..";
|
||||
import { Unit } from "./unit";
|
||||
import { cloneUnit, spawnGroundUnit } from "../server/server";
|
||||
import { deg2rad, keyEventWasInInput, latLngToMercator, mToFt, mercatorToLatLng, msToKnots, polygonArea, randomPointInPoly, randomUnitBlueprintByRole } from "../other/utils";
|
||||
import { base64ToBytes, deg2rad, keyEventWasInInput, latLngToMercator, mToFt, mercatorToLatLng, msToKnots, polygonArea, randomPointInPoly, randomUnitBlueprintByRole } from "../other/utils";
|
||||
import { CoalitionArea } from "../map/coalitionarea";
|
||||
import { Airbase } from "../missionhandler/airbase";
|
||||
import { groundUnitsDatabase } from "./groundunitsdatabase";
|
||||
@@ -68,9 +68,61 @@ export class UnitsManager {
|
||||
|
||||
}
|
||||
|
||||
update(data: UnitsData) {
|
||||
update(data: string) {
|
||||
var updatedUnits: Unit[] = [];
|
||||
Object.keys(data.units)
|
||||
var buffer = base64ToBytes(data);
|
||||
|
||||
/*Coords position;
|
||||
double speed;
|
||||
double heading;
|
||||
unsigned short fuel;
|
||||
double desiredSpeed;
|
||||
double desiredAltitude;
|
||||
unsigned int targetID;
|
||||
Coords targetPosition;
|
||||
unsigned char state;
|
||||
unsigned char ROE;
|
||||
unsigned char reactionToThreat;
|
||||
unsigned char emissionsCountermeasures;
|
||||
Options::TACAN TACAN;
|
||||
Options::Radio Radio;
|
||||
unsigned short pathLength;
|
||||
unsigned char nameLength;
|
||||
unsigned char unitNameLength;
|
||||
unsigned char groupNameLength;
|
||||
unsigned char categoryLength;
|
||||
unsigned char coalitionLength;*/
|
||||
|
||||
var offset = 0;
|
||||
var dataview = new DataView(buffer);
|
||||
const ID = dataview.getUint32(offset, true); offset += 4;
|
||||
const bitmask = dataview.getUint32(offset , true); offset += 4;
|
||||
const alive = bitmask & (1 << 0);
|
||||
const human = bitmask >> 1 & 1;
|
||||
const controlled = bitmask >> 2 & 1;
|
||||
const hasTask = bitmask >> 3 & 1;
|
||||
const desiredAltitudeType = bitmask >> 16 & 1;
|
||||
const desiredSpeedType = bitmask >> 17 & 1;
|
||||
const isTanker = bitmask >> 18 & 1;
|
||||
const isAWACS = bitmask >> 19 & 1;
|
||||
const onOff = bitmask >> 20 & 1;
|
||||
const followRoads = bitmask >> 21 & 1;
|
||||
const EPLRS = bitmask >> 22 & 1;
|
||||
const prohibitAA = bitmask >> 23 & 1;
|
||||
const prohibitAfterburner = bitmask >> 24 & 1;
|
||||
const prohibitAG = bitmask >> 25 & 1;
|
||||
const prohibitAirWpn = bitmask >> 26 & 1;
|
||||
const prohibitJettison = bitmask >> 27 & 1;
|
||||
|
||||
const latitude = dataview.getFloat64(offset , true); offset += 8;
|
||||
const longitude = dataview.getFloat64(offset , true); offset += 8;
|
||||
const altitude = dataview.getFloat64(offset , true); offset += 8;
|
||||
const speed = dataview.getFloat64(offset , true); offset += 8;
|
||||
const heading = dataview.getFloat64(offset , true); offset += 8;
|
||||
|
||||
|
||||
var foo = 12;
|
||||
/*Object.keys(data.units)
|
||||
.filter((ID: string) => !(ID in this.#units))
|
||||
.reduce((timeout: number, ID: string) => {
|
||||
window.setTimeout(() => {
|
||||
@@ -91,7 +143,7 @@ export class UnitsManager {
|
||||
this.getSelectedUnits().forEach((unit: Unit) => {
|
||||
if (!updatedUnits.includes(unit))
|
||||
unit.setData({})
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
setHiddenType(key: string, value: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user