you do not need timer, the map or list shoul work fine, in fact there are many more funtionalitity to do stuff like that in 2.00 that in 1.53
Beside in 1.53 contact end was no call when body separate either. or when body when to rest in contact
2.0 have many more funtion to adress those issues, 2.0 is the game play programmen best friend with Joint iterators, body iterators, Material iterators, and concact iterators.
here one way using the contact iterator in the body, say you have a list. you write function to update you sound updtae like this.
- Code: Select all
UpdateSound()
{
for each body in list
{
bool bodyInContact = false;
for (contactJoint = body->GetFistContact (); conatctJoint; contact = NewtonGetNextContact (body, conttact) {
if ((jointbody0 == Terrain) or (jointbody2 == Terrain) {
PlaySound (body)
bodyInContact = true;
}
}
if (BodyInCntact == false) {
RemoveBodyFoprmList (body)
}
}
}
you have it almost right but you try to make it too complex by implemnetiong everything in the contact proccess callback,
but it work better function if the cfuntion is after the Newton update since when body detach from collision there is not notification callback.
nor there is notification when body are in contact by they are at rest.
with this function you can querie all information you need from the contact joint. and when the contact is destroyed, the list is cleanup up automatically, so it is efficent.
- Code: Select all
MyLoop()
{
NetwonUPdate();
UpdateSound();
....
...
}
Then in your contact proccess all you need to do is add the bodies for wich your logic decides it should play looping sounds.
you save all relevant info to modulate the sound volome, and pitch.
Thsio will start teh soudn by and event send form Netwon update, an dwill stop teh soudn by and event send form teh SoundUpdate.
The code is very efficient since only body in contct are update, and they are remove for the list automatically, just once, that is and even.
Not Event trigger would be having to iterate over the array of all bodies in the scene.
There are many different ways to do it you just need to use your creativity.