CBotTF2HealSched::CBotTF2HealSched(edict_t *pHeal) { CFindPathTask *findpath = new CFindPathTask(pHeal); findpath->SetCompleteInterrupt(CONDITION_SEE_HEAL); AddTask(findpath); AddTask(new CBotTF2MedicHeal()); }
CGotoHideSpotSched::CGotoHideSpotSched(CBot *pBot, edict_t *pEdict, bool bIsGrenade) { // run at flank while shooting CFindPathTask *pHideGoalPoint = new CFindPathTask(pEdict); pBot->SetCoverFrom(pEdict); AddTask(new CFindGoodHideSpot(pEdict)); AddTask(pHideGoalPoint); //if ( bIsGrenade ) //AddTask(new CDODWaitForGrenadeTask(pEdict)); // don't need to hide if the player we're hiding from died while we're running away pHideGoalPoint->FailIfTaskEdictDead(); pHideGoalPoint->SetLookTask(LOOK_WAYPOINT); // no interrupts, should be a quick waypoint path anyway pHideGoalPoint->SetNoInterruptions(); // get vector from good hide spot task pHideGoalPoint->GetPassedVector(); pHideGoalPoint->DontGoToEdict(); if (bIsGrenade) { pHideGoalPoint->SetRange(BLAST_RADIUS + 100.0f); pHideGoalPoint->CompleteOutOfRangeFromEdict(); } }
///Adds a NEW task to the queue. Creates a queue if the tracks associated with the task is not in the list /// ///@param task the task to add ///@param lockMutex locks the mutexes if true (default). This function is used within other ODManager calls, which many need to set this to false. void ODManager::AddNewTask(movable_ptr<ODTask> &&mtask, bool lockMutex) { auto task = mtask.get(); ODWaveTrackTaskQueue* queue = NULL; if(lockMutex) mQueuesMutex.Lock(); for(unsigned int i=0;i<mQueues.size();i++) { //search for a task containing the lead track. wavetrack removal is threadsafe and bound to the mQueuesMutex //note that GetWaveTrack is not threadsafe, but we are assuming task is not running on a different thread yet. if(mQueues[i]->ContainsWaveTrack(task->GetWaveTrack(0))) queue = mQueues[i].get(); } if(queue) { //Add it to the existing queue but keep the lock since this reference can be deleted. queue->AddTask(std::move(mtask)); if(lockMutex) mQueuesMutex.Unlock(); } else { //Make a NEW one, add it to the local track queue, and to the immediate running task list, //since this task is definitely at the head auto newqueue = make_movable<ODWaveTrackTaskQueue>(); newqueue->AddTask(std::move(mtask)); mQueues.push_back(std::move(newqueue)); if(lockMutex) mQueuesMutex.Unlock(); AddTask(task); } }
void DispatchTask (void){ uint8_t n=0; if (flags.RunFlag==1){ // если таймер выставил флаг task tmp; // переменная для хранения нулевого элемента tmp=TaskArray[0]; while (((TaskArray[n].pfunc != 0) || (TaskArray[n].countdown!=0)) && (n < MAXnTASKS)){ n++; //мотаем пока счетчик не дойдет до задачи с нужной задержкой TaskArray[n-1]=TaskArray[n]; //сдвигаем очередь вперед if (TaskArray[n-1].countdown) TaskArray[n-1].countdown-=dt; //вычитаем прошедшее время из каждой задачи } DeleteTask(n); //удаляем последнюю задачу switch (tmp.numRun){ case 0: if (*tmp.nextfunc!=Idle) AddTask(*tmp.nextfunc,Idle,tmp.nextdelay,0,tmp.numRun);break; case 0xffff: AddTask(*tmp.pfunc,*tmp.nextfunc,tmp.delay,tmp.nextdelay,tmp.numRun);break; default: if (tmp.numRun&&tmp.numRun!=0xffff) AddTask(*tmp.pfunc,*tmp.nextfunc,tmp.delay,tmp.nextdelay,--tmp.numRun);break; } if (TaskArray[0].countdown!=0) {delay_time=TaskArray[0].countdown;} // если здесь +1 , то немного работает )))) else {delay_time=1;} //можно флаг запуска добавить сюда , но в очереди будет нечего убавлять и ф-ию зациклит dt=delay_time; //или воткнуть туда значение уменьшения , только его нужно брать для точности (*tmp.pfunc)(); flags.RunFlag=0; //из расчета кол-ва тиков выполняемой функции и частоты прерывания таймера } }
CBotFollowLastEnemy::CBotFollowLastEnemy(CBot *pBot, edict_t *pEnemy, Vector vLastSee) { Vector vVelocity = Vector(0, 0, 0); CClient *pClient = CClients::Get(pEnemy); CFindPathTask *pFindPath = new CFindPathTask(vLastSee, LOOK_LAST_ENEMY); if (CClassInterface::GetVelocity(pEnemy, &vVelocity)) { if (pClient && (vVelocity == Vector(0, 0, 0))) vVelocity = pClient->GetVelocity(); } else if (pClient) vVelocity = pClient->GetVelocity(); pFindPath->SetCompleteInterrupt(CONDITION_SEE_CUR_ENEMY); AddTask(pFindPath); /*if ( pBot->isTF2() ) { int playerclass = ((CBotTF2*)pBot)->getClass(); if ( ( playerclass == TF_CLASS_SOLDIER ) || (playerclass == TF_CLASS_DEMOMAN) ) AddTask(new CBotTF2ShootLastEnemyPosition(vLastSee,pEnemy,vVelocity)); }*/ AddTask(new CFindLastEnemy(vLastSee, vVelocity)); ////////////// pFindPath->SetNoInterruptions(); }
CBotRemoveSapperSched::CBotRemoveSapperSched(edict_t *pBuilding, eEngiBuild id) { CFindPathTask *pathtask = new CFindPathTask(pBuilding); AddTask(pathtask); pathtask->CompleteInRangeFromEdict(); pathtask->SetRange(150.0f); AddTask(new CBotRemoveSapper(pBuilding, id)); }
CBotTF2GetFlagSched::CBotTF2GetFlagSched(Vector vOrigin, bool bUseRoute, Vector vRoute) { if (bUseRoute) AddTask(new CFindPathTask(vRoute)); AddTask(new CFindPathTask(vOrigin)); // first AddTask(new CBotTF2WaitFlagTask(vOrigin)); // second }
CBotDefendSched::CBotDefendSched(int iWaypointID, float fMaxTime) { CWaypoint *pWaypoint; pWaypoint = CWaypoints::GetWaypoint(iWaypointID); AddTask(new CFindPathTask(iWaypointID)); AddTask(new CBotDefendTask(pWaypoint->GetOrigin(), fMaxTime, 8, false, Vector(0, 0, 0), LOOK_SNIPE, pWaypoint->GetFlags())); }
CBotSpySapBuildingSched::CBotSpySapBuildingSched(edict_t *pBuilding, eEngiBuild id) { CFindPathTask *findpath = new CFindPathTask(pBuilding); AddTask(findpath); // first AddTask(new CBotTF2SpySap(pBuilding, id)); // second findpath->SetDangerPoint(CWaypointLocations::NearestWaypoint(CBotGlobals::EntityOrigin(pBuilding), 200.0f, -1)); }
void DS18B20InitializeSensorTask() { DS18B20InitializeSensorAction(); if (DS18B20ResultInitializeSensor == DS18B20OperationOK) { AddTask(DS18B20ConvertTemperatureTask, DS18B20ConvertTemperatureTaskDelay); } else { AddTask(DS18B20InitializeSensorTask, DS18B20RepeatInitializeSensorTaskDelay); } }
int main(void) { init_scheduler(); AddTask(0,50, keypak, NULL); AddTask(1, 20, keypak1, NULL); AddTask(7, 500, NULL, NULL); init_timer_irq(); execute(); }
CBotTFEngiBuild::CBotTFEngiBuild(CBot *pBot, eEngiBuild iObject, CWaypoint *pWaypoint) { CFindPathTask *pathtask = new CFindPathTask(CWaypoints::GetWaypointIndex(pWaypoint)); AddTask(pathtask); // first pathtask->SetInterruptFunction(new CBotTF2EngineerInterrupt(pBot)); AddTask(new CBotTFEngiBuildTask(iObject, pWaypoint)); // second }
void main(void) { Init_Device(); #if WITH_TASKER InitTasker(); led_task = AddTask(&LedToggle,1000,INFINITE_TASK); #endif #if WITH_BINDER InitBinder(); #endif P0 &= (~0x80); #if WITH_COMM_LINK StartCommLinkCommunication(0x26); #endif #if WITH_Z_UNO_CHANNEL_DEBUG { BYTE result = setupUserChannels(); } #endif #if WITH_LCD LCD_Init_VIM878(); #endif #if WITH_BUTTONS ButtonsInit(); AddTask(ButtonsPoll, 10, INFINITE_TASK); #endif while(TRUE) { #if WITH_Z_UNO_CODE ApplicationPoll(); #endif #if WITH_UART0 CheckUART(); #endif #if WITH_SODA_UART checkSodaUart(); #endif #if WITH_BUTTONS ParseButtonEvents(); ClearButtonEvents(); #endif #if WITH_TASKER if (tasker_flag == TRUE) { tasker_flag = FALSE; Tasker(); } #endif #if WITH_BINDER EventBinder(); #endif #if WITH_GENERAL_TESTING_FILE generalTestingRoutine(); #endif } }
CBotBackstabSched::CBotBackstabSched(edict_t *pEnemy) { Vector vrear; Vector vangles; AngleVectors(CBotGlobals::EntityEyeAngles(pEnemy), &vangles); vrear = CBotGlobals::EntityOrigin(pEnemy) - (vangles * 45) + Vector(0, 0, 32); AddTask(new CFindPathTask(vrear)); AddTask(new CBotBackstab(pEnemy)); }
CBotTF2SnipeSched::CBotTF2SnipeSched(Vector vOrigin, int iWpt) { CBotTask *pFindPath = new CFindPathTask(iWpt); CBotTask *pSnipeTask = new CBotTF2Snipe(vOrigin, iWpt); AddTask(pFindPath); // first AddTask(pSnipeTask); // second pFindPath->SetFailInterrupt(CONDITION_PARANOID); pSnipeTask->SetFailInterrupt(CONDITION_PARANOID); }
CBotGetMetalSched::CBotGetMetalSched(Vector vOrigin) { CFindPathTask *task1 = new CFindPathTask(vOrigin); CBotTF2WaitAmmoTask *task2 = new CBotTF2WaitAmmoTask(vOrigin); task1->SetCompleteInterrupt(0, CONDITION_NEED_AMMO); task2->SetCompleteInterrupt(0, CONDITION_NEED_AMMO); AddTask(task1); // first AddTask(task2); }
CBotTF2AttackSentryGun::CBotTF2AttackSentryGun(edict_t *pSentry, CBotWeapon *pWeapon) { CFindPathTask *path = new CFindPathTask(pSentry); AddTask(path); AddTask(new CBotTF2AttackSentryGunTask(pSentry, pWeapon)); path->CompleteInRangeFromEdict(); path->CompleteIfSeeTaskEdict(); path->SetRange(pWeapon->PrimaryMaxRange() - 100); }
CBotEngiMoveBuilding::CBotEngiMoveBuilding(edict_t *pBotEdict, edict_t *pBuilding, eEngiBuild iObject, Vector vNewLocation, bool bCarrying) { // not carrying if (!bCarrying) { AddTask(new CFindPathTask(pBuilding)); AddTask(new CBotTaskEngiPickupBuilding(pBuilding)); } // otherwise already carrying AddTask(new CFindPathTask(vNewLocation)); AddTask(new CBotTaskEngiPlaceBuilding(iObject, vNewLocation)); }
int main(void) { DDRA = 0xFF; //PORTA = 0b11111111; // AtMega 16 PORTA = 0b00000000; AddTask(Set0, 1, 0); AddTask(Set1, 2, 1); AddTask(Set2, 3, 2); AddTask(Set3, 4, 3); schedule(); }
CBotTF2GetAmmoSched::CBotTF2GetAmmoSched(Vector vOrigin) { CFindPathTask *task1 = new CFindPathTask(vOrigin); CBotTF2WaitAmmoTask *task2 = new CBotTF2WaitAmmoTask(vOrigin); // if bot doesn't have need ammo flag anymore .... // fail so that the bot doesn't move onto the next task task1->SetCompleteInterrupt(0, CONDITION_NEED_AMMO); task2->SetCompleteInterrupt(0, CONDITION_NEED_AMMO); AddTask(task1); // first AddTask(task2); // second }
CBotUseDispSched::CBotUseDispSched(CBot *pBot, edict_t *pDisp)//, bool bNest ) { CFindPathTask *pathtask = new CFindPathTask(pDisp); CBotTF2WaitHealthTask *gethealth = new CBotTF2WaitHealthTask(CBotGlobals::EntityOrigin(pDisp)); AddTask(pathtask); pathtask->SetInterruptFunction(new CBotTF2EngineerInterrupt(pBot)); AddTask(gethealth); // second gethealth->SetInterruptFunction(new CBotTF2EngineerInterrupt(pBot)); //if ( bNest ) // AddTask(new CBotNest()); // third }
CGotoHideSpotSched::CGotoHideSpotSched(CBot *pBot, Vector vOrigin, IBotTaskInterrupt *interrupt) { // run at flank while shooting CFindPathTask *pHideGoalPoint = new CFindPathTask(); pBot->SetCoverFrom(NULL); AddTask(new CFindGoodHideSpot(vOrigin)); AddTask(pHideGoalPoint); // no interrupts, should be a quick waypoint path anyway pHideGoalPoint->SetNoInterruptions(); pHideGoalPoint->SetInterruptFunction(interrupt); // get vector from good hide spot task pHideGoalPoint->GetPassedVector(); }
int main(void) { // Timer 0 w trybie OCR TIMSK |= (1 << OCIE0); // COMP overflow OCR0 = 250; // 250 * 64 = 16MHz = 1000 przerwañ na sekundê TCCR0 |= (1 << CS00) | (1 << CS01); // Prescaller 64 sei(); AddTask(0, 1, &Led1, 0); AddTask(1, 2, &Led2, 0); AddTask(2, 3, &Led3, 0); execute(); }
int main(int argc, char **argv) { int arg_ins=1; float arg_exit=7; if (0 != InitPool()) return 1; AddTask(Task1, &arg_ins, NULL, &arg_exit); AddTask(Task2, &arg_ins, NULL, &arg_exit); while(1) { SLEEP(10); } return 0; }
void ODManager::AddTaskToWaveTrack(ODTask* task, WaveTrack* track) { ODWaveTrackTaskQueue* queue = NULL; mQueuesMutex.Lock(); for(int i=0;i<mQueues.size();i++) { if(mQueues[i]->ContainsWaveTrack(track)) queue=mQueues[i]; } if(queue) { //Add it to the existing queue but keep the lock since this reference can be deleted. queue->AddTask(task); mQueuesMutex.Unlock(); } else { //Make a new one, add it to the local track queue, and to the immediate running task list, //since this task is definitely at the head queue = new ODWaveTrackTaskQueue(track); queue->AddTask(task); mQueues.push_back(queue); mQueuesMutex.Unlock(); AddTask(task); } }
///remove tasks from ODWaveTrackTaskQueues that have been done. Schedules new ones if they exist ///Also remove queues that have become empty. void ODManager::UpdateQueues() { mQueuesMutex.Lock(); for(int i=0;i<mQueues.size();i++) { if(mQueues[i]->IsFrontTaskComplete()) { mQueues[i]->RemoveFrontTask(); //schedule next. if(!mQueues[i]->IsEmpty()) { //we need to release the lock on the queue vector before using the task vector's lock or we deadlock //so get a temp. ODWaveTrackTaskQueue* queue; queue = mQueues[i]; mQueuesMutex.Unlock(); AddTask(queue->GetFrontTask()); mQueuesMutex.Lock(); } } //if the queue is empty delete it. if(mQueues[i]->IsEmpty()) { delete mQueues[i]; mQueues.erase(mQueues.begin()+i); i--; } } mQueuesMutex.Unlock(); }
bool Scene_Inca_Passage::ObjectClicked(const char *szObjectName, float x, float y) { /* Cartouches */ if (strcmp(szObjectName, "inca_cartouche1_ground") == 0) { PickupSimple(szObjectName, "inv_inca_cartouche1"); } if (strcmp(szObjectName, "inca_cartouche2_ground") == 0) { if (TaskResolved("task_inca_fillhole")) { PickupSimple(szObjectName, "inv_inca_cartouche2"); } else { _lpSceneDirector->getSequencer()->Talk(NULL, CHARACTER_POSX, CHARACTER_POSY, KStr("INCA_YUMANCO_HOLE"), "", true, false); AddTask("task_inca_fillhole"); } } /* Artefacts */ if (strcmp(szObjectName, "inca_artefact3") == 0) { PickupSimple(szObjectName, "inv_inca_artefact3"); ResolveTask("task_inca_getartefact3"); TestTaskArtefacts(); } if (strcmp(szObjectName, "inca_artefact4") == 0) { PickupSimple(szObjectName, "inv_inca_artefact4"); ResolveTask("task_inca_getartefact4"); TestTaskArtefacts(); } return false; }
void Scheduler::CreateTask(TaskF const& fn) { Task* tk = new Task(fn, GetOptions().stack_size); ++task_count_; ++runnale_task_count_; AddTask(tk); }
///remove tasks from ODWaveTrackTaskQueues that have been done. Schedules NEW ones if they exist ///Also remove queues that have become empty. void ODManager::UpdateQueues() { mQueuesMutex.Lock(); for(unsigned int i=0;i<mQueues.size();i++) { if(mQueues[i]->IsFrontTaskComplete()) { //this should DELETE and remove the front task instance. mQueues[i]->RemoveFrontTask(); //schedule next. if(!mQueues[i]->IsEmpty()) { //we need to release the lock on the queue vector before using the task vector's lock or we deadlock //so get a temp. ODWaveTrackTaskQueue* queue = mQueues[i].get(); AddTask(queue->GetFrontTask()); } } //if the queue is empty DELETE it. if(mQueues[i]->IsEmpty()) { mQueues.erase(mQueues.begin()+i); i--; } } mQueuesMutex.Unlock(); }
void ThreadPool::AddTask(Closure<void()>* callback) { // The memory address is random enough for load balance, but need // remove low alignment part. (The lowest 5 bits of allocated object // address are always 0 for 64 bit system). unsigned int dispatch_key = reinterpret_cast<uintptr_t>(callback) / 32; AddTask(callback, dispatch_key); }