From 395974a2fc30e50787a1d2fdeda1615af574aa26 Mon Sep 17 00:00:00 2001 From: Sam Sung <51686767+samwhosung@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:53:41 +0700 Subject: [PATCH] Lane guard names the flip's bar; login cache clears run in the handler (#2698) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first two pieces of the event-core move (#2168, #2217). - The lane guard now states what firing each packet's events inside the dispatch needs. Its old in-between list splits into the obstacles and the rows that are right after the packets in 1.12.1. Frame time runs after the packets (`0x420d63` after `0x420d55`), but a unit's arrival snap is written inside the packet (`0x7c6420`). A new list holds every placed-queue reader that pushes a lane, and `flip_readiness` prints what is left. - The login's cache clears run inside the login handler, before the world's first packet, as `DBCacheClearUnsaved` does at `0x48f586`. Before, a name asked by a later packet in the login frame was asked twice. Each list's test fails on a new or stale row, and the login test fails on main. Part of #2168 Part of #2217 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 --- crates/benilla-app/src/lanes/guard_tests.rs | 305 +++++++++++++----- .../benilla-app/src/lanes/host_read_tests.rs | 229 ++++++++----- crates/benilla-app/src/net.rs | 2 +- crates/benilla-app/src/net/session.rs | 59 ++++ crates/benilla-app/src/query_cache.rs | 43 ++- 5 files changed, 463 insertions(+), 175 deletions(-) diff --git a/crates/benilla-app/src/lanes/guard_tests.rs b/crates/benilla-app/src/lanes/guard_tests.rs index 92f2e8e3e..287ebd533 100644 --- a/crates/benilla-app/src/lanes/guard_tests.rs +++ b/crates/benilla-app/src/lanes/guard_tests.rs @@ -23,7 +23,7 @@ fn headless_client() -> App { /// What a row names. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum Row { +pub(super) enum Row { /// A queue the handlers fill that a feed of the `UiFeed` phase takes and fires itself, by a /// suffix of its type's name. Queue, @@ -44,7 +44,7 @@ enum Row { /// What still fires in the frame's system order rather than the packets', with what it is. A /// queue's row stays while any feed takes that queue; each goes when its producer moves onto a /// lane, and a row whose queue, feed or system is gone fails as stale. -const NOT_YET_ON_A_LANE: &[(Row, &str, &str)] = &[ +pub(super) const NOT_YET_ON_A_LANE: &[(Row, &str, &str)] = &[ ( Row::Queue, "::account_data::AccountData", @@ -218,7 +218,7 @@ const NOT_YET_ON_A_LANE: &[(Row, &str, &str)] = &[ /// raised. Each goes once its feeds are read, to a [`Row::HostHeld`] row when one does, or named /// quiet beside why when none does; a new one fails, and an entry whose queue the handlers or the /// host no longer hold fails as stale. -const HOST_HELD_UNREAD: &[&str] = &[ +pub(super) const HOST_HELD_UNREAD: &[&str] = &[ "::creature_anim::AttackStopInFlight", "::creature_anim::PlaySeq", // Read through the host by the set block, and quiet: a member's answer rebuilds the tooltip @@ -1150,7 +1150,8 @@ fn every_handler_queue_a_feed_takes_is_on_a_lane_or_listed() { /// The handler queues whose items carry their place among what the packets queued, so a system /// that pushes onto a lane off one pushes at the item's place, not its own: the field edges' /// `at`, and the aura watcher's calls'. A wrong entry lets a system that pushes at its own place, -/// behind every packet of the frame, pass [`every_lane_push_off_a_handler_queue_keeps_its_place`]. +/// behind every packet of the frame, pass [`every_lane_push_off_a_handler_queue_keeps_its_place`]; +/// their readers that push are [`PLACED_OUTSIDE_THE_DISPATCH`]'s. fn placed_queues() -> [TypeId; 2] { [ TypeId::of::>(), @@ -1180,21 +1181,11 @@ const AT_THEIR_OWN_PLACE: &[(&str, &str)] = &[ "::ui_chat::channels::end_session_channels_on_disconnect", "a dead socket ends the channel session, and no packet follows it", ), - ( - "::query_cache::release_on_enter", - "the world entry forgets the guild cache's in-flight asks, so each is asked again \ - (`0x5557c0`): it queues nothing", - ), - ( - "::query_cache::release_on_enter", - "the world entry forgets the quest cache's in-flight asks, so each is asked again \ - (`0x5557c0`): it queues nothing", - ), ]; /// The systems outside the phase that lend the call host and take a handler queue, firing off it /// in system order: remaining work, which only shrinks, by a suffix of the system's name. -const NOT_YET_PLACED: &[(&str, &str)] = &[ +pub(super) const NOT_YET_PLACED: &[(&str, &str)] = &[ ( "::swing_refusal::apply_swing_refusals", "the server's swing stop `0x5ecac0`, `CancelNextSwingSpells` (`0x6e6f30`) and the \ @@ -1213,83 +1204,177 @@ const NOT_YET_PLACED: &[(&str, &str)] = &[ ), ]; +/// The systems that take a placed queue ([`placed_queues`]) after the dispatch and push onto a +/// lane, at the item's place or, from their commands, at their own, by a suffix of the system's +/// name: remaining work, which only shrinks. The order of those at the item's place holds today, +/// as the drain fires the whole frame by stamp after them; once +/// the dispatch fires each packet's lanes after its handlers, an item stamped at an earlier +/// packet and pushed after the dispatch fires behind every later packet's. The reference runs +/// each of these inside the update packet's notify pass (`0x465277` → `0x465330`). +pub(super) const PLACED_OUTSIDE_THE_DISPATCH: &[(&str, &str)] = &[ + ( + "::ui_chat::combat::watch::aura_lines", + "the combat log's aura lines, which the aura watchers write (`0x604d00`, `0x604ea0`)", + ), + ( + "::ui_chat::combat::watch::death_lines", + "the unit-death line, which the health watcher writes (`0x6046f0` → `0x625190`)", + ), + ( + "::ui_chat::combat::watch::pet_loyalty_lines", + "the pet-loyalty line, which the loyalty watcher writes (`0x5ff860`)", + ), + ( + "::ui_pet::unit::feed_pet_unit", + "the pet's rename, `LOCALPLAYER_PET_RENAMED`, off its name stamp's edge", + ), + ( + "::ui_session::release::release_on_field_edges", + "the form change's latch release and the lost service flags' closes, run from its \ + commands at its own place, behind every packet of the frame", + ), +]; + +/// The placed queues' readers that defer work to their commands and push nothing onto a lane +/// from them, by a suffix of the system's name, with what the commands do. +const DEFERS_NO_LANE_ITEM: &[(&str, &str)] = &[ + ( + "::creature_anim::spell_visual::arm_aura_state_fx", + "removes and inserts the aura state kit's pins, which no script reads", + ), + ( + "::go_anim::drive_go_collision", + "turns an object's collider off and on, which no script reads", + ), +]; + +/// What [`lane_pushes_off_handler_queues`] finds, each a system's name with its line. +struct LanePushes { + /// Off a queue whose items carry no place: pushed at the system's own place. + unplaced: BTreeSet<(String, String)>, + /// Off a [`placed_queues`] queue: pushed at the item's place, after the dispatch. + placed: BTreeSet<(String, String)>, + /// A [`placed_queues`] queue's readers that push no lane themselves and defer work to their + /// commands, which may. + deferring: BTreeSet<(String, String)>, +} + +/// Every system of `Update` that takes a handler queue and pushes onto a lane; `None` in a build +/// that carries no type names. +fn lane_pushes_off_handler_queues() -> Option { + let mut app = headless_client(); + let caches = census(&mut headless_client(), Update, SyncPoints::Declared) + .classes + .caches; + let queues = handler_queues(app.world(), &caches); + let (pushes, placed_pushes, deferring, systems) = + app.world_mut().schedule_scope(Update, |world, schedule| { + schedule.graph_mut().systems.initialize(world); + let host = call_host_access(world); + let id = |t: TypeId| world.components().get_resource_id(t); + let vm = id(TypeId::of::()); + let lanes: Vec = lane_types().into_iter().filter_map(id).collect(); + // The chat lane is pushed through a shared reference, the others through a write. + let chat = id(TypeId::of::()); + let pushes_onto = |access: &bevy::ecs::query::Access, lane: ComponentId| { + if Some(lane) == chat { + access.has_resource_read(lane) + } else { + access.has_resource_write(lane) + } + }; + let placed: Vec = placed_queues().into_iter().filter_map(id).collect(); + let graph = schedule.graph(); + let mut pushes = BTreeSet::new(); + let mut placed_pushes = BTreeSet::new(); + let mut deferring = BTreeSet::new(); + let mut systems = BTreeSet::new(); + for (key, system, _) in graph.systems.iter() { + systems.insert(system.name().to_string()); + let Some(with_access) = graph.systems.get(key) else { + continue; + }; + let access = with_access.access.combined_access(); + let fires = vm.is_some_and(|vm| access.has_resource_write(vm)); + if system.is_exclusive() { + continue; + } + let name = system.name().to_string(); + let pushes_a_lane = lanes.iter().any(|&l| pushes_onto(access, l)); + // A placed queue's reader pushes at the item's place wherever it runs, so every one + // that pushes counts, a feed of the phase among them; one that defers its work to + // its commands may push from them, which its access does not show. + for &q in &placed { + if access.has_resource_read(q) + && !access.has_resource_write(q) + && !host.has_resource_read(q) + { + let n = self::name(world, q); + if pushes_a_lane { + placed_pushes.insert((name.clone(), format!("{name} takes {n}"))); + } else if system.has_deferred() { + deferring.insert((name.clone(), format!("{name} defers off {n}"))); + } + } + } + if !pushes_a_lane { + continue; + } + // A feed of the phase that fires is the other guard's, and an exclusive one is its + // row; a system that lends the call host outside the phase is judged here, by the + // queues it reads: a plain resource it writes is its verbs' own state. + if fires && in_feed(graph, bevy::ecs::schedule::NodeId::System(key)) { + continue; + } + let lends = host.is_subset_resources(access); + for &q in &queues { + if Some(q) == vm || lanes.contains(&q) || placed.contains(&q) { + continue; + } + let n = self::name(world, q); + // The host's own state is what a call touches, never a queue taken. + let takes = if ends_with_any(&n, FILLED_THROUGH_A_READ) { + access.has_resource_read(q) && !host.has_resource_read(q) + } else if is_messages(world, q) { + access.has_resource_read(q) + && !access.has_resource_write(q) + && !host.has_resource_read(q) + } else { + !lends + && access.has_resource_write(q) + && !host.has_resource_read(q) + && !host.has_resource_write(q) + }; + if takes { + pushes.insert((name.clone(), format!("{name} takes {n}"))); + } + } + } + (pushes, placed_pushes, deferring, systems) + }); + systems + .iter() + .any(|n| n.contains("benilla_app::")) + .then_some(LanePushes { + unplaced: pushes, + placed: placed_pushes, + deferring, + }) +} + /// A system of any phase that takes a handler queue and pushes onto a lane stamps the push where /// it runs, behind every packet of the frame, unless the queue's items carry their place /// ([`placed_queues`]). Each such system needs a row in [`AT_THEIR_OWN_PLACE`] or /// [`NOT_YET_PLACED`]. #[test] fn every_lane_push_off_a_handler_queue_keeps_its_place() { - let mut app = headless_client(); - let caches = census(&mut headless_client(), Update, SyncPoints::Declared) - .classes - .caches; - let queues = handler_queues(app.world(), &caches); - let (pushes, systems) = app.world_mut().schedule_scope(Update, |world, schedule| { - schedule.graph_mut().systems.initialize(world); - let host = call_host_access(world); - let id = |t: TypeId| world.components().get_resource_id(t); - let vm = id(TypeId::of::()); - let lanes: Vec = lane_types().into_iter().filter_map(id).collect(); - // The chat lane is pushed through a shared reference, the others through a write. - let chat = id(TypeId::of::()); - let pushes_onto = |access: &bevy::ecs::query::Access, lane: ComponentId| { - if Some(lane) == chat { - access.has_resource_read(lane) - } else { - access.has_resource_write(lane) - } - }; - let placed: Vec = placed_queues().into_iter().filter_map(id).collect(); - let graph = schedule.graph(); - let mut pushes = BTreeSet::new(); - let mut systems = BTreeSet::new(); - for (key, system, _) in graph.systems.iter() { - systems.insert(system.name().to_string()); - let Some(with_access) = graph.systems.get(key) else { - continue; - }; - let access = with_access.access.combined_access(); - let fires = vm.is_some_and(|vm| access.has_resource_write(vm)); - // A feed of the phase that fires is the other guard's, and an exclusive one is its - // row; a system that lends the call host outside the phase is judged here, by the - // queues it reads: a plain resource it writes is its verbs' own state. - if system.is_exclusive() - || (fires && in_feed(graph, bevy::ecs::schedule::NodeId::System(key))) - || !lanes.iter().any(|&l| pushes_onto(access, l)) - { - continue; - } - let name = system.name().to_string(); - let lends = host.is_subset_resources(access); - for &q in &queues { - if Some(q) == vm || lanes.contains(&q) || placed.contains(&q) { - continue; - } - let n = self::name(world, q); - // The host's own state is what a call touches, never a queue taken. - let takes = if ends_with_any(&n, FILLED_THROUGH_A_READ) { - access.has_resource_read(q) && !host.has_resource_read(q) - } else if is_messages(world, q) { - access.has_resource_read(q) - && !access.has_resource_write(q) - && !host.has_resource_read(q) - } else { - !lends - && access.has_resource_write(q) - && !host.has_resource_read(q) - && !host.has_resource_write(q) - }; - if takes { - pushes.insert((name.clone(), format!("{name} takes {n}"))); - } - } - } - (pushes, systems) - }); - if !systems.iter().any(|n| n.contains("benilla_app::")) { + let Some(LanePushes { + unplaced: pushes, .. + }) = lane_pushes_off_handler_queues() + else { eprintln!("skipped: this build carries no type names"); return; - } + }; let rows: Vec<&str> = AT_THEIR_OWN_PLACE .iter() .chain(NOT_YET_PLACED) @@ -1317,6 +1402,56 @@ fn every_lane_push_off_a_handler_queue_keeps_its_place() { assert!(stale.is_empty(), "stale rows: {stale:?}"); } +/// Every system that takes a placed queue and pushes onto a lane outside the dispatch has its row +/// in [`PLACED_OUTSIDE_THE_DISPATCH`], found as +/// [`every_lane_push_off_a_handler_queue_keeps_its_place`] finds pushes, without its exemption +/// of the placed queues; a row whose system no longer does is stale. +#[test] +fn every_lane_push_off_a_placed_queue_is_listed() { + let Some(LanePushes { + mut placed, + deferring, + .. + }) = lane_pushes_off_handler_queues() + else { + eprintln!("skipped: this build carries no type names"); + return; + }; + let quiet: Vec<&str> = DEFERS_NO_LANE_ITEM.iter().map(|(s, _)| *s).collect(); + let gone: Vec<&str> = quiet + .iter() + .copied() + .filter(|s| !deferring.iter().any(|(system, _)| system.ends_with(s))) + .collect(); + assert!(gone.is_empty(), "stale DEFERS_NO_LANE_ITEM rows: {gone:?}"); + placed.extend( + deferring + .into_iter() + .filter(|(system, _)| !ends_with_any(system, &quiet)), + ); + let rows: Vec<&str> = PLACED_OUTSIDE_THE_DISPATCH + .iter() + .map(|(s, _)| *s) + .collect(); + let unlisted: Vec<&str> = placed + .iter() + .filter(|(system, _)| !ends_with_any(system, &rows)) + .map(|(_, line)| line.as_str()) + .collect(); + assert!( + unlisted.is_empty(), + "these push onto a lane off a placed queue after the dispatch, or defer to commands that \ + may: push from the handler's notify step instead, or give the system a row in \ + PLACED_OUTSIDE_THE_DISPATCH, or in DEFERS_NO_LANE_ITEM when its commands push none:\n {}", + unlisted.join("\n ") + ); + let stale: Vec<&str> = rows + .into_iter() + .filter(|s| !placed.iter().any(|(system, _)| system.ends_with(s))) + .collect(); + assert!(stale.is_empty(), "stale rows: {stale:?}"); +} + /// The drain is exclusive, so bevy lists its pairs with every system no declared order places /// against it with no component. What those systems meet of the drain's (its lanes' firings' /// access, and the unit edits it applies in place after each: every component a change writes, @@ -1600,7 +1735,7 @@ const VERSIONED_FOR_THE_DRAIN: &[&str] = &["net::reputations::Reputations"]; /// only shrinks: a read goes once a log versions it ([`crate::ui_unit::views`]), and a row that no /// longer matches its firing fails. #[rustfmt::skip] -const LANE_READS_FRAME_FINAL: &[(&str, &[&str])] = &[ +pub(super) const LANE_READS_FRAME_FINAL: &[(&str, &[&str])] = &[ // The chat setup's restore reads the channel rows its shortcuts and auto-joins come from as // the frame left them, past the notices of the packets after the section's. ("chat setup arrivals", &["ui_chat::edit::ChannelState"]), diff --git a/crates/benilla-app/src/lanes/host_read_tests.rs b/crates/benilla-app/src/lanes/host_read_tests.rs index 55c5466d0..a8f2d433e 100644 --- a/crates/benilla-app/src/lanes/host_read_tests.rs +++ b/crates/benilla-app/src/lanes/host_read_tests.rs @@ -1,16 +1,29 @@ //! The readiness guard for firing each packet's lanes inside the net dispatch, after its handlers, //! with the host lent: the reference's handler signals inside itself (`0x703e50`) and runs whole //! before the next packet's (`0x537ae5`), so a listener reads the live state its packet left and -//! its sends go out in packet order. That move is right only once a lane's listener reads nothing -//! a later system of the frame writes or pushes, which two lists name, each the whole of that -//! remaining work and only shrinking; the move needs both empty. +//! its sends go out in packet order. That move is right once five lists are empty, each the whole +//! of its remaining work and only shrinking; [`flip_readiness`] prints where they stand. //! -//! - The feeds that push a view of what a handler writes, which a getter reads in place of the -//! live state through the host: [`super::guard_tests::READS_FRAME_FINAL`], held here to its -//! count. A family's getters going live ([`crate::script_calls::live`]) drops its feed's row. -//! - [`BETWEEN_THE_DISPATCH_AND_THE_DRAIN`]: the systems that may run after the dispatch and -//! ahead of the drain and write what the host's live reads read, or push a view the drain waits -//! for. +//! - [`super::guard_tests::READS_FRAME_FINAL`], held here to its count: the feeds that push a +//! view of what a handler writes, which a getter reads in place of the live state. A family's +//! getters going live ([`crate::script_calls::live`]) drops its feed's row. +//! - [`BETWEEN_THE_DISPATCH_AND_THE_DRAIN`]: the systems after the dispatch and ahead of the drain +//! that write what the host's live reads read, or push a view the drain waits for, where the +//! reference writes inside a packet. A listener fired inside the dispatch would read each as the +//! frame before left it. The writers the reference too runs after the packets, and those no +//! listener can see, are [`AFTER_THE_PACKETS_IN_THE_REFERENCE`]'s, which stays. +//! - [`super::guard_tests::NOT_YET_ON_A_LANE`]: what fires off a handler's queue or edge from a +//! feed, ahead of every lane. Once the lanes fire inside the dispatch, each such event moves +//! from ahead of every packet event of its frame to behind them all. +//! - [`super::guard_tests::NOT_YET_PLACED`]: the systems outside the phase that fire off a +//! handler queue in system order. +//! - [`super::guard_tests::PLACED_OUTSIDE_THE_DISPATCH`]: the systems that push lane items off a +//! placed queue's field edges after the dispatch, at the edge's earlier stamp, which the +//! dispatch's own firing would already have passed, or at their own. +//! +//! [`super::guard_tests::LANE_READS_FRAME_FINAL`] empties at the flip itself, which makes the +//! world a lane firing reads its packet's, and every entry of +//! [`super::guard_tests::HOST_HELD_UNREAD`] is read first, as quiet or as a row of its own. use std::any::TypeId; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; @@ -29,8 +42,11 @@ const FRAME_FINAL_INPUTS: usize = 237; /// The systems that may run after the dispatch (`apply_net_updates`) and run ahead of the drain /// (`fire_in_order`), by a suffix of the system's name, with what each writes of the host's live -/// reads ([`crate::script_calls::live::LiveReads`]), by its name in the crate, and why. A listener -/// fired inside the dispatch would read each of these as the frame before left it. `UiScript` +/// reads ([`crate::script_calls::live::LiveReads`]), by its name in the crate, and why: the +/// obstacles to the flip, each a write the reference makes inside a packet, or a view pushed in +/// its place. A listener fired inside the dispatch would read each of these as the frame before +/// left it. The writers the reference also runs after the packets are +/// [`AFTER_THE_PACKETS_IN_THE_REFERENCE`]'s, not these. `UiScript` /// names a view the drain waits for ([`crate::ui_unit::field_events::FieldEventPushes`]); /// `Commands` names a component a system filters out and may add with its commands, which /// access does not show; `exclusive` a system whose access Bevy does not report. @@ -39,37 +55,11 @@ const BETWEEN_THE_DISPATCH_AND_THE_DRAIN: &[(&str, &[&str], &str)] = &[ ("::net::apply::tag_self_player", &["Commands net::SelfPlayer"], "tags our created entity as the player, which the token resolver finds it by; the \ reference makes it the active player inside its create (`0x5dea50`)"), - ("::net::motion::facing::drive_display_facing", &["Transform"], - "turns the units' models toward their facing each frame; the range verbs read the \ - translation alone, which this leaves"), ("::net::motion::remote::extrapolate_remote_units", &["Transform"], - "advances the remote units along their last movement each frame, the positions the range \ - verbs measure, outside any packet's handler"), - ("::net::motion::spline::ground_clamp_creatures", &["Transform"], - "settles the creatures on the ground each frame, the height the range verbs measure, \ - outside any packet's handler"), - ("::net::motion::spline::sample_splines", &["Transform"], - "moves the units along their splines each frame, the positions the range verbs measure, \ - outside any packet's handler"), + "the arrival snap `0x7c6420` (`0x618dfc`) is written inside the packet"), ("::player::wire_in::regain_control_on_arrival", &["player::state::OwnControlLost"], "gives control back on our own create, which the stance bar's usability walk reads \ (`0x6e3dc3`); the reference raises it inside the create (`0x5deb56`)"), - ("::query_cache::release_on_enter", - &["go_templates::GameObjectTemplates"], - "clears the object cache's in-flight asks on world entry, so each is asked again; the \ - npc's object name reads the cache (`0x5f8100`)"), - ("::query_cache::release_on_enter", - &["item_names::ItemNames"], - "clears the item-name cache's in-flight asks on world entry, so each is asked again"), - ("::query_cache::release_on_enter", &["items::Items"], - "clears the item cache's in-flight asks on world entry, so each is asked again"), - ("::query_cache::release_on_enter", &["names::NameCache"], - "clears the name cache's in-flight asks on world entry, so each is asked again"), - ("::query_cache::release_on_enter", &["ui_guild::GuildState"], - "clears the guild cache's in-flight asks on world entry, so each is asked again"), - ("::query_cache::release_on_enter", - &["ui_petition::PetitionRecords"], - "clears the petition cache's in-flight asks on world entry, so each is asked again"), ("::spell::group_relation::publish_group_roster", &["spell::group_relation::GroupRoster"], "copies the group's roster, which the relation reads take, once the packets are in"), ("::spell::mods::track_class_family", &["spell::mods::SpellModifiers"], @@ -79,29 +69,16 @@ const BETWEEN_THE_DISPATCH_AND_THE_DRAIN: &[(&str, &[&str], &str)] = &[ "holds the attack seam, whose selection release lowers the pet's attack latch \ (`0x493a18`); the server's silent stop it runs (`0x625ab8`) reaches no release"), ("::transport::compose_riders", &["Transform"], - "places the riders on their transports each frame, the positions the range verbs \ - measure, outside any packet's handler"), - ("::transport::ground_deck_riders", &["Transform"], - "settles the riders on their decks each frame, the positions the range verbs measure, \ - outside any packet's handler"), - ("::transport::tick_transports", &["Transform"], - "moves the transports along their paths each frame, which carry their riders' positions \ - the range verbs measure, outside any packet's handler"), - ("::ui_action::cooldown_lane::drop_cooldown_log", - &["spell::cooldowns::Cooldowns"], - "drops the player's cooldown log with no in-game interface up; it goes with the log"), - ("::ui_action::cooldown_lane::drop_cooldown_log", - &["ui_pet::PetBar"], - "drops the pet's cooldown log with no in-game interface up; it goes with the log"), + "the arrival snap `0x7c6420` (`0x618dfc`) is written inside the packet"), ("::ui_action::feed::feed_actions", &["ui_action::PlayerActions"], "clears the bar's re-resolve flag; the known spells the book and the talents read are \ the learn handlers' alone"), - ("::ui_action::unlearn::clear_unlearned_slots", &["ui_action::PlayerActions"], - "drains the unlearned spells the bar clears; the known spells are the handlers' alone"), ("::ui_action::state::feed_action_state", &["spell::cooldowns::Cooldowns", "ui_action::state::ActionStateMemory"], "keeps the frame's `GetTime` clock the cooldown reads map each start through, and \ writes the list as it walks the slots"), + ("::ui_action::unlearn::clear_unlearned_slots", &["ui_action::PlayerActions"], + "drains the unlearned spells the bar clears; the known spells are the handlers' alone"), ("::ui_aura::feed_auras", &["ui_aura::AuraFeedMemory"], "rebuilds the raid filter's books and the world entry's player the aura walk reads, and \ keeps the clock pair the buff timers map the duration stamps through"), @@ -147,19 +124,54 @@ const BETWEEN_THE_DISPATCH_AND_THE_DRAIN: &[(&str, &[&str], &str)] = &[ &["ui_talent_wipe::TalentWipeState"], "closes the respec question once the player leaves service range, which \ `CheckTalentMasterDist` reports; the reference tests the range at the call (`0x5df980`)"), - ("::ui_reputation::drop_reputation_log", &["net::reputations::Reputations"], - "drops the reputation log with no in-game interface up; it goes with the log"), ("::ui_tooltip::spell_feed::feed_spell_tooltips", &["items::Items"], "writes the item cache as it builds the spell tooltips"), ("::ui_unit::feed_units", &["UiScript", "ui_pet::PetAttackLatch", "ui_pet::PetBar"], "a field event's listeners read its push; the world entry's pet reset writes the bar and \ lowers the attack latch (`0x4bc6f0`, `0x4bc8ce`)"), - ("::ui_unit::views::drop_unit_views", &["ui_unit::views::UnitViews"], - "drops the unit views' log with no in-game interface up; it goes with the log"), ]; -/// The systems [`BETWEEN_THE_DISPATCH_AND_THE_DRAIN`] holds to, with what each writes of the -/// host's live reads, by suffix; see its doc for the kinds. +/// The systems between the dispatch and the drain that write what the host's live reads read, +/// as [`BETWEEN_THE_DISPATCH_AND_THE_DRAIN`]'s, but where the reference too runs them after the +/// packets, or where no listener can read them: they stay after the flip, and a listener fired +/// inside the dispatch reads them as the frame before left them, as 1.12.1's does. Same shape, +/// held to its systems' access by the same test. +#[rustfmt::skip] +const AFTER_THE_PACKETS_IN_THE_REFERENCE: &[(&str, &[&str], &str)] = &[ + ("::net::motion::facing::drive_display_facing", &["Transform"], + "turns the units' models toward their facing; unit movement is \ + frame time, which the reference runs after the packets (`0x420d63` after `0x420d55`)"), + ("::net::motion::spline::ground_clamp_creatures", &["Transform"], + "settles the creatures on the ground; unit movement is \ + frame time, which the reference runs after the packets (`0x420d63` after `0x420d55`)"), + ("::net::motion::spline::sample_splines", &["Transform"], + "moves the units along their splines; unit movement is \ + frame time, which the reference runs after the packets (`0x420d63` after `0x420d55`)"), + ("::transport::ground_deck_riders", &["Transform"], + "settles the riders on their decks; unit movement is \ + frame time, which the reference runs after the packets (`0x420d63` after `0x420d55`)"), + ("::transport::tick_transports", &["Transform"], + "moves the transports along their paths; unit movement is \ + frame time, which the reference runs after the packets (`0x420d63` after `0x420d55`)"), + ("::ui_action::cooldown_lane::drop_cooldown_log", + &["spell::cooldowns::Cooldowns"], + "drops the player's cooldown log, run only while no in-game interface \ + is up, so no listener exists; it goes with the log"), + ("::ui_action::cooldown_lane::drop_cooldown_log", + &["ui_pet::PetBar"], + "drops the pet's cooldown log, run only while no in-game interface \ + is up, so no listener exists; it goes with the log"), + ("::ui_reputation::drop_reputation_log", &["net::reputations::Reputations"], + "drops the reputation log, run only while no in-game interface \ + is up, so no listener exists; it goes with the log"), + ("::ui_unit::views::drop_unit_views", &["ui_unit::views::UnitViews"], + "drops the unit views' log, run only while no in-game interface \ + is up, so no listener exists; it goes with the log"), +]; + +/// The systems [`BETWEEN_THE_DISPATCH_AND_THE_DRAIN`] and [`AFTER_THE_PACKETS_IN_THE_REFERENCE`] +/// hold to, with what each writes of the host's live reads, by suffix; see the first's doc for the +/// kinds. fn writers_between(app: &mut App) -> Option>> { let world = app.world_mut(); use bevy::ecs::system::System; @@ -304,8 +316,17 @@ fn writers_between(app: &mut App) -> Option>> Some(found) } +/// Every row between the dispatch and the drain: the obstacles, then the writers that stay. +fn rows_between( +) -> impl Iterator { + BETWEEN_THE_DISPATCH_AND_THE_DRAIN + .iter() + .chain(AFTER_THE_PACKETS_IN_THE_REFERENCE) +} + /// Every system between the dispatch and the drain that writes what the host's live reads read -/// has its row, as it stands, and a row whose system no longer does is stale. +/// has its row, in one of the two lists, as it stands, and a row whose system no longer does is +/// stale. #[test] fn every_writer_between_the_dispatch_and_the_drain_is_listed() { let mut app = crate::game_plugins::schedule_tests::headless_client(); @@ -313,11 +334,17 @@ fn every_writer_between_the_dispatch_and_the_drain_is_listed() { eprintln!("skipped: this build carries no type names"); return; }; - let row = |system: &str| { - BETWEEN_THE_DISPATCH_AND_THE_DRAIN - .iter() - .find(|(s, _, _)| format!("::{system}").ends_with(s)) - }; + let twice: Vec<&str> = BETWEEN_THE_DISPATCH_AND_THE_DRAIN + .iter() + .filter(|(s, _, _)| { + AFTER_THE_PACKETS_IN_THE_REFERENCE + .iter() + .any(|(a, _, _)| a == s) + }) + .map(|(s, _, _)| *s) + .collect(); + assert!(twice.is_empty(), "rows in both lists: {twice:?}"); + let row = |system: &str| rows_between().find(|(s, _, _)| format!("::{system}").ends_with(s)); let wrong: Vec = found .iter() .filter(|(system, writes)| { @@ -334,8 +361,7 @@ fn every_writer_between_the_dispatch_and_the_drain_is_listed() { format!("(\"::{system}\", &[{}], \"\"),", writes.join(", ")) }) .collect(); - let stale: Vec<&str> = BETWEEN_THE_DISPATCH_AND_THE_DRAIN - .iter() + let stale: Vec<&str> = rows_between() .filter(|(s, _, _)| { !found .keys() @@ -346,13 +372,13 @@ fn every_writer_between_the_dispatch_and_the_drain_is_listed() { assert!( wrong.is_empty(), "these run between the dispatch and the drain and write what the host's live reads read: \ - move the write into its handler, or give each its row in \ - BETWEEN_THE_DISPATCH_AND_THE_DRAIN as it stands:\n {}", + move the write into its handler, or give each its row as it stands: in \ + AFTER_THE_PACKETS_IN_THE_REFERENCE when the reference too writes it after the packets, \ + else in BETWEEN_THE_DISPATCH_AND_THE_DRAIN:\n {}", wrong.join("\n ") ); assert!(stale.is_empty(), "stale rows: {stale:?}"); - let empty: Vec<&str> = BETWEEN_THE_DISPATCH_AND_THE_DRAIN - .iter() + let empty: Vec<&str> = rows_between() .filter(|(_, _, why)| why.is_empty()) .map(|(s, _, _)| *s) .collect(); @@ -372,3 +398,62 @@ fn the_frame_final_views_only_shrink() { rows.len() ); } + +/// Where the flip stands: every list's count, printed, failing nothing (`cargo test +/// flip_readiness -- --nocapture`). The flip needs the first five empty; the rest are context. +#[test] +fn flip_readiness() { + use super::guard_tests as g; + let inputs: usize = g::READS_FRAME_FINAL.iter().map(|(_, i)| i.len()).sum(); + let lane_inputs: usize = g::LANE_READS_FRAME_FINAL.iter().map(|(_, i)| i.len()).sum(); + let needs = [ + ( + "READS_FRAME_FINAL", + g::READS_FRAME_FINAL.len(), + format!(" ({inputs} inputs)"), + ), + ( + "BETWEEN_THE_DISPATCH_AND_THE_DRAIN", + BETWEEN_THE_DISPATCH_AND_THE_DRAIN.len(), + String::new(), + ), + ( + "NOT_YET_ON_A_LANE", + g::NOT_YET_ON_A_LANE.len(), + String::new(), + ), + ("NOT_YET_PLACED", g::NOT_YET_PLACED.len(), String::new()), + ( + "PLACED_OUTSIDE_THE_DISPATCH", + g::PLACED_OUTSIDE_THE_DISPATCH.len(), + String::new(), + ), + ]; + let context = [ + ( + "HOST_HELD_UNREAD (to read; a quiet entry stays)", + g::HOST_HELD_UNREAD.len(), + String::new(), + ), + ( + "LANE_READS_FRAME_FINAL (empties at the flip)", + g::LANE_READS_FRAME_FINAL.len(), + format!(" ({lane_inputs} inputs)"), + ), + ( + "AFTER_THE_PACKETS_IN_THE_REFERENCE (stays)", + AFTER_THE_PACKETS_IN_THE_REFERENCE.len(), + String::new(), + ), + ]; + let left: usize = needs.iter().map(|(_, n, _)| n).sum(); + let mut out = format!("flip readiness: {left} rows to empty\n"); + for (list, n, extra) in &needs { + out += &format!(" {n:>4} {list}{extra}\n"); + } + out += " context:\n"; + for (list, n, extra) in &context { + out += &format!(" {n:>4} {list}{extra}\n"); + } + eprint!("{out}"); +} diff --git a/crates/benilla-app/src/net.rs b/crates/benilla-app/src/net.rs index a46fa7d0a..d5283d0ef 100644 --- a/crates/benilla-app/src/net.rs +++ b/crates/benilla-app/src/net.rs @@ -69,7 +69,7 @@ pub(crate) struct NetOffline; impl Plugin for NetPlugin { fn build(&self, app: &mut App) { - // The release-on-enter for the ask-once caches this plugin owns. + // The ask-once caches this plugin owns, whose in-flight asks the world entry releases. crate::query_cache::register::(app); crate::query_cache::register::(app); crate::query_cache::register::(app); diff --git a/crates/benilla-app/src/net/session.rs b/crates/benilla-app/src/net/session.rs index 9a25d37ae..d07194ba6 100644 --- a/crates/benilla-app/src/net/session.rs +++ b/crates/benilla-app/src/net/session.rs @@ -197,6 +197,7 @@ fn on_connected(In(ev): In, mut e: Edges, mut b: Bridge) { name, tutorial_flags, addon_info, + &mut b.commands, &mut e.addon_reply, &mut b.self_guid, &mut b.status, @@ -735,6 +736,7 @@ fn connected( name: String, tutorial_flags: Option>, addon_info: Option>, + commands: &mut Commands, addon_reply: &mut crate::net::AddonInfoReply, self_guid: &mut SelfGuid, status: &mut NetStatus, @@ -748,6 +750,9 @@ fn connected( // The reference clears player and pet names at every world entry (`0x555740`, arm // `0x5557ad`), since a guid may name a new character; creature templates survive. names.clear_world_session(); + // And every ask-once cache's in-flight asks, applied with this handler's commands, before + // the next packet's handlers can ask. + commands.queue(crate::query_cache::release_pending); // Our own name came with the login, so "player" never queries. names.insert_player(guid, name, None); // Set before the world-entry UI load reads it, and every login, so a silent server inherits @@ -1453,3 +1458,57 @@ mod worldport_tests { assert_eq!(kept_across(false), (false, false)); } } + +#[cfg(test)] +mod login_ask_tests { + use super::*; + const CHALLENGER: u64 = 0x99; + + /// `SMSG_DUEL_REQUESTED`, whose handler asks the challenger's name (`0x4d4a83`). + fn requested() -> SessionEvent { + SessionEvent::DuelRequested { + arbiter: 0xF110_0000_0000_0001, + challenger: CHALLENGER, + } + } + + /// The world entry clears the caches' in-flight asks in its handler, ahead of the world's + /// first packet (`0x48f586` → `0x555740`), so a name a later packet of the login frame asks + /// stays pending through the frame, and the next packet's ask of it sends nothing. + #[test] + fn a_name_asked_in_the_login_frame_is_asked_once() { + let mut app = crate::game_plugins::schedule_tests::headless_client(); + app.insert_resource(bevy::ecs::error::DefaultErrorHandler( + bevy::ecs::error::ignore, + )); + let (tx, sent) = crossbeam_channel::unbounded(); + app.insert_resource(NetCommands(tx)); + let (inbound, rx) = crossbeam_channel::unbounded(); + app.insert_resource(crate::net::NetEvents::for_test(rx)); + let frame = |app: &mut App, events: Vec| { + for ev in events { + inbound.send(ev).unwrap(); + } + app.update(); + }; + let login = SessionEvent::Connected { + self_guid: 0x2a, + name: "Probeseven".into(), + billing: Default::default(), + tutorial_flags: None, + addon_info: None, + }; + frame(&mut app, vec![login, requested()]); + assert_eq!( + app.world().resource::().0, + Some(0x2a), + "the login handler ran" + ); + frame(&mut app, vec![requested()]); + let asked = crate::query_cache::queries(&sent) + .into_iter() + .filter(|c| matches!(c, crate::net::ClientCommand::NameQuery { guid: CHALLENGER })) + .count(); + assert_eq!(asked, 1, "the login frame forgot its packet's pending ask"); + } +} diff --git a/crates/benilla-app/src/query_cache.rs b/crates/benilla-app/src/query_cache.rs index 5254b5835..2724b5ea3 100644 --- a/crates/benilla-app/src/query_cache.rs +++ b/crates/benilla-app/src/query_cache.rs @@ -32,7 +32,7 @@ use std::sync::Mutex; use benilla_assets::LockRecover; use bevy::prelude::*; -use crate::net::{EnteredWorldMessage, NetCommands}; +use crate::net::NetCommands; /// How a read reaches the server on a miss: the reference's lookup with a callback or without, and /// the runs of a reader that builds its view every frame between the events that stand for the @@ -242,7 +242,7 @@ impl QueryCache { } /// Forgets the in-flight asks, which a disconnect or a send before the writer existed may - /// have dropped; [`register`] runs it on every world entry. + /// have dropped; [`release_pending`] runs it on every world entry. pub(crate) fn clear_pending(&mut self) { self.pending .get_mut() @@ -286,25 +286,34 @@ pub(crate) trait AskOnce: Resource { fn clear_pending(&mut self); } -/// Registers a cache owner to clear its in-flight asks on world entry, so a key asked before the -/// writer existed, or across a disconnect, is asked again. +/// Every registered owner's clear, in registration order. +#[derive(Resource, Default)] +struct AskOnceOwners(Vec); + +/// Registers a cache owner to clear its in-flight asks on world entry ([`release_pending`]), so a +/// key asked before the writer existed, or across a disconnect, is asked again. pub(crate) fn register(app: &mut App) { - app.add_systems( - Update, - release_on_enter:: - .in_set(benilla_world::schedule::WorldStage::Net) - .after(crate::net::apply_net_updates), - ); + app.world_mut() + .get_resource_or_init::() + .0 + .push(|world| { + if let Some(mut cache) = world.get_resource_mut::() { + cache.clear_pending(); + } + }); } -fn release_on_enter( - mut entered: MessageReader, - mut cache: ResMut, -) { - if entered.read().count() == 0 { - return; +/// Forgets every registered cache's in-flight asks: run by the world entry's handler, where the +/// reference clears its caches at `CGGameUI::InitializeGame` (`0x48f586` → `0x555740`), ahead +/// of the world's first packet, so an ask a later packet of the login frame makes stands. +pub(crate) fn release_pending(world: &mut World) { + let owners = world + .get_resource::() + .map(|o| o.0.clone()) + .unwrap_or_default(); + for clear in owners { + clear(world); } - cache.clear_pending(); } /// The cache queries `rx` holds, drained: what a reader's runs asked.