quote: InnocuousFox
This I like! And all it would have to do is be linked to a particular state.
Precisely. It''s so simple I''m amazed it hasn''t shown up in games yet (most of my ideas show up within a year a two, in keeping with the "great minds think alike" maxim - which makes me feel good since it means I have a great mind, right? )
Say we have a state register (and I apologize to all the pure designers to be delving this far into implementation specifics here) - 32-bits should do. This defines 32 independent binary conditions. Various combinations of these conditions result in our available states - integer values. Plug the state register as an index into a table of sort (array of function pointers, switch statement, which ever is most appropriate) and, well, this may shock you but, we''re done.
// This example employs 4 states from a 2D Mario clone// declare some state indicesconst int state_alive = 1; // are we aliveconst int state_fireball = 2; // do we have the fireballconst int state_feather = 4; // do we have the featherconst int state_BFG = 8; // do we have the BFG. I know....long player_state = 0;.inline void SetState(int state){ (player_state & state) |= 1;}inline void ClearState(int state){ (player_state & state) &= 0;}.void main_loop(){ if( /* we pick up the fireball */ ) SetState(state_fireball); if( ?8 we get hit and _lose_ the fireball */ ) ClearState(state_fireball); ... if( /* we get hit and game over */ ) ClearState(state_alive); ... // eval states and determine action map switch(player_state) { case 2: case 4: case 6: case 8: case 10: case 12: case 14: // we''re dead. state_alive not set. game over game_over = true; return 0; case 1: // we''re alive but have nothing break; case 3: // we have fire! (but nothing else) ActionMap[button_1] = Fire; // ActionMap is an array of function pointers break; case 5: // gentlemen, we have the lift off! ActionMap[button_2] = Fly; break; case 7: // Aha! we have fire and flight ActionMap[button_1] = FlyingFire; // interaction of states break; // etc... }}
Okay, so it''s a corny and simplistic example, but hopefully it communicates ideas on how easy this is to implement.
quote: Let''s work this one a bit. (You ARE going to the GDC, aren''t you?)
Unfortunately, not this year. I had planned to since last year, but my finances recently took a plunge. Next year, no doubt, and maybe some other conventions later in the year if I can return to relative affluence quickly enough.
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!