Skip to content

count, isEmpty and first ignore Changed/Added/Removed filters #2

Description

@k9p5

Summary

On a tick-filtered query, count, isEmpty and first report the structural match set and ignore the Changed() / Added() / Removed() terms. each and iteration apply the filter; the scalar accessors do not.

Repro

import { World, Trait, f32, Changed } from 'apecs';
const Position = new Trait({ x: f32(0) });
const w = new World();
w.spawn(Position); w.spawn(Position); w.spawn(Position);

const q = w.query(Changed(Position));
q.each(() => {});   // consume the initial state
w.step();

let n = 0; q.each(() => n++);
console.log(n);          // 0
console.log(q.count);    // 3
console.log(q.isEmpty);  // false
console.log(q.first);    // an entity

Cause

count, isEmpty and first in src/core/result.ts sum archetype.rows across the matched archetypes and never consult the RowFilter.

Why it matters

The README's Queries table lists query.count / .isEmpty / .first with no caveat, so world.query(Changed(Position)).isEmpty reads as a natural "anything changed?" check and silently answers the wrong question.

Options

  1. Route the three accessors through the filter when one is present. count becomes a scan, which is the same cost each already pays for these queries.
  2. Keep them structural, document it in the README table and spec §8, and add a dev-build assertion that throws when they are read on a tick-filtered query.

Found by a post-publish smoke test of 0.1.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions