ゲームには垂直同期信号というのにしばしば悩まされます。
1フレームという単位があって、約1/60秒を差します。
大体のゲームは1秒に60回画面を書き換える事が出来ることができます。
それ以上の速度で処理をしても基本的に無意味ですから
これを一単位として使う事がおおいわけです。
1/60秒は約17ミリ秒です。
1回の処理に20ミリ秒かかると、次の垂直同期信号を待たないといけません。
ちょうど電車が出た途端に駅に着く、って感じですね。
つまり、17ミリ秒を超えた瞬間、いきなり速度が半分になります。
いわゆる処理落ちです。
一部のゲームではこの処理落ちをゲーム性に組み込んでいるものもありますが、
望ましい結果とは言えません。
そこで、処理落ちが発生した場合は描画処理を飛ばして
なるべくゲーム速度を保つ方法を考えてみます。
で、いろいろ考えた結果が以下のソースになります。
timeGetTime()は1ミリ秒単位で現在時間を取得する関数で、
waitvsync()が垂直同期信号を待つ関数です。
unsigned int befour t = timeGetTime();
unsigned int ctrltime = 0;
while(1){
unsigned int now = timeGetTime();
unsigned int dttime = befour - now;
befour = now;
for (ctrltime += dttime; 0 < ctrltime; ctrltime -= 17){
control();
}
draw();
waitvsync();
}
処理と描画の完全分離です。
control()を一度呼び出すたびに1フレームの動作をします。
draw()は描画処理に特化し、control()を呼び出さなければ
全く同じ画面が描画されます。
XNAなんかはこの考えが浸透している感じですね。
なお、draw()はボトルネックになっていても、
control()は無視できる速度で処理が終わることを前提としています。
どちらが足を引っ張っているのかは確認してください。
あと問題は、コントローラの入力を不定期に取ってしまう事です。
独歩頂膝がでねーぞ!!って事になりかねません。
そんな人にはPC買い換えろとやさしい言葉をかけて解決としましょう。