Files
benilla-octo/crates/benilla-world/src/world_map.rs
T
Sam SungandClaude Opus 5.5 fdfd8d39ec Comments in benilla-world: one line of fact each, no history, no record numbers (#121)
Part of #41: the comments of `benilla-world`, Rust and WGSL, are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 24,226 comment lines become 8,863.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - `0x6b62e0` is the WMO group's liquid renderer, not a doodad drawer.
  - The reference creates a WMO's props once, when a group enters its streaming window (`0x698720` → `0x695aa0`). It then admits them each frame the portal walk visits the group (`0x685d70` → `0x6838f0`). The old text had them created per visible group.
  - The liquid query's comments now state the reference's order: the map-object leg first, then the ADT (`0x69b6d0`). They no longer call the Outdoors/Inside split a match.
  - The interior probe runs from the character, not the camera.
  - The reference lights ground clutter. The old comment said it draws unlit.
  - The model-particle "pool order" deviation was wrong. Each instance is its own mesh, depth-sorted every frame.
  - The reference's vertical field of view follows the aspect ratio (44.1° at 16:9). The comment now gives it beside our fixed 45°.
  - The effect shader's far wall is the live `farclip`, 177 to 777 yd, not a fixed 777 yd.
  - Dozens more turned up on the way: renamed or deleted items, docs sitting on the wrong item, stale counts and links.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. An unbuilt behaviour says so plainly.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Five second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the reference.

Defects the rewrite surfaced outside the comments are filed as their own issues (#106, #114, #115, #116). The comments here state what the code does. String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 17:43:40 +07:00

89 lines
3.4 KiB
Rust

//! World-map state: the `Map.dbc` catalog and the current map id, for every subsystem that keys
//! off the map (the terrain and WDL streamers, the loading screen, time-of-day lighting).
use benilla_assets::MapCatalogRes;
use benilla_formats::load_map_catalog;
use bevy::prelude::*;
use benilla_assets::LockRecover;
use benilla_assets::{AssetSet, WorldAssets};
/// The map before the server names one: Eastern Kingdoms (`Map.dbc` id 0).
pub(crate) const DEFAULT_MAP_ID: u32 = 0;
/// `$WOW_MAP`: the `Map.dbc` id a server-less run starts on (`0` Azeroth, `1` Kalimdor), unset
/// giving [`DEFAULT_MAP_ID`]. A value that does not parse panics rather than falling back.
fn map_id_from_env() -> u32 {
match std::env::var("WOW_MAP") {
Err(_) => DEFAULT_MAP_ID,
Ok(v) => v.trim().parse().unwrap_or_else(|_| {
panic!("WOW_MAP={v:?} is not a Map.dbc id — it takes a NUMBER (0 = Azeroth, 1 = Kalimdor), not a name")
}),
}
}
/// The map the player is on, rewritten by the game on every worldport, login's included.
#[derive(Resource, Clone, Copy)]
pub struct CurrentMap(pub u32);
/// A cross-map transition, the world-scope teardown signal: every map-scoped strong-handle cache
/// clears on it, since one that kept its handles would pin every map visited. A clear is safe
/// mid-session, as live users hold their own handles.
#[derive(Message, Clone, Copy)]
pub struct MapChange;
/// The startup set the map catalog loads in, which the streamers' setup runs after.
#[derive(SystemSet, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct WorldMapLoad;
/// Loads `Map.dbc` and seeds [`CurrentMap`] at startup, after the patch chain opens.
pub(crate) struct WorldMapPlugin;
impl Plugin for WorldMapPlugin {
fn build(&self, app: &mut App) {
app.add_message::<MapChange>().add_systems(
Startup,
load_world_map.after(AssetSet::Open).in_set(WorldMapLoad),
);
app.add_systems(Update, announce_map_change);
}
}
/// Announce every [`CurrentMap`] flip as a [`MapChange`]; the startup seed and a same-map
/// worldport announce nothing.
fn announce_map_change(
map: Option<Res<CurrentMap>>,
mut last: Local<Option<u32>>,
mut changes: MessageWriter<MapChange>,
) {
let Some(map) = map else { return };
if let Some(prev) = last.replace(map.0) {
if prev != map.0 {
info!(
"map change: {prev} → {} — evicting map-scoped caches",
map.0
);
changes.write(MapChange);
}
}
}
/// Read `Map.dbc` off the patch chain into [`MapCatalogRes`] and seed [`CurrentMap`].
fn load_world_map(mut commands: Commands, world_assets: Option<Res<WorldAssets>>) {
let Some(world_assets) = world_assets else {
return;
};
let mut chain = world_assets.chain.lock_recover();
match load_map_catalog(&mut chain) {
Ok(c) => {
info!("Map.dbc: {} maps catalogued", c.len());
commands.insert_resource(MapCatalogRes(c));
// `$WOW_MAP` picks a server-less run's map (a named capture scenario sets it before
// `Startup`); a live session's `player::wire_in` overwrites it from the server.
let map = map_id_from_env();
commands.insert_resource(CurrentMap(map));
}
Err(e) => error!("failed to load Map.dbc, cross-map teleport disabled: {e:#}"),
}
}