Run function after X miliseconds [message #417956] |
Mon, 18 January 2010 10:35 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
I currently have a piece of code that will run Function A on level loaded
This function initiates Function B a little later.
In Function B im getting the length of an MP3 file (in miliseconds)
After this, Function B has to run again after that time, while any other code still runs.
Problem is i cant use Sleep(); or w/e to wait that long because all other code must continue running.
Afaik i cant make it a script either (so i can use Start_Timer + Timer_Expired) that will be attached to a player because it'll will then restart the whole code after every die (AKA object change)
void FunctionA()
{
//Code here; read file containing sounds
FunctionB();
}
void FunctionB()
{
if(runnow)
{
//Pick a random song from the file
//Play the song
fsystem->update();
{
//Set Volume
//Get song length (in miliseconds)
}
FunctionB(); //This should run after 'song length' above
}
//More code; should still run and not only after X miliseconds as Sleep(); would do
}
If needed i'll upload the whole file
EDIT:
i believe in Javascript you have something like setInterval() that does what i want
EDIT2:
Oh and if anyone knows how to get the music volume settings from renegade, please tell ^^
[Updated on: Mon, 18 January 2010 10:42] Report message to a moderator
|
|
|
|
Re: Run function after X miliseconds [message #417966 is a reply to message #417956] |
Mon, 18 January 2010 12:05 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
If i understand you correctly (i think this is multi threading which is new for me) it should be something like this??
HANDLE hThread;
DWORD CALLBACK ThreadProc(void *pArg)
{
while(playnow)
{
DWORD delay;
delay = PtrToUlong(pArg);
Sleep(delay);
FunctionB();
}
return 0;
}
void FunctionA()
{
//Code here; read file containing sounds
FunctionB();
}
void FunctionB()
{
if(runnow)
{
//Pick a random song from the file
//Play the song
fsystem->update();
{
//Set Volume
//Get song length (in miliseconds)
}
DWORD tid;
hThread = CreateThread(NULL, 0, ThreadProc, ULongToPtr(songlength), 0, &tid);
}
//More code; should still run and not only after X miliseconds as Sleep(); would do
}
void FunctionC()
{
//Close file etc
CloseHandle(hThread);
}
[Updated on: Mon, 18 January 2010 12:27] Report message to a moderator
|
|
|
|