Pyrogenesis  trunk
Classes | Functions
CCmpAIManager.cpp File Reference

Player AI interface. More...

#include "precompiled.h"
#include "simulation2/system/Component.h"
#include "ICmpAIManager.h"
#include "simulation2/MessageTypes.h"
#include "graphics/Terrain.h"
#include "lib/timer.h"
#include "lib/tex/tex.h"
#include "lib/allocators/shared_ptr.h"
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "ps/Profile.h"
#include "ps/Util.h"
#include "simulation2/components/ICmpAIInterface.h"
#include "simulation2/components/ICmpCommandQueue.h"
#include "simulation2/components/ICmpObstructionManager.h"
#include "simulation2/components/ICmpRangeManager.h"
#include "simulation2/components/ICmpTemplateManager.h"
#include "simulation2/components/ICmpDataTemplateManager.h"
#include "simulation2/components/ICmpTerritoryManager.h"
#include "simulation2/helpers/LongPathfinder.h"
#include "simulation2/serialization/DebugSerializer.h"
#include "simulation2/serialization/StdDeserializer.h"
#include "simulation2/serialization/StdSerializer.h"
#include "simulation2/serialization/SerializeTemplates.h"
Include dependency graph for CCmpAIManager.cpp:

Classes

class  CAIWorker
 Implements worker thread for CCmpAIManager. More...
 
class  CAIWorker::CAIPlayer
 
struct  CAIWorker::SCommandSets
 
class  CCmpAIManager
 Implementation of ICmpAIManager. More...
 

Functions

void kill_mainloop ()
 

Detailed Description

Player AI interface.

AI is primarily scripted, and the CCmpAIManager component defined here takes care of managing all the scripts.

To avoid slow AI scripts causing jerky rendering, they are run in a background thread (maintained by CAIWorker) so that it's okay if they take a whole simulation turn before returning their results (though preferably they shouldn't use nearly that much CPU).

CCmpAIManager grabs the world state after each turn (making use of AIInterface.js and AIProxy.js to decide what data to include) then passes it to CAIWorker. The AI scripts will then run asynchronously and return a list of commands to execute. Any attempts to read the command list (including indirectly via serialization) will block until it's actually completed, so the rest of the engine should avoid reading it for as long as possible.

JS values are passed between the game and AI threads using ScriptInterface::StructuredClone.

TODO: actually the thread isn't implemented yet, because performance hasn't been sufficiently problematic to justify the complexity yet, but the CAIWorker interface is designed to hopefully support threading when we want it.

Function Documentation

void kill_mainloop ( )