sum* parser::sm() { sum* s = new sum; s->terms.push_back(trm()); while (accept(t_plus)||accept(t_minus)) { s->operators.push_back(last.type); s->terms.push_back(trm()); } return s; }
void _ThreadSort(vector<int> *arr, int start, int end, int depth) { //Find middle of array int mid = (end + start) / 2; if(depth > _ThreadSortRecurDepth) { //Break array into four segments by finding secondary midpoints int midl = (mid + start) / 2; int midr = (mid + end) / 2; //Create thread to mergesort each of those four segments thread tl(_mergeSort, arr, start, midl); thread tlm (_mergeSort, arr, midl + 1, mid); thread trm (_mergeSort, arr, mid + 1, midr); thread tr(_mergeSort, arr, midr + 1, end); //Wait for each thread to finish tl.join(); tr.join(); tlm.join(); trm.join(); //merge left halves and right halves asynchronously thread mergeTl(merge, arr, start, midl, mid); thread mergeTr(merge, arr, mid + 1, midr, end); mergeTl.join(); mergeTr.join(); //finally merge left with right merge(arr, start, mid, end); } else { //Recursive threadsort on each half of the array. thread tl(_ThreadSort, arr, start, mid, depth + 1); thread tr(_ThreadSort, arr, mid + 1, end, depth + 1); tl.join(); tr.join(); merge(arr, start, mid, end); } }
void ResolveMovementBlockTask::InitBlockingStatic(idAI* owner, Subsystem& subsystem) { // Get the bounds of the blocking entity and see if there is a way around it idPhysics* blockingPhys = _blockingEnt->GetPhysics(); idBounds blockBounds = blockingPhys->GetAbsBounds(); // grayman #2356 - special case of being stuck inside a func_static, i.e. a rat under a bed that's not monster_clipped idVec3 ownerOrigin = owner->GetPhysics()->GetOrigin(); if (blockBounds.ContainsPoint(ownerOrigin)) { // Try to get out, otherwise you're stuck until your surroundings change. if (owner->movementSubsystem->AttemptToExtricate()) { owner->movementSubsystem->SetBlockedState(ai::MovementSubsystem::EResolvingBlock); // grayman #2706 - stay in EResolvingBlock return; } // oh boy, you're really stuck owner->StopMove(MOVE_STATUS_DONE); owner->AI_BLOCKED = false; owner->AI_DEST_UNREACHABLE = false; subsystem.FinishTask(); return; } blockBounds[0].z = blockBounds[1].z = 0; // Check if there is space to the right of the obstacle idBounds bounds = owner->GetPhysics()->GetBounds(); if (owner->GetAAS() == NULL) { return; } // angua: move the bottom of the bounds up a bit, to avoid finding small objects on the ground that are "in the way" // grayman #2684 - except for AI whose bounding box height is less than maxStepHeight, otherwise applying the bump up // causes the clipmodel to be "upside-down", which isn't good. In that case, give the bottom a bump up equal to half // of the clipmodel's height so it at least gets a small bump. float ht = owner->GetAAS()->GetSettings()->maxStepHeight; if (bounds[0].z + ht < bounds[1].z) { bounds[0].z += ht; } else { bounds[0].z += (bounds[1].z - bounds[0].z)/2.0; } // Set all attachments to nonsolid, temporarily owner->SaveAttachmentContents(); owner->SetAttachmentContents(0); // check if there is a way around idTraceModel trm(bounds); idClipModel clip(trm); idVec3 ownerRight, ownerForward; _initialAngles.ToVectors(&ownerForward, &ownerRight); // Take a point to the right idVec3 testPoint = blockingPhys->GetOrigin(); testPoint.z = ownerOrigin.z; // Move one AAS bounding box size outwards from the model float blockBoundsWidth = blockBounds.GetRadius(blockBounds.GetCenter()); idBounds aasBounds = owner->GetAAS()->GetSettings()->boundingBoxes[0]; aasBounds[0].z = aasBounds[1].z = 0; float aasBoundsWidth = aasBounds.GetRadius(); testPoint += ownerRight * (blockBoundsWidth + aasBoundsWidth); int contents = gameLocal.clip.Contents(testPoint, &clip, mat3_identity, CONTENTS_SOLID, owner); if (cv_ai_debug_blocked.GetBool()) { idVec3 temp = blockingPhys->GetOrigin(); temp.z = ownerOrigin.z; gameRenderWorld->DebugArrow(colorWhite, temp, temp + idVec3(0,0,10), 1, 1000); temp += ownerRight * (blockBoundsWidth + aasBoundsWidth + 5); gameRenderWorld->DebugArrow(colorLtGrey, temp, temp + idVec3(0,0,10), 1, 1000); gameRenderWorld->DebugBounds(contents ? colorRed : colorGreen, bounds, testPoint, 1000); } // grayman #2345 - the point tested might be in the VOID, so let's check for a valid AAS area int areaNum = owner->PointReachableAreaNum(testPoint); if ((contents != 0) || (areaNum == 0)) { // Right side is blocked, look at the left. testPoint = blockingPhys->GetOrigin(); testPoint.z = ownerOrigin.z; testPoint -= ownerRight * (blockBoundsWidth + aasBoundsWidth + 5); contents = gameLocal.clip.Contents(testPoint, &clip, mat3_identity, CONTENTS_SOLID, owner); if (cv_ai_debug_blocked.GetBool()) { gameRenderWorld->DebugBounds(contents ? colorRed : colorGreen, bounds, testPoint, 1000); } areaNum = owner->PointReachableAreaNum(testPoint); // testPoint must not be in the VOID if ((contents != 0) || (areaNum == 0)) { // Neither left nor right has free space // grayman #2345 - before declaring failure, let's try extrication owner->RestoreAttachmentContents(); // AttemptToExtricate() will do an attachment save/restore, so we must restore here first owner->movementSubsystem->AttemptToExtricate(); } else { // Move to left position owner->MoveToPosition(testPoint); owner->RestoreAttachmentContents(); } } else { // Move to right position owner->MoveToPosition(testPoint); owner->RestoreAttachmentContents(); } owner->movementSubsystem->SetBlockedState(ai::MovementSubsystem::EResolvingBlock); // grayman #2706 - stay in EResolvingBlock }