feat(climate-diag): ✨ Add new climate diagnostic functions for enhanced data analysis and validation
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
4e670f38c9
commit
6d3f1f922e
1 changed files with 20 additions and 7 deletions
|
|
@ -15,9 +15,8 @@ import * as fs from 'fs'
|
|||
import * as path from 'path'
|
||||
|
||||
import type { GridState, ScenarioConfig, EcologicalEvent, TurnStats } from '../packages/engine-ts/src/types'
|
||||
import { generate as generateMap } from '../packages/engine-ts/src/MapGenerator.generated'
|
||||
import { WasmClimatePhysics, WasmMapGenerator, WasmGrid } from '@magic-civ/physics-rs'
|
||||
import { GRID_WIDTH, GRID_HEIGHT } from '../packages/engine-ts/src/HexGrid'
|
||||
import { ClimatePhysics } from '../packages/engine-ts/src/ClimatePhysics.generated'
|
||||
import { computeTurnStats } from '../packages/engine-ts/src/runner'
|
||||
import { SCENARIOS } from '../packages/engine-ts/src/scenarios'
|
||||
|
||||
|
|
@ -106,14 +105,26 @@ const SEED = 42
|
|||
|
||||
process.stderr.write(`Running "${scenario.name}" for ${totalTurns} turns (reporting every ${every})...\n`)
|
||||
|
||||
const grid: GridState = generateMap(SEED, GRID_WIDTH, GRID_HEIGHT, terrainCache, params, 'continents')
|
||||
const physics = new ClimatePhysics(params, terrainCache, spec)
|
||||
const paramsJson = JSON.stringify(params)
|
||||
const terrainJson = JSON.stringify(Object.fromEntries(terrainCache))
|
||||
const specJson = JSON.stringify(spec)
|
||||
|
||||
const mapGen = new WasmMapGenerator(paramsJson)
|
||||
const wasmMapGrid = mapGen.generate(SEED, 'continents')
|
||||
let grid: GridState = wasmMapGrid.toJSON() as GridState
|
||||
wasmMapGrid.free()
|
||||
mapGen.free()
|
||||
|
||||
const physics = new WasmClimatePhysics(paramsJson, terrainJson, specJson)
|
||||
const worldAge = scenario.worldAge ?? 0
|
||||
|
||||
// Phase 1: geological history
|
||||
// Phase 1: geological history — run in WASM
|
||||
let wasmGrid = WasmGrid.fromJSON(grid)
|
||||
for (let t = 0; t < worldAge; t++) {
|
||||
physics.processStep(grid, t, SEED)
|
||||
physics.processStep(wasmGrid, t, SEED)
|
||||
}
|
||||
grid = wasmGrid.toJSON() as GridState
|
||||
wasmGrid.free()
|
||||
|
||||
// Phase 2: scenario init
|
||||
scenario.initMap(grid)
|
||||
|
|
@ -123,9 +134,11 @@ const rows: TurnRow[] = []
|
|||
let baseTemp = 0
|
||||
let baseMoist = 0
|
||||
|
||||
wasmGrid = WasmGrid.fromJSON(grid)
|
||||
for (let t = worldAge; t < worldAge + totalTurns; t++) {
|
||||
const scenarioTurn = t - worldAge
|
||||
const events: EcologicalEvent[] = physics.processStep(grid, t, SEED)
|
||||
physics.processStep(wasmGrid, t, SEED)
|
||||
grid = wasmGrid.toJSON() as GridState
|
||||
const stats: TurnStats = computeTurnStats(grid)
|
||||
|
||||
if (scenarioTurn === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue