mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-19 07:46:26 +00:00
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:
@@ -34,11 +34,7 @@ import {
|
|||||||
PlayerUpdate,
|
PlayerUpdate,
|
||||||
UnitUpdate,
|
UnitUpdate,
|
||||||
} from "./GameUpdates";
|
} from "./GameUpdates";
|
||||||
import {
|
import { MotionPlanRecord, unpackMotionPlans } from "./MotionPlans";
|
||||||
MOTION_PLANS_SCHEMA_VERSION,
|
|
||||||
MotionPlanRecord,
|
|
||||||
unpackMotionPlans,
|
|
||||||
} from "./MotionPlans";
|
|
||||||
import { TerrainMapData } from "./TerrainMapLoader";
|
import { TerrainMapData } from "./TerrainMapLoader";
|
||||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||||
import { UnitGrid, UnitPredicate } from "./UnitGrid";
|
import { UnitGrid, UnitPredicate } from "./UnitGrid";
|
||||||
@@ -725,12 +721,8 @@ export class GameView implements GameMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gu.packedMotionPlans) {
|
if (gu.packedMotionPlans) {
|
||||||
const { schemaVersion, records } = unpackMotionPlans(
|
const records = unpackMotionPlans(gu.packedMotionPlans);
|
||||||
gu.packedMotionPlans,
|
this.applyMotionPlanRecords(records);
|
||||||
);
|
|
||||||
if (schemaVersion === MOTION_PLANS_SCHEMA_VERSION) {
|
|
||||||
this.applyMotionPlanRecords(records);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gu.updates === null) {
|
if (gu.updates === null) {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { TileRef } from "./GameMap";
|
import { TileRef } from "./GameMap";
|
||||||
|
|
||||||
export const MOTION_PLANS_SCHEMA_VERSION = 4;
|
|
||||||
|
|
||||||
export enum PackedMotionPlanKind {
|
export enum PackedMotionPlanKind {
|
||||||
GridPathSet = 1,
|
GridPathSet = 1,
|
||||||
TrainRailPathSet = 2,
|
TrainRailPathSet = 2,
|
||||||
@@ -41,7 +39,7 @@ export type MotionPlanRecord = GridPathPlan | TrainRailPathPlan;
|
|||||||
export function packMotionPlans(
|
export function packMotionPlans(
|
||||||
records: readonly MotionPlanRecord[],
|
records: readonly MotionPlanRecord[],
|
||||||
): Uint32Array {
|
): Uint32Array {
|
||||||
let totalWords = 2;
|
let totalWords = 1;
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
switch (record.kind) {
|
switch (record.kind) {
|
||||||
case "grid": {
|
case "grid": {
|
||||||
@@ -59,10 +57,9 @@ export function packMotionPlans(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const out = new Uint32Array(totalWords);
|
const out = new Uint32Array(totalWords);
|
||||||
out[0] = MOTION_PLANS_SCHEMA_VERSION >>> 0;
|
out[0] = records.length >>> 0;
|
||||||
out[1] = records.length >>> 0;
|
|
||||||
|
|
||||||
let offset = 2;
|
let offset = 1;
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
switch (record.kind) {
|
switch (record.kind) {
|
||||||
case "grid": {
|
case "grid": {
|
||||||
@@ -120,19 +117,14 @@ export function packMotionPlans(
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unpackMotionPlans(packed: Uint32Array): {
|
export function unpackMotionPlans(packed: Uint32Array): MotionPlanRecord[] {
|
||||||
schemaVersion: number;
|
if (packed.length < 1) {
|
||||||
records: MotionPlanRecord[];
|
return [];
|
||||||
} {
|
|
||||||
if (packed.length < 2) {
|
|
||||||
return { schemaVersion: 0, records: [] };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const schemaVersion = packed[0] >>> 0;
|
const recordCount = packed[0] >>> 0;
|
||||||
const recordCount = packed[1] >>> 0;
|
|
||||||
|
|
||||||
const records: MotionPlanRecord[] = [];
|
const records: MotionPlanRecord[] = [];
|
||||||
let offset = 2;
|
let offset = 1;
|
||||||
|
|
||||||
for (let i = 0; i < recordCount && offset + 1 < packed.length; i++) {
|
for (let i = 0; i < recordCount && offset + 1 < packed.length; i++) {
|
||||||
const kind = packed[offset] >>> 0;
|
const kind = packed[offset] >>> 0;
|
||||||
@@ -216,5 +208,5 @@ export function unpackMotionPlans(packed: Uint32Array): {
|
|||||||
offset += wordCount;
|
offset += wordCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { schemaVersion, records };
|
return records;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user