Garbage Collection

塵も積もれば山

目次

Blog 利用状況

ニュース

C++とかC#とか数学ネタを投下していく予定です。

[その他のページ]
日々の四方山話を綴った日記出水の日記帳

書庫

日記カテゴリ

[アルゴリズム]突っ込みにも負けるな

ここまで突っ込まれるとは…ということで、前回の「処理落ちに負けるな」の補足です。

前回のループでは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以下の単位で処理をしたいところです。

ということで、描画と処理は必ずしも同期する必要はない、と考えた方が幅が広がるかと思います。

投稿日時 : 2008年12月17日 22:12

Feedback

# re: [アルゴリズム]突っ込みにも負けるな 2008/12/18 0:48 とっちゃん@おうち

vsync 使うなら素直にフリップしてもいいんじゃないかと
おじさんは考える。。。w

Win系に限って言えばvsyncとれる=Flipあるだった気がするw

# re: [アルゴリズム]突っ込みにも負けるな 2008/12/18 21:17 出水

waitsync()がvsync待ち+フリップのつもりでした

# re: [アルゴリズム]突っ込みにも負けるな 2008/12/19 11:41 とっちゃん

見えないコードからそうだろうなぁ?とは思ったw

けど、ここは、ダブルバッファリングを明確にうたって、フリップする!のほうが
ゲームプログラミング的にはおいしいかなぁとw

ダブルバッファリング(あるいはトリプル)の本質は
オフスクリーン描画ではなくて、VSYNC同期に間に合わなかったときに
グラフィックハードウェアサイドだけで再描画できるというところにあるから。
#こんなんゲーム作ってる人間には基礎中の基礎だけどもwww
#そこはオープンなBlogということでw

# re: [アルゴリズム]突っ込みにも負けるな 2008/12/19 17:30 ゆーち

VSYNC・・・なつかしい。

昔使いましたが、いったい何のために利用したのかさえも忘れてしまいましたw

# buy admission essay q929tj 2022/09/03 16:09 Charlosmox


You made your position pretty effectively!! https://definitionessays.com/ why do i want to go to college essay

# graphic organizers for writing an essay j61qkj 2022/09/08 18:31 Charlosmox


Whoa tons of helpful knowledge. https://definitionessays.com/ custom essay org

# best paper writing service 2017 p22tro 2023/03/01 6:34 StevenGrelo


Factor effectively regarded.!
cheap college paper writing service https://service-essay.com/ ultius paper writing service

# buy cheap essays u784io 2023/03/06 19:41 Gregorysaipt


Fantastic write ups, Kudos!
youtube essay writing https://buyanessayscheaponline.com blog writing services packages https://custompaperwritingservices.com

# buy essays online u16fod 2023/03/07 18:06 Gregorysaipt


Whoa tons of fantastic info.
help with report writing https://essaywritingservicelinked.com personal statement writing help https://domyhomeworkformecheap.com

# digital dissertation j18fvw 2023/03/08 7:43 EugeneSib


Wonderful information. Thanks!
doctoral dissertation grants https://helpmedomyxyzhomework.com no dissertation doctorate https://essaywritingservicehelp.com

# master thesis writer c612ky 2023/03/08 16:26 Gregorysaipt


Cheers, Useful information!
personal college essay https://writeadissertation.com thesis phd https://essaywritingservicetop.com

# research proposal writing o389ga 2023/03/08 23:45 EugeneSib

You stated this terrifically.
best custom essay sites https://researchpaperwriterservices.com i need help on writing an essay https://essaywritingservicehelp.com

# type of essay writing e922wg 2023/03/09 15:18 EugeneSib

You actually stated it adequately!
write the essay https://essaywritingservicehelp.com dissertation literature review https://essayservicehelp.com

# cheap custom writing service f408ux 2023/03/10 11:43 Gregorysaipt


With thanks! Lots of posts!
college board essay https://dissertationwritingtops.com custom writing services https://cheapessaywriteronlineservices.com

# essays to get into college i854hz 2023/03/12 2:30 EugeneSib


Incredible a good deal of good data.
essay websites https://writingresearchtermpaperservice.com college essay promts https://buyanessayscheaponline.com

# customized essay d92pvy 2023/03/12 7:08 Gregorysaipt


Nicely put. With thanks!
social science dissertation https://essayservicehelp.com essay writing service scams https://essayssolution.com

# writing persuasive essays b502mx 2023/03/13 4:54 Gregorysaipt


You've made your stand pretty clearly!!
how to write an college essay https://essayssolution.com essay writer cheap https://domycollegehomeworkforme.com

# essay on writing w13ndq 2023/04/03 0:20 EugeneSib


Fine stuff. Cheers.
essay correction service https://essaywritinghelperonline.com university thesis https://service-essay.com

# The plugins developed for WordPress 2023/05/09 21:16 Justas

The plugins developed for WordPress serve to enhance the features and functions of a WordPress website, allowing you to build your awesome and functional site https://t.me/wpigaming/648 Customise WordPress with powerful, professional and intuitive fields.

タイトル
名前
Url
コメント