-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entitas Modules / Packs / Kits #307
Comments
Awesome idea!! |
It #309 It can help in the dependencies of another Kits |
I gave the whole idea some thoughts which I want to share. As I see it there are two ways how a Kit can be implemented.
Both approaches has complications. I personally would rather try to tackle the problem of entity mapping. We could introduce a mechanism which a Kit developer could introduce in order to make the mapping automatic. Like for Example provide an interface which my components have to implement in order for the kit to run through an "unknown" entity and extract data which it needs. So for example Kit has a I believe actor model is much more superior to the inheritance model in simplicity, but than again I am biased :) |
TL;DR The setup:I've create a new C# solution with 2 projects
I updated the project's Entitas.properties with new Kit syntax. When specifying contexts you can optionally register Kits like this
The code generator will pick this up and when generating extensions for the Game context it will load and inspect the PhysicsKit and also generate extensions. This works great. You can now write sth like this var context = new GameContext();
var e = context.CreateEntity();
// SomeComponent from the Game context
e.Some();
// Generated extensions from the Physics Kit. The Game context and the GameEntity can now also use the components from the Kit
e.AddPhysicsKitPosition(4, 5, 6);
e.AddPhysicsKitVelocity(10, 10, 10);
Console.WriteLine("e: " + e);
Console.WriteLine("e.position.x: " + e.position.x);
Console.WriteLine("e.physicsKitPosition.x: " + e.physicsKitPosition.x); The code generator produces a few new interfaces as well. Matchers are different now, you access them through the context: context.matcher.physicsKitPosition This is necessary because in the scope of the PhysicsKit, the PositionComponent might have index 0, but when used as a Kit the index gets remapped ontop of already existing indices and will be another index. Since This is what I called Phase I. Works great. Done. But: Phase II is about also using systems from another Kit. So I added a simple MoveSystem to the PhysicsKit project using Entitas;
namespace PhysicsKit {
public sealed class MoveSystem : IExecuteSystem {
readonly IGroup<PhysicsKitEntity> _group;
public MoveSystem(IPhysicsKitContext context) {
_group = context.GetGroup(context.matcher.AllOf(
context.matcher.physicsKitPosition,
context.matcher.physicsKitVelocity
));
}
public void Execute() {
foreach (var e in _group) {
var p = e.physicsKitPosition;
var v = e.physicsKitVelocity;
e.ReplacePhysicsKitPosition(p.x + v.x, p.y + v.y, p.z + v.z);
}
}
}
} Going back to the MyGame project and using it like this would be the goal var system = new MoveSystem(context); The problem:My current problem is to resolve the casting problems. In theory MyGame context, entity and matchers will implements IPhysicsContext, IPhysicsEntity, IPhysicsMatcher. Problem 1: I see, the text is already pretty long, so I guess I'll stop here ;) |
Here's the project if anyone want to see the setup. Pretty simple. EntitasKitsTest.sln contains boths projects. Goal: Get rid of compiler errors :) Or find a completely new approach. Go and check the generated code and maybe modify it, e.g. try what happens if GameContext also implements IPhysicsContext... I'm currently trying to find out what the generated code should look like. So main objective is to mess with the generated code. |
Seems to me if I'm going through the trouble of telling the code generator what context I want the kit to exist in that the code generator should generate code to integrate it transparently into said context. As an end user of a kit, do I really need to make the distinction at compile-time that a set of components/systems came from a kit? It makes sense to me that the code generator would generate versions of the kit's systems/components that function/appear the same as systems/components I've authored myself. Otherwise I'm taking on additional mental overhead to use a kit, which is contrary to the reason I'm using a kit in the first place. Perhaps that means creating kit-authoring-specific types (Context, Entity, Matcher, etc) that can function for testing/building a kit and easily be replaced by the code generator with the end user's types? |
Do any of you know tips on how to reuse:
I tried to make a few Entitas components, systems, and MonoBehaviours that I could reuse between games. I ran into problems that are related to those discussed above.
I can generalize to Or I can specify the entity and context. Then the code in the library is non-compatible with the code in the specific game, because the library code needs to be generated to function, but the specific game code also needs to generate code, which goes into the specific game's folder. So the library is always in a broken state. It can't be tested outside of a game. Namespacing is important to write library code. I'm probably doing it wrong, but last I tried, namespaces made awkwardly verbose generated code by prefixing the namespace to the component variables in the context. |
Right now Kit feature blockers are:
Solutions could be:
#407 Entitas.Generic solved these in one way |
What if Entitas adopts a standard set of contexts (but continues to allow new ones)? |
Actually, wait, here's a better idea; what if instead of directly distributing custom systems or components, custom code generators that generate these systems or components are shared instead? The code generators, to my knowledge, don't care how Entitas is implemented, so this wouldn't require a fundamental rework of Entitas. Instead, this would require more documentation and guidance for custom code generators. And, just as importantly, this would require the code generator implementation process to be more streamlined, with less boilerplate required by the user. |
I was thinking about a code gen oriented solution to kits recently. |
Do tell. |
I'm not super advanced in my thinking here, but as Jesse said, the code gen are pretty much walled off from your specific implementation. The idea would be to add a host of new attributes for kits, that would generate things. You could have the cg generate components and systems and even contexts, and the user could have a bit more custom control over the naming / prefixes / suffixes etc with some configs. |
This means that instead of talking about how to implement kits, we can now talk about how to improve the usability and documentation of custom code generators. What do you think, @sschmid? |
@sschmid the module/packs/kits idea is something I implemented with flecs modules, where just like you describe, there are a number of reusable modules that implement a feature, like rendering, collision detection, movement etc. Some of the projects created with these modules are this, this and this. I'll deposit some ideas on challenges I had to overcome here, in case it's useful for the Entitas design: Ordering
The guiding principle is: there should be no direct dependencies between systems in different modules, but there can be dependencies between modules. So far this seems to work, though I'm still refining the different phases. In Entitas this may be easier, as you could use the Unity execution order. Module organization Performance degradation because of redundant systems
UI clutter Anyway, that's a blurb with some thoughts, hope it is helpful :) |
I haven't forgotten about this ancient issue :D |
I think that is actually the next big cool feature if I manage to find a solution. I was thinking about Entitas and modules / packs / Kits and how one could tackle this.
The goal
Someone writes a bunch of systems and components, packs them and calls it
PathFindingKit
orPhysicsKit
orAnimationKit
. Basically a self contained and tested module that you drop into your game and voila you havePathFinding
,Physics
orAnimation
.Kits most likely come with their own contexts and components, so first of all I have to find a solution for #303 (Support for multiple contexts in ReactiveSystem).
Vision
You download a
PathFindingKit
. I comes with components, systems and contexts. You install / register this kit somehow with Entitas and declare that your ownGameEntity
is also aPathFindingEntity
(defined in the Kit). Now yourGameEntity
supports methods likee.AddPath()
and things like that.It's an interesting though which would enable the Entitas community to share Kits which solve certain problems. We basically could create small reusable building blocks and put them together in our games
The text was updated successfully, but these errors were encountered: