EmiOnGit / warbler_grass

A bevy plugin for creating 3d grass in your game
Apache License 2.0
120 stars 11 forks source link

Visibility bug for grass not visible at start #16

Closed EmiOnGit closed 1 year ago

EmiOnGit commented 1 year ago

Describe the bug

If an entity is spawned with ComputedVisibility set to not visible, it will not registered and be invisible even if ComputedVisibility is set to visible.

To Reproduce

It can be seen in the load_many_chunks example. 100 chunks should be loaded into a grid but only the ones that are visible in the default view are registered. Use cargo -r r --example load_many_chunks to reproduce. Use keys Q,W,E,A,S,D for movement

EmiOnGit commented 1 year ago

This behavior is caused by the extract_grass function. Since Changed<Grass> is only triggered on startup

EmiOnGit commented 1 year ago

Any idea @janhohenheim ?

janhohenheim commented 1 year ago

Huh, strange. I'll check later

janhohenheim commented 1 year ago

I tried replacing Changed<Grass> by Changed<ComputedVisibility>, but turns out ComputedVisibility is mutably dereferenced and thus "changed" every frame. The best I can think of for now is removing the Changed constraint, querying ChangeTrackers<Grass> and adding the following to the loop for a tiny optimization:

if !tracker.is_changed() && entity_cache.contains(&entity) {
    continue;
}

Quite suboptimal, because we'd iterate over all entities :/

EmiOnGit commented 1 year ago

Glad we came up to a similar conclusion..

EmiOnGit commented 1 year ago

Should be solved by #19