
On 01/31/2013 05:31 AM, Jeffrey Lee Hellrung, Jr. wrote:
On Wed, Jan 30, 2013 at 11:53 AM, Borislav Stanimirov <b.stanimirov@abv.bg>wrote:
Hello,
[...snip long post...]
Okay, I'm gonna try to read this later, but it might be helpful (and I'd be more inclined to read the original post) if you included a short code snippet of your library in action. Ideally something that makes me say "whoa, that's cool" :)
You're absolutely right, but unfortunately, as other entity-component libraries, this one is mainly useful when used in medium to big projects. Especially since one of its goals is to reduce spaghetti code. When I was writing the basic example it was hard to illustrate the features in fewer than 22 files :) At least all of them are very short But anyway, let's a shorter snippet. Again, imagine a game (and let me remind you that a mixin is basically a component in the context of entity-component systems): The things from the library used in this example are `object`, the message declaration macros, and the mutate (object_transformer) class. All other symbols are part of the hypothetical product: BOOST_MIXIN_CONST_MESSAGE_1(void, draw, render_target*, target); // handled by: void <some_class>::draw(render_target*, target) const; BOOST_MIXIN_CONST_MULTICAST_MESSAGE_1(void, trace, ostream&, o); // handled by multiple mixins BOOST_MIXIN_MESSAGE_0(void, think) // handle by the ai //.... //.... object* o = new object; // all things added here are regular c++ classes // none of this example code requires to actually // "see" the actual class definitions // it works with forward declarations only mutate(o) .add<scene_element>() .add<d3d_rendering>() .add<animated_model>() .add<monster_ai>() .add<rpg_attributes>(); //.... // the d3d_rendering mixin handles this draw(o, main_target); // this is a mutlicast, so potentially all mixins handle this // output could be: // > scene element with id 14, rendering: d3d, // > animated model: "monster.model" // > ai: monster_ai // > rpg attributes: str 14, cha 3, int 3 trace(o, cout); // we decide to switch the rendering system mutate(o) .remove<d3d_rendering>() .add<opengl_rendeing>(); // now the opengl rendering mixin handles this draw(o, main_target); // we decide to make the monster aggresive mutate(o) .remove<monster_ai>() .add<berserk_ai>(); think(o); // the berserk ai will handle this - Borislav