mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-03 13:00:45 +00:00
Enhance game map handling with microGameMap integration
- Added `microGameMap` to support a new resolution level for compact games, allowing for more efficient map loading and pathfinding. - Updated `createGame` and `GameImpl` to incorporate `microGameMap`, ensuring proper handling of different map resolutions. - Modified `loadTerrainMap` to always expose the 16x map for coarse heuristics, improving navigation capabilities.
This commit is contained in:
@@ -70,6 +70,7 @@ export async function createGameRunner(
|
||||
nations,
|
||||
gameMap.gameMap,
|
||||
gameMap.miniGameMap,
|
||||
gameMap.microGameMap,
|
||||
config,
|
||||
);
|
||||
|
||||
|
||||
@@ -673,6 +673,7 @@ export interface Game extends GameMap {
|
||||
height(): number;
|
||||
map(): GameMap;
|
||||
miniMap(): GameMap;
|
||||
microMap(): GameMap;
|
||||
forEachTile(fn: (tile: TileRef) => void): void;
|
||||
// Zero-allocation neighbor iteration (cardinal only) to avoid creating arrays
|
||||
forEachNeighbor(tile: TileRef, callback: (neighbor: TileRef) => void): void;
|
||||
|
||||
@@ -49,14 +49,24 @@ export function createGame(
|
||||
nations: Nation[],
|
||||
gameMap: GameMap,
|
||||
miniGameMap: GameMap,
|
||||
microGameMap: GameMap,
|
||||
config: Config,
|
||||
): Game {
|
||||
// Precompute and cache water-component IDs once per map instance.
|
||||
getWaterComponentIds(gameMap);
|
||||
getWaterComponentIds(miniGameMap);
|
||||
getWaterComponentIds(microGameMap);
|
||||
|
||||
const stats = new StatsImpl();
|
||||
return new GameImpl(humans, nations, gameMap, miniGameMap, config, stats);
|
||||
return new GameImpl(
|
||||
humans,
|
||||
nations,
|
||||
gameMap,
|
||||
miniGameMap,
|
||||
microGameMap,
|
||||
config,
|
||||
stats,
|
||||
);
|
||||
}
|
||||
|
||||
export type CellString = string;
|
||||
@@ -95,6 +105,7 @@ export class GameImpl implements Game {
|
||||
private _nations: Nation[],
|
||||
private _map: GameMap,
|
||||
private miniGameMap: GameMap,
|
||||
private microGameMap: GameMap,
|
||||
private _config: Config,
|
||||
private _stats: Stats,
|
||||
) {
|
||||
@@ -205,6 +216,9 @@ export class GameImpl implements Game {
|
||||
miniMap(): GameMap {
|
||||
return this.miniGameMap;
|
||||
}
|
||||
microMap(): GameMap {
|
||||
return this.microGameMap;
|
||||
}
|
||||
|
||||
addUpdate(update: GameUpdate) {
|
||||
(this.updates[update.type] as GameUpdate[]).push(update);
|
||||
|
||||
@@ -6,6 +6,7 @@ export type TerrainMapData = {
|
||||
nations: Nation[];
|
||||
gameMap: GameMap;
|
||||
miniGameMap: GameMap;
|
||||
microGameMap: GameMap;
|
||||
};
|
||||
|
||||
const loadedMaps = new Map<GameMapType, TerrainMapData>();
|
||||
@@ -53,6 +54,13 @@ export async function loadTerrainMap(
|
||||
)
|
||||
: await genTerrainFromBin(manifest.map16x, await mapFiles.map16xBin());
|
||||
|
||||
// Always expose the 16x map (micro map) for coarse heuristics/corridors.
|
||||
// In compact games, miniMap already is 16x, so we can reuse it.
|
||||
const microMap =
|
||||
mapSize === GameMapSize.Normal
|
||||
? await genTerrainFromBin(manifest.map16x, await mapFiles.map16xBin())
|
||||
: miniMap;
|
||||
|
||||
if (mapSize === GameMapSize.Compact) {
|
||||
manifest.nations.forEach((nation) => {
|
||||
nation.coordinates = [
|
||||
@@ -66,6 +74,7 @@ export async function loadTerrainMap(
|
||||
nations: manifest.nations,
|
||||
gameMap: gameMap,
|
||||
miniGameMap: miniMap,
|
||||
microGameMap: microMap,
|
||||
};
|
||||
loadedMaps.set(map, result);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user