syncronization issue between openframeworks and director

as i’m coming to an end to my project, i have a last issue which i may be solving in openframeworks.

the problem is, i’ve succesfully developed the racing car game in director, the motion vector analysis thing is working very stable in oF (big thanks to theo), and i’m sending all the data from oF to director using ofxUDPManager.

in director, i’ve TDPUDP-xtra, and all i have in this regard are:

init code on startupmovie

TCPUDP = new(xtra "TCPUDPXtra")  

game code

if TCPUDP.hasNext() then  
     message= TCPUDP.getNext()  
      if message[1] > 1 then  
        car_rotation=  "L"  
      else if message[1] < 0 then   
        car_rotation=  "R"  
        car_rotation=  "0"  
      end if  
    end if  

but, i have to open oF before director, and it starts immediately sending UDP data.
and after i open director and wait for data and process incoming UDP sockets, there is a slightly lag between UDP initialization and start getting packets, which results on having the past UDP data to come to director and thus my car rotates with 4-5 seconds lag. And sometimes there are many objects in the 3d scene, director can not get data at 25 fps rate. so the lag widens.

There are 2-3 things coming to my mind:

  • I can clean the UDP stack in 5 second intervals.
  • I can send a udp data to oF which triggers oF to start sending data from UDP.
  • I can set a TTL to UDP data in oF, so packets sent and not received in a second should drop and not wait in UDP queue.

what do you think?


TTL combined with director reading all available data might work quite well.
So each time you check for data you read till there is no more queued udp data left.

There are two things you could do with the extra data:

1 - drop it. only apply the last (most recent message).
2 - sum it up so that all the data is applied to the direction of the car.

Can you do something like this in director?

(method 1)

while( TCPUDP.hasNext() ){  
   message= TCPUDP.getNext()   
   if message[1] > 1 then   
     car_rotation=  "L"   
   else if message[1] < 0 then   
     car_rotation=  "R"   
     car_rotation=  "0"   
   end if   

The other option would be for director to send a udp request to OF saying - hey give me data!
Then OF sends back only when it is needed. But then you need to setup a udp client in openFrameworks and thats a bit tricky to do well without threading.


how does ttl work with ofxUDPManager?



udpmanager.Send( tmp, strlen(tmp) );  

this does not seem to work… i’ve got gazillion of packets waiting in the queue after i close oF application and restart racing game.

ok, it’s all working now.
except, after running the program, stopping it, and rerun, it waits enormously long time to get any valid packet.

it might be a director bug, or TCPUDP xtra bug, or me being idiot.

while( TCPUDP.hasNext() ){   


repeat while TCPUDP.hasNext()  
 message= TCPUDP.getNext()   
end repeat  

in director.

thanks again for the great tip.