drop schema version header

Remove MOTION_PLANS_SCHEMA_VERSION and simplify packed motion plan buffers to
`[recordCount, ...records]`; update GameView to apply unpacked records directly.
This commit is contained in:
scamiv
2026-02-25 22:23:24 +01:00
parent efe3b1e9e5
commit 940ff3efd7
2 changed files with 12 additions and 28 deletions
+3 -11
View File
@@ -34,11 +34,7 @@ import {
PlayerUpdate,
UnitUpdate,
} from "./GameUpdates";
import {
MOTION_PLANS_SCHEMA_VERSION,
MotionPlanRecord,
unpackMotionPlans,
} from "./MotionPlans";
import { MotionPlanRecord, unpackMotionPlans } from "./MotionPlans";
import { TerrainMapData } from "./TerrainMapLoader";
import { TerraNulliusImpl } from "./TerraNulliusImpl";
import { UnitGrid, UnitPredicate } from "./UnitGrid";
@@ -725,12 +721,8 @@ export class GameView implements GameMap {
}
if (gu.packedMotionPlans) {
const { schemaVersion, records } = unpackMotionPlans(
gu.packedMotionPlans,
);
if (schemaVersion === MOTION_PLANS_SCHEMA_VERSION) {
this.applyMotionPlanRecords(records);
}
const records = unpackMotionPlans(gu.packedMotionPlans);
this.applyMotionPlanRecords(records);
}
if (gu.updates === null) {
+9 -17
View File
@@ -1,7 +1,5 @@
import { TileRef } from "./GameMap";
export const MOTION_PLANS_SCHEMA_VERSION = 4;
export enum PackedMotionPlanKind {
GridPathSet = 1,
TrainRailPathSet = 2,
@@ -41,7 +39,7 @@ export type MotionPlanRecord = GridPathPlan | TrainRailPathPlan;
export function packMotionPlans(
records: readonly MotionPlanRecord[],
): Uint32Array {
let totalWords = 2;
let totalWords = 1;
for (const record of records) {
switch (record.kind) {
case "grid": {
@@ -59,10 +57,9 @@ export function packMotionPlans(
}
const out = new Uint32Array(totalWords);
out[0] = MOTION_PLANS_SCHEMA_VERSION >>> 0;
out[1] = records.length >>> 0;
out[0] = records.length >>> 0;
let offset = 2;
let offset = 1;
for (const record of records) {
switch (record.kind) {
case "grid": {
@@ -120,19 +117,14 @@ export function packMotionPlans(
return out;
}
export function unpackMotionPlans(packed: Uint32Array): {
schemaVersion: number;
records: MotionPlanRecord[];
} {
if (packed.length < 2) {
return { schemaVersion: 0, records: [] };
export function unpackMotionPlans(packed: Uint32Array): MotionPlanRecord[] {
if (packed.length < 1) {
return [];
}
const schemaVersion = packed[0] >>> 0;
const recordCount = packed[1] >>> 0;
const recordCount = packed[0] >>> 0;
const records: MotionPlanRecord[] = [];
let offset = 2;
let offset = 1;
for (let i = 0; i < recordCount && offset + 1 < packed.length; i++) {
const kind = packed[offset] >>> 0;
@@ -216,5 +208,5 @@ export function unpackMotionPlans(packed: Uint32Array): {
offset += wordCount;
}
return { schemaVersion, records };
return records;
}