mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-10 23:34:12 +00:00
a7f992e9b0
Restructure the single src/ tree into an npm-workspaces monorepo under
packages/, rename core -> engine, extract a types-only core-public layer,
and break the pre-existing engine -> client dependency cycle.
Structure (packages/):
core-public public API/wire schemas + shared enums (clean leaf)
shared framework-agnostic helpers (clean leaf)
engine deterministic simulation (was src/core)
client rendering/UI (was src/client)
server coordination (was src/server)
Dependency DAG: engine -> {core-public, shared}; client -> {core-public,
shared, engine}; server -> {core-public, engine}.
- npm workspaces: root package.json workspaces + per-package package.json;
tsconfig.base.json holds shared options + path aliases
(core-public/* shared/* engine/* client/* server/*) resolved uniformly by
tsc, Vite (resolve.tsconfigPaths), Vitest, and tsx. Lockfile regenerated.
- core-public: moved Schemas/ApiSchemas/CosmeticSchemas/StatsSchemas/
ClanApiSchemas/WorkerSchemas/Base64/PatternDecoder; extracted the enums
(GameTypes), GameEvent type, emoji table, and GraphicsOverrides schema.
Engine re-exports the moved enums/types so existing imports keep working.
- Broke engine -> client cycle:
- renderNumber/renderTroops -> shared/format
- NameBoxCalculator moved into engine
- username validation returns translation key + params; client translates
- applyStateUpdate moved to client (operates on the render-only PlayerState)
- Config/UnitGrid/execution-Util/GameImpl now use structural read
interfaces (engine/game/ReadViews: PlayerLike/UnitLike/GameLike) instead
of importing client view classes; client imports view classes from a new
client/view barrel; deleted the engine/game/GameView re-export shim.
- Build/deploy updated: vite.config, index.html, eslint, Dockerfile
(copies packages/ + tsconfig.base.json before npm ci), .vscode, tests.
Verified: tsc --noEmit clean; 1364 + 65 tests pass; production vite build
succeeds; engine has zero client/server imports; core-public and shared are
dependency leaves.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
144 lines
4.0 KiB
TypeScript
144 lines
4.0 KiB
TypeScript
import Benchmark from "benchmark";
|
|
import { dirname } from "path";
|
|
import { fileURLToPath } from "url";
|
|
import { MirvExecution } from "engine/execution/MIRVExecution";
|
|
import { PlayerInfo, PlayerType, UnitType } from "engine/game/Game";
|
|
import { setup } from "../util/Setup";
|
|
|
|
// Setup sparse territory scenario (small target area)
|
|
const sparseTerritoryGame = await setup(
|
|
"big_plains",
|
|
{
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
},
|
|
[new PlayerInfo("player", PlayerType.Human, "client_id1", "player_id")],
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
);
|
|
|
|
const sparsePlayer = sparseTerritoryGame.player("player_id");
|
|
|
|
function claimRow(y: number, length: number) {
|
|
for (let x = 0; x < 200; x++) {
|
|
for (let dy = y; dy < y + length; dy++) {
|
|
const tile = sparseTerritoryGame.ref(x, dy);
|
|
if (sparseTerritoryGame.map().isLand(tile)) {
|
|
sparsePlayer.conquer(tile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
claimRow(0, 15);
|
|
claimRow(40, 15);
|
|
claimRow(90, 15);
|
|
claimRow(140, 15);
|
|
claimRow(185, 15);
|
|
|
|
sparsePlayer.buildUnit(
|
|
UnitType.MissileSilo,
|
|
sparseTerritoryGame.ref(10, 10),
|
|
{},
|
|
);
|
|
|
|
// Setup dense territory scenario (large target area)
|
|
const denseTerritoryGame = await setup(
|
|
"big_plains",
|
|
{
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
},
|
|
[new PlayerInfo("player", PlayerType.Human, "client_id1", "player_id")],
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
);
|
|
|
|
const densePlayer = denseTerritoryGame.player("player_id");
|
|
|
|
for (let x = 0; x < 200; x++) {
|
|
for (let y = 0; y < 200; y++) {
|
|
const tile = denseTerritoryGame.ref(x, y);
|
|
if (denseTerritoryGame.map().isLand(tile)) {
|
|
densePlayer.conquer(tile);
|
|
}
|
|
}
|
|
}
|
|
|
|
densePlayer.buildUnit(UnitType.MissileSilo, denseTerritoryGame.ref(10, 10), {});
|
|
|
|
// Setup giant world map scenario (realistic large-scale test)
|
|
const giantMapGame = await setup(
|
|
"giantworldmap",
|
|
{
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
},
|
|
[new PlayerInfo("player", PlayerType.Human, "client_id1", "player_id")],
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
);
|
|
|
|
const giantMapPlayer = giantMapGame.player("player_id");
|
|
|
|
// Conquer ALL available land tiles on the giant world map
|
|
console.log("Conquering all tiles on giant world map...");
|
|
let conqueredCount = 0;
|
|
for (let x = 0; x < giantMapGame.map().width(); x++) {
|
|
for (let y = 0; y < giantMapGame.map().height(); y++) {
|
|
const tile = giantMapGame.ref(x, y);
|
|
if (giantMapGame.map().isLand(tile)) {
|
|
giantMapPlayer.conquer(tile);
|
|
conqueredCount++;
|
|
}
|
|
}
|
|
}
|
|
console.log(`Conquered ${conqueredCount} tiles on giant world map`);
|
|
|
|
giantMapPlayer.buildUnit(UnitType.MissileSilo, giantMapGame.ref(800, 350), {});
|
|
|
|
const results: string[] = [];
|
|
|
|
new Benchmark.Suite()
|
|
.add("MIRV target selection - sparse territory", () => {
|
|
const targetTile = sparseTerritoryGame.ref(100, 100);
|
|
const mirvExec = new MirvExecution(sparsePlayer, targetTile);
|
|
|
|
mirvExec.init(sparseTerritoryGame, sparseTerritoryGame.ticks());
|
|
|
|
let ticks = 0;
|
|
while (mirvExec.isActive() && ticks < 1000) {
|
|
mirvExec.tick(ticks++);
|
|
}
|
|
})
|
|
.add("MIRV target selection - dense territory", () => {
|
|
const targetTile = denseTerritoryGame.ref(100, 100);
|
|
const mirvExec = new MirvExecution(densePlayer, targetTile);
|
|
|
|
mirvExec.init(denseTerritoryGame, denseTerritoryGame.ticks());
|
|
|
|
let ticks = 0;
|
|
while (mirvExec.isActive() && ticks < 1000) {
|
|
mirvExec.tick(ticks++);
|
|
}
|
|
})
|
|
.add("MIRV target selection - giant world map (350 targets)", () => {
|
|
const targetTile = giantMapGame.ref(2150, 800);
|
|
const mirvExec = new MirvExecution(giantMapPlayer, targetTile);
|
|
|
|
mirvExec.init(giantMapGame, giantMapGame.ticks());
|
|
|
|
let ticks = 0;
|
|
while (mirvExec.isActive() && ticks < 1000) {
|
|
mirvExec.tick(ticks++);
|
|
}
|
|
})
|
|
.on("cycle", (event: any) => {
|
|
results.push(String(event.target));
|
|
})
|
|
.on("complete", () => {
|
|
console.log("\n=== MIRV Performance Benchmark Results ===");
|
|
|
|
for (const result of results) {
|
|
console.log(result);
|
|
}
|
|
})
|
|
.run({ async: true });
|