perf(engine): route remaining drag card→entity lookups through CardEntityIndex
Replace O(n) `Query::iter().find()` card scans with O(1) `CardEntityIndex`
lookups in the mouse and touch drag pipelines (`follow_drag`, `end_drag`,
`touch_follow_drag`, `touch_end_drag`) and `update_drag_shadow` — 7 sites
across 5 systems. Each ran per dragged card per frame during a drag.
`InputPlugin` now defensively `init_resource::<CardEntityIndex>()` (idempotent;
`CardPlugin` still owns and rebuilds it) so the plugin is self-sufficient in
tests. The lone remaining card-keyed `.find` is a `#[cfg(test)]` world-query
helper, which is the correct pattern there.
Completes the CardEntityIndex migration started in ef1efdc.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1487,6 +1487,7 @@ fn update_drag_shadow(
|
||||
drag: Res<DragState>,
|
||||
layout: Option<Res<LayoutResource>>,
|
||||
card_entities: Query<(&CardEntity, &Transform)>,
|
||||
card_index: Res<CardEntityIndex>,
|
||||
mut shadow: Local<Option<Entity>>,
|
||||
) {
|
||||
if drag.is_idle() {
|
||||
@@ -1503,9 +1504,9 @@ fn update_drag_shadow(
|
||||
|
||||
// Find the world position of the first (top) dragged card.
|
||||
let top_pos = drag.cards.first().and_then(|first_card| {
|
||||
card_entities
|
||||
.iter()
|
||||
.find(|(marker, _)| marker.card == *first_card)
|
||||
card_index
|
||||
.get(first_card)
|
||||
.and_then(|entity| card_entities.get(entity).ok())
|
||||
.map(|(_, t)| t.translation)
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user