(svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
-Note: the threading is pretty poor right now, with slow CSleep(1) in them. Code is required to make this better, but it is a start.
-Change: entry point in AI is now Start(). If you return from that, your AI dies.
-Change: if you now run a DoCommand, you won't get a result till one tick later, or worse in MP.
/* $Id$ */
/** @file squirrel.hpp declarations of the class for squirrel loader */
#ifndef AI_SQUIRREL_HPP
#define AI_SQUIRREL_HPP
class AIControllerSquirrel: public AIController {
private:
Squirrel *engine; ///< The Squirrel engine
HSQOBJECT SQ_instance; ///< The internal instance of squirrel
/**
* Registers all our classes, so it can be used from Squirrel.
*/
void RegisterClasses();
public:
AIControllerSquirrel(const char *script_dir, const char *class_name);
~AIControllerSquirrel();
/* virtual */ void Start();
uint GetTick() { return AIController::GetTick(); }
void Sleep(uint ticks) { return AIController::Sleep(ticks); }
};
class FSquirrel: public AIFactory<FSquirrel> {
private:
Squirrel *engine; ///< The Squirrel engine
const char *current_script; ///< Temporary variable to know which script defines which class
/**
* The constructor for when a script makes an instance of the Factory class.
*/
static SQInteger FactoryConstructor(HSQUIRRELVM vm);
/**
* Scans a dir to see if there are dirs in it which have a file called 'main.nut'.
* If found it loads the script.
*/
void ScanDir(const char *dirname);
public:
~FSquirrel();
/* virtual */ const char *GetAuthor() { return "OpenTTD Dev Team"; }
/* virtual */ const char *GetName() { return "Squirrel"; }
/* virtual */ const char *GetDescription() { return "Squirrel Module for loading scripts"; }
/* virtual */ int GetVersion() { return 0; }
/* virtual */ const char *GetDate() { return ""; }
/* virtual */ AIController *CreateInstance() { return NULL; }
/* virtual */ bool AllowStartup() { return false; }
/* virtual */ void Initializer();
};
#endif /* AI_SQUIRREL_HPP */