English



  Inicio

  Características

  API

  Licencia

  Contactar



  Download


 

StateCore v0.5 (Beta)

StateCore es una genérica maquina de estados finitos (FSM), basado en el patrón estado y escrito en C++. StateCore fue creado con la idea de ayudar a los desarrolladores. Esto fue creado bajo la licencia LGPL. Esto quiere decir que es completamente gratis para utilizarlo en aplicaciones comerciales y no comerciales.

Tu puedes utilizar esto para aplicar estados a:

  • aplicaciones, ... (networking, videojuegos, ...)
  • objetos, armas, personajes, enemigos, ... (cinematicas, videojuegos, ...)
  • redes neuronales, pathfinding, A*, inteligencia artificial, ... (AI)

Ejemplo utilizando la clase implementación

Este es un pequeño ejemplo que muestra como crear una maquina de estados utilizando la clase implementación.

// Incluimos el archivo de cabecera que contiene la clase implementacion.
#include <ceStateCoreImpl.h>
#include <cstdio> // Para printf.

// utilizamos el namespace "ce" (CorEngine) por defecto (Opcional).
using namespace ce;

// Creamos nuestros propios estados, heredando la clase interfaz para los estados.
class CGlobalState : public IState

{
  public:

    // Esto se ejecutara cuando se entre al estado.
    inline void OnEnter(const IStateManager *Owner)
    { 
std::printf("\n + Entering in the > Global state \n"); };

    // Esto es llamado por la función de actualización del dueño
    // en cada paso - de actualización.

    inline void OnExecute(const IStateManager *Owner)
    { std::printf(" > This is the > Global state \n"); };

    // Esto se ejecutara cuando se salga del estado.
    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the > Global state \n"); };

} GlobalState;

class CGamePlayState : public IState

{
  public:

    inline void OnEnter(const IStateManager *Owner)
    { std::printf("\n + Entering in the GamePlay state \n"); };

    inline void OnExecute(const IStateManager *Owner)
    { std::printf(" > This is the GamePlay state \n"); };

    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the GamePlay state \n"); };

GamePlayState;

class CMenuState : public IState

{
  public:

    inline void OnEnter(const IStateManager *Owner)
    { std::printf("\n + Entering in the Menu state \n"); };

    inline void OnExecute(const IStateManager *Owner)
    {
      std::printf(" > This is the Menu state \n");
      // Cambiar a un nuevo estado actual.
      Owner -> ChangeState(
&GamePlayState);
    };

    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the Menu state \n"); };

MenuState;

class CIntroState : public IState
{
  public:

    inline void OnEnter(const IStateManager *Owner)
    { std::printf("\n + Entering in the Intro state \n"); };

    inline void OnExecute(const IStateManager *Owner)
    {
      std::printf(" > This is the Intro state \n");
      Owner -> ChangeState(&
MenuState);
    };

    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the Intro state \n"); };

IntroState;

// Creamos nuestra propia clase manager, heredando la clase implementacion.
class CStateManager : public IStateManagerImpl<
CStateManager>
{
  public:

    inline void Example(void) const
    {
      // Le pasamos un estado global que será llamado cada vez que el FSM
      // sea actualizado.

      this -> State -> SetGlobalState(&GlobalState);
      // Le pasamos un estado actual que será llamado cada vez que el FSM
      // sea actualizado.

      this -> State -> SetCurrentState(&IntroState);

      // Esta función provocará la actualización en el estado global y
      // el estado actual.

      this -> State -> Update();
     
this -> State -> Update();
      this -> State -> Update();
    };

    // Operador -> (Opcional).
    const
CStateManager* operator -> (void) const
    { return this; };

};


int main(int argc, char **argv)
{

  // Creamos una instancia de nuestra clase manager.
  const 
CStateManager State;

  // Verificamos la integridad de la clase manager
(Opcional).
  if (
State -> VerifyStateManager() == 0) return 1;

  State -> Example();

  return 0;

}

Ejemplo utilizando la clase interfaz

Este es un pequeño ejemplo que muestra como crear una maquina de estados utilizando la clase interfaz.

// Incluimos el archivo de cabecera que contiene la clase interfaze.
#include <ceStateCore.h>
#include <cstdio> // para printf.

// utilizamos el namespace "ce" (CorEngine) por defecto (Opcional).
using namespace ce;

// Creamos nuestros propios estados, heredando la clase interfaz para los estados.
class CGlobalState : public IState

{
  public:

    // Esto se ejecutara cuando se entre al estado.
    inline void OnEnter(const IStateManager *Owner)
    { 
std::printf("\n + Entering in the > Global state \n"); };

    // Esto es llamado por la función de actualización del dueño
    // en cada paso - de actualización.

    inline void OnExecute(const IStateManager *Owner)
    { std::printf(" > This is the > Global state \n"); };

    // Esto se ejecutara cuando se salga del estado.
    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the > Global state \n"); };

} GlobalState;

class CGamePlayState : public IState

{
  public:

    inline void OnEnter(const IStateManager *Owner)
    { std::printf("\n + Entering in the GamePlay state \n"); };

    inline void OnExecute(const IStateManager *Owner)
    { std::printf(" > This is the GamePlay state \n"); };

    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the GamePlay state \n"); };

GamePlayState;

class CMenuState : public IState

{
  public:

    inline void OnEnter(const IStateManager *Owner)
    { std::printf("\n + Entering in the Menu state \n"); };

    inline void OnExecute(const IStateManager *Owner)
    {
      std::printf(" > This is the Menu state \n");
      // Cambiar a un nuevo estado actual.
      Owner -> ChangeState(
&GamePlayState);
    };

    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the Menu state \n"); };

MenuState;

class CIntroState : public IState
{
  public:

    inline void OnEnter(const IStateManager *Owner)
    { std::printf("\n + Entering in the Intro state \n"); };

    inline void OnExecute(const IStateManager *Owner)
    {
      std::printf(" > This is the Intro state \n");
      Owner -> ChangeState(&
MenuState);
    };

    inline void OnExit(const IStateManager *Owner)
    { std::printf(" - Leaving the Intro state \n"); };

IntroState;

int main(int argc, char **argv)
{

  // Creamos una instancia de la clase manager.
  
IStateManager *State = CreateStateManager();
  if (State == NULL) return 1;

  
// Le pasamos un estado global que será llamado cada vez que el FSM
  // sea actualizado.

  State -> SetGlobalState(&GlobalState);
  
// Le pasamos un estado actual que será llamado cada vez que el FSM
  // sea actualizado.

  State -> SetCurrentState(&IntroState);

  
// Esta función provocará la actualización en el estado global y
  // el estado actual.

  State -> Update();
  State -> Update();
  State -> Update();

 
// Liberamos la instancia de la clase manager.
  DestroyStateManager(&State);
  return 0;

}

Hasta aquí ya sabes lo básico para su utilización, para mas información, recomiendo leer la documentación de la API. Para soporte o ante cualquier duda o sugerencia, no dudes en contactarme.

Copyleft (cc) 2010 por FX Programmer. Algunos Derechos Reservados.