0

I'm new to C++ programming and have been studying the Behavior Tree Starter Kit to build a new AI framework. I'm having a hard time understanding the Behavior Tree Starter Kit code. Given this C++ code for a Game AI behavior Tree, what does the part of the code at the top (that seems to be setting the intial status or something) mean? And what is the virtual piece?


Behavior()
:   m_eStatus(BH_INVALID)
{
}

virtual ~Behavior()
{
}

Here is the full code, also what does virtual Status update() = 0; mean:

class Behavior
/**
 * Base class for actions, conditions and composites.
 */
{
public:
    virtual Status update()             = 0;

    virtual void onInitialize()         {}
    virtual void onTerminate(Status)    {}

    Behavior()
    :   m_eStatus(BH_INVALID)
    {
    }

    virtual ~Behavior()
    {
    }

    Status tick()
    {
        if (m_eStatus != BH_RUNNING)
        {
            onInitialize();
        }

        m_eStatus = update();

        if (m_eStatus != BH_RUNNING)
        {
            onTerminate(m_eStatus);
        }
        return m_eStatus;
    }

    void reset()
    {
        m_eStatus = BH_INVALID;
    }

    void abort()
    {
        onTerminate(BH_ABORTED);
        m_eStatus = BH_ABORTED;
    }

    bool isTerminated() const
    {
        return m_eStatus == BH_SUCCESS  ||  m_eStatus == BH_FAILURE;
    }

    bool isRunning() const
    {
        return m_eStatus == BH_RUNNING;
    }

    Status getStatus() const
    {
        return m_eStatus;
    }

private:
    Status m_eStatus;
};
Eric Steen
  • 719
  • 2
  • 8
  • 19
  • Where are you learning C++ from? Since initializer lists, `virtual` functions, and pure virtual functions are all fundamental parts of the language, you should check the [C++ book list](https://stackoverflow.com/a/388282). – 1201ProgramAlarm Feb 08 '20 at 18:25
  • 1
    _"new to C++ programming"_ + _"build a new AI framework"_ = feeling lucky? That's rather ambitious. Maybe learn C++ first? You already have multiple questions about the language that have nothing to do with AI. For one, I know there's a duplicate at [hat is this weird colon-member (“ : ”) syntax in the constructor?](https://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor), while for the others, I'd go with either "get a good reference book" or "please avoid asking multiple questions at once". – JaMiT Feb 08 '20 at 18:47
  • I'm not building in C++, I'm translating this into Elixir. – Eric Steen Feb 09 '20 at 04:24

0 Answers0