| 298 | } |
| 299 | |
| 300 | void GameLoop::initProcessMessages() |
| 301 | { |
| 302 | /* Connect to the socket between the program and the game */ |
| 303 | bool inited = initSocketProgram(fork_pid); |
| 304 | if (!inited) { |
| 305 | loopExit(); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /* Receive informations from the game */ |
| 310 | int message = receiveMessage(); |
| 311 | while (message != MSGB_END_INIT) { |
| 312 | |
| 313 | switch (message) { |
| 314 | /* Get the game process pid */ |
| 315 | case MSGB_PID_ARCH: { |
| 316 | int addr_size; |
| 317 | receiveData(&context->game_pid, sizeof(pid_t)); |
| 318 | receiveData(&addr_size, sizeof(int)); |
| 319 | MemAccess::init(context->game_pid, addr_size); |
| 320 | break; |
| 321 | } |
| 322 | |
| 323 | case MSGB_GIT_COMMIT: |
| 324 | { |
| 325 | std::string lib_commit = receiveString(); |
| 326 | #ifdef LIBTAS_INTERIM_COMMIT |
| 327 | std::string gui_commit = LIBTAS_INTERIM_COMMIT; |
| 328 | if (lib_commit.compare(gui_commit) != 0) { |
| 329 | std::cerr << "Interim commit of GUI (" << gui_commit << ") does not match commit of library (" << lib_commit << ")!" << std::endl; |
| 330 | } |
| 331 | #else |
| 332 | std::cerr << "Library has interim commit (" << lib_commit << ") but not GUI!" << std::endl; |
| 333 | #endif |
| 334 | } |
| 335 | break; |
| 336 | |
| 337 | default: |
| 338 | // ui_print("Message init: unknown message\n"); |
| 339 | loopExit(); |
| 340 | return; |
| 341 | } |
| 342 | message = receiveMessage(); |
| 343 | } |
| 344 | |
| 345 | /* Send informations to the game */ |
| 346 | |
| 347 | /* Send shared config size */ |
| 348 | sendMessage(MSGN_CONFIG_SIZE); |
| 349 | int config_size = sizeof(SharedConfig); |
| 350 | sendData(&config_size, sizeof(int)); |
| 351 | |
| 352 | /* Send shared config */ |
| 353 | |
| 354 | /* This is a bit hackish, change the initial time to the current realtime before |
| 355 | * sending so that the game gets the correct time after restarting. */ |
| 356 | struct timespec it = {context->config.sc.initial_time_sec, context->config.sc.initial_time_nsec}; |
| 357 | context->config.sc.initial_time_sec = context->current_realtime_sec; |
nothing calls this directly
no test coverage detected