AiGameDev.com

“Join leading experts and industry veterans in Paris on June 23-24 for the largest independent conference about artifical intelligence in video games.” — Alex

membership

The Premium Membership area at AiGameDev.com is the best place to stay on the cutting edge of artificial intelligence in video games.
Find out more!

sponsors

categories


subscribe

Search


related articles

Sponsors

SpirOps

PathEngine


Observers for Individual Tasks

Alex J. Champandard
June 03, 2007

Having a way to monitor all tasks in a scheduler is particularly useful from a software architecture perspective. But behaviors most often are only interested in specific tasks rather than every one. Having an individual task observer is a great way to accomplish this.

These observers are most often used by composite tasks that have to manage multiple children. The composites ask the interpreter to run a task, and pass an observer with it to get notified when it’s done. The code looks like this:

class TaskObserver
{
public:
    virtual void onTaskFinished(Status) = 0;
    virtual ~TaskObserver();
};

A custom composite task should derive from this class, and implement the pure virtual function. Then, when requesting child tasks to be executed, it would pass itself as the observer. The scheduler’s run function would change to have an extra optional parameter for the observer.

// class Scheduler
bool run(Task&, TaskObserver* = 0);

Note that it’s particularly useful for these observers to get the final return status of a task, as they can take action according to the outcome. Dealing with return status codes is very important for the robustness of the AI logic.


Bookmark and Share




Comments