Skip to content
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

How to make a component detect change? #4

Open
WarlockD opened this issue Aug 14, 2016 · 4 comments
Open

How to make a component detect change? #4

WarlockD opened this issue Aug 14, 2016 · 4 comments

Comments

@WarlockD
Copy link

Lets say I have three components, position, scale, rotation that updates a matrix component to trasforms a sprite. Is there a way I can detect that position/scale/rotation component has changed in the system?

The idea being that I only have to update the transform component if its changed. then if the transform component has changed, update the verticies then.

The only way I can figure out is to wrap my vector class in a struct that flips a flag when the value is changed and then reset when it goes though the system.

Any ideas?

PS - Humm. You know, when I think of it, I think I am looking for a message system. Is there any examples of that?

@r-lyeh-archived
Copy link
Owner

r-lyeh-archived commented Aug 14, 2016

I think your approach would need 5 components { position, rotation, scale, matrix, dirty }. And then,

  • Everytime position, rotation or scale gets updated, they set the dirty flag.
  • Everytime you update the matrix components, check the dirty flags. Transform the pos/rot/sca components into the matrix, and clear the bit.

About messages, in the same spirit of ECS messages, are not implemented at the moment. I have yet to figure out if they're handy or just cumbersome in the end (ie, message-hell).

You can still create blank dynamic entities with a message-component and feed them to a hypothetical message-system btw.

@r-lyeh-archived
Copy link
Owner

@WarlockD
Copy link
Author

Humm, this is a good point. would it be better that, instead of a dirty flag, to just add a "dirty" component? This way the join operation only joins all the entity's that are dirty or does that break some programming convention?

Maybe instead of messages call backs? Its wracking my brain now, I rewrote this paragraph six times already. You could just copy the component system to be an array of std::function<set? this way you could have something like call(player,badguy) in a system.

I feel like you can even remove using the set entirely and program all the callbacks in some kind of template programming. I am still learning about template programming, its just hard to get your head around it sometimes.

@r-lyeh-archived
Copy link
Owner

From my point of view/experience, messages can be very nasty to debug, specially when you have hundred or thousands per frame.

I rather like to examine and inspect the structs and datas in memory as they're when debugged.

You have two approaches from this point:

  • Everytime you touch a node, a moveable message is sent, then all listeners (including matrix component) will rebuild their stuff because of it. This scheme is what I would avoid for now (plus you would need to implement the messaging yourself at the moment; Kult has no messages for now).
  • Make a single transform component that holds the whole { vec3 pos, rot, sca; matrix4 mt; bool dirty } set. Setters for pos, sca and rot set the dirty flag. Update system would retrieve matrix mt if dirty flag is clean, else, would construct matrix from pos,rot,sca and clear the dirty flag for next update. This is the direct/simpler approach I'd like to use if I were you. Keep it simple (and debuggable :)

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants