ここまで突っ込まれるとは…ということで、前回の「処理落ちに負けるな」の補足です。
前回のループでは17msと決め打ちで回していますが、
vsyncに合わす、という意味ではあまり良いとは言えません。
vsync割り込みを利用するとして書き直すと前回のソースはこうなります。
unsigned int vsynccount = 0;
// vsyncが発生するたびに呼ばれる関数
void callback(){ vsynccount++; }
while(1){
while(0 < vsynccount){
control();
vsync--;
}
draw();
waitvsync();
}
draw()の処理途中にcontrol()が呼ばれるのは良くありませんので、
vsync割り込みの中ではカウンタだけインクリメントしてその回数だけループを回します。
しかし、理想形まで行けばこんな感じでしょうか。
deque<Pad> queue;
// vsyncが発生するたびに呼ばれる関数
void callback(){
queue.push_back(getPad());
}
while(1){
while( !queue.empty() ){
control( *queue.begin() );
queue.pop_front();
}
draw();
waitvsync();
}
vsyncの度にコントローラの状態をキューに貯めておき
その値を使いながらcontrol()を回す方法です。
これであれば、相手がシンクロ連射でも確実に連射状態になります。
ただ、前回に17msと決め打ったのは、vsyncが1/60秒でないことを考慮したためです。
PCならvsyncが1/60とは限りませんし、vsyncはブラウン管の名残です。
液晶が全盛となった今にvsyncに頼るのは果たしていいのか疑問が残ります。
凪瀬さんのコメントのように処理のみ120fpsで行うってのもありでしょう。
レースゲームでは大抵0.01秒まで出ますから、10ms以下の単位で処理をしたいところです。
ということで、描画と処理は必ずしも同期する必要はない、と考えた方が幅が広がるかと思います。