hi,
I have been out of my hobbies for a while, but in the meanwhile I wrote a little system that works as a global state machines collection manager. I was wondering if it could fit on tust or it is reinventing the wheel xP

DOWNLOAD

I wrote it translucent for the user, where he has only to start the system, add new state machines and close the system at the end. All the added machines will run automatically.

It can manage any object pointer as machine holder (same concept as 'me' pointer in entity actions) and it is function pointer based. It executes functions with the state machine passed as first paremeter, where the state of any machine can be changed.

Code:
void stateHappy ( STMACHINE *stm ) 
{
   ENTITY *ent = stm_me ( stm );
   ENTITY *entFriend = stm_me ( stm_by_index ( stm_index ( friends_index ) ) );
   if ( entFriend->happyness > 50 )
      ent->happyness += time_step;
   else
      ent->happyness -= time_step * 0.5;
   if ( ent->happyness < 50 )
      stm_set_state ( stm, stateWretch, 0 );
   if ( ent->happyness > 80 )
      stm_set_state ( stm, stateSmiling, 0 );
}



In order to avoid any state change preference between machines I aded a system that ensures that every machine executes its actual function before been changed by another machine.

It can be used for automate almost eveything and the resultant coding style is normally quite clean and readable. Look into main.c to see it by yourself.

What do you think about this? Is it usefull?