From b90ab800abd081c58e93db7481d1df84dbfa40f7 Mon Sep 17 00:00:00 2001 From: Sam Sung <51686767+samwhosung@users.noreply.github.com> Date: Sat, 31 Oct 2026 06:59:51 +0700 Subject: [PATCH] Zone channels walk at the zone commit and its three other callers (#2869) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The zone-channel walk `0x49a210` reads the stored zone `0xb4e314`, and runs from four places only: `UpdateZoneText` `0x494780` on the area poll's tenth tick, behind its taxi and cinematic gates; the cinematic's end; the chat settings' load; and the flags reflex when the taxi bit clears (`0x5ff56e`). benilla walked whenever its own per-frame copy of the live area changed, so channels left and rejoined across a line crossed and recrossed between polls, and at each zone crossed in flight. Now `CommittedZone` is the walk's one input, and each of the four callers walks at its place. The real zone text (`0xb4b404`) outlives a reload, an empty name keeps it, and its compare ignores case. The indoor dedup stores no zone. Tests: each walk site, the flight, the reload, the empty name and the dedup. Fixes #2846 Fixes #2791 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 --- crates/benilla-app/src/area.rs | 175 ++++++--- crates/benilla-app/src/cinematic.rs | 25 ++ crates/benilla-app/src/lanes/guard_tests.rs | 28 +- crates/benilla-app/src/ui_chat.rs | 17 +- crates/benilla-app/src/ui_chat/channels.rs | 361 ++++++++++-------- crates/benilla-app/src/ui_chat/recruitment.rs | 12 +- crates/benilla-app/src/ui_chat/settings.rs | 8 +- crates/benilla-app/src/ui_chat/slot_tests.rs | 3 +- .../src/ui_chat/walk_live_tests.rs | 244 +++++++++++- crates/benilla-app/src/vm_pass.rs | 18 - .../benilla-world/src/wmo_portal/interior.rs | 5 + crates/benilla-world/src/wmo_portal/mod.rs | 2 +- docs/DEVIATIONS.md | 9 +- 13 files changed, 620 insertions(+), 287 deletions(-) diff --git a/crates/benilla-app/src/area.rs b/crates/benilla-app/src/area.rs index 3ba99d599..f166f11b8 100644 --- a/crates/benilla-app/src/area.rs +++ b/crates/benilla-app/src/area.rs @@ -69,16 +69,24 @@ fn load_area_table(mut commands: Commands, assets: Option>) { #[derive(Resource, Default, Clone, Copy, PartialEq, Eq, Debug)] pub(crate) struct CommittedZone(pub(crate) Option); -/// The session's end, standing in for `ShutdownGame`'s zeroing of `0xb4e314` (`0x491180`). -fn clear_committed_zone(mut zone: ResMut) { +/// `s_realZoneText` (`0xb4b404`): the real zone name the last commit stored. Its change walks the +/// zone channels (`0x4948b7` → `0x494931`). Like the zone it outlives a reload and is cleared only +/// at the session's end (`0x491180`); an empty name leaves it as it was (`0x49489a`). +#[derive(Resource, Default)] +pub(crate) struct CommittedZoneText(String); + +/// The session's end, standing in for `ShutdownGame`'s zeroing of `0xb4e314` and `0xb4b404` +/// (`0x491180`). +fn clear_committed_zone(mut zone: ResMut, mut text: ResMut) { zone.set_if_neq(CommittedZone(None)); + text.0.clear(); } /// The client's zone-text cache: the compare targets of `0x494780`, the minimap line's cache /// (`0x494970`) and the indoor dedup pair (`[0x868608]`, `[0x86860c]`). It lives per VM, so every /// login starts zeroed and its first resolve is a NEW_AREA. #[derive(Default)] -struct ZoneCache { +pub(crate) struct ZoneCache { /// `None` until the first resolve. zone_id: Option, zone_text: String, @@ -91,6 +99,22 @@ struct ZoneCache { wmo_group: u32, /// The realm flag last pushed to this VM. realm_pvp: Option, + /// The zone the VM's channel catalog was last fed for ([`crate::ui_chat::ZoneCommit`]). + catalog: Option>, +} + +/// What a commit leaves for the steps after the stores: the walk and the events. +struct Committed { + /// `0x494780` ran. A hit group the indoor dedup passes stops short of it (`0x67e510`), with + /// nothing after to do. + called: bool, + zone: u32, + /// The real zone text changed to a nonempty one. + real_changed: bool, + event: Option<&'static str>, + /// `MINIMAP_ZONE_CHANGED`'s new text. + minimap: Option, + texts: (String, String), } /// One resolve's compare inputs. @@ -116,35 +140,39 @@ fn elect_event(cache: &ZoneCache, next: &ZoneSignal) -> Option<&'static str> { None } -/// Resolves the texts and PvP info, pushes the zone caches, then fires the elected zone event and, -/// independently, `MINIMAP_ZONE_CHANGED`. The poll `0x5db900` counts every tick in `ticks` -/// (`0xc4d790`), which nothing resets, and reports only on the tenth, subtracting ten (`0x5db906`, -/// `0x5db917`); the other nine return at once. It reports the active mover's position, else the -/// active player's, and nothing with neither held (`0x5db937`, `0x5db956`, `0x5db95d`): after a -/// worldport frees every object, the commit waits for our player's create. It runs on the tick -/// after the tick's packets (category 6's drain `0x403620`, then category 5's `0x401ec0`), so it -/// reads a player that arrived this frame. +/// Resolves the texts and PvP info, pushes the zone caches, then walks the zone channels and fires +/// the elected zone event and, independently, `MINIMAP_ZONE_CHANGED`. The poll `0x5db900` counts +/// every tick in `ticks` (`0xc4d790`), which nothing resets, and reports only on the tenth, +/// subtracting ten (`0x5db906`, `0x5db917`); the other nine return at once. It reports the active +/// mover's position, else the active player's, and nothing with neither held (`0x5db937`, +/// `0x5db956`, `0x5db95d`): after a worldport frees every object, the commit waits for our +/// player's create. It runs on the tick after the tick's packets (category 6's drain `0x403620`, +/// then category 5's `0x401ec0`), so it reads a player that arrived this frame. +/// +/// The walk is `UpdateZoneText`'s own (`0x494931`), after the caches and ahead of the event +/// (`0x49493f`, `0x49495f`), when the real zone text changed; the zone feeds the verbs' catalog +/// as it is stored (`0x49479a`). #[allow(clippy::too_many_arguments)] // a Bevy system's full input set -fn feed_zone_events( +pub(crate) fn feed_zone_events( mut ticks: Local, - mut hosted_vm: crate::script_calls::HostedVm, + mut vm: crate::script_calls::VmWith>, me: Query<(), (With, With)>, world: benilla_world::world_point::WorldPoint, areas: Option>, factions: Option>, realm_pvp: Option>, mut cache: Local>, - mut committed: ResMut, + mut real_text: ResMut, + cinematic: Option>, + mut cascade: Option>, ) { *ticks += 1; let due = *ticks >= 10; if due { *ticks -= 10; } - hosted_vm.run(|script| { - let Some(script) = script else { - return; - }; + let done = vm.run(|script| { + let script = script?; let cache = cache.get(script); let realm_pvp = realm_pvp.is_some_and(|r| r.0); if cache.realm_pvp != Some(realm_pvp) { @@ -152,25 +180,20 @@ fn feed_zone_events( script.set_realm_pvp(realm_pvp); } if !due { - return; + return None; } - let Some(areas) = areas else { - return; - }; + let areas = areas.as_deref()?; if me.is_empty() { - return; + return None; } - let Some(leaf) = world.area() else { return }; - let Some(leaf_row) = areas.0.get(leaf) else { - // An unknown id keeps the last state, as the resolver does for areaId 0. - return; - }; + let leaf = world.area()?; + // An unknown id keeps the last state, as the resolver does for areaId 0. + let leaf_row = areas.0.get(leaf)?; let zone = if leaf_row.zone_id == 0 { leaf } else { leaf_row.zone_id }; - committed.set_if_neq(CommittedZone(Some(zone))); let real_zone_text = areas.0.name(zone).unwrap_or_default().to_string(); let indoor = world.area_interior().is_some(); @@ -190,7 +213,14 @@ fn feed_zone_events( && k.group_area_id != 0 && (cache.wmo_id, cache.wmo_group) == (k.wmo_id, wmo_group) { - return; + return Some(Committed { + called: false, + zone, + real_changed: false, + event: None, + minimap: None, + texts: Default::default(), + }); } cache.wmo_id = k.wmo_id; // The whole-WMO -1 row. An unnamed one with `AreaTableID` 0 takes the leaf's name, @@ -237,37 +267,71 @@ fn feed_zone_events( let event = elect_event(cache, &signal); let minimap_changed = cache.minimap_text != minimap_text; - if event.is_none() && !minimap_changed { - return; - } - - script.set_zone_texts(benilla_ui::script::ZoneTexts { - zone: signal.zone_text.clone(), - real_zone: real_zone_text, - subzone: signal.subzone_text.clone(), - minimap: minimap_text.clone(), - pvp_zone: zone_pvp(areas.0.get(zone), factions.as_deref()), - is_arena: leaf_row.flags & 0x80 != 0, - }); - - if let Some(event) = event { - script.fire_event(event, vec![]); - debug!( - "area: {event} → zone {:?} / sub {:?}", - signal.zone_text, signal.subzone_text - ); - } - if minimap_changed { - script.fire_event("MINIMAP_ZONE_CHANGED", vec![]); - debug!("area: minimap zone text → {minimap_text:?}"); + // An empty name stores nothing and walks nothing (`0x49489a` → `0x494936`); the compare + // ignores case (`0x4948b0` → `0x64a4c0`). + let real_changed = + !real_zone_text.is_empty() && !real_text.0.eq_ignore_ascii_case(&real_zone_text); + let texts = (signal.zone_text.clone(), signal.subzone_text.clone()); + if event.is_some() || minimap_changed || real_changed { + script.set_zone_texts(benilla_ui::script::ZoneTexts { + zone: signal.zone_text.clone(), + real_zone: real_zone_text.clone(), + subzone: signal.subzone_text.clone(), + minimap: minimap_text.clone(), + pvp_zone: zone_pvp(areas.0.get(zone), factions.as_deref()), + is_arena: leaf_row.flags & 0x80 != 0, + }); } cache.zone_id = Some(signal.zone_id); cache.zone_text = signal.zone_text; cache.subzone_text = signal.subzone_text; - cache.minimap_text = minimap_text; + if real_changed { + real_text.0 = real_zone_text; + } + cache.minimap_text.clone_from(&minimap_text); cache.indoor = signal.indoor; cache.wmo_group = wmo_group; - }) + Some(Committed { + called: true, + zone, + real_changed, + event, + minimap: minimap_changed.then_some(minimap_text), + texts, + }) + }); + let Some(done) = done else { return }; + + // The zone is stored (`0x49479a`) outside the host's reads, feeds the verbs, and the walk + // follows the caches (`0x494931`). + let walked = vm.turn(|script, mut commit| { + if done.called { + commit.store_zone(done.zone); + } + let Some(script) = script else { return false }; + commit.feed_catalog(script, Some(done.zone), &mut cache.get(script).catalog); + done.called + && commit.walk_on_commit(script, done.zone, done.real_changed, cinematic.as_deref()) + }); + vm.run(|script| { + let Some(script) = script else { return }; + if walked { + if let Some(cascade) = cascade.as_deref_mut() { + cascade.tail(script); + } + } + if let Some(event) = done.event { + script.fire_event(event, vec![]); + debug!( + "area: {event} → zone {:?} / sub {:?}", + done.texts.0, done.texts.1 + ); + } + if let Some(minimap) = done.minimap { + script.fire_event("MINIMAP_ZONE_CHANGED", vec![]); + debug!("area: minimap zone text → {minimap:?}"); + } + }); } /// What `GetZonePVPInfo` (`0x48d540`) reads of the committed zone's row `zone`: the capital bit @@ -328,6 +392,7 @@ impl Plugin for AreaPlugin { fn build(&self, app: &mut App) { app.init_resource::() .init_resource::() + .init_resource::() // The session's end stands in for `ShutdownGame` (`0x491180`), the one zeroing. .add_systems( OnExit(crate::client_state::ClientState::InWorld), diff --git a/crates/benilla-app/src/cinematic.rs b/crates/benilla-app/src/cinematic.rs index 2f2c6208c..0e51a09a2 100644 --- a/crates/benilla-app/src/cinematic.rs +++ b/crates/benilla-app/src/cinematic.rs @@ -68,6 +68,9 @@ pub(crate) struct Cinematic { /// How many far shots have asked for a reload so far: the stream's focus carries it, so its /// load re-arms for each (a cinematic's focus is unpaced throughout, with no pacing edge). reloads: u32, + /// EndCinematic's zone-channel walk (`0x48f1d0`) is owed: a shot ended or was skipped, and the + /// walk has not run since ([`crate::ui_chat::walk_when_cinematic_ends`]). + end_walk: bool, } /// The black a shot that moved the camera past the reload gate holds before it fades in. @@ -117,6 +120,11 @@ impl Cinematic { self.playing.is_some() } + /// Take EndCinematic's owed walk ([`Cinematic::end_walk`]). + pub(crate) fn take_end_walk(&mut self) -> bool { + std::mem::take(&mut self.end_walk) + } + /// The far reloads shots have asked for so far. pub(crate) fn reloads(&self) -> u32 { self.reloads @@ -149,6 +157,14 @@ impl Cinematic { } } + /// A cinematic that just ended, EndCinematic's walk still owed. + pub(crate) fn ended_for_test() -> Self { + Self { + end_walk: true, + ..Self::default() + } + } + /// A shot-less cinematic for tests that only ask [`Cinematic::is_playing`]; a [`CinematicPath`] /// needs a real `Cameras\*.m2`, so anything that reads a shot panics here. pub(crate) fn playing_for_test() -> Self { @@ -165,6 +181,7 @@ impl Cinematic { skip: false, hold: None, reloads: 0, + end_walk: false, } } @@ -227,6 +244,13 @@ impl Plugin for CinematicPlugin { Update, drive_letterbox.in_set(WorldStage::Input).after(drive), ) + // EndCinematic's walk of the zone channels (`0x48f1d0`), the frame the shot ends. + .add_systems( + Update, + crate::ui_chat::walk_when_cinematic_ends + .in_set(WorldStage::Input) + .after(drive), + ) // Leaving the world drops a cinematic with no ack, as the reference's teardown does // (`0x490a80` clears the flag and sends no `CMSG_COMPLETE_CINEMATIC`); the exit // edge drops a latch too, where a departure with the sweep spent leaves one. @@ -644,6 +668,7 @@ fn drive( } } if ended { + cine.end_walk = true; // Not faded in yet: the world around the body streamed away during the flight, so // hold the black the reference shows while its own load blocks. EndCinematic // reloads the body's spot only when the camera ended more than 30 yards from the diff --git a/crates/benilla-app/src/lanes/guard_tests.rs b/crates/benilla-app/src/lanes/guard_tests.rs index 124980048..896fd32dc 100644 --- a/crates/benilla-app/src/lanes/guard_tests.rs +++ b/crates/benilla-app/src/lanes/guard_tests.rs @@ -406,13 +406,15 @@ pub(super) const BUILT_OUTSIDE_THE_PACKETS_IN_THE_REFERENCE: &[(&str, &[&str], & "the frame pass's `OnUpdate` walk (`0x764330` → `0x765650`), its screen and scale"), ("::ui_script::extract::paint_script", &["video::Widescreen"], "the UI pass's paint, after the walk, which no getter reads"), - ("::ui_chat::channels::auto_join_zone_channels", &["net::ObjectStore", - "ui_chat::edit::ChannelState"], + ("::area::feed_zone_events", &["net::ObjectStore", "ui_chat::edit::ChannelState"], "the zone text's update `0x494780`, whose walk (`0x494931`, gated on our taxi flag at \ `0x494908`-`0x49491a`) the area poll runs in the idle pass after the packets \ - (`0x401ece` → `0x5db900` → `0x67e510` → `0x494780`), and `EndCinematic`'s (`0x48f1d0`), \ - in the frame pass; its runs inside a packet run there: the chat cache's load \ - (`0x499a22`) and the taxi flag's clear (`0x5ff56e`)"), + (`0x401ece` → `0x5db900` → `0x67e510` → `0x494780`); its runs inside a packet run \ + there: the chat cache's load (`0x499a22`) and the taxi flag's clear (`0x5ff56e`)"), + ("::ui_chat::channels::walk_when_cinematic_ends", &["net::ObjectStore", + "ui_chat::edit::ChannelState"], + "`EndCinematic`'s walk (`0x48f1d0`, gated on our taxi flag at `0x48f1c3`-`0x48f1ce`), in \ + the frame pass where the shot ends"), ]; /// The systems that write the VM and push no view a getter reads of what a handler writes, by a @@ -575,12 +577,10 @@ pub(super) const READ_ONLY_TO_HANDLERS: &[&str] = &[ "::glue_session::roster::Roster", // `0xb4e314`, which the party snapshot reads; only the zone feed commits it. "::area::CommittedZone", - // The walk's committed zone, which the recruitment cascade's plan reads through the host - // (`0x49ead7`), and the slots; the walk's poll and the notice lane's taxi walk write them - // through their own `ResMut`. Both sit here only because the scan cannot see an exclusive - // handler's writes: the chat cache's read writes both inside its section's settle, in its - // packet (`0x499a22`). - "::ui_chat::channels::ZoneChannelWalk", + // The slots, which the recruitment cascade's plan reads through the host (`0x49eac3`); the + // zone commit's walk and the notice lane's taxi walk write them through their own `ResMut`. + // They sit here only because the scan cannot see an exclusive handler's writes: the chat + // cache's read writes them inside its section's settle, in its packet (`0x499a22`). "::ui_chat::edit::ChannelState", // The console's registry, which a `ConsoleExec` a listener makes reads. "::console::ConsoleCommands", @@ -1325,12 +1325,6 @@ const AT_THEIR_OWN_PLACE: &[(&str, &str)] = &[ "the login and character screens' answers, which come before the in-game interface: \ the drain runs only with it up", ), - ( - "::ui_chat::channels::auto_join_zone_channels", - "world entry only arms the zone-channel walk, whose one push is a walk's refusal onto \ - the ui-error lane, made where the zone text's update walks, after the packets \ - (`0x401ece` → `0x494931`)", - ), ( "::player::controller::control", "the mover's queue sends the root and unroot acks at its frame update (`0x616438`, \ diff --git a/crates/benilla-app/src/ui_chat.rs b/crates/benilla-app/src/ui_chat.rs index 7a2d664a7..d80cbfb7a 100644 --- a/crates/benilla-app/src/ui_chat.rs +++ b/crates/benilla-app/src/ui_chat.rs @@ -63,7 +63,9 @@ pub(crate) use away::AfkMirror; pub(crate) use broadcast::Broadcast; /// The zone-channel catalog's seed, called from the world-entry UI load: addons read the catalog /// at file scope, before an `Update` push would land. -pub(crate) use channels::{seed_zone_channel_catalog, TaxiWalk}; +pub(crate) use channels::{ + seed_zone_channel_catalog, walk_when_cinematic_ends, TaxiWalk, ZoneCommit, +}; /// The joined-channel roster and the `ChatChannels.dbc` catalog. pub(crate) use edit::ChannelState; /// Test-only: `ui_script::chat_tests` checks every fired name against the live `ChatTypeInfo`. @@ -211,19 +213,18 @@ impl Plugin for UiChatPlugin { .before(channels::end_session_channels_on_disconnect) .in_set(crate::client_state::InWorldGated), ) - // The zone-channel auto-join, which vmangos leaves to the client. The disconnect clear - // runs first, so a same-frame drop cannot leave the walk diffing stale membership. - // After `AreaAuthoritySet`, since a stale area joins and leaves the wrong channels, and - // after the settle state's release, which the walk's gate reads. + // The zone-channel auto-join, which vmangos leaves to the client, runs inside the zone + // commit ([`crate::area::feed_zone_events`]). The disconnect clear runs first, so a + // same-frame drop cannot leave the walk diffing stale membership, and world entry + // arms the walk ahead of the commit. .add_systems( Update, ( channels::end_session_channels_on_disconnect, - channels::auto_join_zone_channels.in_set(crate::client_state::InWorldGated), + channels::arm_zone_channel_walk.in_set(crate::client_state::InWorldGated), ) .chain() - .after(benilla_world::terrain_stream::AreaAuthoritySet) - .after(crate::player::WorldFocusSet), + .before(crate::area::feed_zone_events), ) // After the shutdown's `PLAYER_LOGOUT`, whose handlers read the windows and the // channels as they stood, and before the glue VM goes in. diff --git a/crates/benilla-app/src/ui_chat/channels.rs b/crates/benilla-app/src/ui_chat/channels.rs index 84dc20822..4385bc9cd 100644 --- a/crates/benilla-app/src/ui_chat/channels.rs +++ b/crates/benilla-app/src/ui_chat/channels.rs @@ -40,41 +40,44 @@ pub(crate) fn city_word(areas: &benilla_formats::AreaTableCatalog) -> Option<&st } /// The walk's own state; the joined list is not copied here, as the reference's pass 1 walks the -/// slot array itself ([`ChannelState::joined`]). -#[derive(Resource, Default)] +/// slot array itself ([`ChannelState::joined`]), and the zone it walks against is the commit's +/// ([`crate::area::CommittedZone`]). +#[derive(Resource)] pub(crate) struct ZoneChannelWalk { - /// The top-level zone the last walk ran for; `None` walks from scratch. - at: Option, - /// The zone the walk may act on this frame, the reference's `ds:0xb4e314`, read by the walk - /// (`0x49a243`) and the guild-recruitment cascade (`0x49ead7`); `None` while a gate holds. - pub(super) zone_id: Option, - /// A character session is live: without it the logout frame, still `InWorld` with `at` just - /// cleared, would join the zone being left. + /// The session's channels have not been walked since they were last emptied: the next commit + /// walks whatever its zone text did, as a world entry's first commit does on the reference's + /// empty zone cache. Deviation: a dropped link re-enters the world in this session, where the + /// reference logs in anew, because of benilla's same-character reconnect, which the reference + /// lacks. + owed: bool, + /// A character session is live: without it the logout frame, still `InWorld`, would join the + /// zone being left. live: bool, } -impl ZoneChannelWalk { - /// Walk again at the next settled frame, whatever the zone: the cache loader's call - /// (`0x499a22`) when no zone is committed to walk it against yet, which runs the deferred - /// joins it just seated. - pub(super) fn rewalk(&mut self) { - self.at = None; - } - - /// A live session that walked `zone` and holds it committed. - #[cfg(test)] - pub(super) fn walked_for_test(zone: u32) -> Self { +impl Default for ZoneChannelWalk { + fn default() -> Self { ZoneChannelWalk { - at: Some(zone), - zone_id: Some(zone), - live: true, + owed: true, + live: false, } } +} + +impl ZoneChannelWalk { + /// A live session whose channels `zone` was walked for and committed. + #[cfg(test)] + pub(super) fn seat_for_test(world: &mut World, zone: u32) { + world.insert_resource(ZoneChannelWalk { + owed: false, + live: true, + }); + world.insert_resource(crate::area::CommittedZone(Some(zone))); + } /// Forget the session: the next world entry re-joins from nothing. fn clear_session(&mut self) { - self.at = None; - self.zone_id = None; + self.owed = true; self.live = false; } } @@ -406,32 +409,25 @@ pub(super) fn walk_zone( } } -/// Whether the zone under the player is final: an active avatar done settling, benilla's stand-in -/// for the loading screen the reference walks after. -fn zone_is_settled(player: Option<&crate::player::Player>) -> bool { - player.is_some_and(|p| p.active && !p.settling) -} - /// Whether our `UNIT_FIELD_FLAGS` has the taxi flight bit, which holds the zone commit's walk off -/// (`0x494908`-`0x49491a`). -fn on_a_flight(me: &Query<&crate::net::ObjectStore, With>) -> bool { - me.iter() - .next() - .is_some_and(|s| s.0.unit_flags() & crate::player::UNIT_FLAG_TAXI_FLIGHT != 0) +/// (`0x494908`-`0x49491a`) and EndCinematic's (`0x48f1c3`-`0x48f1ce`). +fn on_a_flight(store: &crate::net::ObjectStore) -> bool { + store.0.unit_flags() & crate::player::UNIT_FLAG_TAXI_FLIGHT != 0 } -/// One walk against the committed zone [`ZoneChannelWalk::zone_id`], the reference's -/// `ds:0xb4e314`: nothing while the chat is not ready (`0x49a219`, the mask unseated) or with no -/// zone row (`0x49a243`-`0x49a275`), else [`walk_zone`] and the zone noted. Whether it walked, for -/// the tail ([`GuildRecruitmentCascade::tail`]). +/// One walk against the committed zone `zone`, the reference's `ds:0xb4e314`: nothing while the +/// chat is not ready (`0x49a219`, the mask unseated) or with no zone row (`0x49a243`-`0x49a275`), +/// else [`walk_zone`], the walk no longer owed. Whether it walked, for the tail +/// ([`GuildRecruitmentCascade::tail`]). fn walk_committed( channels: &mut ChannelState, walk: &mut ZoneChannelWalk, + zone: Option, areas: Option<&AreaTableRes>, net: (&NetCommands, &crate::ui_action::UiErrorKeys), script: Option<&mut benilla_ui::script::UiScript>, ) -> bool { - let (Some(zone_id), Some(areas)) = (walk.zone_id, areas) else { + let (Some(zone_id), Some(areas)) = (zone, areas) else { return false; }; let Some(row) = areas.0.get(zone_id) else { @@ -442,101 +438,152 @@ fn walk_committed( } let (name, flags) = (row.name.clone(), row.flags); walk_zone(channels, &name, flags, city_word(&areas.0), net, script); - walk.at = Some(zone_id); + walk.owed = false; true } -/// The walk, re-run whenever the zone changes. It composes from the real zone name, the -/// `GetRealZoneText` cache (`0xb4b404`), never the display text, which the indoor override -/// (`0x67e670`) renames. -/// -/// The reference walks in `UpdateZoneText 0x494780` on each zone change (`0x494931`), which the -/// area poll runs in the frame's idle pass after the packets (`0x401ece` → `0x5db900` → -/// `0x67e510` → `0x494780`), skipped while our taxi flag is set (`0x494908`-`0x49491a`); this -/// polls the same inputs every frame. It waits while the world arrives (`Player::settling`), as -/// the reference walks after its loading screen and our leaf area moves while terrain streams in, -/// and for the chat cache to seat the mask, as the reference bails on its ready flag (`0x49a219`). -/// The walks the reference makes inside a packet run there: the cache loader's -/// ([`walk_at_settle`]) and the taxi flag's clear ([`on_field_edge`]). The walk's tail runs the -/// recruitment cascade's retry (`0x49a6a4`-`0x49a6b2`). -pub(super) fn auto_join_zone_channels( - commands: Res, - // The slots and the walk beside the VM: the walk runs no Lua, so it is an engine turn. - mut vm: crate::script_calls::VmWith, - areas: Option>, - world: benilla_world::world_point::WorldPoint, - // One parameter for clippy's argument limit: the body's settle and a cinematic's view. - body: ( - Option>, - Option>, - ), +/// The zone's name and area flags, what the walk and the verbs compose a channel's name from. +fn zone_row(areas: Option<&AreaTableRes>, zone: Option) -> Option<(String, u32)> { + areas?.0.get(zone?).map(|row| (row.name.clone(), row.flags)) +} + +/// World entry arms the walk; the session-end edges disarm it. +pub(super) fn arm_zone_channel_walk( + mut walk: ResMut, mut entered: MessageReader, - mut catalog_fed: Local>>, - // The taxi flag the zone commit's walk waits on, and the tail's retry. - (errors, me, mut cascade): ( - Res, - Query<&crate::net::ObjectStore, With>, - ResMut, - ), ) { - let walked = vm.turn(|script, (mut channels, mut walk)| { - let (player, cinematic) = (&body.0, &body.1); - // World entry arms the walk; the session-end edges disarm it. - if entered.read().next().is_some() { - walk.live = true; + if entered.read().count() > 0 { + walk.live = true; + } +} + +/// What the zone-text commit walks with, beside the notice lane's VM +/// ([`crate::area::feed_zone_events`]): the slots and the walk, which the host reads, the zone +/// rows, the wire, and our player for the commit's gates. +#[derive(bevy::ecs::system::SystemParam)] +pub(crate) struct ZoneCommit<'w, 's> { + channels: Option>, + walk: Option>, + committed: Option>, + areas: Option>, + commands: Option>, + errors: Option>, + me: Query<'w, 's, &'static crate::net::ObjectStore, With>, +} + +impl ZoneCommit<'_, '_> { + /// `UpdateZoneText` stores the zone (`0x49479a`). + pub(crate) fn store_zone(&mut self, zone: u32) { + if let Some(committed) = self.committed.as_mut() { + committed.set_if_neq(crate::area::CommittedZone(Some(zone))); } + } - // A cinematic suppresses the rejoin: two of the six reads of the reference's cinematic cell - // `[0xb4e310]`, `0x49491c` (the zone-text update) and `0x5ff565` (an `UPDATEFLAGS` reflex), - // skip `ZoneChannelRefresh` (`0x49a210`) while one runs, and `EndCinematic` calls it at - // `0x48f1d0`. A race intro flies the streaming focus far off a body that has not moved. - let cinematic_running = cinematic.as_deref().is_some_and(|c| c.is_playing()); - let areas = areas.as_deref(); - - // `None` with no session, during a cinematic, while the world arrives, or with no area - // answer. - let zone_id = (walk.live && !cinematic_running && zone_is_settled(player.as_deref())) - .then(|| { - let areas = areas?; - world.area().and_then(|leaf| areas.0.top_zone(leaf)) - }) - .flatten(); - walk.zone_id = zone_id; - let zone = zone_id - .and_then(|id| areas?.0.get(id)) - .map(|row| (row.name.clone(), row.flags)); - - // The VM's catalog is fed before those gates: to its verbs an empty catalog means "no such - // built-in channel", which files `General` as a custom channel and joins one of that name. - // Zone-less, a zone row carries `resolved: None`, the reference's nil leg (`0x4a10d9`, - // `0x49ece5`). - let mut script = script; - if !channels.channels.is_empty() { - if let Some(script) = script.as_mut() { - let at = zone.clone().unwrap_or_default(); - let fed = catalog_fed.get(script); - if fed.as_ref() != Some(&at) { - script.set_zone_channel_catalog(zone_channel_catalog( - &channels.channels, - &at.0, - at.1, - areas.and_then(|a| city_word(&a.0)), - )); - *fed = Some(at); - } - } + /// The VM's channel catalog for the zone just stored at `0xb4e314` (`0x49479a`), which the + /// verbs read at their call: `JoinChannel`'s resolve (`0x4a10d9`), `EnumerateServerChannels` + /// (`0x4a17a8`) and the cascade's name (`0x49ece5`). Fed once per zone and VM, `fed` the + /// zone this VM holds; a row's `resolved` is `None` with no zone, the verbs' nil leg. + pub(crate) fn feed_catalog( + &self, + script: &mut benilla_ui::script::UiScript, + zone: Option, + fed: &mut Option>, + ) { + let Some(channels) = self.channels.as_deref() else { + return; + }; + if channels.channels.is_empty() || *fed == Some(zone) { + return; } + let areas = self.areas.as_deref(); + let (name, flags) = zone_row(areas, zone).unwrap_or_default(); + script.set_zone_channel_catalog(zone_channel_catalog( + &channels.channels, + &name, + flags, + areas.and_then(|a| city_word(&a.0)), + )); + *fed = Some(zone); + } - if zone_id.is_none() || walk.at == zone_id || on_a_flight(&me) { - return false; // nothing to walk against, the same zone as last frame, or aloft + /// Our player is held and aloft or not: the active player `0x468460` finds (`0x494904`), its + /// taxi bit clear (`0x494908`-`0x49491a`). + fn afoot(&self) -> bool { + self.me + .iter() + .next() + .is_some_and(|store| !on_a_flight(store)) + } + + /// The walk `UpdateZoneText` makes when the real zone text changed (`0x4948b7` → `0x494931`), + /// after the gates in the reference's order: the active player (`0x494904`), the taxi bit + /// (`0x494908`-`0x49491a`), a cinematic running (`0x49491c`) and one pending (`0x494928` → + /// `0x5efc90`, `[0xc4d75c]`). `real_changed` is that text's change; a walk the session still + /// owes runs whatever it did. Whether it walked, for the tail. + pub(crate) fn walk_on_commit( + &mut self, + script: &mut benilla_ui::script::UiScript, + zone: u32, + real_changed: bool, + cinematic: Option<&crate::cinematic::Cinematic>, + ) -> bool { + if !self.afoot() { + return false; + } + if cinematic.is_some_and(|c| c.is_playing() || c.is_pending()) { + return false; + } + if !real_changed && !self.walk.as_deref().is_some_and(|w| w.owed) { + return false; + } + self.walk_now(script, Some(zone)) + } + + /// EndCinematic's walk (`0x48f1d0`), past its own gates, the active player and the taxi bit + /// (`0x48f1b4`-`0x48f1ce`), the cinematic cell just cleared (`0x48f183`). + pub(crate) fn walk_at_cinematic_end( + &mut self, + script: &mut benilla_ui::script::UiScript, + ) -> bool { + let zone = self.committed.as_deref().and_then(|c| c.0); + self.afoot() && self.walk_now(script, zone) + } + + fn walk_now(&mut self, script: &mut benilla_ui::script::UiScript, zone: Option) -> bool { + let (Some(channels), Some(walk), Some(commands), Some(errors)) = ( + self.channels.as_deref_mut(), + self.walk.as_deref_mut(), + self.commands.as_deref(), + self.errors.as_deref(), + ) else { + return false; + }; + if !walk.live { + return false; } walk_committed( - &mut channels, - &mut walk, - areas, - (&commands, &errors), - script, + channels, + walk, + zone, + self.areas.as_deref(), + (commands, errors), + Some(script), ) + } +} + +/// EndCinematic's walk (`0x48f1d0`), run when a cinematic has ended ([`Cinematic::take_end_walk`]): +/// the committed zone's channels, with the tail. +pub(crate) fn walk_when_cinematic_ends( + mut cine: ResMut, + mut vm: crate::script_calls::VmWith>, + mut cascade: ResMut, +) { + if !cine.take_end_walk() { + return; + } + let walked = vm.turn(|script, mut commit| { + script.is_some_and(|script| commit.walk_at_cinematic_end(script)) }); if walked { vm.run(|script| { @@ -549,16 +596,16 @@ pub(super) fn auto_join_zone_channels( /// The cache loader's walk (`0x499a22`, after its burst), inside the chat section's settle or the /// interface load that reads it ([`super::settings`]), against the committed zone, with the tail. -/// With no zone committed yet the walk would bail, and the poll walks at the first settled frame, -/// which runs the deferred joins the loader seated. +/// With no zone committed yet the walk would bail, and the first commit's walk, which the session +/// still owes, runs the deferred joins the loader seated. pub(super) fn walk_at_settle(world: &mut World, script: &mut benilla_ui::script::UiScript) { + let zone = world + .get_resource::() + .and_then(|z| z.0); let live = world .get_resource::() - .is_some_and(|w| w.live && w.zone_id.is_some()); - if !live { - if let Some(mut walk) = world.get_resource_mut::() { - walk.rewalk(); - } + .is_some_and(|w| w.live); + if !live || zone.is_none() { return; } let walked = world.resource_scope::(|world, mut channels| { @@ -572,6 +619,7 @@ pub(super) fn walk_at_settle(world: &mut World, script: &mut benilla_ui::script: walk_committed( &mut channels, &mut walk, + zone, world.get_resource::(), (commands, errors), Some(script), @@ -592,6 +640,7 @@ pub(super) fn walk_at_settle(world: &mut World, script: &mut benilla_ui::script: pub(crate) struct TaxiWalk<'w> { channels: Option>, walk: Option>, + committed: Option>, areas: Option>, commands: Option>, errors: Option>, @@ -621,6 +670,7 @@ impl TaxiWalk<'_> { walk_committed( channels, walk, + self.committed.as_deref().and_then(|c| c.0), self.areas.as_deref(), (commands, errors), script, @@ -628,8 +678,9 @@ impl TaxiWalk<'_> { } } -/// Feed the VM the zone-less catalog before any interface file runs: world entry runs FrameXML -/// and the addons in one call, ahead of the walk's first tick. +/// Feed a new VM the catalog for the zone stored at `0xb4e314` before any interface file runs: +/// world entry runs FrameXML and the addons in one call, ahead of the first commit, and a reload +/// keeps the stored zone ([`crate::area::CommittedZone`]). pub(crate) fn seed_zone_channel_catalog( world: &mut World, script: &mut benilla_ui::script::UiScript, @@ -638,12 +689,19 @@ pub(crate) fn seed_zone_channel_catalog( return; }; if channels.channels.is_empty() { - return; // no `ChatChannels.dbc`: nothing to feed, as in the walk + return; // no `ChatChannels.dbc`: nothing to feed, as in the commit } - let city = world - .get_resource::() - .and_then(|a| city_word(&a.0)); - script.set_zone_channel_catalog(zone_channel_catalog(&channels.channels, "", 0, city)); + let areas = world.get_resource::(); + let zone = world + .get_resource::() + .and_then(|z| z.0); + let (name, flags) = zone_row(areas, zone).unwrap_or_default(); + script.set_zone_channel_catalog(zone_channel_catalog( + &channels.channels, + &name, + flags, + areas.and_then(|a| city_word(&a.0)), + )); } /// Every `ChatChannels.dbc` row as the VM needs it: the id, the Shortcut the verbs match a typed @@ -771,27 +829,6 @@ mod tests { assert!(wanted_channels(&catalog(), SEED, "", CAPITAL, CITY).is_empty()); } - #[test] - fn the_walk_waits_for_the_world_under_the_player() { - use crate::player::Player; - - assert!(!zone_is_settled(None), "no avatar: no zone to believe"); - - let mut p = Player::default(); - assert!(!zone_is_settled(Some(&p)), "inactive avatar"); - - p.active = true; - p.settling = true; - assert!( - !zone_is_settled(Some(&p)), - "settling — the destination's terrain and WMOs are still arriving, so the leaf area \ - under the body is still moving" - ); - - p.settling = false; - assert!(zone_is_settled(Some(&p)), "settled: the zone is now final"); - } - #[test] fn leaving_the_world_ends_the_channel_session() { let mut channels = state(SEED); @@ -800,8 +837,7 @@ mod tests { joined("LocalDefense - Tanaris"), ]; let mut walk = ZoneChannelWalk { - at: Some(440), - zone_id: Some(440), + owed: false, live: true, }; let mut cascade = GuildRecruitmentCascade::default(); @@ -810,8 +846,7 @@ mod tests { // No VM in a unit test: the mirror leg is the one line this cannot reach. end_channel_session(None, &mut channels, &mut walk, &mut cascade); - assert_eq!(walk.at, None, "the next entry re-walks from scratch"); - assert_eq!(walk.zone_id, None); + assert!(walk.owed, "the next entry re-walks from scratch"); assert!(!walk.live); assert!( channels.joined.is_empty(), diff --git a/crates/benilla-app/src/ui_chat/recruitment.rs b/crates/benilla-app/src/ui_chat/recruitment.rs index 902c75c63..16160d3c7 100644 --- a/crates/benilla-app/src/ui_chat/recruitment.rs +++ b/crates/benilla-app/src/ui_chat/recruitment.rs @@ -18,7 +18,7 @@ use benilla_ui::script::RecruitmentPlan; use crate::area::AreaTableRes; use crate::net::{ObjectStore, SelfPlayer}; -use super::channels::{city_word, ZoneChannelWalk, AREA_FLAG_CAPITAL}; +use super::channels::{city_word, AREA_FLAG_CAPITAL}; use super::edit::ChannelState; /// The cascade's retry: the one-shot `[0xb6e5e4]` a run that cannot act arms (`0x49eaf5`, @@ -94,7 +94,7 @@ pub(crate) fn cascade(auto: bool, guild_id: u32, in_capital: bool) -> Option, areas: Option<&AreaTableRes>, ) -> RecruitmentPlan { // Wait for the chat-cache restore, which seats the latch and the mask. @@ -105,7 +105,7 @@ fn plan( let Some(areas) = areas else { return RecruitmentPlan::Retry; }; - let Some(row) = walk.zone_id.and_then(|id| areas.0.get(id)) else { + let Some(row) = zone.and_then(|id| areas.0.get(id)) else { return RecruitmentPlan::Retry; }; let action = cascade(true, guild_id, row.flags & AREA_FLAG_CAPITAL != 0); @@ -142,20 +142,20 @@ fn plan( pub(crate) struct RecruitmentLive<'w, 's> { me: Query<'w, 's, &'static ObjectStore, With>, channels: Option>, - walk: Option>, + committed: Option>, areas: Option>, } impl crate::script_calls::live::LiveFamily for RecruitmentLive<'_, '_> { fn answer(&mut self, ask: &mut benilla_ui::script::live::LiveAsk<'_>) -> bool { ask.answer(|_: &benilla_ui::script::RecruitmentPlanQuery| { - let (channels, walk) = (self.channels.as_deref()?, self.walk.as_deref()?); + let (channels, committed) = (self.channels.as_deref()?, self.committed.as_deref()?); // With no player object the cascade returns owing nothing (`0x49eac3`). Some(match self.me.iter().next() { Some(store) => plan( store.0.player_guild_id(), channels, - walk, + committed.0, self.areas.as_deref(), ), None => RecruitmentPlan::NoPlayer, diff --git a/crates/benilla-app/src/ui_chat/settings.rs b/crates/benilla-app/src/ui_chat/settings.rs index 6754b8152..3780d35ff 100644 --- a/crates/benilla-app/src/ui_chat/settings.rs +++ b/crates/benilla-app/src/ui_chat/settings.rs @@ -1509,9 +1509,7 @@ mod tests { ), ..Default::default() }); - world.insert_resource(super::super::channels::ZoneChannelWalk::walked_for_test( - ELWYNN, - )); + super::super::channels::ZoneChannelWalk::seat_for_test(&mut world, ELWYNN); world.insert_resource(crate::area::AreaTableRes( benilla_formats::AreaTableCatalog::from_rows(vec![( ELWYNN, @@ -1609,9 +1607,7 @@ mod tests { ]), ..Default::default() }); - world.insert_resource(super::super::channels::ZoneChannelWalk::walked_for_test( - STORMWIND, - )); + super::super::channels::ZoneChannelWalk::seat_for_test(world, STORMWIND); let row = |flags, name: &str| benilla_formats::AreaTableRow { map_id: 0, zone_id: 0, diff --git a/crates/benilla-app/src/ui_chat/slot_tests.rs b/crates/benilla-app/src/ui_chat/slot_tests.rs index b4e7e6261..8bdd8d338 100644 --- a/crates/benilla-app/src/ui_chat/slot_tests.rs +++ b/crates/benilla-app/src/ui_chat/slot_tests.rs @@ -490,8 +490,7 @@ fn unguilded_in_a_capital(c: &mut Client) { ]), )); c.world() - .resource_mut::() - .zone_id = Some(1519); + .insert_resource(crate::area::CommittedZone(Some(1519))); } /// `SetGuildRecruitmentMode(1)` runs the cascade inside the verb (`0x49ea7b` → `0x49eb55` → diff --git a/crates/benilla-app/src/ui_chat/walk_live_tests.rs b/crates/benilla-app/src/ui_chat/walk_live_tests.rs index 63106cc6b..03f212a2d 100644 --- a/crates/benilla-app/src/ui_chat/walk_live_tests.rs +++ b/crates/benilla-app/src/ui_chat/walk_live_tests.rs @@ -29,6 +29,9 @@ const WESTFALL: u32 = 40; const STORMWIND: u32 = 1519; /// The city word's row (`0x200`). const CITY: u32 = 3459; +/// An area whose row has no name, and one named as Elwynn in capitals. +const NAMELESS: u32 = 5000; +const SHOUTING: u32 = 5001; /// The client's world, driven a packet at a time through the dispatch, which fires each packet's /// lanes after its handlers, and the frame's end, the zone commit's poll. @@ -43,11 +46,12 @@ impl Client { let world = self.app.world_mut(); crate::net::handlers::dispatch(world, wire(packets)); crate::lanes::fire_in_order(world); - bevy::ecs::system::RunSystemOnce::run_system_once( - world, - super::channels::auto_join_zone_channels, - ) - .expect("the poll runs"); + // The poll's tenth tick (`0x5db906`). + for _ in 0..10 { + world + .run_system_cached(crate::area::feed_zone_events) + .expect("the poll runs"); + } } /// What went out, joins and leaves by name, emptied. @@ -107,6 +111,8 @@ fn client(zone: u32, held: Option<&[(u16, u32)]>) -> Client { (WESTFALL, row(0, "Westfall")), (STORMWIND, row(0x138, "Stormwind City")), (CITY, row(0x200, "City")), + (NAMELESS, row(0, "")), + (SHOUTING, row(0, "ELWYNN FOREST")), ]), )); let catalog = benilla_formats::ChatChannelsCatalog::from_rows( @@ -126,12 +132,22 @@ fn client(zone: u32, held: Option<&[(u16, u32)]>) -> Client { ) .collect(), ); + // The zone's channels already joined, as the first commit's walk finds them. + let zone_name = ["Elwynn Forest", "Westfall", "Stormwind City"][match zone { + ELWYNN => 0, + WESTFALL => 1, + _ => 2, + }]; world.insert_resource(ChannelState { channels: catalog, zone_mask: Some(1 | 1 << 21), + joined: vec![ + ChannelSlot::confirmed(&format!("General - {zone_name}"), 1).into(), + ChannelSlot::confirmed(&format!("LocalDefense - {zone_name}"), 22).into(), + ], ..Default::default() }); - world.insert_resource(ZoneChannelWalk::walked_for_test(zone)); + ZoneChannelWalk::seat_for_test(world, zone); world.resource_mut::().0 = Some(ME); if let Some(fields) = held { crate::test_support::hold_self_player(world, ME, fields); @@ -341,6 +357,220 @@ fn our_create_runs_the_cascade_inside_its_packet() { r#"table.insert(Heard, tostring((GetChannelName("GuildRecruitment - City"))))"#, ); c.frame(vec![vec![created()], combo(2)]); - assert_eq!(c.heard(), ["1"]); + assert_eq!(c.heard(), ["3"], "after General and LocalDefense"); assert_eq!(c.wire(), ["join GuildRecruitment - City"]); } + +/// The poll's ticks (`0x5db900`), the tenth committing. +fn tick(c: &mut Client, n: usize) { + for _ in 0..n { + c.app + .world_mut() + .run_system_cached(crate::area::feed_zone_events) + .expect("the feed runs"); + } +} + +/// Elwynn committed and walked, its slots joined, the wire empty. +fn settled_in_elwynn() -> Client { + let mut c = client(ELWYNN, Some(&[])); + c.channels().joined = vec![ + ChannelSlot::confirmed("General - Elwynn Forest", 1).into(), + ChannelSlot::confirmed("LocalDefense - Elwynn Forest", 22).into(), + ]; + tick(&mut c, 10); + c.wire(); + c +} + +fn stand_in(c: &mut Client, area: u32) { + c.app + .world_mut() + .insert_resource(benilla_world::terrain_stream::CurrentArea(Some(area))); +} + +/// The walk is `UpdateZoneText`'s (`0x494931`), run by the poll's tenth tick: a zone line crossed +/// and crossed back between two polls changes nothing on the wire. +#[test] +fn a_zone_line_crossed_and_back_between_polls_walks_nothing() { + let mut c = settled_in_elwynn(); + stand_in(&mut c, WESTFALL); + tick(&mut c, 3); + stand_in(&mut c, ELWYNN); + tick(&mut c, 7); + assert!(c.wire().is_empty(), "the poll saw Elwynn both times"); +} + +/// The channels change at the commit's tick, not on the frame the area moved. +#[test] +fn the_walk_runs_at_the_commits_tick_not_before_it() { + let mut c = settled_in_elwynn(); + stand_in(&mut c, WESTFALL); + tick(&mut c, 9); + assert!(c.wire().is_empty(), "nine ticks return"); + tick(&mut c, 1); + assert_eq!( + c.wire(), + [ + "leave General - Elwynn Forest", + "join General - Westfall", + "leave LocalDefense - Elwynn Forest", + "join LocalDefense - Westfall", + ] + ); +} + +/// An area with no row commits nothing (the commit keeps the last zone), so the zone +/// stays walked and the guild-recruitment cascade reads the last zone's row (`0x49ead7`). +#[test] +fn an_area_with_no_row_keeps_the_last_zone_and_the_cascade_reads_it() { + let mut c = client(STORMWIND, Some(&[])); + crate::script_calls::with_hosted_vm(c.app.world_mut(), |s| { + s.expect("a VM").set_guild_recruitment_mode(0); + }); + tick(&mut c, 10); + c.wire(); + stand_in(&mut c, 4242); + tick(&mut c, 10); + assert!(c.wire().is_empty(), "no row, no walk"); + crate::script_calls::with_hosted_vm(c.app.world_mut(), |s| { + s.expect("a VM") + .run("SetGuildRecruitmentMode(1)") + .expect("the verb") + }); + assert_eq!( + c.wire(), + ["join GuildRecruitment - City"], + "the cascade finds Stormwind, a capital, committed" + ); +} + +/// The walk comes before the commit's `ZONE_CHANGED_NEW_AREA` (`0x494931` before `0x49493f`): its +/// listener finds the renamed slot. +#[test] +fn the_walk_runs_before_the_commits_new_area_listeners() { + let mut c = settled_in_elwynn(); + crate::script_calls::with_hosted_vm(c.app.world_mut(), |s| { + s.expect("a VM") + .run( + r#" + local f = CreateFrame("Frame") + f:RegisterEvent("ZONE_CHANGED_NEW_AREA") + f:SetScript("OnEvent", function() + table.insert(Heard, tostring((GetChannelName("General - Westfall")))) + end) + "#, + ) + .expect("the listener") + }); + tick(&mut c, 9); + stand_in(&mut c, WESTFALL); + tick(&mut c, 1); + assert_eq!(c.heard(), ["1"]); +} + +const WESTFALL_WALK: [&str; 4] = [ + "leave General - Elwynn Forest", + "join General - Westfall", + "leave LocalDefense - Elwynn Forest", + "join LocalDefense - Westfall", +]; + +/// A cinematic running (`0x49491c`) or latched (`0x494928` → `0x5efc90`) holds the commit's walk +/// off; the commit still stores the zone, and EndCinematic's walk (`0x48f1d0`) walks it. +#[test] +fn a_cinematic_holds_the_commits_walk_and_its_end_walks_the_committed_zone() { + for held in [ + crate::cinematic::Cinematic::playing_for_test(), + crate::cinematic::Cinematic::pending_for_test(41), + ] { + let mut c = settled_in_elwynn(); + c.app.world_mut().insert_resource(held); + stand_in(&mut c, WESTFALL); + tick(&mut c, 10); + assert!(c.wire().is_empty(), "no walk under a cinematic"); + assert_eq!( + c.app.world().resource::().0, + Some(WESTFALL), + "the zone is stored all the same" + ); + c.app + .world_mut() + .insert_resource(crate::cinematic::Cinematic::ended_for_test()); + c.app + .world_mut() + .run_system_cached(super::channels::walk_when_cinematic_ends) + .expect("the end walk runs"); + assert_eq!( + c.wire(), + WESTFALL_WALK, + "EndCinematic walks the stored zone" + ); + } +} + +/// A reload builds a new VM and keeps the stored zone and the real zone text (`0xb4b404`, +/// `0x495664` → `0x490bd0`): its first commit finds no change, so it walks nothing. +#[test] +fn a_reload_keeps_the_real_zone_text_and_walks_nothing() { + let mut c = settled_in_elwynn(); + c.channels().joined = vec![ChannelSlot::confirmed("General - Stale", 1).into()]; + c.app + .world_mut() + .insert_non_send_resource(UiScript::new().expect("a VM")); + tick(&mut c, 10); + assert!(c.wire().is_empty(), "Elwynn was walked before the reload"); +} + +/// An empty name leaves the real zone text as it was (`0x49489a` → `0x494936`), so the next +/// name is compared with the one before it, ignoring case (`0x64a4c0`). +#[test] +fn an_empty_or_recased_name_walks_nothing() { + let mut c = settled_in_elwynn(); + // Stale names, so that any walk shows on the wire. + c.channels().joined = vec![ChannelSlot::confirmed("General - Stale", 1).into()]; + stand_in(&mut c, NAMELESS); + tick(&mut c, 10); + stand_in(&mut c, ELWYNN); + tick(&mut c, 10); + assert!(c.wire().is_empty(), "Elwynn again after an unnamed zone"); + stand_in(&mut c, SHOUTING); + tick(&mut c, 10); + assert!(c.wire().is_empty(), "the same name in capitals"); +} + +/// A hit group the indoor dedup passes never reaches `0x494780` (`0x67e510`): the zone is not +/// stored. +#[test] +fn the_indoor_dedup_stores_no_zone() { + use benilla_world::wmo_portal::{CurrentAreaInterior, WmoInteriorKeys}; + let mut c = settled_in_elwynn(); + let keys = WmoInteriorKeys { + wmo_id: 1, + name_set: 0, + group_area_id: 7, + }; + let room = benilla_formats::WmoArea { + id: 1, + sound_provider: [0; 2], + ambience: 0, + zone_music: 0, + intro_sound: 0, + area_table_id: 0, + name: String::new(), + }; + let world = c.app.world_mut(); + benilla_world::wmo_portal::seat_wmo_areas( + world, + benilla_formats::WmoAreaCatalog::from_rows([(1, 0, 7, room)]), + ); + world.insert_resource(CurrentAreaInterior(Some(keys))); + tick(&mut c, 10); + stand_in(&mut c, WESTFALL); + tick(&mut c, 10); + assert_eq!( + c.app.world().resource::().0, + Some(ELWYNN), + "the same room: the update is skipped" + ); +} diff --git a/crates/benilla-app/src/vm_pass.rs b/crates/benilla-app/src/vm_pass.rs index 5ceee9f66..b394c30e2 100644 --- a/crates/benilla-app/src/vm_pass.rs +++ b/crates/benilla-app/src/vm_pass.rs @@ -1121,22 +1121,4 @@ mod tests { "the CVar callbacks run after the look session reads their knobs" ); } - - /// The stream focus's publish and the post-snap hold's release, which write the player's - /// settle state the hosts read, run among the hosts in the world's order (after the input - /// stage, around the stream), so a host after them reads this frame's: the zone channels' - /// walk, whose gate reads it, runs after the release. - #[test] - fn the_settle_state_is_published_before_its_readers() { - let app = headless_client(); - let Some(order) = pass_order(&app) else { - return; - }; - let at = |name: &str| at(&order, name); - let release = at("::release_post_snap_hold"); - assert!( - at("::publish_view_focus") < release && release < at("::auto_join_zone_channels"), - "{order:?}" - ); - } } diff --git a/crates/benilla-world/src/wmo_portal/interior.rs b/crates/benilla-world/src/wmo_portal/interior.rs index 364ddae68..f31f61ccb 100644 --- a/crates/benilla-world/src/wmo_portal/interior.rs +++ b/crates/benilla-world/src/wmo_portal/interior.rs @@ -11,6 +11,11 @@ use bevy::prelude::*; #[derive(Resource)] pub(crate) struct WmoAreas(pub(crate) benilla_formats::WmoAreaCatalog); +/// Seat `catalog` as the `WMOAreaTable` catalog, for a harness that runs without an install. +pub fn seat_wmo_areas(world: &mut World, catalog: benilla_formats::WmoAreaCatalog) { + world.insert_resource(WmoAreas(catalog)); +} + pub(super) fn load_wmo_areas( mut commands: Commands, assets: Option>, diff --git a/crates/benilla-world/src/wmo_portal/mod.rs b/crates/benilla-world/src/wmo_portal/mod.rs index 19214c241..9862812de 100644 --- a/crates/benilla-world/src/wmo_portal/mod.rs +++ b/crates/benilla-world/src/wmo_portal/mod.rs @@ -28,7 +28,7 @@ mod seed; use fog::select_wmo_fog; pub use fog::{CameraWmoFog, WmoFogTarget}; pub use interior::{ - indoor_verdict_at, indoors_at, terrain_z_local, IndoorVerdict, LightAttach, + indoor_verdict_at, indoors_at, seat_wmo_areas, terrain_z_local, IndoorVerdict, LightAttach, INTERIOR_PROBE_HEIGHT, }; pub(crate) use interior::{surface_terrain_sample, WmoAreas, POSITION_PROBE_LIFT}; diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md index 44f223140..55ffe2a8e 100644 --- a/docs/DEVIATIONS.md +++ b/docs/DEVIATIONS.md @@ -29,7 +29,7 @@ A setting boots at the reference's default unless it is listed here (`docs/METHO Each entry is the first sentence of a `Deviation:` comment, linking to where it lives. -- [benilla-app](#benilla-app): 251 +- [benilla-app](#benilla-app): 252 - [benilla-assets](#benilla-assets): 6 - [benilla-blp](#benilla-blp): 1 - [benilla-formats](#benilla-formats): 24 @@ -98,7 +98,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it #### cinematic -- Bevy UI nodes computed per frame, not `CinematicFrame.xml`'s textures, because that way a window resized mid-cinematic stays letterboxed. `CinematicFrame` still shows and owns ESC. ([`src/cinematic.rs:187`](../crates/benilla-app/src/cinematic.rs#L187)) +- Bevy UI nodes computed per frame, not `CinematicFrame.xml`'s textures, because that way a window resized mid-cinematic stays letterboxed. `CinematicFrame` still shows and owns ESC. ([`src/cinematic.rs:204`](../crates/benilla-app/src/cinematic.rs#L204)) #### combat_text @@ -315,9 +315,10 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it #### ui_chat -- Not run on benilla's same-character reconnect, which the reference lacks (it returns to the login screen), because that way the window keeps its scrollback there. ([`src/ui_chat.rs:266`](../crates/benilla-app/src/ui_chat.rs#L266)) +- Not run on benilla's same-character reconnect, which the reference lacks (it returns to the login screen), because that way the window keeps its scrollback there. ([`src/ui_chat.rs:267`](../crates/benilla-app/src/ui_chat.rs#L267)) - A missing global prints nothing, where the reference prints an empty line (`0x703c02`), because benilla's other `DisplayError` routes do the same. ([`src/ui_chat/broadcast.rs:167`](../crates/benilla-app/src/ui_chat/broadcast.rs#L167)) -- In a capital with a blank city word the walk composes `"Trade - "` (it tests the row pointer, not the string, `0x49a2e4`-`0x49a2ed`); we decline, because a wrong channel name is joined silently and for good. ([`src/ui_chat/channels.rs:157`](../crates/benilla-app/src/ui_chat/channels.rs#L157)) +- A dropped link re-enters the world in this session, where the reference logs in anew, because of benilla's same-character reconnect, which the reference lacks. ([`src/ui_chat/channels.rs:49`](../crates/benilla-app/src/ui_chat/channels.rs#L49)) +- In a capital with a blank city word the walk composes `"Trade - "` (it tests the row pointer, not the string, `0x49a2e4`-`0x49a2ed`); we decline, because a wrong channel name is joined silently and for good. ([`src/ui_chat/channels.rs:160`](../crates/benilla-app/src/ui_chat/channels.rs#L160)) - The reference holds every line that waits on its `$`-macro subject's name in the name cache's callback list (`0x49daea` → `0x55f080`) until the name answers, with no bound; here at most `MAX_HELD_SUBJECT_LINES` wait, the oldest dropped past that, because a subject no player owns never answers. ([`src/ui_chat/feed.rs:396`](../crates/benilla-app/src/ui_chat/feed.rs#L396)) - A probe's bare `/assist` assists the live selection, `AssistByName("")` (`0x489c89`), where the stock handler (`ChatFrame.lua:740`) resolves a selected player's name through `AssistByName`, because a name resolve can land on a different player. ([`src/ui_chat/input/mod.rs:594`](../crates/benilla-app/src/ui_chat/input/mod.rs#L594)) - A line of 256 bytes or more, which reaches here only through `chat_send`'s deviation for `0x49f604`, is slurred whole instead of cut to that buffer, because that way it reaches the server whole for the refusal that deviation leaves to it. ([`src/ui_chat/input/send.rs:305`](../crates/benilla-app/src/ui_chat/input/send.rs#L305))