20 kTargetFpsValue(target_fps),
21 kOneFrameTime(static_cast<int>(1000.0 / target_fps)),
22 kListMax(target_fps * 2),
23 need_skip_draw_screen_(false)
30 if (!TargetFpsIsValid())
38 if (CheckNeedSkipDrawScreen(&wait_time))
43 RegisterTime(GetNowCount());
50 RegisterTime(time_list_.back() + kOneFrameTime);
52 need_skip_draw_screen_ =
true;
59 if (!TargetFpsIsValid())
65 if (need_skip_draw_screen_)
67 need_skip_draw_screen_ =
false;
76 if (!TargetFpsIsValid())
78 printfDx(
"FPS:%dは推奨されません.(FPSの調整は行われません.)\n",
83 if (time_list_.size() < 2)
90 const int duration = (time_list_.back() - time_list_.front()) /
91 static_cast<int>(time_list_.size() - 1);
93 printfDx(
"FPS:%d\n",
static_cast<int>(1000.0 / duration));
97void FpsController::RegisterTime(
const int now_time)
99 time_list_.push_back(now_time);
101 if (time_list_.size() > kListMax)
104 time_list_.pop_front();
109bool FpsController::CheckNeedSkipDrawScreen(
int* time)
const
115 if (time_list_.empty())
122 int actually_took_time = GetNowCount() - time_list_.back();
125 int wait_time = kOneFrameTime - actually_took_time;
139 if (
static_cast<int>(abs(wait_time)) < kOneFrameTime)
152bool FpsController::TargetFpsIsValid()
const
155 if (kTargetFpsValue <= 0)
161 if (kTargetFpsValue > 60)
void Wait()
処理が早すぎる場合,FPSを一定にするために待つ.
bool SkipDrawScene()
60Hz以上のモニター使用時に処理が詰まって画面がちらつかないように, 描画処理をスキップするかどうかを判定する.