トップページ > 過去ログ > 記事閲覧
WaitVsync Problem
名前:W.X. 日時: 2010/04/24 14:42

こんにちは。I'm W.X. from Taiwan. I have some problem when trying use WaitVsync. For example: DxLib::SetWaitVSyncFlag(TRUE); DxLib::SetGraphMode(640, 480, 16, 60); __int64 hcount; hcount = DxLib::GetNowHiPerformanceCount(); DxLib::WaitVsync(x); hcount = DxLib::GetNowHiPerformanceCount() - hcount; When x = 2, hcount = 33ms (2 frames) But when I set x = 1, hcount = 4ms. I think hcount should be 16ms when I use x = 1.. Is there any wrong I got in my code? Thanks for reply.

Page: 1 |

Re: WaitVsync Problem ( No.1 )
名前:いっち 日時:2010/04/25 00:02

Perhaps it is specification. Try this code. #include "DxLib.h" int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { ChangeWindowMode( TRUE ); // SetWaitVSyncFlag( TRUE ); // WaitVSync() isn't influenced by SetWaitVSyncFlag(). ("TRUE" is the default behavior.) SetGraphMode( 640, 480, 32, 60 ); if ( DxLib_Init( ) == -1 ) return -1; int StrColor = GetColor( 255, 255, 255 ); __int64 buff; int cnttime[10]; buff = GetNowHiPerformanceCount( ); // Maybe.... There is no end of V-Sync here. WaitVSync( 1 ); cnttime[0] = (int)(GetNowHiPerformanceCount( ) - buff); // The first time is not accurate. for ( int i = 1; i < 10; i++ ) { buff = GetNowHiPerformanceCount( ); WaitVSync( 1 ); cnttime[i] = (int)(GetNowHiPerformanceCount( ) - buff); // The second time and any more time is accurate. } while ( ProcessMessage( ) == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 ) { ClearDrawScreen( ); for ( int i = 0; i < 10; i++ ) { DrawFormatString( 0, i * 20, StrColor, "%2d = %d", i, cnttime[i] ); } } DxLib_End( ); return 0; } -- Japanese -- 英語のあやしさ全開なので、どなたかフォローして頂けると助かります。
Re: WaitVsync Problem ( No.2 )
名前:W.X. 日時:2010/04/25 21:51

