Boost logo

Boost :

Subject: Re: [boost] [mixin] Introducing a new library.
From: Borislav Stanimirov (b.stanimirov_at_[hidden])
Date: 2013-01-31 01:42:13

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_at_[hidden]>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


// 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

// now the opengl rendering mixin handles this
draw(o, main_target);

// we decide to make the monster aggresive

think(o); // the berserk ai will handle this

- Borislav

Boost list run by bdawes at, gregod at, cpdaniel at, john at