Feature: Sends request to increase update rate

This commit is contained in:
2025-11-13 19:36:13 +00:00
parent 32b496b596
commit 8c6577bb2e
3 changed files with 82 additions and 33 deletions
+25 -2
View File
@@ -21,7 +21,6 @@
const char *API_SOCKET_PATH = "/tmp/ACplayer_socket";
const int MAX_PLAYERS = 64;
const char *SERVER_OUT_IP = "127.0.0.1";
u_int8_t SERVER_ID;
@@ -259,7 +258,13 @@ int main(int argc, char *argv[]) {
trackInfo.session_name = (char *)malloc(64);
char message[124] = {0}; // just a place to put info messages from the server itself
u_char update_rate_message[2] = {0};
// EXPERIMENTAL: Send a message to the server to increase update rate - USING ACSP_REALTIMEPOS_INTERVAL
update_rate_message[0] = (u_char)ACSP_REALTIMEPOS_INTERVAL;
update_rate_message[1] = 255; // ms
u_char updateSent = 0;
printf("\n");
while (1) {
offset = 0;
@@ -267,7 +272,13 @@ int main(int argc, char *argv[]) {
memset(buffer, 0, sizeof(buffer));
// FIX: Its not garanted to receive a full packet in one recvfrom call, but the error -1 is not handled by a unsigned size_t
size_t recv_bytes = (size_t)recvfrom(recv_sock_fd, buffer, sizeof(buffer), 0, NULL, NULL);
size_t recv_bytes = (size_t)recvfrom(recv_sock_fd, buffer, sizeof(buffer), 0, NULL, NULL);
// Send update rate message to server ONCE
if (updateSent != 1) {
sendto(send_sock_fd, update_rate_message, sizeof(update_rate_message), 0, NULL, 0);
updateSent = 1;
}
// Convert buffer to utf-8 string and print it
#if DEBUG_CAR_INFO
@@ -613,12 +624,17 @@ int main(int argc, char *argv[]) {
update.cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
update.total_cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
current_packet.message_type = ACSP_LAP_COMPLETED;
printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name);
printf("\tLap Time: %5d ms\n", update.lap_time);
printf("\tCuts this lap: %d\n", update.cuts);
printf("\tTotal Cuts (this session): %d\n\n", update.total_cuts);
current_packet.cars_colided[0] = update.carID;
players[update.carID].total_laps_completed++;
update_api_packet(trackInfo, players);
break;
@@ -650,6 +666,10 @@ int main(int argc, char *argv[]) {
// TODO: Update total contacts for both players in the database
// TAG:2 Update total contacts for both players
current_packet.message_type = ACSP_CE_COLLISION_WITH_CAR;
current_packet.cars_colided[0] = update.carID;
current_packet.cars_colided[1] = event_car_id;
update_api_packet(trackInfo, players);
} break;
@@ -663,6 +683,9 @@ int main(int argc, char *argv[]) {
// TODO: Update total contacts for the player in the database
// TAG:2 Update total contacts for the player
current_packet.message_type = ACSP_CE_COLLISION_WITH_ENV;
current_packet.cars_colided[0] = update.carID;
update_api_packet(trackInfo, players);
} break;
}