Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 730867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:57:39+00:00 2026-05-14T06:57:39+00:00

I was wondering if there’s a way I could code some kind of generic

  • 0

I was wondering if there’s a way I could code some kind of “generic” FSM for a game with C++?.

My game has a component oriented design, so I use a FSM Component.

my Finite State Machine (FSM) Component, looks more or less this way.

class gecFSM : public gecBehaviour 
{

public:
    //Constructors
    gecFSM() { state = kEntityState_walk; }
    gecFSM(kEntityState s) { state = s; }

    //Interface
    void setRule(kEntityState initialState, int inputAction, kEntityState resultingState);
    void performAction(int action);

private:
    kEntityState fsmTable[MAX_STATES][MAX_ACTIONS];

};

I would love to hear your opinions/ideas or suggestions about how to make this FSM component, generic. With generic I mean:

1) Creating the fsmTable from an xml file is really easy, I mean it’s just a bunch of integers that can be loaded to create an MAX_STATESxMAX_ACTION matrix.

void gecFSM::setRule(kEntityState initialState, int inputAction, kEntityState resultingState)
{
    fsmTable[initialState][inputAction] = resultingState;
}

2) But what about the “perform Action” method ?

void gecFSM::performAction(int action)
{
    switch( smTable[ ownerEntity->getState() ][ action ] )
    {
        case WALK:
            /*Walk action*/
        break;
        case STAND:
            /*Stand action*/
        break;
        case JUMP:
            /*Jump action*/
        break;
        case RUN:
            /*Run action*/
        break;
    }
}

What if I wanted to make the “actions” and the switch generic?

This in order to avoid creating a different FSM component class for each GameEntity? (gecFSMZombie, gecFSMDryad, gecFSMBoss etc ?). That would allow me to go “Data Driven” and construct my generic FSM’s from files for example.

What do you people suggest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:57:40+00:00Added an answer on May 14, 2026 at 6:57 am

    Have a look at the Boost Statechart Library. (formerly known as boost::fsm)
    It comes with a very nice photo camera example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just wondering if there is a way to reduce the amount of code needed
Wondering if there is a way I could trigger an event, so that any
Hi there i was wondering is there a way to write your code so
just wondering: is there some kind of 'Express' edition of Windows Server 2008 that
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
Just wondering is there any way I can check whether the url links to
Just wondering if there is any way to get the NS records in C#.
HI there I was wondering if there is a better way of testing that
Im wondering if there is some means of just plopping a prepaired statement into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.