Hi, いっち. I have tried your code. All cnttime[] I got is about 4ms on my PC. But on my laptop, sometimes it got 16ms correctly.. @@ I think maybe this problem occurs base on computer hardware.. So I decided to use another way to do frame/time sync. For example: __int64 LoopStartCount; do { LoopStartCount = DxLib::GetNowHiPerformanceCount(); // doing something while (DxLib::GetNowHiPerformanceCount() - LoopStartCount < 15000) // Sleep 1ms beforce reach to 15ms { ::Sleep(1); } while (DxLib::GetNowHiPerformanceCount() - LoopStartCount < 16666); // Busy-wait until reach 16.6ms ErrorCode = DxLib::ProcessMessage(); } while (!ErrorCode); Anyway, thanks for your replay.
Re: WaitVsync Problem ( No.3 )
名前:管理人 日時:2010/04/25 23:55

グラフィックスデバイスの設定でVSYNCを待たないようになっているのかもしれません 若しくはグラフィックスデバイスドライバの不具合の可能性も・・・ よろしければVSYNCの設定や最新のドライバをインストールしてみてください DXライブラリを使われているということは、日本語でも大丈夫なのでしょうか・・・? と思ったので日本語でご返答してみました・・・
Re: WaitVsync Problem ( No.4 )
名前:いっち 日時:2010/04/26 01:55

Please invalidate "ChangeWindowMode( TRUE )" by comment out. And try a code(No.1) again if you can. Reply (No.3) was written by author of DxLib. -- He said: -- Possibly value for V-Sync may be setting "no wait" at graphic settings. Please check your PC about graphic settings, or install a new graphic driver. -------------- (I'm not good at English. If I'm wrong, I'm sorry.) -- Japanese (We are discussing about V-Sync in Japanese.) -- 訳してみました。(正確にはYahoo翻訳さんに訳して頂きました。) ちょっと謎ですね。W.X.さんは最初に以下のように説明なさっていたので、 WaitVSync(1) -> 4ms WaitVSync(2) -> 33ms WaitVSyncの仕様を誤解されているのかと思っていましたが、 レス(No.2)ではWaitVSync(1)を何度やっても4msが経過するとおっしゃっています。 cnttime[0] -> 4ms ... cnttime[9] -> 4ms リフレッシュレートが240Hzというのはさすがに無いと思いますが、4msは4msで微妙にウェイトが入っているようにも見えます。 (テレビ用の液晶だとターボモードみたいなのがあるのかも?) たまに台湾の方をお見かけしますが、台湾にDxLibのコミュニティとかあるのでしょうか・・・(英語経由かも?)
Re: WaitVsync Problem ( No.5 )
名前:W.X. 日時:2010/04/26 18:18

Hi, いっち I updated the video driver and the result seems no problem now. (orz) I think it is not good to use WaitVsync(1) to wait for 1 frame time. As you said in code, "The first time is not accurate.". So every single time we call WaitVsync(1), it works just like first time calling WaitVsync(1). I'm using the method I posted on No.2 to do frame/time sync. To author: I can read a little Japanes but can not write. :( So please forgive me using English. I found DxLib from 2ch board.. And I know some people in Taiwan using DxLib. Maybe I'll make a DxLib community in Taiwan later. (Is that allow?) Anyway, thank you いっち and 管理人.
Re: WaitVsync Problem ( No.6 )
名前:いっち 日時:2010/04/26 21:50

> I can read a little Japanes It's awesome. I write in Japanese, too. Please tell me if you can't understand. W.X.さんのPCでScreenFlip()がどの様に動作するのか興味があります。 (ScreenFlip()もV-Syncを待ちます。SetWaitVSyncFlag()はScreenFlip()の既定の動作を変えるための関数です) もしできるなら、以下のコードを試してください。 そして、結果を教えてください。お願いします。 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { SetGraphMode( 640, 480, 32, 60 ); if ( DxLib_Init( ) == -1 ) return -1; SetDrawScreen( DX_SCREEN_BACK ); int StrColor = GetColor( 255, 255, 255 ); int RefreshRate = GetRefreshRate( ); __int64 buff; int cnttime[10]; WaitTimer( 1000 ); for ( int i = 0; i < 10; i++ ) { buff = GetNowHiPerformanceCount( ); ScreenFlip( ); cnttime[i] = (int)(GetNowHiPerformanceCount( ) - buff); } while ( ProcessMessage( ) == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 ) { ClearDrawScreen( ); DrawFormatString( 0, 0, StrColor, "Refresh Rate = %d", RefreshRate ); for ( int i = 0; i < 10; i++ ) { DrawFormatString( 0, i * 20 + 20, StrColor, "%2d = %d", i, cnttime[i] ); } ScreenFlip( ); } DxLib_End( ); return 0; } > Maybe I'll make a DxLib community in Taiwan later. Maybe either will do. I hope that you just enjoy programming.
Re: WaitVsync Problem ( No.7 )
名前:W.X. 日時:2010/04/27 00:53

Hi, いっち. Here is the result: 0 = 600~700 1 = 6000~7000 2 = 15000~166xx 3 ~ 9 = 166xx (I tested about 10 times) ttp://wayne.cs.nthu.edu.tw/~splash/DxLib_Test2.png (snapshot) By the way, My video card is nVidia 9800GT, CPU is i5-750, OS = Windows XP Pro
Re: WaitVsync Problem ( No.8 )
名前:いっち 日時:2010/04/27 13:19

Thank you W.X. Good job. この結果について考えると、ゲーム全体のループの中で、画面の描画にScreenFlip()を1回利用していれば、 リフレッシュレートに合わせてFPSは安定すると思います。 この方法はDxLibでFPSを安定させる一般的な方法です。 (ただし、ScreenFlip()の始めの数回は不安定なようです) もちろん、(No.2)のように行えば、より完全です。 (ScreenFlip()と(No.2)を組み合わせる場合、ScreenFlip()がV-Syncを逃さないように気をつけて下さい) 今回の結果について、管理人さんや他の人が意見をくれるかもしません。 次の週末ぐらいまでは見ていて下さい。 とりあえず、私にできることはもう無いようです。 あまり助けにならなくて、ごめんなさい。
Re: WaitVsync Problem ( No.9 )
名前:W.X. 日時:2010/04/27 14:37

いっち that's ok. I learned more details about DxLib with your help. Thank you.
Re: WaitVsync Problem ( No.10 )
名前:管理人 日時:2010/05/01 17:38

英語力が低くてすいません、ドライバを更新した後でいっちさんがお書き込みになられた No.1 のプログラムを実行した際の cnttime[] の値は正常になった、ということでしょうか? ところで、WaitVSync は 16.66666ms * SyncNum 待つ関数ではなく、一定間隔で発生し続けるVSYNC( 垂直同期信号 )を待つ関数です そして、VSYNC は画面に設定されているリフレッシュレートによって発生する間隔が変化します 60Hz の場合 1000ms / 60 = 16.666666 ms 75Hz の場合 1000ms / 75 = 13.333333 ms 120Hz の場合 1000ms / 120 = 8.333333 ms ms = Millisecond なので、VSYNCが発生する直前に WaitVSync( 1 ) ; とした場合は、関数を呼び出した後に直ぐに VSYNC が発生するため、関数は直ぐに返ってきます WaitVSync( 2 ) ; とした場合も同じで、必ずしも WaitVSync( 2 ) = ( 1000 / リフレッシュレート ) * 2 ms となるわけではありません 例:リフレッシュレートが60Hz の場合 VSYNC! 1ms 2ms 3ms 4ms 5ms 6ms 7ms 8ms 9ms 10ms 11ms 12ms 13ms 14ms 15ms 16ms VSYNC! 1ms 2ms 3ms 4ms 5ms 6ms 7ms 8ms 9ms 10ms 11ms WaitVSync( 1 ) ; 12ms 13ms 14ms 15ms 16ms VSYNC! WaitVSync の関数から出る、このときの WaitVSync 内で消費する時間は 5〜6ms となります 1ms 2ms WaitVSync( 1 ) ; 3ms 4ms 5ms 6ms 7ms 8ms 9ms 10ms 11ms 12ms 13ms 14ms 15ms 16ms VSYNC! WaitVSync の関数から出る、このときの WaitVSync 内で消費する時間は 14〜15ms となります 前述の通り VSYNC の発生間隔はリフレッシュレートによって変化しますので、ゲームの進行を WaitVSync や ScreenFlip のVSYNC( 垂直同期信号 )待ちに任せるとリフレッシュレートの設定次第でゲームの進行速度が変化してしまいます なので、No.2 のような同期処理をするのが安全です ( 若しくは、リフレッシュレートが 60Hz かどうかを確認して、60Hz の場合のみゲームの同期処理に VSYNC を使うようにするのが良いです ) > I found DxLib from 2ch board.. And I know some people in Taiwan using DxLib. > Maybe I'll make a DxLib community in Taiwan later. (Is that allow?) DXライブラリをお知りになった経緯が 2chというのにも驚きました 台湾の方も 2ch を見ているということと、そんなにDXライブラリが話題にならない 2ch でDXライブラリをお知りになったという二重の意味で (^ ^; 英語や中国語でのサポートはできませんが、コミュニティをお作りになるのは全く問題ありません
Re: WaitVsync Problem ( No.11 )
名前:W.X. 日時:2010/05/05 23:20

Hi 管理人: (1)The result of program in No.1 was no problem after I update the video driver to last version. :) (2)As you said, if we use WaitVsync(n) to do frame/time sync, the game may works ok if we use same refresh rate as developer use. But when we use refresh rate different to developer use, game will runs in 1.25x or 2x.. So I wrote code in No.2 to make sure that each game loop will run at least 16.6ms. The only problem may got in No.2 is when system is busy and the main thread does not wake up on time. (3)Thank you. I'll translate function reference to Tradition Chinese first. ありがとう, 管理人 :)

Page: 1 |