2 ms·
New game engines and ECS frameworks are cool to see. Taking a look at the ECS part, Bang, here's an example of a component abridged/adapted from their Ludum Dar
by skitter 3y ago
New game engines and ECS frameworks are cool to see. Taking a look at the ECS part, Bang, here's an example of a component abridged/adapted from their Ludum Dare entry:
internal readonly struct CarComponent : IComponent {
public readonly float Speed = 100f;
[Slider(1,20f)] public readonly float Mass = 1;
public CarComponent() {}
}
and of a system:
[Filter(typeof(CarComponent), typeof(AgentImpulseComponent))]
[Filter(ContextAccessorFilter.NoneOf, typeof(DisableAgentComponent), typeof(CarEngineStoppedComponent) )]
internal class CarMoverSystem : IFixedUpdateSystem {
public void FixedUpdate(Context context) {
foreach (var e in context.Entities) {
var car = e.GetComponent<CarComponent>();
Vector2 startVelocity = e.TryGetVelocity()?.Velocity ?? Vector2.Zero;
var result = DoSomeCalculations(car, startVelocity);
e.RemoveFriction();
e.SetVelocity(result);
}
}
}
Looks a bit like DOTS (but I haven't really tried that one either). A system is a class, and which interface it implements determines when it runs. Haven't seen yet where systems are get added to the game / how systems of the same kind get ordered. I'm also curious how a system that does multiple different querries (e.g. one for cars and one for obstacles) looks like.
Bang seems to use source code generators – unlike the generic GetComponent<T> above, TryGetVelocity, RemoveFriction and SetVelocity seem to be generated based on the existence of the Velocity and Friction components. I'm not sure why that is, maybe to cache the component id?
This isn't an archetype-based framework, instead each entity stores a dictionary of component id => component and each system tracks what entities match (also, each entity stores hooks for e.g. when a component gets added, which is used update which systems know about this entity). I don't know how good that's for performance, but for plenty of games performance isn't as important as ease of development.
Also looks like changes are applied immediately. Does this mean that if a system add/remove a component to an entity that affects whether the entity matches the systems filter, it depends on the entity id whether the system processes the entity the same tick?
- lewispollard 3y ago> how systems of the same kind get ordered Curious about this too - it can be frustrating to manually have to add new systems to a fixed list (the amount of times I've got stuck into building a system, then wonder why nothing's happening at runtime - because I forgot to new() it and add it to the system group!), but at the same time, it's often important to fix at compile-time the order that systems run in as they can often be implicitly dependent on each other. I didn't see anything in the docs from a glance that would allow this dependency/ordering to be explicitly marked, so I'm curious to see how it handles this.