have core/ directory use consolex for remote logging

This commit is contained in:
evanpelle
2024-12-18 12:00:00 -08:00
parent 642d5dc4ca
commit ff02d9d8b6
31 changed files with 91 additions and 66 deletions
+2 -8
View File
@@ -1,7 +1,8 @@
import { Config } from "../core/configuration/Config"
import { SendLogEvent } from "../core/Consolex"
import { EventBus, GameEvent } from "../core/EventBus"
import { AllianceRequest, AllPlayers, Cell, GameType, Player, PlayerID, PlayerType, Tile, UnitType } from "../core/game/Game"
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ClientPingMessageSchema, GameConfig, ClientLogMessageSchema, LogSeverity } from "../core/Schemas"
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ClientPingMessageSchema, GameConfig, ClientLogMessageSchema } from "../core/Schemas"
import { LobbyConfig } from "./GameRunner"
import { LocalServer } from "./LocalServer"
@@ -82,13 +83,6 @@ export class SendSetTargetTroopRatioEvent implements GameEvent {
) { }
}
export class SendLogEvent implements GameEvent {
constructor(
public readonly severity: LogSeverity,
public readonly log: string,
) { }
}
export class Transport {
private socket: WebSocket
+8 -3
View File
@@ -1,6 +1,5 @@
import { EventBus } from "./EventBus"
import { EventBus, GameEvent } from "./EventBus"
import { LogSeverity } from "./Schemas"
import { SendLogEvent } from "../client/Transport"
export const consolex = {
log: console.log,
@@ -31,4 +30,10 @@ export function initRemoteSender(eventBus: EventBus) {
console.error(...args);
eventBus.emit(new SendLogEvent(LogSeverity.Error, args.join(' ')))
}
}
}
export class SendLogEvent implements GameEvent {
constructor(
public readonly severity: LogSeverity,
public readonly log: string
) { }
}
+4 -3
View File
@@ -4,6 +4,7 @@ import { devConfig } from "./DevConfig";
import { GameID } from "../Schemas";
import { preprodConfig } from "./PreprodConfig";
import { prodConfig } from "./ProdConfig";
import { consolex } from "../Consolex";
export enum GameEnv {
Dev,
@@ -13,13 +14,13 @@ export enum GameEnv {
export function getConfig(): Config {
switch (process.env.GAME_ENV) {
case 'dev':
console.log('using dev config')
consolex.log('using dev config')
return devConfig
case 'preprod':
console.log('using preprod config')
consolex.log('using preprod config')
return preprodConfig
case 'prod':
console.log('using prod config')
consolex.log('using prod config')
return prodConfig
default:
throw Error(`unsupported server configuration: ${process.env.GAME_ENV}`)
+1 -1
View File
@@ -264,7 +264,7 @@ export abstract class DefaultConfig implements Config {
const ratio = 1 - (player.population() / max)
toAdd *= ratio
toAdd *= .5
// console.log(`to add ${toAdd}`)
// consolex.log(`to add ${toAdd}`)
if (player.type() == PlayerType.FakeHuman) {
toAdd *= 1.0
+2 -2
View File
@@ -130,8 +130,8 @@ export class AttackExecution implements Execution {
}
let numTilesPerTick = this.mg.config().attackTilesPerTick(this._owner, this.target, this.border.size + this.random.nextInt(0, 5))
// console.log(`num tiles per tick: ${numTilesPerTick}`)
// console.log(`num execs: ${this.mg.executions().length}`)
// consolex.log(`num tiles per tick: ${numTilesPerTick}`)
// consolex.log(`num execs: ${this.mg.executions().length}`)
while (numTilesPerTick > 0) {
+2 -1
View File
@@ -5,6 +5,7 @@ import { SerialAStar } from "../pathfinding/SerialAStar";
import { PseudoRandom } from "../PseudoRandom";
import { distSort, distSortUnit, manhattanDist } from "../Util";
import { ShellExecution } from "./ShellExecution";
import { consolex } from "../Consolex";
export class BattleshipExecution implements Execution {
private random: PseudoRandom
@@ -66,7 +67,7 @@ export class BattleshipExecution implements Execution {
case PathFindResultType.Pending:
return
case PathFindResultType.PathNotFound:
console.log(`path not found to patrol tile`)
consolex.log(`path not found to patrol tile`)
this.patrolTile = this.randomTile()
break
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import {Cell, Game, PlayerType, Tile, TileEvent} from "../game/Game";
import {PseudoRandom} from "../PseudoRandom";
import {GameID, SpawnIntent} from "../Schemas";
@@ -16,7 +17,7 @@ export class BotSpawner {
let tries = 0
while (this.bots.length < numBots) {
if (tries > 10000) {
console.log('too many retries while spawning bots, giving up')
consolex.log('too many retries while spawning bots, giving up')
return this.bots
}
const spawn = this.spawnBot("Bot" + this.bots.length)
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { bfs, dist } from "../Util";
@@ -21,7 +22,7 @@ export class CityExecution implements Execution {
if (this.city == null) {
const spawnTile = this.player.canBuild(UnitType.City, this.tile)
if (spawnTile == false) {
console.warn('cannot build Defense Post')
consolex.warn('cannot build Defense Post')
this.active = false
return
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { bfs, dist } from "../Util";
@@ -23,7 +24,7 @@ export class DefensePostExecution implements Execution {
if (this.post == null) {
const spawnTile = this.player.canBuild(UnitType.DefensePost, this.tile)
if (spawnTile == false) {
console.warn('cannot build Defense Post')
consolex.warn('cannot build Defense Post')
this.active = false
return
}
+3 -2
View File
@@ -4,6 +4,7 @@ import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { PseudoRandom } from "../PseudoRandom";
import { distSort, distSortUnit, manhattanDist } from "../Util";
import { consolex } from "../Consolex";
export class DestroyerExecution implements Execution {
private random: PseudoRandom
@@ -72,7 +73,7 @@ export class DestroyerExecution implements Execution {
case PathFindResultType.Pending:
return
case PathFindResultType.PathNotFound:
console.log(`path not found to patrol tile`)
consolex.log(`path not found to patrol tile`)
this.patrolTile = this.randomTile()
break
}
@@ -110,7 +111,7 @@ export class DestroyerExecution implements Execution {
case PathFindResultType.Pending:
break
case PathFindResultType.PathNotFound:
console.log(`path not found to target`)
consolex.log(`path not found to target`)
break
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
export class DonateExecution implements Execution {
@@ -26,7 +27,7 @@ export class DonateExecution implements Execution {
if (this.sender.canDonate(this.recipient)) {
this.sender.donate(this.recipient, this.troops)
} else {
console.warn(`cannot send tropps from ${this.sender} to ${this.recipient}`)
consolex.warn(`cannot send tropps from ${this.sender} to ${this.recipient}`)
}
this.active = false
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
export class EmojiExecution implements Execution {
@@ -23,7 +24,7 @@ export class EmojiExecution implements Execution {
if (this.requestor.canSendEmoji(this.recipient)) {
this.requestor.sendEmoji(this.recipient, this.emoji)
} else {
console.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`)
consolex.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`)
}
this.active = false
}
+3 -2
View File
@@ -10,6 +10,7 @@ import { PathFinder } from "../pathfinding/PathFinding";
import { DestroyerExecution } from "./DestroyerExecution";
import { BattleshipExecution } from "./BattleshipExecution";
import { GameID } from "../Schemas";
import { consolex } from "../Consolex";
export class FakeHumanExecution implements Execution {
@@ -42,7 +43,7 @@ export class FakeHumanExecution implements Execution {
if (ticks % this.random.nextInt(5, 30) == 0) {
const rl = this.randomLand()
if (rl == null) {
console.warn(`cannot spawn ${this.playerInfo.name}`)
consolex.warn(`cannot spawn ${this.playerInfo.name}`)
return
}
this.mg.addExecution(new SpawnExecution(
@@ -180,7 +181,7 @@ export class FakeHumanExecution implements Execution {
}
const canBuild = this.player.canBuild(UnitType.Destroyer, targetTile)
if (canBuild == false) {
console.warn('cannot spawn destroyer')
consolex.warn('cannot spawn destroyer')
return false
}
switch (shipType) {
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, Player, PlayerID, Tile, Unit, UnitType } from "../game/Game";
export class MissileSiloExecution implements Execution {
@@ -22,7 +23,7 @@ export class MissileSiloExecution implements Execution {
if (this.silo == null) {
const tile = this.mg.tile(this.cell)
if (!this.player.canBuild(UnitType.MissileSilo, tile)) {
console.warn(`player ${this.player} cannot build port at ${this.cell}`)
consolex.warn(`player ${this.player} cannot build port at ${this.cell}`)
this.active = false
return
}
+3 -2
View File
@@ -4,6 +4,7 @@ import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, distSortUnit, euclideanDist, manhattanDist } from "../Util";
import { consolex } from "../Consolex";
export class NukeExecution implements Execution {
@@ -35,7 +36,7 @@ export class NukeExecution implements Execution {
if (this.nuke == null) {
const spawn = this.player.canBuild(this.type, this.dst)
if (spawn == false) {
console.warn(`cannot build Nuke`)
consolex.warn(`cannot build Nuke`)
this.active = false
return
}
@@ -55,7 +56,7 @@ export class NukeExecution implements Execution {
case PathFindResultType.Pending:
break
case PathFindResultType.PathNotFound:
console.warn(`nuke cannot find path from ${this.nuke.tile()} to ${this.dst}`)
consolex.warn(`nuke cannot find path from ${this.nuke.tile()} to ${this.dst}`)
this.active = false
return
}
+4 -3
View File
@@ -2,6 +2,7 @@ import { Config } from "../configuration/Config"
import { Execution, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile } from "../game/Game"
import { bfs, calculateBoundingBox, getMode, inscribed, simpleHash } from "../Util"
import { GameImpl } from "../game/GameImpl"
import { consolex } from "../Consolex"
export class PlayerExecution implements Execution {
@@ -71,7 +72,7 @@ export class PlayerExecution implements Execution {
this.removeClusters()
const end = performance.now()
if (end - start > 1000) {
console.log(`player ${this.player.name()}, took ${end - start}ms`)
consolex.log(`player ${this.player.name()}, took ${end - start}ms`)
}
}
}
@@ -138,7 +139,7 @@ export class PlayerExecution implements Execution {
const arr = Array.from(cluster)
const mode = getMode(arr.flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.player).map(t => t.owner().id()))
if (!this.mg.hasPlayer(mode)) {
console.warn('mode is not found')
consolex.warn('mode is not found')
return
}
const firstTile = arr[0]
@@ -147,7 +148,7 @@ export class PlayerExecution implements Execution {
const modePlayer = this.mg.player(mode)
if (modePlayer == null) {
console.warn('mode player is null')
consolex.warn('mode player is null')
}
for (const tile of tiles) {
modePlayer.conquer(tile)
+5 -4
View File
@@ -6,6 +6,7 @@ import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, manhattanDist } from "../Util";
import { TradeShipExecution } from "./TradeShipExecution";
import { ParallelAStar, WorkerClient } from "../worker/WorkerClient";
import { consolex } from "../Consolex";
export class PortExecution implements Execution {
@@ -35,7 +36,7 @@ export class PortExecution implements Execution {
const tile = this.mg.tile(this.cell)
const player = this.mg.player(this._owner)
if (!player.canBuild(UnitType.Port, tile)) {
console.warn(`player ${player} cannot build port at ${this.cell}`)
consolex.warn(`player ${player} cannot build port at ${this.cell}`)
this.active = false
return
}
@@ -44,7 +45,7 @@ export class PortExecution implements Execution {
.sort((a, b) => manhattanDist(a.cell(), tile.cell()) - manhattanDist(b.cell(), tile.cell()))
if (spawns.length == 0) {
console.warn(`cannot find spawn for port`)
consolex.warn(`cannot find spawn for port`)
this.active = false
return
}
@@ -78,13 +79,13 @@ export class PortExecution implements Execution {
case PathFindResultType.Pending:
break
case PathFindResultType.PathNotFound:
console.warn(`path not found to port`)
consolex.warn(`path not found to port`)
break
}
continue
}
const asyncPF = this.worker.createParallelAStar(this.port.tile(), port.tile(), 25, [TerrainType.Ocean])
// console.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`)
// consolex.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`)
this.computingPaths.set(port, asyncPF)
}
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Execution, MutableGame, MutablePlayer, PlayerID } from "../game/Game";
export class SetTargetTroopRatioExecution implements Execution {
@@ -15,7 +16,7 @@ export class SetTargetTroopRatioExecution implements Execution {
tick(ticks: number): void {
if (this.targetTroopsRatio < 0 || this.targetTroopsRatio > 1) {
console.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`)
consolex.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`)
} else {
this.player.setTargetTroopRatio(this.targetTroopsRatio)
}
+2 -1
View File
@@ -1,6 +1,7 @@
import { Execution, MutableGame, MutablePlayer, MutableUnit, Tile, Unit, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { consolex } from "../Consolex";
export class ShellExecution implements Execution {
@@ -43,7 +44,7 @@ export class ShellExecution implements Execution {
case PathFindResultType.Pending:
return
case PathFindResultType.PathNotFound:
console.log(`Shell ${this.shell} could not find target`)
consolex.log(`Shell ${this.shell} could not find target`)
this.active = false
this.shell.delete(false)
return
+3 -2
View File
@@ -6,6 +6,7 @@ import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, distSortUnit, manhattanDist } from "../Util";
import { consolex } from "../Consolex";
export class TradeShipExecution implements Execution {
@@ -35,7 +36,7 @@ export class TradeShipExecution implements Execution {
if (this.tradeShip == null) {
const spawn = this.origOwner.canBuild(UnitType.TradeShip, this.srcPort.tile())
if (spawn == false) {
console.warn(`cannot build trade ship`)
consolex.warn(`cannot build trade ship`)
this.active = false
return
}
@@ -86,7 +87,7 @@ export class TradeShipExecution implements Execution {
this.tradeShip.move(result.tile)
break
case PathFindResultType.PathNotFound:
console.warn('captured trade ship cannot find route')
consolex.warn('captured trade ship cannot find route')
this.active = false
break
}
+4 -3
View File
@@ -5,6 +5,7 @@ import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/E
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { consolex } from "../Consolex";
export class TransportShipExecution implements Execution {
@@ -68,13 +69,13 @@ export class TransportShipExecution implements Execution {
this.dst = targetTransportTile(this.mg, this.mg.tile(this.cell))
if (this.dst == null) {
console.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`)
consolex.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`)
this.active = false
return
}
const src = this.attacker.canBuild(UnitType.TransportShip, this.dst)
if (src == false) {
console.warn(`can't build transport ship`)
consolex.warn(`can't build transport ship`)
this.active = false
return
}
@@ -124,7 +125,7 @@ export class TransportShipExecution implements Execution {
break
case PathFindResultType.PathNotFound:
// TODO: add to poisoned port list
console.warn(`path not found tot dst`)
consolex.warn(`path not found tot dst`)
this.boat.delete(false)
this.active = false
return
@@ -1,3 +1,4 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class AllianceRequestExecution implements Execution {
@@ -16,9 +17,9 @@ export class AllianceRequestExecution implements Execution {
tick(ticks: number): void {
if (this.requestor.isAlliedWith(this.recipient)) {
console.warn('already allied')
consolex.warn('already allied')
} else if (this.requestor.recentOrPendingAllianceRequestWith(this.recipient)) {
console.warn('recent or pending alliance request')
consolex.warn('recent or pending alliance request')
} else {
this.requestor.createAllianceRequest(this.recipient)
}
@@ -1,3 +1,4 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class AllianceRequestReplyExecution implements Execution {
@@ -16,11 +17,11 @@ export class AllianceRequestReplyExecution implements Execution {
tick(ticks: number): void {
if (this.requestor.isAlliedWith(this.recipient)) {
console.warn('already allied')
consolex.warn('already allied')
} else {
const request = this.requestor.outgoingAllianceRequests().find(ar => ar.recipient() == this.recipient)
if (request == null) {
console.warn('no alliance request found')
consolex.warn('no alliance request found')
} else {
if (this.accept) {
request.accept()
@@ -1,3 +1,4 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class BreakAllianceExecution implements Execution {
@@ -15,7 +16,7 @@ export class BreakAllianceExecution implements Execution {
tick(ticks: number): void {
const alliance = this.requestor.allianceWith(this.recipient)
if (alliance == null) {
console.warn('cant break alliance, not allied')
consolex.warn('cant break alliance, not allied')
} else {
this.requestor.breakAlliance(alliance)
}
+5 -4
View File
@@ -11,6 +11,7 @@ import { AllianceImpl } from "./AllianceImpl";
import { ClientID, GameConfig } from "../Schemas";
import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/EventsDisplay";
import { UnitImpl } from "./UnitImpl";
import { consolex } from "../Consolex";
export function createGame(terrainMap: TerrainMapImpl, miniMap: TerrainMap, eventBus: EventBus, config: Config, gameConfig: GameConfig): Game {
return new GameImpl(terrainMap, miniMap, eventBus, config, gameConfig)
@@ -104,16 +105,16 @@ export class GameImpl implements MutableGame {
createAllianceRequest(requestor: MutablePlayer, recipient: Player): MutableAllianceRequest {
if (requestor.isAlliedWith(recipient)) {
console.log('cannot request alliance, already allied')
consolex.log('cannot request alliance, already allied')
return
}
if (recipient.incomingAllianceRequests().find(ar => ar.requestor() == requestor) != null) {
console.log(`duplicate alliance request from ${requestor.name()}`)
consolex.log(`duplicate alliance request from ${requestor.name()}`)
return
}
const correspondingReq = requestor.incomingAllianceRequests().find(ar => ar.requestor() == recipient)
if (correspondingReq != null) {
console.log(`got corresponding alliance requests, accepting`)
consolex.log(`got corresponding alliance requests, accepting`)
correspondingReq.accept()
return
}
@@ -182,7 +183,7 @@ export class GameImpl implements MutableGame {
this._players.forEach(p => {
hash += p.hash()
})
console.log(`tick ${this._ticks}: hash ${hash}`)
consolex.log(`tick ${this._ticks}: hash ${hash}`)
}
}
+5 -4
View File
@@ -14,6 +14,7 @@ import northAmericaInfo from "../../../resources/maps/NorthAmerica.json"
import oceaniaBin from "!!binary-loader!../../../resources/maps/Oceania.bin"
import oceaniaInfo from "../../../resources/maps/Oceania.json"
import { consolex } from '../Consolex';
const maps = new Map()
.set(GameMap.World, { bin: worldBin, info: worldInfo })
@@ -113,13 +114,13 @@ export async function loadTerrainMap(map: GameMap): Promise<TerrainMapImpl> {
setTimeout(() => resolve(mapData.bin), 100);
});
console.log(`Loaded data length: ${fileData.length} bytes`);
consolex.log(`Loaded data length: ${fileData.length} bytes`);
// Extract width and height from the first 4 bytes
const width = (fileData.charCodeAt(1) << 8) | fileData.charCodeAt(0);
const height = (fileData.charCodeAt(3) << 8) | fileData.charCodeAt(2);
console.log(`Decoded dimensions: ${width}x${height}`);
consolex.log(`Decoded dimensions: ${width}x${height}`);
// Check if the data length matches the expected size
if (fileData.length != width * height + 4) { // +4 for the width and height bytes
@@ -221,13 +222,13 @@ export async function createMiniMap(tm: TerrainMap): Promise<TerrainMap> {
function logBinaryAsAscii(data: string, length: number = 8) {
console.log('Binary data (1 = set bit, 0 = unset bit):');
consolex.log('Binary data (1 = set bit, 0 = unset bit):');
for (let i = 0; i < Math.min(length, data.length); i++) {
let byte = data.charCodeAt(i);
let byteString = '';
for (let j = 7; j >= 0; j--) {
byteString += (byte & (1 << j)) ? '1' : '0';
}
console.log(`Byte ${i}: ${byteString}`);
consolex.log(`Byte ${i}: ${byteString}`);
}
}
+3 -2
View File
@@ -4,6 +4,7 @@ import { AStar, PathFindResultType, SearchNode, TileResult } from "./AStar";
import { ParallelAStar, WorkerClient } from "../worker/WorkerClient";
import { SerialAStar } from "./SerialAStar";
import { MiniAStar } from "./MiniAStar";
import { consolex } from "../Consolex";
export class PathFinder {
@@ -65,10 +66,10 @@ export class PathFinder {
nextTile(curr: Tile, dst: Tile, dist: number = 1): TileResult {
if (curr == null) {
console.error('curr is null')
consolex.error('curr is null')
}
if (dst == null) {
console.error('dst is null')
consolex.error('dst is null')
}
if (manhattanDist(curr.cell(), dst.cell()) < dist) {
+2 -1
View File
@@ -2,6 +2,7 @@ import { PriorityQueue } from "@datastructures-js/priority-queue";
import { AStar, SearchNode } from "./AStar";
import { PathFindResultType } from "./AStar";
import { Cell } from "../game/Game";
import { consolex } from "../Consolex";
export class SerialAStar implements AStar {
@@ -111,7 +112,7 @@ export class SerialAStar implements AStar {
try {
return 1.1 * Math.abs(a.cell().x - b.cell().x) + Math.abs(a.cell().y - b.cell().y);
} catch {
console.log('uh oh')
consolex.log('uh oh')
}
}
+2 -1
View File
@@ -5,6 +5,7 @@ import { PriorityQueue } from "@datastructures-js/priority-queue";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { AStar, PathFindResultType, SearchNode } from "../pathfinding/AStar";
import { MiniAStar } from "../pathfinding/MiniAStar";
import { consolex } from "../Consolex";
let terrainMapPromise: Promise<{
terrainMap: TerrainMap,
@@ -99,7 +100,7 @@ function computeSearches() {
searches.push(search)
break
case PathFindResultType.PathNotFound:
console.warn(`worker: path not found to port`);
consolex.warn(`worker: path not found to port`);
self.postMessage({
type: 'pathNotFound',
requestId: search.requestId,
+4 -3
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, Game, GameMap, TerrainTile, TerrainType, Tile } from "../game/Game";
import { AStar, PathFindResultType } from "../pathfinding/AStar";
import { MiniAStar } from "../pathfinding/MiniAStar";
@@ -111,7 +112,7 @@ export class ParallelAStar implements AStar {
}
// Path was not found in worker thread in time, so now we need
// to recompute it in main thread. This will lock up game.
console.warn(`path not completed in worker thread, recomputing`)
consolex.warn(`path not completed in worker thread, recomputing`)
const local = new MiniAStar(
this.game.terrainMap(),
this.game.terrainMiniMap(),
@@ -123,7 +124,7 @@ export class ParallelAStar implements AStar {
const result = local.compute()
switch (result) {
case PathFindResultType.Completed:
console.log('recomputed path in worker client')
consolex.log('recomputed path in worker client')
this.path = local.reconstructPath()
break
case PathFindResultType.PathNotFound:
@@ -131,7 +132,7 @@ export class ParallelAStar implements AStar {
break
case PathFindResultType.Pending:
// TODO: make sure same number of tries as worker thread.
console.warn("path not found after many tries")
consolex.warn("path not found after many tries")
this.path = "NOT_FOUND"
break
}
+2 -2
View File
@@ -45,7 +45,7 @@ app.get('/lobbies', (req, res) => {
app.post('/private_lobby', (req, res) => {
const id = gm.createPrivateGame()
console.logx('creating private lobby with id ${id}')
console.log('creating private lobby with id ${id}')
res.json({
id: id
});
@@ -79,7 +79,7 @@ app.post('/archive_singleplayer_game', (req, res) => {
})
app.post('/start_private_lobby/:id', (req, res) => {
console.logx(`starting private lobby with id ${req.params.id}`)
console.log(`starting private lobby with id ${req.params.id}`)
gm.startPrivateGame(req.params.id)
});