amethyst / specs

Specs - Parallel ECS
https://amethyst.github.io/specs/
Apache License 2.0
2.51k stars 221 forks source link

Turn U64Marker/U64MarkerAllocator into generics over a "marker" trait #592

Closed ldesgoui closed 5 years ago

ldesgoui commented 5 years ago

Description

U64Marker becomes U64Marker<T: ?Sized>, U64MarkerAllocator turns into U64MarkerAllocator<T: ?Sized>, allowing the following:

struct Networked;
struct FileSaved;

fn setup(world: &mut World) {
    world.register::<U64Marker<Networked>>;
    world.register::<U64Marker<FileSaved>>;
    world.add_resource(U64MarkerAllocator::<Networked>::default());
    world.add_resource(U64MarkerAllocator::<FileSaved>::default());
}

Motivation

The provided implementation for Marker is most likely good enough for a large majority of the use-cases, however the inability to use it more than once is limiting.

Drawbacks

It is a breaking change

Arguably, the added set of carets for the generic type makes the code busier. ZST, etc might not be the friendliest to newcomers. I don't see how performance could be impacted.

Unresolved questions

I'm not the most knowledgeable in terms of generics, isn't it possible to have "default" generics? If so, the changes would only be additive and not breaking. If it comes down to breaking changes, a rename should be considered, I feel that SimpleMarker could be more appropriate.


I should be able to spend time on a PR implementing this if accepted

torkleyy commented 5 years ago

I like the change, but I would be cautios about default parameters. If you forget the perameter, you can easily access the wrong marker accidentally.