I'm trying to write a simple F1 2016 telemetry program. ( The game just sends some data through UDP and i'm trying to receive this data in SFML ). For that i'm trying to receive data every x miliseconds ( to decrease CPU usage ) and display it. The fault is, that if the game is running there is no enough CPU time and the receive app should skip some packets, but instead of doing that it's queuing packets and displaying it with a big delay which increase in time. The worst thing is that if i try to increase time between receive, delay is getting worse ( and if i set to receive every 0.5s it displays it every 0.5s, but the data.m_time shows that it's receiving every package, but i don't know why? The packages are sent by the game every ~1/60s ).
part of main.cpp:
sf::Time time;
sf::Clock clock;
UDPSocket socket;
socket.bind(port,ip);
socket.setBlocking(false);
F1datastruct data; // It contains the variables that are used for data receiving
sf::Packet packet;
while (true)
{
packet.clear();
time = clock.getElapsedTime();
if (time.asMilliseconds() > 50)
{
socket.receive(packet, ip, port);
packet >> data.m_time >> data.m_lapTime >> (...) >> data.m_vehicleFlags;
cout << endl;
cout << "Time: " << data.m_time << endl;
cout << "Lap time: " << data.m_lapTime << endl;
clock.restart();
time = clock.getElapsedTime();
}
}
Sorry for my bad english.
EDIT:
Trying to catch it on video: