static void gaim_loop(GameData &d) { register const timestamp_t loop_cap = 1000/60 + 1; register timestamp_t timesand; register uint64_t total_sand = 0; register uint16_t numloops = 0; InputControl inputControl(d); while (!d.bools->exit && !d.bools->won) { // get gaim loop starting time d.currTime = timesand = currTime = getTimestamp(); // Handle input events inputControl(); if (!d.bools->paused) { // Progress everything AnimatorHolder::Progress(timesand); std::for_each(d.akmovs.begin(), d.akmovs.end(), AnimatorProgressor(timesand)); // collision checking happens through callbacks d.cc->Commit(); // Run scheduled tasks d.sch->check(timesand); // Draw on the screen SDL_FillRect(d.screen, NULL, d.bg); d.animdata->plathold->displayPlatforms(d.screen); d.animdata->spritehold->displaySprites(d.screen); d.stats->Draw(d.screen); SDL_Flip(d.screen); } // Cap gaim loop speed timestamp_t sanddiff = timestamp_diff( cs454_2006::getTimestamp(), timesand); SDL_Delay(sanddiff > loop_cap ? 0 : timestamp_diff(loop_cap, sanddiff)); // Time statistics total_sand += timestamp_diff(getTimestamp(), timesand); numloops++; } // gaim loop while double loop_avg = CAST(double, total_sand) / numloops; std::cerr << "Average gaim loop duration: " << loop_avg << std::endl << "Average fps: " << (1000 / loop_avg) << std::endl; } // gaim_loop
int main(void) { //Kontrollib kas vajalikud failid eksisteerivad if (inputControl() != 0){ exit(1);} process(); return 0; }
int main(void) { FILE *inputFile = fopen(INPUT_FILE, "r");; if (inputControl(inputFile) != 0){ exit(1);} process(inputFile); fclose(inputFile); return 0; }
void Player::logic(int stage_velocity) { animationControl(); if(this->hp!=0) { inputControl(); }else { if(orientation!="destroyed" && this->sonido->soundExists(name+".destroyed")) this->sonido->playSound(name+".destroyed"); orientation="destroyed"; //this->hitbox.setValues(0,0,0,0,0); } //Enable or disable slow if(isSlowPressed() && !slow_in_cooldown) { enableSlow(); current_slow-=slow_decrement; }else { disableSlow(); if(slow_in_cooldown) current_slow+=slow_cooldown_increment; else current_slow+=slow_increment; } //Check max and min slow if(current_slow<=0) { current_slow=0; } if(current_slow>max_slow) { current_slow=max_slow; } //Slow cooldown if(slow_in_cooldown && current_slow>=max_slow) { slow_in_cooldown=false; } if(!slow_in_cooldown && current_slow<=0) { slow_in_cooldown=true; } spellControl(stage_velocity); iteration++; }
int main(void) { LINKER person[32]; int i=0; int numName=0; int totalSalary=0; int avgSalary=0; //Kontrollib kas vajalikud failid eksisteerivad if (inputControl() != 0) { exit(1); } FILE *inputFileNames = fopen(INPUT_FILE_NAMES, "r"); FILE *inputFileSalary = fopen(INPUT_FILE_SALARY, "r"); FILE *outputFile = fopen(OUTPUT_FILE, "w"); while((fscanf(inputFileNames, "%[^\n]\n", person[i].name) != EOF)&&(fscanf(inputFileSalary, "%d\n", &person[i].salary) != EOF)) { numName++; printf("Failist sisse loetud: %s %10d\n", person[i].name, person[i].salary);/*Debugimiseks prindib ekraanile*/ totalSalary += person[i].salary; fprintf(outputFile, "%s %10d\n", person[i].name, person[i].salary); } /*Keskmine palk*/ avgSalary = totalSalary/numName; printf("Palgad kokku: %i\n", totalSalary);/*Debugimiseks prindib ekraanile*/ printf("Keskmine Palk: %i\n", avgSalary);/*Debugimiseks prindib ekraanile*/ fprintf(outputFile, "\nKeskmine Palk: %i\n", avgSalary); /*Sulgeb avatud failid*/ fclose(inputFileNames); fclose(inputFileSalary); fclose(outputFile); salarySort(); return 0; }