BeanCheeseBurrito / Flecs.NET

A C# wrapper for flecs
MIT License
145 stars 18 forks source link

[v4] Wildcard observers not emitting #30

Closed xentripetal closed 3 months ago

xentripetal commented 3 months ago

The current v4 branch (060afe73ba8d4180a32149663b256e43b1fd46d4) does not seem to support wildcard events on observers. The below test suite passes for TestSpecificObserverBehavior and fails on TestWildcardObserverBehavior.

The v4 flecs docs says this should be supported https://github.com/SanderMertens/flecs/blob/v4/docs/ObserversManual.md#multi-event-observers

    record struct Pos
    {
        public float X;
    }

    [Fact]
    public void TestWildcardObserverBehavior()
    {
        using var world = World.Create();
        bool called = false;
        world.Observer<Pos>().Event(Ecs.Wildcard).Each((Iter iter, int i, ref Pos p) => {
            called = true;
        });
        world.Entity().Set(new Pos());
        Assert.True(called);
    }

    [Fact]
    public void TestSpecificObserverBehavior()
    {
        using var world = World.Create();
        bool called = false;
        world.Observer<Pos>().Event(Ecs.OnSet).Each((Iter iter, int i, ref Pos p) => {
            called = true;
        });
        world.Entity().Set(new Pos());
        Assert.True(called);

    }
BeanCheeseBurrito commented 3 months ago

Looks like this is a bug in flecs as it is also reproducible in C and C++ on the v4 branch. This should be reported on the flecs repo.

#include "flecs.h"

typedef struct {
    int x, y;
} Position;

void OnPosition(ecs_iter_t* it) {
    printf("Called\n");
}

int main(void) {
    ecs_world_t* world = ecs_init();
    ECS_COMPONENT(world, Position);
    ECS_OBSERVER(world, OnPosition, EcsOnAdd, Position); // Change to EcsWildcard and it doesn't print anything.

    ecs_entity_t e = ecs_new(world);
    ecs_add(world, e, Position);
}
BeanCheeseBurrito commented 3 months ago

This is bug was fixed in the latest NuGet package.