void Player::logic() { switch (mAction) { case STAND: case SIT: case DEAD: case HURT: break; case WALK: mFrame = (get_elapsed_time(mWalkTime) * 6) / getWalkSpeed(); if (mFrame >= 6) nextStep(); break; case ATTACK: int rotation = 0; std::string particleEffect = ""; int frames = 4; if (mEquippedWeapon && mEquippedWeapon->getAttackType() == ACTION_ATTACK_BOW) { frames = 5; } mFrame = (get_elapsed_time(mWalkTime) * frames) / mAttackSpeed; //attack particle effect if (mEquippedWeapon) particleEffect = mEquippedWeapon->getParticleEffect(); if (!particleEffect.empty() && mParticleEffects && mFrame == 1) { switch (mDirection) { case DOWN: rotation = 0; break; case LEFT: rotation = 90; break; case UP: rotation = 180; break; case RIGHT: rotation = 270; break; default: break; } Particle *p; p = particleEngine->addEffect("graphics/particles/" + particleEffect, 0, 0, rotation); controlParticle(p); } if (mFrame >= frames) nextStep(); break; } Being::logic(); }
int perft_test_perft(EPDFile* epdFile) { int i = 0; Timer totalTimer, perftTimer; printf("Testing %i perfts\n", epdFile->numEPD); start_timer(&totalTimer); for (i = 0; i < epdFile->numEPD; ++i) { EPD* epd = &epdFile->epds[i]; int depth = 1; char depthKey[8]; unsigned int perftExpected = 0, perftActual; printf("%i/%i %s\n", i + 1, epdFile->numEPD, epd->description); while (1) { snprintf(depthKey, 8, "D%i", depth); if (!epd_has_operation(epd, depthKey)) { break; } perftExpected = epd_uint_operation(epd, depthKey); start_timer(&perftTimer); perftActual = perft_perft(&epd->board, depth); stop_timer(&perftTimer); printf("perft %i: %i [%03fs] (%i) %s\n", depth, perftActual, get_elapsed_time(&perftTimer), perftExpected, perftActual == perftExpected ? "PASS" : "FAIL"); if (perftActual != perftExpected) { printf("Fail in perft test\n"); printf("FEN: %s\n", epd->description); printf("Level: %i\n", depth); printf("Expected: %i\n", perftExpected); printf("Found: %i\n", perftActual); return 0; } ++depth; } printf("\n"); } stop_timer(&totalTimer); printf("Perft suite finished in %03fs\n", get_elapsed_time(&totalTimer)); return 1; }
void Map::updateAmbientLayers(float scrollX, float scrollY) { static int lastTick = tick_time; // static = only initialized at first call if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) { // First call - initialisation mLastScrollX = scrollX; mLastScrollY = scrollY; } // Update Overlays float dx = scrollX - mLastScrollX; float dy = scrollY - mLastScrollY; int timePassed = get_elapsed_time(lastTick); std::list<AmbientLayer*>::iterator i; for (i = mBackgrounds.begin(); i != mBackgrounds.end(); i++) { (*i)->update(timePassed, dx, dy); } for (i = mForegrounds.begin(); i != mForegrounds.end(); i++) { (*i)->update(timePassed, dx, dy); } mLastScrollX = scrollX; mLastScrollY = scrollY; lastTick = tick_time; }
/* This is the emulation timing stuff * Should be called at the END of the emulation loop. * Input parameter: microseconds needed for the "real" (emulated) computer to do our loop * This function also does the sleep itself */ static void emu_timekeeping_delay ( int td_em ) { int td, td_pc = get_elapsed_time(et_start, &et_end, NULL); // the time was needed for our emulation loop if (td_pc < 0) { DEBUG("TIMING: negative amount of time spent for an emulation loop?!" NL); td = 0; } else td = td_em - td_pc; // the time difference (+X = PC is faster - real time EP emulation, -X = EP is faster - real time EP emulation is not possible) DEBUG("DELAY: pc=%d em=%d sleep=%d" NL, td_pc, td_em, td); /* for reporting only: BEGIN */ td_em_ALL += td_em; td_pc_ALL += td_pc; if (td_count_ALL == 50) { char buf[256]; //DEBUG("STAT: count = %d, EM = %d, PC = %d, usage = %f%" NL, td_count_ALL, td_em_ALL, td_pc_ALL, 100.0 * (double)td_pc_ALL / (double)td_em_ALL); snprintf(buf, sizeof buf, "%s [%.2fMHz ~ %d%%]%s", WINDOW_TITLE " v" VERSION " ", CPU_CLOCK / 1000000.0, td_em_ALL ? (td_pc_ALL * 100 / td_em_ALL) : -1, paused ? " PAUSED" : "" ); SDL_SetWindowTitle(sdl_win, buf); td_count_ALL = 0; td_pc_ALL = 0; td_em_ALL = 0; } else td_count_ALL++; /* for reporting only: END */ td_balancer += td; /* insane time-diff balancer values ... */ if (td_balancer > 1000000 || td_balancer < -1000000) td_balancer = 0; DEBUG("Balancer = %d" NL, td_balancer); // Should be the last, as with Emscripten, it's not a real sleep, but the settimeout JS stuff ... emu_sleep(td_balancer); }
/* Should be started on each time, emulation is started/resumed (ie after any delay in emulation like pause, etc) * You DO NOT need this during the active emulation loop! */ void emu_timekeeping_start ( void ) { (void)get_elapsed_time(0, &et_start, &unix_time); et_end = et_start; td_balancer = 0; rtc_update_trigger = 1; }
//================================================================================================= void eve::thr::profiler::get_sample(eve::thr::profiler_sample & p_sample) const noexcept { p_sample.name_ = get_name(); p_sample.sample_time_ = get_sample_time(); p_sample.time_elapsed_ = get_elapsed_time(); p_sample.clock_cycle_num_ = get_clock_cycle_num(); }
void executor_test(string_t description, function func) { pre_executor_test(description); start_clock(); func(); stop_clock(); post_executor_test(get_elapsed_time()); }
// // Member Function // int CWallPadKcm::Write(UCHAR *pData, int size) { CContextSetup* pContextSetup = NULL; int ret = ERROR; ULONG ulTick, delay; if(m_serial.IsOpen()) { DBGMSG(DBG_WALLPAD, "[WallPad:KCM] Try To Write\r\n"); DBGDMP(DBG_WALLPAD, pData, size, TRUE); //수신중일경우 대기 ulTick = get_mono_time(); while(m_isRecv) { usleep(1000); if(get_elapsed_time(ulTick) >= 300) { DBGMSG(DBG_WALLPAD, "[WallPad:KCM] Wait for read done: Timeout!!\r\n"); return -1; } } // 485 Enable g_gpio_mtm.SetGpioOutPin(GPIO_RS485_CTRL, LOW); // TX Enable후 최초 패킷을 전송하기까지 1.5[ms] 지연 usleep(10); ret = m_serial.Write(pData, size); if(ret == size) { memcpy((UCHAR *)&m_packet, pData, sizeof(KCM_PACKET)); } else { DBGMSG(DBG_WALLPAD, "[WallPad:KCM] Write Bytes Error, write=%d, expect=%d\e\n", ret, size); } //마지막 패킷 전송후 TX Disable 하기까지 지연 (패킷사이즈 전송시간 + 1.5[ms]) delay = (size * 1042) + 10; // 9600[bps]에서 1start+8bit+1stop 전송속도는 1.04167[ms] 이므로 21 byte는 21.875[ms] usleep(delay); // 485 Disable g_gpio_mtm.SetGpioOutPin(GPIO_RS485_CTRL, HIGH); #if 1 if(g_isContextSetupWallPad) { pContextSetup = (CContextSetup*)g_state.GetCurrContext(); if(pContextSetup) { pContextSetup->PrintPacket(pData, size, CYAN, FALSE); } } #endif }
void update_frame_time() { frame_time_ = get_elapsed_time(); if(frame_time_ > 0.25) { frame_time_ = 0.25; } if(is_fixed_) { accumulator_ += frame_time_; } }
/*** * Print out an optional message followed by the current timer timing. */ void Timer::check(const char* msg) { // Print an optional message, something like "Checking timer t"; if (msg) { std::cerr << msg << " : "; } // VERBOSE(1, "[" << std::setiosflags(std::ios::fixed) << std::setprecision(2) << (running ? elapsed_time() : 0) << "] seconds\n"); std::cerr << "[" << (running ? get_elapsed_time() : 0) << "] seconds\n"; }
int dtq_clear_entry(TIMR_ENT *entry) { int time_left, deltat = 0; DISABLE_AST deltat = get_elapsed_time(); time_left = entry->time_left - deltat; entry->time_left = entry->time + deltat; ENABLE_AST return(time_left); }
static void emu_timekeeping_check ( void ) { // check how much time we slept, initiated by last call of emu_timekeeping_delay() // we also store current UT in "unix_time" to be used by emulator (ie, RTC emulation) int td = get_elapsed_time(et_end, &et_start, &unix_time); if (td >= 0) // td should be greater than zero or sleep was about for _minus_ time? eh, give me that time machine, dude! :) td_balancer -= td; // time-difference balancer, decrease with time slept else DEBUG("TIMING: negative amount of time spent for sleeping?!" NL); rtc_update_trigger = 1; }
void Monster::logic() { if (mAction != STAND) { mFrame = (get_elapsed_time(mWalkTime) * 4) / getWalkSpeed(); if (mFrame >= 4 && mAction != DEAD) nextStep(); } Being::logic(); }
void LocalPlayer::setWalkingDir(int dir) { mWalkingDir = dir; // If we're not already walking, start walking. if (mAction != WALK && dir #ifdef TMWSERV_SUPPORT && get_elapsed_time(mLocalWalkTime) >= walkingKeyboardDelay #endif ) { walk(dir); } }
// // Obtain and print the elapsed time to the result file // void print_elapsed_time() { double elapsed ; double resolution ; // Obtain and display elapsed execution time elapsed = get_elapsed_time() ; resolution = 1.0 / CLOCKS_PER_SEC ; fprintf(result_file, " Elapsed time: %9.3f (%8.6f sec resolution)\n", elapsed, resolution) ; }
void gen_heightmap() { use_shader(shader_generate); uniform("time", get_elapsed_time()); blend_mode(false); depth_test(false); depth_write(false); glBindFramebuffer(GL_FRAMEBUFFER, rt_heightmap.fbo); glViewport(0, 0, rt_heightmap.width, rt_heightmap.height); clearc(0x00000000); mesh_quad.draw(); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, window_width, window_height); }
int main(int argc, char** argv) { srand(time(NULL)); initialize_state(); initialize_timer(); print_state(stdout, 1.0f); printf("Score: %d\n", game_state.score); char input; double dTime = 0; while (1) { dTime += get_elapsed_time(); if (dTime > 1) { printf("Tick.\n"); dTime -= 1; } } while (input = getchar()) { switch (input) { case 'D': if (move_down()) return 0; break; case 'G': if (gravity_tick()) return 0; break; case 'L': move_left(); break; case 'R': move_right(); break; case 'U': rotate(); break; } print_state(stdout, 1.0f); printf("Score: %d\n", game_state.score); } return 0; }
//================================================================================================= void eve::thr::profiler::store_sample(void) { eve::thr::profiler_sample s; s.name_ = get_name(); s.sample_time_ = get_sample_time(); s.time_elapsed_ = get_elapsed_time(); s.clock_cycle_num_ = get_clock_cycle_num(); // FIFO storage. if (samples_.size() > samples_num_) { samples_.erase(samples_.begin()); } samples_.emplace_back(std::move(s)); }
void Viewport::mouseDragged(gcn::MouseEvent &event) { if (!mMap || !player_node) return; if (mPlayerFollowMouse && !event.isShiftPressed()) { if (get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay) { mLocalWalkTime = tick_time; player_node->setDestination(event.getX() + (int) mPixelViewX, event.getY() + (int) mPixelViewY); player_node->pathSetByMouse(); } } }
bool test_resize_image(qivon::Image<unsigned char> &_src, size_t _width, size_t _height) { if (_src.isEmpty()) return false; qivon::Image<unsigned char> resized_img; set_start_now(); qivon::resizeImage(_src, resized_img, _width, _height); std::cout << __FUNCTION__ << " time " << get_elapsed_time() << " ms\n"; if (resized_img.isEmpty()) return false; else return qivon::writePngFile("resize.png", resized_img); }
int dtq_task(void *dummy) { int deltat; static int to_go; if(dummy){} while(1) { if(DIM_next_time) { DISABLE_AST DIM_time_left = DIM_next_time; if(DIM_time_left == -1) DIM_time_left = 0; to_go = DIM_next_time; DIM_next_time = 0; ENABLE_AST } if(DIM_time_left < 0) { DIM_time_left = 0; alrm_sig_handler(2); #ifndef WIN32 return(1); #endif } else if(DIM_time_left > 0) { dim_usleep(100000); deltat = get_elapsed_time(); DIM_time_left = to_go - deltat; if(DIM_time_left <= 0) { alrm_sig_handler(2); #ifndef WIN32 return(1); #endif } } else { dim_usleep(1000); } } }
static int stop_it() { int min_time; int deltat = 0; DISABLE_AST if(Alarm_runs) { my_alarm(0); deltat = get_elapsed_time(); if(deltat != 0) DIM_last_time = get_current_time(&DIM_last_time_millies); Alarm_runs = 0; } min_time = get_minimum(deltat); ENABLE_AST return(min_time); }
bool test_crop_image(qivon::Image<unsigned char> &_src, size_t _start_x, size_t _start_y, size_t _end_x, size_t _end_y) { if (_src.isEmpty()) return false; qivon::Image<unsigned char> cropped_img; set_start_now(); qivon::cropImage(_src, cropped_img, _start_x, _start_y, _end_x, _end_y); std::cout << __FUNCTION__ << " time " << get_elapsed_time() << " ms\n"; if (cropped_img.isEmpty()) return false; else return qivon::writePngFile("crop.png", cropped_img); }
bool test_mean_filter_3x3(qivon::Image<unsigned char> &_src, size_t _run_time) { if (_src.isEmpty()) return false; qivon::Image<unsigned char> mean; set_start_now(); for (size_t i = 0; i < _run_time; ++i) qivon::meanFilter3x3(_src, mean); std::cout << __FUNCTION__ << " time " << get_elapsed_time() / _run_time << " ms\n"; if (mean.isEmpty()) return false; else return qivon::writePngFile("mean.png", mean); }
int Being::getOffset(char pos, char neg) const { // Check whether we're walking in the requested direction if (mAction != WALK || !(mDirection & (pos | neg))) return 0; int offset = (get_elapsed_time(mWalkTime) * 32) / mWalkSpeed; // We calculate the offset _from_ the _target_ location offset -= 32; if (offset > 0) offset = 0; // Going into negative direction? Invert the offset. if (mDirection & pos) offset = -offset; return offset; }
int dtq_rem_entry(int queue_id, TIMR_ENT *entry) { int time_left, deltat = 0; DISABLE_AST deltat = get_elapsed_time(); time_left = entry->time_left - deltat; if( Inside_ast ) { timer_queues[queue_id].remove_entries++; entry->time = -1; ENABLE_AST return(time_left); } dll_remove(entry); free(entry); ENABLE_AST return(time_left); }
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_step (JNIEnv *env, jclass jcls) { double curr_tick = get_elapsed_time(); double dt = curr_tick - last_tick; last_tick = curr_tick; update_app(dt); render_app(dt); GLenum error = glGetError(); bool were_errors = false; while (error != GL_NO_ERROR) { LOGD("An OPENGL error occured %s", get_gl_error_msg(error)); were_errors = true; error = glGetError(); } if (were_errors) exit(1); }
/** Service the switch queue. This function is called * periodically to see if any pending switch transitions have * completed their debounce time. If any switch becomes * unstable before the period expires, it will be removed * from the queue prior to this function being called. So * all that is needed here is to decrement the timers, and if * one reaches zero, consider that switch transitioned. */ void switch_service_queue (void) { pending_switch_t *entry; U8 elapsed_time; /* See how long since the last time we serviced the queue. This is in 16ms ticks. */ elapsed_time = get_elapsed_time (switch_last_service_time); entry = switch_queue; while (unlikely (entry < switch_queue_top)) { entry->timer -= elapsed_time; if (entry->timer <= 0) { /* Debounce interval is complete. The entry can be removed from the queue */ switch_queue_remove (entry); /* See if the switch held its state during the debounce period */ if (bit_test (sw_unstable, entry->id)) { /* Debouncing failed, so don't process the switch. * Restart IRQ-level scanning. */ disable_irq (); bit_off (sw_stable, entry->id); bit_off (sw_unstable, entry->id); enable_irq (); } else { /* Debouncing succeeded, so process the switch */ switch_transitioned (entry->id); } } entry++; } switch_last_service_time = get_sys_time (); }
void Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail) { static int lastTick = tick_time; // Detail 0: no overlays if (detail <= 0) return; if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) { // First call - initialisation mLastScrollX = scrollX; mLastScrollY = scrollY; } // Update Overlays int timePassed = get_elapsed_time(lastTick); float dx = scrollX - mLastScrollX; float dy = scrollY - mLastScrollY; std::list<AmbientOverlay*>::iterator i; for (i = mOverlays.begin(); i != mOverlays.end(); i++) { (*i)->update(timePassed, dx, dy); } mLastScrollX = scrollX; mLastScrollY = scrollY; lastTick = tick_time; // Draw overlays for (i = mOverlays.begin(); i != mOverlays.end(); i++) { (*i)->draw(graphics, graphics->getWidth(), graphics->getHeight()); // Detail 1: only one overlay, higher: all overlays if (detail == 1) break; } }
int main() { // sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "SFML works!", sf::Style::Fullscreen); sf::RenderWindow window(sf::VideoMode(704,480), "SFML works!", sf::Style::Close); // sf::RenderWindow window(sf::VideoMode(1680,1050), "SFML works!", sf::Style::Close); // window.setFramerateLimit(120); Game g; Game_view game(&g); // sf::Time dt; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyReleased); game.handle_event(&event); } dt = get_elapsed_time(); game.handle_event(); game.handle_camera(); game.animate(); window.clear(); window.draw(game); // window.setMouseCursorVisible(false); //TODO : à activer plus tard window.setView(game.get_camera()); window.display(); } return 0; }