This C++ header file defines a simple entity that contains components for animation from Ogre, and a behavioral brain component from Game::AI++.

The behaviors rely on the Actions defined in the Actions.h header file.

#ifndef _DOG_H_
#define _DOG_H_

#include <Ogre.h>
#include <alive/Brain.h>

#include "Action.h"

Dog Entity

A simple entity class in the game logic. implemented as an aggregation of lower-level classes. It currently stores very little additional information to the Ogre entity and scene graph node.

class Dog
{
public:

    /**
     * Setup this entity from the global scene manager.
     */
    void init(Ogre::SceneManager&);

    /**
     * Perform one tick of the logic in this entity.  This function is called
     * every frame.
     */
    void update(const Ogre::FrameEvent&);

    // Exposes the animation system and other aspects of the model.
    Ogre::Entity*            m_pDogEntity;

    /// Used for 3D transformations of the entity in space.
    Ogre::SceneNode*        m_pDogNode;

    /// The AI engine which manages the execution of the behavior tree.
    alive::Brain              m_Brain;
};

Initializing Actions

The AI connects with the game engine mainly via actions. These actions are initialized using the visitor pattern, as defined below. This implementation is used to setup the actions correctly and bind then to the necessary Ogre entities or scene graph nodes.

struct InitializeAction
                        : public alive::RegistryVisitor
                        , public alive::Visitor< ActionAnimate >
                        , public alive::Visitor< SpatialAction >
{
    /**
     * Pass the ogre entity to the action for playing animations.
     */
    virtual void visit(ActionAnimate&);

    /**
     * Setup the scene graph node for rotation and translation actions.
     */
    virtual void visit(SpatialAction&);

    InitializeAction(Dog& dog);

    Ogre::Entity* m_pEntity;
    Ogre::Node* m_pNode;
};


#endif //_DOG_H_