mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 19:01:00 +00:00
af451be606
## Description: Created test that has astar pathfind from top left to bottom right of giant world map. * Before these changes: took ~950ms * replaced queue with fastqueue library: ~600ms * Changes heuristic to be more greedy (1.1 * dist => 2 * dist): ~90ms Resulting in a roughly 10x improvement. Other paths also saw improvements as well, although not as dramatic. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import {
|
|
Difficulty,
|
|
Game,
|
|
GameMapType,
|
|
GameMode,
|
|
GameType,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
} from "../../src/core/game/Game";
|
|
import { createGame } from "../../src/core/game/GameImpl";
|
|
import {
|
|
genTerrainFromBin,
|
|
MapManifest,
|
|
} from "../../src/core/game/TerrainMapLoader";
|
|
import { UserSettings } from "../../src/core/game/UserSettings";
|
|
import { GameConfig } from "../../src/core/Schemas";
|
|
import { TestConfig } from "./TestConfig";
|
|
import { TestServerConfig } from "./TestServerConfig";
|
|
|
|
export async function setup(
|
|
mapName: string,
|
|
_gameConfig: Partial<GameConfig> = {},
|
|
humans: PlayerInfo[] = [],
|
|
currentDir: string = __dirname,
|
|
): Promise<Game> {
|
|
// Suppress console.debug for tests.
|
|
console.debug = () => {};
|
|
|
|
// Simple binary file loading using fs.readFileSync()
|
|
const mapBinPath = path.join(
|
|
currentDir,
|
|
`../testdata/maps/${mapName}/map.bin`,
|
|
);
|
|
const miniMapBinPath = path.join(
|
|
currentDir,
|
|
`../testdata/maps/${mapName}/mini_map.bin`,
|
|
);
|
|
const manifestPath = path.join(
|
|
currentDir,
|
|
`../testdata/maps/${mapName}/manifest.json`,
|
|
);
|
|
|
|
const mapBinBuffer = fs.readFileSync(mapBinPath);
|
|
const miniMapBinBuffer = fs.readFileSync(miniMapBinPath);
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(manifestPath, "utf8"),
|
|
) satisfies MapManifest;
|
|
|
|
// Convert Buffer to string (binary encoding)
|
|
const mapBinString = mapBinBuffer.toString("binary");
|
|
const miniMapBinString = miniMapBinBuffer.toString("binary");
|
|
|
|
const gameMap = await genTerrainFromBin(manifest.map, mapBinString);
|
|
const miniGameMap = await genTerrainFromBin(
|
|
manifest.mini_map,
|
|
miniMapBinString,
|
|
);
|
|
|
|
// Configure the game
|
|
const serverConfig = new TestServerConfig();
|
|
const gameConfig: GameConfig = {
|
|
gameMap: GameMapType.Asia,
|
|
gameMode: GameMode.FFA,
|
|
gameType: GameType.Singleplayer,
|
|
difficulty: Difficulty.Medium,
|
|
disableNPCs: false,
|
|
bots: 0,
|
|
infiniteGold: false,
|
|
infiniteTroops: false,
|
|
instantBuild: false,
|
|
..._gameConfig,
|
|
};
|
|
const config = new TestConfig(
|
|
serverConfig,
|
|
gameConfig,
|
|
new UserSettings(),
|
|
false,
|
|
);
|
|
|
|
return createGame(humans, [], gameMap, miniGameMap, config);
|
|
}
|
|
|
|
export function playerInfo(name: string, type: PlayerType): PlayerInfo {
|
|
return new PlayerInfo(undefined, "fr", name, type, null, name);
|
|
}
|