Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World configuration management #237

Open
Sceat opened this issue Feb 12, 2025 · 0 comments
Open

World configuration management #237

Sceat opened this issue Feb 12, 2025 · 0 comments
Assignees
Labels
world Concerns the procedural world

Comments

@Sceat
Copy link
Member

Sceat commented Feb 12, 2025

The world is shared between the dapp and the server. It would be more intuitive to have a properly defined config which is not mutated at runtime.

since it often changes, it's complex to not have outdated or wrong code. Avoiding mutations is the best way to remove side effects (if world_env is modified elsewhere and we don't know about it, it can cause havoc in the app)

Improved isolation:

new World({ seed: '', ...config }).generate_chunk()

Ex from the server, I use a single object.

import { WorldEnv, Heightmap } from '@aresrpg/aresrpg-world'

import { SCHEMATICS_FILES } from './schematics_files.js'
import { LANDSCAPE, SCHEMATICS_BLOCKS_MAPPING } from './world_settings.js'

const world_settings = {
  seed: 'aresrpg',
  sea_level: 76,
  patch_view: {
    near: 4,
  },
  biomes: LANDSCAPE,
  schematics: {
    blocks_mapping: SCHEMATICS_BLOCKS_MAPPING,
    files: SCHEMATICS_FILES,
  },
  boards: {
    radius: 20,
    thickness: 3,
  },
  heightmap: {
    spread: 0.42,
    harmonics: 6,
  },
  chunks: {
    size: { xz: 64, y: 64 },
    altitude: { min: -1, max: 400 },
  },
}

WorldEnv.current.seaLevel = world_settings.sea_level
WorldEnv.current.patchViewCount.near = world_settings.patch_view.near // chunks view below ground surface

// EXTERNAL CONFIGS/RESOURCES
WorldEnv.current.biomes.rawConf = world_settings.biomes
// populate inventory with schematics
WorldEnv.current.schematics.globalBlocksMapping =
  world_settings.schematics.blocks_mapping
// @ts-ignore
WorldEnv.current.schematics.filesIndex = world_settings.schematics.files

// BOARDS
WorldEnv.current.boardSettings.boardRadius = world_settings.boards.radius
WorldEnv.current.boardSettings.boardThickness = world_settings.boards.thickness

Heightmap.instance.heightmap.params.spreading = world_settings.heightmap.spread
Heightmap.instance.heightmap.sampling.harmonicsCount =
  world_settings.heightmap.harmonics

// chunks gen
WorldEnv.current.chunks.range.bottomId = Math.floor(
  world_settings.chunks.altitude.min / world_settings.chunks.size.y,
)
WorldEnv.current.chunks.range.topId = Math.floor(
  world_settings.chunks.altitude.max / world_settings.chunks.size.y,
)

world_env.seeds.main = world_settings.seed
@Sceat Sceat added the world Concerns the procedural world label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
world Concerns the procedural world
Projects
Status: Todo
Development

No branches or pull requests

2 participants