[問題] 我應該直接問音樂遊戲的計時器該怎麼做 QQ
看板C_and_CPP (C/C++)作者crazytea (............)時間16年前 (2009/04/25 21:18)推噓1(1推 0噓 10→)留言11則, 3人參與討論串1/1
其實前面的碼表問題本來是希望能夠自己解決,
沒想到問的詞不達意還無法解決問題 囧
所以就直接問了!
音樂遊戲一定要藉由精準的時間判定來播放botton
該在幾秒案就該在幾秒按
雖然拍子跟秒數之間有公式可以算(bpm)
例如:150 bpm (即 1 分鐘 150拍 )
但是算到後來一拍的時間也是幾百 ms
要如何計算從音樂開始播放後
每隔固定時間(拍子)播放botton
是我現在的瓶頸~~
我有下載跳舞機模擬器( stepMania ) 的原始碼來看,
但是由於程式過於龐大,
目前只針對timeGetTime()尋找整個專案
找到相關程式碼如下:
static bool g_bTimerInitialized;
static DWORD g_iStartTime;
static void InitTimer()
{
if( g_bTimerInitialized )
return;
g_bTimerInitialized = true;
timeBeginPeriod( 1 );
g_iStartTime = timeGetTime();
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
if( !g_bTimerInitialized )
InitTimer();
int64_t ret = (timeGetTime() - g_iStartTime) * int64_t(1000);
if( bAccurate )
{
ret = FixupTimeIfLooped( ret );
ret = FixupTimeIfBackwards( ret );
}
return ret;
}
uint64_t ArchHooks::FixupTimeIfLooped( uint64_t usecs )
{
static uint64_t last = 0;
static uint64_t offset_us = 0;
/* The time has wrapped if the last time was very high and the current time is
very low. */
const uint64_t i32BitMaxMs = uint64_t(1) << 32;
const uint64_t i32BitMaxUs = i32BitMaxMs*1000;
const uint64_t one_day = uint64_t(24*60*60)*1000000;
if( last > (i32BitMaxUs-one_day) && usecs < one_day )
offset_us += i32BitMaxUs;
last = usecs;
return usecs + offset_us;
}
uint64_t ArchHooks::FixupTimeIfBackwards( uint64_t usecs )
{
static uint64_t last = 0;
static uint64_t offset_us = 0;
if( usecs < last )
{
/* The time has moved backwards. Increase the offset by the amount we moved.
*/
offset_us += last - usecs;
}
last = usecs;
return usecs + offset_us;
}
還是搞不懂他在幹啥?
或是有更好的方法嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 192.192.154.40
→
04/25 21:58, , 1F
04/25 21:58, 1F
→
04/25 21:59, , 2F
04/25 21:59, 2F
→
04/25 21:59, , 3F
04/25 21:59, 3F
→
04/25 22:00, , 4F
04/25 22:00, 4F
→
04/25 22:16, , 5F
04/25 22:16, 5F
→
04/25 22:20, , 6F
04/25 22:20, 6F
→
04/25 22:22, , 7F
04/25 22:22, 7F
推
04/25 22:23, , 8F
04/25 22:23, 8F
→
04/25 22:24, , 9F
04/25 22:24, 9F
→
04/25 22:25, , 10F
04/25 22:25, 10F
→
04/25 22:25, , 11F
04/25 22:25, 11F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章