Iter consecutive_find(Iter current, Iter last, std::size_t n) { Iter marker(current), lead(current); while (lead != last) { std::size_t count(1); lead = std::next(marker); while ((lead != last) && (*marker == *lead)) { ++count; ++lead; } if (count == n) { if ((lead == last) || (*lead != *marker)) return lead - count; ++lead; } marker = lead; } return last; }
bool PNS_DIFF_PAIR_PLACER::propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNewP ) { PNS_VIA virtHead = makeVia( aP, -1 ); if( m_placingVia ) virtHead.SetDiameter( viaGap() + 2 * virtHead.Diameter() ); else { virtHead.SetLayer( m_currentLayer ); virtHead.SetDiameter( m_sizes.DiffPairGap() + 2 * m_sizes.TrackWidth() ); } VECTOR2I lead( 0, 0 );// = aP - m_currentStart ; VECTOR2I force; bool solidsOnly = true; if( m_currentMode == RM_MarkObstacles ) { aNewP = aP; return true; } else if( m_currentMode == RM_Walkaround ) { solidsOnly = false; } // fixme: I'm too lazy to do it well. Circular approximaton will do for the moment. if( virtHead.PushoutForce( m_currentNode, lead, force, solidsOnly, 40 ) ) { aNewP = aP + force; return true; } return false; }
Iter consecutive_find(Iter first, Iter last, typename std::iterator_traits<Iter>::difference_type n) { Iter marker(first), lead(first); using value_type = typename std::iterator_traits<Iter>::value_type; while (marker != last) { lead = std::next(marker); lead = std::find_if_not(lead, last, [&lead] (value_type const& x) { return x == *lead; }); if (std::distance(marker, lead) == n) { if ((lead == last) || !(*lead == *marker)) return marker; lead = std::find_if_not(lead, last, [&lead] (value_type const& x) { return x == *lead; }); } marker = lead; } return last; }
static inline int32_t ALWAYS_INLINE lg3a (int32_t x) { int32_t result ; x += 3 ; result = lead (x) ; return 31 - result ; }
int main(int argc, char *argv[]) { printf("DEBUG: sizeof(char): %ld\n", sizeof(char)); printf("DEBUG: sizeof(short): %ld\n", sizeof(short)); unlink(PATH); lead(PATH, "test-0.1.0-1"); signature(PATH, NULL); return 0; }
void yarrAI :: pursue(spaceShip* enemy) { // lead the enemy spacePoint leadpos = lead(enemy, puppet->maxvel); // seek the lead, unless we get too close //if(puppet->pos.dist(enemy->pos) > standoff_range) seek(leadpos); //else // avoid(leadpos); thrust(); }
void yarrAI :: attack(spaceShip* enemy) { /// Lead an enemy with turrets and attack. Does not make the ship pursue /// uses : turrets, fire // FIXME BROKEN : leading for guns is currently broken, need to make it // take into account the attacker's velocity SPfloat gaugedspeed = gunspeed + (rand()%(int)(inaccuracy * 2) - inaccuracy); spacePoint leadpos = lead(enemy, gaugedspeed); aimat(leadpos); if( puppet->pos.dist(leadpos) <= gunrange ) puppet->fire(); }
poly<T>& poly<T>::operator/=(poly<T> const& rhs) { if (rhs.size()==1) { for (size_t i=0; i!=this->size(); ++i) (*this)[i] /= rhs[0]; return *this; } if (this->size() < rhs.size()) return *this = poly<T>(0, T(0)); size_t deg = this->size() - rhs.size(); T lc = (this->lcff()/rhs.lcff()); if (deg == 0) return *this = poly<T>(0, lc); poly<T> lead(deg, lc); *this -= rhs*lead; return *this = lead + (*this/rhs); }
int ipc_bench(char * flag_str) { double time_elapced; struct shmid_ds ds; int semid, shmid; short sarray[NUMSEMS] = { 1, 1 }; // if (argc < 2) { // printf( // "Please specifivy the IPC method.\nAvailable methotds:\nPIP\nFILE\nSHM\n"); // exit(0); // } int flag; if (strcmp(flag_str, (char *) SHM_IPC) == 0) { key_t semkey = ftok(SLEADKEY, 'S'); key_t shmkey = ftok(BUFKEY, 'B'); semid = semget(semkey, NUMSEM, IPC_CREAT | IPC_EXCL); if (semid == -1) { // printf ("SEMMSL is %d \n",SEMMNI); perror("semget: semget failed"); exit(1); } shmid = shmget(shmkey, MAX_BUF_SIZE * sizeof(int), IPC_CREAT | S_IRUSR | S_IWUSR); flag = SHM_IPC_ID; } else if (strcmp(flag_str, (char *) FILE_IPC) == 0) { flag = FILE_IPC_ID; } else if (strcmp(flag_str, (char *) PIP_IPC) == 0) { flag = PIP_IPC_ID; } else { printf( "BAD INPUT\nPlease specifivy the IPC method.\nAvailable methotds:\nPIP\nFILE\nSHM\n"); exit(1); } // if (file_exist(LEAD_FILE_BUF)){ // printf("exist\n"); // } // exit(0); int itr; for (itr = 0; itr < NUM_ITRS; itr++) { // printf("Iteration %d\n", itr); switch (flag) { case PIP_IPC_ID: unlink(lead_pipfile(itr)); unlink(follow_pipfile(itr)); break; case FILE_IPC_ID: unlink(LOCK_FILE_LEAD); unlink(LOCK_FILE_FOLO); unlink(LEAD_FILE_BUF); unlink(FOLO_FILE_BUF); break; case SHM_IPC_ID: shmctl(shmid, IPC_STAT, &ds); semctl(semid, 0, SETVAL, sarray); break; default: exit(1); } pid_t pid = fork(); if (pid == 0) { follow(itr, flag); exit(0); } else { double lead_time = 0; lead_time = lead(itr, flag); lead_time /= (double) NUM_ITRS; time_elapced += lead_time; wait(NULL); } } if (flag == SHM_IPC_ID) { semctl(semid, 1, IPC_RMID); } printf("> %s IPC: %f seconds\n", flag_str, time_elapced); return 0; }
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow ) { CoInitialize(NULL); Mycapp.Initilize(hInstance,TEXT("MY"),WndProc); hwnd = Mycapp.GetHWND(); ghInstance = hInstance; w.Initialize(Mycapp); CInput cinput; cinput.Initialize(hInstance,Mycapp.GetHWND()); pcinput = &cinput; RECT _rect ={0,0,640,480}; PlaySound(TEXT("melody of life.wav"),hInstance,SND_LOOP|SND_FILENAME|SND_ASYNC ); LeadReader r; Attribute attr = r.GetAttr(); CLead lead(&w,attr); lead.Initialize(); CWeaponReader cwR; CSceneReader cr; vector<WeaponInfo> vecWeapon = cwR.GetWeapons(); CWeapons Weapon(&w); Weapon.SetVec(vecWeapon); psmanger.SetWeapon(&Weapon); psmanger.SetDraw(&w); psmanger.SetOverImage(TEXT("gameover.bmp")); CSceneInit csi; CScene* pscene = csi.InitScene("4096",&lead,&w,pcinput); CScene* pscene2 = csi.InitScene("4097",&lead,&w,pcinput); CScene* pscene3 = csi.InitScene("4098",&lead,&w,pcinput); CScene* pscene4 = csi.InitScene("4099",&lead,&w,pcinput); CScene* pscene5 = csi.InitScene("4100",&lead,&w,pcinput); CPathReader cpr; psmanger.SetPaths(cpr.GetPaths()); psmanger.RegisterScene(pscene); psmanger.RegisterScene(pscene2); psmanger.RegisterScene(pscene3); psmanger.RegisterScene(pscene4); psmanger.RegisterScene(pscene5); CSceneReader sr; SceneDesc scenedesc = sr.GetDesc("4097"); scenedesc.lpImage = NULL; scenedesc.pCDraw = &w; scenedesc.pcInput = &cinput; scenedesc.lpwFileName = TEXT("4.bmp"); scenedesc.bIsFightable = true; CMyMenu menuRectVictory(TEXT("6.bmp"),pcinput,&w,250,400); CMyMenu menuSelect(TEXT("6.bmp"),pcinput,&w,250,200); menuSelect.Initialize(); menuSelect.AddItem(TEXT("Attack!")); menuSelect.AddItem(TEXT("使用药水:10个")); CMyMenu menuStatus(TEXT("6.bmp"),pcinput,&w,250,200); menuStatus.Initialize(); menuStatus.AddItem(TEXT("主 角 H P:")); menuStatus.AddItem(TEXT("主角攻击力:")); menuStatus.AddItem(TEXT("主角防御力:")); menuRectVictory.Initialize(); CFightScene csceneFight(scenedesc,&menuRectVictory,&menuSelect,TEXT("bomb.bmp"),&menuStatus); CMyMenu menuSelectBuy(TEXT("6.bmp"),pcinput,&w,250,400); menuSelectBuy.Initialize(); cwR.FillItems( vecWeapon,menuSelectBuy); CSellScene css(scenedesc,&menuSelectBuy); css.Initialize(); css.SetWeapons(&Weapon); css.RegisterLead(&lead); psmanger.SetSellScene(&css); csceneFight.Initialize(); psmanger.SetFightScene(&csceneFight); #ifndef WINDOW_DEBUG psmanger.Draw(); #else psmanger.Draw(Mycapp.GetHWND()); #endif MSG msg; msg.message = WM_NULL; for(;;) { if(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message == WM_QUIT) break; else { #ifndef WINDOW_DEBUG psmanger.Draw(); #else psmanger.Draw(Mycapp.GetHWND()); #endif } } CoUninitialize(); return msg.message; }
void CTrackingMissile::Update(void) { CQuaternion q; float t; m_Age = g_time - m_CreationTime; if(m_Age > m_LifeTime) { Die(); return; } if (!m_Tracking) { if (m_Age <= 0.4f) { if (m_FlyLeft) m_RenderObj.MoveRight(-20.0f * g_FrameTime, 0); else m_RenderObj.MoveRight(20.0f * g_FrameTime, 0); t = m_Age; QuatSlerp(&q, &m_Q0, &m_Q1, t * 2.5f); m_RenderObj.GetFrame(0)->SetOrientation(&q); } else if (m_Age <= 0.8f && !m_Target) { t = m_Age - 0.4f; QuatSlerp(&q, &m_Q1, &m_Q2, t * 2.5f); m_RenderObj.GetFrame(0)->SetOrientation(&q); } else { m_Tracking = true; m_RenderObj.GetFrame(0)->GetOrientation(&m_Q0); m_Q1 = m_Q0; m_Velocity = 120.0f; m_LastUpdate = g_time - m_UpdatePeriod; } } else { if (m_Target) { if (m_Target->IsActive()) { t = g_time - m_LastUpdate; if (t >= m_UpdatePeriod) { CVector3f oldfwd, newfwd, tpos, pos, lead(0.0f, 0.0f, 0.0f); m_Q0 = m_Q1; // Find new orientation, lead target a little m_RenderObj.GetFrame(0)->GetForward(&oldfwd); m_Target->GetPosition(&tpos, 0); m_Target->GetVelocity(&lead); Vec3fScale(&lead, &lead, m_UpdatePeriod); Vec3fAdd(&tpos, &tpos, &lead); GetPosition(&pos, 0); Vec3fSubtract(&newfwd, &tpos, &pos); Vec3fNormalize(&newfwd, &newfwd); QuatRotationArc(&q, &oldfwd, &newfwd); QuatCrossProduct(&m_Q1, &q, &m_Q1); m_LastUpdate += m_UpdatePeriod; t = g_time - m_LastUpdate; } QuatSlerp(&q, &m_Q0, &m_Q1, t * m_SlerpScale); m_RenderObj.GetFrame(0)->SetOrientation(&q); } else m_Target = 0; } } // Move the shot forward MoveForward(m_Velocity * g_FrameTime, 0); // Update the ambient sound GetPosition(&m_CurPosition, 0); CVector3f Velocity; Velocity.x = (m_CurPosition.x - m_LastPosition.x) / g_FrameTime; Velocity.y = (m_CurPosition.y - m_LastPosition.y) / g_FrameTime; Velocity.z = (m_CurPosition.z - m_LastPosition.z) / g_FrameTime; m_MissileInAir->UpdateSound(m_CurPosition, Velocity); m_LastPosition = m_CurPosition; CGameObject::Update(); }