Skip to content

Instantly share code, notes, and snippets.

@distransient
Created November 26, 2018 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save distransient/9cf5c5dac2084607c4eb0ba28efaad41 to your computer and use it in GitHub Desktop.
Save distransient/9cf5c5dac2084607c4eb0ba28efaad41 to your computer and use it in GitHub Desktop.
let storage = () // this is the placeholder I'm using for your component storage;
//
// this following stuff would go in your system init
//
// create bitsets for each kind in your enum, keep in system struct data
let (head, body, turn, tail) =
(BitSet::default(), BitSet::default(), BitSet::default(), BitSet::default());
// get a flagged storage reader id to also keep in your system struct data
let event_reader_id = storage.register_reader();
//
// and then this following stuff would go in your system's run function
// which would need access to Entities as well as your storage, ofc
//
// get the unread events for your storage
let events = storage.channel().read(event_reader_id);
for event in events {
match event {
ComponentEvent::Modified(id) => {
let component = storage.get(entities.entity(*id)).unwrap();
// probably a better way to do this lol
// but basically this entity might be in one of the wrong bitsets at this point
// but we don't know which! we just know which one it belongs in now
// so we add it to that.
head.remove(*id);
body.remove(*id);
turn.remove(*id);
tail.remove(*id);
match component {
head => head.add(*id),
// etc
};
},
ComponentEvent::Inserted(id) => {
let component = storage.get(entities.entity(*id)).unwrap();
match component {
head => head.add(*id),
// etc
};
},
ComponentEvent::Removed(id) => {
// same problem as before!
// but not that big of a deal I guess
head.remove(*id);
body.remove(*id);
turn.remove(*id);
tail.remove(*id);
},
};
}
for (component, _) in (storage, head).join() {
// now do this to only get heads
// and change the bitset to choose which enum branch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment