r-lyeh-archived / kult

:crystal_ball: Lightweight entity/component/system library (C++11)
zlib License
128 stars 5 forks source link

How to make a component detect change? #4

Open WarlockD opened 8 years ago

WarlockD commented 8 years ago

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 commented 8 years ago

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

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 commented 8 years ago

btw, found this. relevant and simpler approach!

https://www.reddit.com/r/gamedev/comments/1qtvug/entitycomponentsystems_and_dataoriented_design/cdgib2p

WarlockD commented 8 years ago

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 commented 8 years ago

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:

Hope it helps