diff 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
line wrap: on
line diff
--- a/event_log.c	Fri May 08 00:26:34 2020 -0700
+++ b/event_log.c	Fri May 08 11:40:30 2020 -0700
@@ -276,6 +276,7 @@
 	}
 }
 
+uint8_t wrote_since_last_flush;
 void event_log(uint8_t type, uint32_t cycle, uint8_t size, uint8_t *payload)
 {
 	if (!fully_active) {
@@ -294,6 +295,7 @@
 		if (listen_sock) {
 			if ((output_stream.next_out - compressed) > 1280 || !output_stream.avail_out) {
 				flush_socket();
+				wrote_since_last_flush = 1;
 			}
 		} else if (!output_stream.avail_out) {
 			fwrite(compressed, 1, compressed_storage, event_file);
@@ -467,9 +469,22 @@
 		output_stream.avail_out = compressed_storage;
 	} else if (listen_sock) {
 		flush_socket();
+		wrote_since_last_flush = 0;
 	}
 }
 
+void event_soft_flush(uint32_t cycle)
+{
+	if (!fully_active || wrote_since_last_flush || event_file) {
+		return;
+	}
+	event_header(EVENT_FLUSH, cycle);
+	last = cycle;
+	
+	deflate_flush(0);
+	flush_socket();
+}
+
 static void init_event_reader_common(event_reader *reader)
 {
 	reader->last_cycle = 0;