void FrameControl_Remain( FrameControl ctx ) { int64_t current_time; unsigned int n_ms, lost_ms; if( ctx->state == STATE_QUIT ) { return; } lost_ms = 0; current_time = LCUI_GetTime(); LCUIMutex_Lock( &ctx->mutex ); n_ms = (unsigned int)(current_time - ctx->prev_frame_start_time); if( n_ms > ctx->one_frame_remain_time ) { goto normal_exit; } n_ms = ctx->one_frame_remain_time - n_ms; if( n_ms < 1 ) { goto normal_exit; } /* 睡眠一段时间 */ while( lost_ms < n_ms && ctx->state == STATE_RUN ) { LCUICond_TimedWait( &ctx->cond, &ctx->mutex, n_ms - lost_ms ); lost_ms = (unsigned int)LCUI_GetTimeDelta( current_time ); } /* 睡眠结束后,如果当前状态为 PAUSE,则说明睡眠是因为要暂停而终止的 */ if( ctx->state == STATE_PAUSE ) { current_time = LCUI_GetTime(); /* 等待状态改为“继续” */ while( ctx->state == STATE_PAUSE ) { LCUICond_Wait( &ctx->cond, &ctx->mutex ); } lost_ms = (unsigned int)LCUI_GetTimeDelta( current_time ); ctx->pause_time = lost_ms; ctx->prev_frame_start_time += lost_ms; LCUIMutex_Unlock( &ctx->mutex ); return; } normal_exit:; current_time = LCUI_GetTime(); if( current_time - ctx->prev_fps_update_time >= 1000 ) { ctx->current_fps = ctx->temp_fps; ctx->prev_fps_update_time = current_time; ctx->temp_fps = 0; } ctx->prev_frame_start_time = current_time; ++ctx->temp_fps; LCUIMutex_Unlock( &ctx->mutex ); }
void LCUIStats_End(LCUI_Stats stats) { stats->total_time = (uint32_t)LCUI_GetTimeDelta(stats->start_time); if (stats->total_time > 100) { LOG("[stats] \e[1;33mwarning:\e[0m current frame takes " "too long\n"); LCUIStats_Print(stats); }
void LCUIStats_RecordTime(LCUI_Stats stats, unsigned num) { unsigned i; uint32_t delta; delta = (uint32_t)LCUI_GetTimeDelta(stats->start_time); for (i = 0; i < num && i < 4; ++i) { if (delta > stats->time_list[i]) { delta -= stats->time_list[i]; } else { delta = 0; break; } } stats->time_list[num] = delta; }