Skip to content

Short lambda syntax for Systems #76

@d-bucur

Description

@d-bucur

Very cool library! I've just started using it and I'm pretty impressed so far.

One minor nitpick: using systems is a bit more ceremonious compared to the simple lambda syntax allowed by queries. Since in most structured code you will be using systems anyway, it would be nice to allow a simpler syntax to declare very short systems inline. Flecs.NET already allows this, for example: https://github.com/d-bucur/flecs-survivors/blob/935c87c7a7e507430e8cf4cef8f91c1566ea0c82/src/Physics.cs#L106-L110

For now I am using my own helpers to allow me to use this syntax:

var root = new SystemRoot(world) {
	// new LongSystem(),
	LambdaSystems.New((ref Position p, Entity e) => Console.WriteLine("Hello1")),
	LambdaSystems.New((ref Position p, Entity e) => Console.WriteLine("Hello2")),
};

And the helpers:

class LambdaSystems {
	static public LambdaSystem<T1> New<T1>(ForEachEntity<T1> lambda) where T1 : struct, IComponent {
		return new LambdaSystem<T1>(lambda);
	}
}

class LambdaSystem<T1>(ForEachEntity<T1> lambda) : QuerySystem<T1> where T1 : struct, IComponent {
	protected override void OnUpdate() {
		Query.ForEachEntity(lambda);
	}
}

It would be nice to have something like this by default in the library and maybe showing it off in the example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions