World Loading

How GalaxyEggbertGame::LoadWorld() selects, parses, and renders a level.

Decision Tree

LoadWorld(worldNum):
  path = "Content/Data/Level/scene0N.vwr"
  if file exists:
      world_ = World::loadFromFile(path)    // VWR binary
  else:
      path = "Content/Data/Level/scene0N.txt"
      if file exists:
          world_ = make_unique<World>()
          LoadMobileEggbertTerrain(path)    // .txt text format
      else:
          BuildDemoWorld()                  // procedural fallback

  SpawnTerrainNodes()
  UpdateSkyDome(region)

VWR Loading

Delegates entirely to World::loadFromFile() and Chunk::read(). The chunk table is read first; non-empty chunks are deserialized at their stored file offsets. Empty chunks (all-air) are implicitly created as Chunk::createUniform(Block::air()). Full spec: VWR Format.

Mobile-Eggbert .txt Loading

Implemented in GalaxyEggbertGame::LoadMobileEggbertTerrain(path). The file has three sections:

  1. Header — key=value pairs: blupiPos, region. Sets Blupi spawn point and sky index.
  2. Decor section — 100×100 space-separated tile IDs (one row per line). Each tile ID is mapped to a block type via BlockTypes::fromMobileIconId(id). Decorative tiles that have no 3D block equivalent are mapped to Air.
  3. MoveObject entries — zero or more objects with type, posStart, posEnd, speed. Each is placed via decor_->PlaceObject(type, pos, posEnd, speed).

SpawnTerrainNodes()

After the world data model is populated, terrain is made visible:

SpawnTerrainNodes():
  terrainRoot_->RemoveAllChildren()      // clear previous level
  for each chunk (cx, cy, cz):
      if chunk.isEmpty(): continue
      blocks = chunk.unpackBlocks()
      for each (lx, ly, lz) in 10³:
          block = blocks[lx + ly*10 + lz*100]
          if block.isAir(): continue
          worldX = cx*10 + lx - kWCX
          worldY = cy*10 + ly
          worldZ = cz*10 + lz - kWCZ
          node = terrainRoot_->CreateChild()
          node->SetPosition(worldX, worldY, worldZ)
          StaticModel* sm = node->CreateComponent<StaticModel>()
          sm->SetModel(boxModel)
          sm->SetMaterial(GetTileMaterial(block.typeId))

Each non-air block becomes one box static mesh node. Materials are cached per block type ID in tileMatCache_. UV coordinates for the tile icon are computed via BlockTypes::tileUV(typeId) using object-m.png (1301×1431 px, 64×64 tiles, 20 cols).

Sky Dome

UpdateSkyDome(region) sets the sky sphere texture based on the region index (0–3) from the level header, selecting a decor00N.png background image. See Rendering for the per-world sky palette table.

Demo World

BuildDemoWorld() fills the bottom layer (Y=0) of the world with Ground blocks and a few Wall blocks to create a minimal playable arena — used when no level file is found.