[Gcblue-commits] gcb_wx/include/ai BlackboardInterface.h,NONE,1.1 ScriptedTask.h,NONE,1.1 ScriptedTa
Status: Alpha
Brought to you by:
ddcforge
Update of /cvsroot/gcblue/gcb_wx/include/ai In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15468/include/ai Modified Files: Blackboard.h BlackboardItem.h Brain.h Task.h Added Files: BlackboardInterface.h ScriptedTask.h ScriptedTaskInterface.h SelfPreservation.h Log Message: Parallel ai update Index: Blackboard.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/ai/Blackboard.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Blackboard.h 4 Feb 2005 18:50:46 -0000 1.1 --- Blackboard.h 16 Feb 2005 23:13:37 -0000 1.2 *************** *** 39,49 **** { public: - void EraseAll(); void Erase(const std::string& key, double priority); bool KeyExists(const std::string& key) const; BlackboardItem Read(const std::string& key); double ReadPriority(const std::string& key); ! void Write(const std::string& key, const BlackboardItem& item); ! void Write(const std::string& key, long author, double priority, const std::string& message); Blackboard(); --- 39,53 ---- { public: void Erase(const std::string& key, double priority); + void EraseAll(); + void EraseAllFromAuthor(long author); + bool KeyExists(const std::string& key) const; BlackboardItem Read(const std::string& key); + long ReadAuthor(const std::string& key); + const std::string ReadMessage(const std::string& key); double ReadPriority(const std::string& key); ! bool Write(const std::string& key, const BlackboardItem& item); ! bool Write(const std::string& key, long author, double priority, const std::string& message); Blackboard(); --- NEW FILE: BlackboardInterface.h --- /** ** @file BlackboardInterface.h */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _BLACKBOARDINTERFACE_H_ #define _BLACKBOARDINTERFACE_H_ #if _MSC_VER > 1000 #pragma once #endif #include <map> #include <string> #include <vector> namespace ai { class Blackboard; class BlackboardItem; /** * Class to interface with blackboard. Handles priority and * author aspects. */ class BlackboardInterface { public: void SetPriority(double priority_); BlackboardInterface GetBlackboardInterface(); long GetAuthor() const; /// blackboard interface void Erase(const std::string& key); bool KeyExists(const std::string& key) const; BlackboardItem Read(const std::string& key); long ReadAuthor(const std::string& key); const std::string ReadMessage(const std::string& key); double ReadPriority(const std::string& key); bool Write(const std::string& key, const std::string& message); BlackboardInterface(); BlackboardInterface(const BlackboardInterface& source); BlackboardInterface(Blackboard* bb, long author_, double priority_); ~BlackboardInterface(); protected: Blackboard* const board; const long author; double priority; static bool pythonInitialized; static void InitPython(); }; } #endif --- NEW FILE: ScriptedTask.h --- /** ** @file ScriptedTask.h */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SCRIPTEDTASK_H_ #define _SCRIPTEDTASK_H_ #if _MSC_VER > 1000 #pragma once #endif #include "ai/Task.h" #include <map> #include <string> #include <vector> namespace ai { class Blackboard; /** * Task that is scripted through Python */ class ScriptedTask : public Task { public: const std::string& GetMemoryText(const std::string& key); void SetMemoryText(const std::string& key, const std::string& text); double GetMemoryValue(int key); void SetMemoryValue(int key, double value); void Update(double t); ScriptedTask(tcPlatformObject* platform_, Blackboard* bb, long id_, double priority_, const std::string& scriptName_); ~ScriptedTask(); protected: std::map<std::string, std::string> textMemory; std::map<int, double> numberMemory; const char* GetCommandString(); private: wxString commandString; }; } #endif --- NEW FILE: SelfPreservation.h --- /** ** @file SelfPreservation.h */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SELFPRESERVATION_H_ #define _SELFPRESERVATION_H_ #if _MSC_VER > 1000 #pragma once #endif #include "ai/Task.h" #include <map> #include <string> #include <vector> class tcPlatformObject; namespace ai { /** * Basic self preservation behavior. Avoid crashing, run from * threats. */ class SelfPreservation : public Task { public: void Update(double t); void UpdateAir(double t); SelfPreservation(tcPlatformObject* platform_, Blackboard* bb, long id_, double priority_, const std::string& taskName_); ~SelfPreservation(); private: bool haveAltitudeControl; }; } #endif Index: Brain.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/ai/Brain.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Brain.h 8 Feb 2005 12:58:21 -0000 1.2 --- Brain.h 16 Feb 2005 23:13:38 -0000 1.3 *************** *** 33,36 **** --- 33,38 ---- #include "ai/Blackboard.h" + class tcPlatformObject; + namespace ai { *************** *** 48,57 **** { public: ! Brain(); ! ~Brain(); private: Blackboard board; ///< for inter-task communication std::map<std::string, Task*> taskMap; }; --- 50,78 ---- { public: ! /** task codes for C++ tasks */ ! enum ! { ! TEST_TASK = 0 ! }; ! void AddTask(const std::string& taskName, double priority_); ! void RemoveTask(const std::string& taskName); ! bool TaskExists(const std::string& taskName); + void Update(double t); + + Brain(tcPlatformObject* platform_); + ~Brain(); private: + tcPlatformObject* const platform; + const float updateInterval; + long nextId; ///< id assigned to next task + double lastUpdateTime; ///< last time tasks were updated + Blackboard board; ///< for inter-task communication std::map<std::string, Task*> taskMap; + + static std::map<std::string, int> taskNameLookup; + + static void InitTaskNameLookup(); }; --- NEW FILE: ScriptedTaskInterface.h --- /** ** @file ScriptedTaskInterface.h */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SCRIPTEDTASKINTERFACE_H_ #define _SCRIPTEDTASKINTERFACE_H_ #if _MSC_VER > 1000 #pragma once #endif #include "ai/Task.h" #include <map> #include <string> #include <vector> namespace ScriptInterface { class tcPlatformInterface; } namespace ai { class BlackboardInterface; class ScriptedTask; /** * Interface for ScriptedTask passed to Python */ class ScriptedTaskInterface { public: BlackboardInterface GetBlackboardInterface(); tcPlatformInterface GetPlatformInterface(); void SetUpdateInterval(float interval); const std::string GetMemoryText(const std::string& key); void SetMemoryText(const std::string& key, const std::string& text); double GetMemoryValue(int key); void SetMemoryValue(int key, double value); void SetTask(ScriptedTask* scriptedTask); ScriptedTaskInterface(ScriptedTask* scriptedTask); ScriptedTaskInterface(); ~ScriptedTaskInterface(); protected: ScriptedTask* task; static bool pythonInitialized; static void InitPython(); }; } #endif Index: BlackboardItem.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/ai/BlackboardItem.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BlackboardItem.h 4 Feb 2005 18:50:46 -0000 1.1 --- BlackboardItem.h 16 Feb 2005 23:13:38 -0000 1.2 *************** *** 38,42 **** { public: ! long author; ///< -1 for invalid, 0 for anonymous double priority; std::string message; --- 38,42 ---- { public: ! long author; ///< -1 for invalid double priority; std::string message; *************** *** 49,52 **** --- 49,55 ---- BlackboardItem(); ~BlackboardItem(); + + static bool pythonInitialized; + static void InitPython(); }; } Index: Task.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/ai/Task.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Task.h 8 Feb 2005 12:58:21 -0000 1.2 --- Task.h 16 Feb 2005 23:13:38 -0000 1.3 *************** *** 27,35 **** --- 27,44 ---- #endif + #include "ai/BlackboardInterface.h" + #include <map> #include <string> #include <vector> + namespace ScriptInterface + { + class tcPlatformInterface; + } + using ScriptInterface::tcPlatformInterface; + + class tcPlatformObject; namespace ai *************** *** 39,62 **** /** ! * */ ! class Task { public: ! std::map<std::string, std::string> textMemory; ! std::map<int, double> numberMemory; ! void SetBoard(Blackboard* bb); ! void SetId(long id_); ! void SetPriority(double priority_); ! Task(Blackboard* bb, long id_, double priority_); ! Task(); ! ~Task(); private: ! Blackboard* commBoard; ! double priority; ! long id; ! std::string scriptName; }; --- 48,77 ---- /** ! * Base class for ai tasks. Could also call these behaviors. */ ! class Task : public BlackboardInterface { public: ! tcPlatformInterface GetPlatformInterface(); ! ! void FinishUpdate(double t); ! bool IsReadyForUpdate(double t) const; ! void SetUpdateInterval(float interval); ! virtual void Update(double t); ! ! Task(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, const std::string& taskName_); ! virtual ~Task(); ! ! protected: ! tcPlatformObject* const platform; ! ! const std::string taskName; ! private: ! double lastUpdateTime; ! float updateInterval; }; |