comparison event_log.c @ 1971:80920c21bb52

Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
author Michael Pavone <pavone@retrodev.com>
date Fri, 08 May 2020 11:40:30 -0700
parents bd70f1e15684
children f2d37131840e
comparison
equal deleted inserted replaced
1970:41b9509ede38 1971:80920c21bb52
274 remote_send_progress[i] = compressed; 274 remote_send_progress[i] = compressed;
275 } 275 }
276 } 276 }
277 } 277 }
278 278
279 uint8_t wrote_since_last_flush;
279 void event_log(uint8_t type, uint32_t cycle, uint8_t size, uint8_t *payload) 280 void event_log(uint8_t type, uint32_t cycle, uint8_t size, uint8_t *payload)
280 { 281 {
281 if (!fully_active) { 282 if (!fully_active) {
282 return; 283 return;
283 } 284 }
292 fatal_error("deflate returned %d\n", result); 293 fatal_error("deflate returned %d\n", result);
293 } 294 }
294 if (listen_sock) { 295 if (listen_sock) {
295 if ((output_stream.next_out - compressed) > 1280 || !output_stream.avail_out) { 296 if ((output_stream.next_out - compressed) > 1280 || !output_stream.avail_out) {
296 flush_socket(); 297 flush_socket();
298 wrote_since_last_flush = 1;
297 } 299 }
298 } else if (!output_stream.avail_out) { 300 } else if (!output_stream.avail_out) {
299 fwrite(compressed, 1, compressed_storage, event_file); 301 fwrite(compressed, 1, compressed_storage, event_file);
300 output_stream.next_out = compressed; 302 output_stream.next_out = compressed;
301 output_stream.avail_out = compressed_storage; 303 output_stream.avail_out = compressed_storage;
465 fflush(event_file); 467 fflush(event_file);
466 output_stream.next_out = compressed; 468 output_stream.next_out = compressed;
467 output_stream.avail_out = compressed_storage; 469 output_stream.avail_out = compressed_storage;
468 } else if (listen_sock) { 470 } else if (listen_sock) {
469 flush_socket(); 471 flush_socket();
470 } 472 wrote_since_last_flush = 0;
473 }
474 }
475
476 void event_soft_flush(uint32_t cycle)
477 {
478 if (!fully_active || wrote_since_last_flush || event_file) {
479 return;
480 }
481 event_header(EVENT_FLUSH, cycle);
482 last = cycle;
483
484 deflate_flush(0);
485 flush_socket();
471 } 486 }
472 487
473 static void init_event_reader_common(event_reader *reader) 488 static void init_event_reader_common(event_reader *reader)
474 { 489 {
475 reader->last_cycle = 0; 490 reader->last_cycle = 0;