Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

FSM libs out there for games?

This topic is 2080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Well, Flying Spaghetti Monster IS the first hit on google, so it must be right!

 

But in all seriousness.. A simple google search on "FSM Lib" already returned plenty of results, and if it isn't exactly what you are looking for, it is a good starting point to either continue your search, or to better define your post, like what language or specifics you want/need.

Share this post


Link to post
Share on other sites

A state machine is a concept, not an implementation.

 

You can implement a state machine as a single byte indicating the state, as a single object, as a family of objects, as combinations of machines and state objects, as an index into a data table, as a stack of objects or a stack of pointers, as a text string, or as any other form you can imagine.

 

In designing a complex system I may use five or ten or fifty state machines, and each one could potentially have a completely different implementation.

Share this post


Link to post
Share on other sites

I need c++ based. 

 

 

I know it can be coded in many ways... but thought there could be a simple genric templated lib that doesn't use boost

. Okay with c++11

Share this post


Link to post
Share on other sites

I need c++ based. 

 

I know it can be coded in many ways... but thought there could be a simple genric templated lib that doesn't use boost

. Okay with c++11

 

 

I don't need all the smart a** comments... thanks. Looking for help not joke's

 

The difficulty is that your question is nonsensical.  

 

You are quite simply asking "What simple data structure libraries are out there for games?" Without knowing your needs the question really doesn't make sense.

 

 

The answer you get depends entirely on what problems you are trying to design solutions for, and has approximately nothing to do with FSMs generally.

 

I mean, here is a wonderful little state machine:

 

void DoStateMachine() {

 int currentState = 0;

 while (currentState != -1) {

    switch( currentState ) {

       case 0: currentState = DoState0(); break;

       case 1: currentState = DoState1(); break;

       case 2: currentState = DoState2(); break;

       ...

       default: currentState = UnknownStateError(); break;

    }

 }

 return;

}

 

So I could give you that and call your original question answered. 

.

But it doesn't have to be nearly so difficult. Here is another:

 

 ...

  // State machine with three nodes and two edges:

  flag ? DoSomething() : DoSomethingElse();

 ...

 

 

Observe that a state machine does not require C++, does not require a template library, does not require boost or any other library, doesn't require a class, it does not require anything beyond a few concepts. In an article on the site I wrote about a year ago, I demonstrated about ten different implementations of state machines and churned out all of the code in just a few hours.

 

 

Having a look at the first three FSM libraries in Google:

 

* The top list is the AT&T library that was used for weighted FSM transducers designed for speech recognition with probabilistic transitions.  Is that the kind of library you need?

* The next is the Boost FSM library, it offers custom event handlers during transitions, data driven transition maps, introspection of the machine and nodes, consistency checks, and multithreading support. Is that the kind of library you need?

* Next a library from SourceForge (GNU based, probably bad for a game) that is XML data driven and text based. Is that what you need?

 

 

A finite state machine is one of the most basic theoretical machines in computer science. They exist EVERYWHERE. You can make them out of practically nothing, a single bit is enough to drive a state machine.

 

If you have some specific problem you are trying to solve, some specific need you must fulfill, then you can search for an implementation with that specific detail. Otherwise there isn't much help anyone can give you.

Share this post


Link to post
Share on other sites
Here's a basic C++ implementation of a finite state machine that might be along the lines of what you are looking for:
 
 
#include <unordered_map>
#include <functional>

template <typename StateType>
class FSM {
  std::unordered_map<StateType, std::function<StateType(void)>> processing_functions;
  StateType current_state;
  
public:
  void add_state(StateType state, std::function<StateType(void)> processing_function) {
    processing_functions[state] = processing_function;
  }
  
  void set_state(StateType state) {
    current_state = state;
  }
  
  void tick() {
    StateType new_state = processing_functions[current_state]();
    current_state = new_state;
  }
};
Edited by Álvaro

Share this post


Link to post
Share on other sites

I need a program.

What kind of program?

I need a program!

Let's try a different way. 99% of the time, you're going to wind up writing your own FSM from my experience, since you'll generally want one designed around your needs; after all, if you're doing simple text parsing, a switch statement in a loop can be loads better than having massive generic libraries with a hefty inheritance hierarchy. However, something complex may be needed if that is what the situation requires.

So, with that in mind, what do you want to do with the FSM?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!