[Gcblue-commits] gcb_wx/src/ai Brain.cpp,1.4,1.5 ScriptedTaskInterface.cpp,1.1,1.2 Task.cpp,1.2,1.3
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-02-24 22:19:51
|
Update of /cvsroot/gcblue/gcb_wx/src/ai In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11465/src/ai Modified Files: Brain.cpp ScriptedTaskInterface.cpp Task.cpp Log Message: More OpenAL++ changes and ai improvements Index: Task.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/Task.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Task.cpp 16 Feb 2005 23:13:49 -0000 1.2 --- Task.cpp 24 Feb 2005 22:19:15 -0000 1.3 *************** *** 38,41 **** --- 38,45 ---- + void Task::EndTask() + { + GetPlatformInterface().DeleteTask(taskName); + } /** *************** *** 52,55 **** --- 56,64 ---- } + const std::string& Task::GetTaskName() const + { + return taskName; + } + bool Task::IsReadyForUpdate(double t) const { Index: Brain.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/Brain.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Brain.cpp 20 Feb 2005 21:54:32 -0000 1.4 --- Brain.cpp 24 Feb 2005 22:19:15 -0000 1.5 *************** *** 28,31 **** --- 28,32 ---- #include "ai/Brain.h" #include "ai/Task.h" + #include "ai/Nav.h" #include "ai/ScriptedTask.h" #include "sim/tcPlatformObject.h" *************** *** 47,50 **** --- 48,71 ---- } taskNameLookup["Test"] = TEST_TASK; + taskNameLookup["Nav"] = NAV_TASK; + } + + /** + * @return pointer to Nav task or 0 if none exists + */ + Nav* Brain::GetNavTask() + { + std::map<std::string, Task*>::iterator iter = taskMap.find("Nav"); + if (iter != taskMap.end()) + { + wxASSERT(iter->second); + return dynamic_cast<Nav*>(iter->second); + } + else + { + return 0; + } + + } *************** *** 101,104 **** --- 122,135 ---- void Brain::AddTask(const std::string& taskName, double priority_) { + // if task already exists, update priority + std::map<std::string, Task*>::iterator tm_iter = taskMap.find(taskName); + if (tm_iter != taskMap.end()) + { + tm_iter->second->SetPriority(priority_); + fprintf(stderr, "Warning - Brain::AddTask - task already exists, " + "updating priority (%s)\n", priority_); + return; + } + // check taskNameMap for C++ task, otherwise assume python script task std::map<std::string, int>::iterator iter = taskNameLookup.find(taskName); *************** *** 112,120 **** --- 143,191 ---- int taskCode = iter->second; // add switch for C++ task addition + switch (taskCode) + { + case TEST_TASK: + fprintf(stdout, "Test task called with priority %.1f\n", priority_); + break; + case NAV_TASK: + taskMap[taskName] = new Nav(platform, &board, + nextId++, priority_, taskName); + break; + default: + fprintf(stderr, "Unrecognized C++ taskname (%s)\n", taskName.c_str()); + break; + } + + } + } + + /** + * Removes tasks in removeList. This allows a task to safely delete itself. + */ + void Brain::RemovePending() + { + while (!removeList.empty()) + { + std::string taskName = removeList.front(); + removeList.pop(); + + RemoveTaskNow(taskName); } + } + /** + * Adds task to removeList for removal during next update. + */ void Brain::RemoveTask(const std::string& taskName) { + removeList.push(taskName); + } + + /** + * Immediately removes task + */ + void Brain::RemoveTaskNow(const std::string& taskName) + { std::map<std::string, Task*>::iterator iter = taskMap.find(taskName); if (iter != taskMap.end()) *************** *** 138,141 **** --- 209,214 ---- return; } + + RemovePending(); // iterate through task map and update tasks Index: ScriptedTaskInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/ScriptedTaskInterface.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ScriptedTaskInterface.cpp 16 Feb 2005 23:13:49 -0000 1.1 --- ScriptedTaskInterface.cpp 24 Feb 2005 22:19:15 -0000 1.2 *************** *** 52,55 **** --- 52,56 ---- class_<ScriptedTaskInterface>("ScriptedTaskInterface") + .def("EndTask", &ScriptedTaskInterface::EndTask) .def("GetBlackboardInterface", &ScriptedTaskInterface::GetBlackboardInterface) .def("GetPlatformInterface", &ScriptedTaskInterface::GetPlatformInterface) *************** *** 64,67 **** --- 65,77 ---- } + /** + * Call to safely end (remove) this task + */ + void ScriptedTaskInterface::EndTask() + { + wxASSERT(task); + task->EndTask(); + } + BlackboardInterface ScriptedTaskInterface::GetBlackboardInterface() { |