Jump to content
  • Advertisement
Sign in to follow this  
Dospro

BIG problem calculating time

This topic is 5407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I have a terrible problem that is giving me headaches. I need some code inside a "callback" routine, which will do something only when 78 milliseconds had passed. This routine, is called an infinite times per second.(i mean, it is a variable time) I need that in this routine calculate when have passed 78 miliseconds: inline void update_sound(int cycles) { scyc+=cycles; //If we need to make caalculation //if(passed time is 78) //make something... } Im making it with SDL so the function i use is SDL_GetTicks() which return the number of miliseconds that have passed since the library was inited.

Share this post


Link to post
Share on other sites
Advertisement
Is what you are trying to do is: play an arbitrary sound every .078 seconds... or make sure that your playback buffer is always filled? Because I thought that SDL had a function pointer as part of the wav playing mechanism pCallMeWhenSoundIsNearlyPlayedOutSoICanRefillIt() or something.

Yes.. file SDL\docs\html\sdlaudiospec.html.

struct SDL_AudioSpec::callback

int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained);

Share this post


Link to post
Share on other sites
Actually is not sound.
sound i manage it with the callback which is what you are saying.
But what i want is time.

Share this post


Link to post
Share on other sites
I'm a little confused as to what you want, I think what you need is a timer?
If so, this little function I use will give you what you need:

void UpdateTimer()
{
m_uiLastTime = m_uiCurTime;
m_uiCurTime = SDL_GetTicks();
m_fDelta = (float)( (m_uiCurTime - m_uiLastTime)) * 0.001f;
m_uiCountFPS += 1;
m_fTime += m_fDelta;
if(m_fTime > m_fOldTime+1)
{
m_fOldTime = m_fTime;
m_uiFPS = m_uiCountFPS;
m_uiCountFPS = 0;
}
}
Make sure all the variables are initialised to zero, and that this function is called everyframe.
Then for what you need:
static float nextTime = m_fTime+0.78f;
if(m_fTime>=nextTime)
{
//do something
nextTime = m_fTime+0.78f;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!