-
Notifications
You must be signed in to change notification settings - Fork 70
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
Alternative to Dictionary<T, int> #67
Comments
Thanks! :) Haven't seen that one. I will take a look at it. |
Hello, I have good news :). The idea works like a charm. Below is a sample code of how it looks. var world = new World();
// Approach 1: Builders
var builder = new ArcheTypeInfo.Builder();
builder.AddComponent<int>();
builder.AddComponent<ulong>();
var archeTypeInfo = builder.Build(); // We want to avoid creating new ArcheTypes every time so we need a way to locate already existing ArcheTypes. ArcheTypeInfo is a struct that is used as a dictionary key for locating already existing ArcheTypes.
var entity = world.CreateEntity(archeTypeInfo);
// Approach 2: Generic methods that use the builder internally.
// world.CreateEntity<T0..T9>(in T0..T9) If we dont want to use the builder approach. It's a little bit slower than the builder approach.
// Set method with multiple generics so we can quickly assign data for each component type.
entity.Set<T0..T9>(in T0..T9); |
Thats great! :) Just some questions:
However i think the .create call with generics should stay aswell since thats a nice api for quick prototyping, it also sets the values in the same step which is also quite nice :) |
Currently, I don't have a fully working sample. There is no concept of ComponenTypes. A Type is just converted into an index, which is then used to place them inside an array. The more components there is the bigger the array. |
Well this is a problem, i think such an approach does not exclude the concept of componenttypes however. ComponentTypes are pretty important for the underlying chunks and store meta data such as byte size and in the future if the component is managed or not ^^ But if a type can be converted to an index, it can also be converted to the componenttype with that approach i guess. |
In dotnext they created a generic class with a static read-only int field each time somebody accesses the generic class with a new type the static field is incremented. And thus creating a compile-time dictionary. TypeMap There was a discussion about it too somewhere in the c# runtime repository but sadly I lost that.
The text was updated successfully, but these errors were encountered: