void * pipes_function(void * pointer) { INTERF *interf = (INTERF *) pointer; int i; char cadena[10]; ini_pipes(); calculate_next(); copy_pipes(); for (i = 0; i < NUM_PIPES; i++) current_pipes[i]->position = 123 + 35 * i; listo1 = 1; while (!crash() && !fcrash) { for (i = 0; i < NUM_PIPES && !fcrash; i++) { usleep(25000); sprintf(cadena, "%d", score); write_interf(interf, 0, 13, 70, cadena); current_pipes[i]->position--; print_pipe(interf, current_pipes[i]); if (current_pipes[i]->position <= 0) { erase_first(interf); score++; calculate_next_u(i); copy_pipes_u(i); current_pipes[i]->position = 87 + 123; } } } pthread_exit(NULL); }
static void aspeed_timer_mod(AspeedTimer *t) { uint64_t next = calculate_next(t); if (next) { timer_mod(&t->timer, next); } }
void Teleport::beginContact(GameObject* go_ptr, b2Fixture* check) { if (go_ptr==NULL) { return; } if (check!=my_check) return; if (find(incoming.begin(), incoming.end(), go_ptr) == incoming.end()) { Teleport* next=dynamic_cast<Teleport*>(calculate_next()); if (next!=NULL) { next->notify(go_ptr); b2Vec2 target=next->getCurrentPos(); target+=go_ptr->getCurrentPos()-getCurrentPos(); int flipped_delta=next->flipped-flipped; if (flipped_delta<0) flipped_delta=4+flipped_delta; b2Vec2 targetvelocity=go_ptr->getLinearVelocity(); for (;flipped_delta>0;flipped_delta--) { targetvelocity=b2Vec2(targetvelocity.y,-targetvelocity.x); } flipped_delta=next->flipped-flipped; if (flipped_delta%2==0) { go_ptr->teleport(target, targetvelocity, false); } else { go_ptr->teleport(target, targetvelocity, true); } } } }
int strStr(const char *source, const char *target) { // write your code here if(source == NULL || target == NULL) return -1; int n = strlen(target); int m = strlen(source); if(n > m) return -1; else if(n == m) return strcmp(source, target) == 0 ? 0 : -1; else if(*target == '\0') return 0; vector<int> next = calculate_next(target, n); int k = -1; for(int i = 0; i < m; i++) { while(k > -1 && target[k+1] != source[i]) k = next[k]; if(target[k+1] == source[i]) k++; if(k == n - 1) { return i - n + 1; } } return -1; }