From a4eee47265e06d302fc482e68a2abcdd6cd97c81 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 29 Dec 2020 17:45:42 -0300 Subject: Add "foreground" attribute to wait_packet. This prevents AP Timer from pausing main game from a thread (race condition) --- game/04_init.rpy | 11 +++++++---- game/misc.rpy | 2 +- game/script.rpy | 2 -- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/game/04_init.rpy b/game/04_init.rpy index 482ddde..ba7ccd1 100644 --- a/game/04_init.rpy +++ b/game/04_init.rpy @@ -116,13 +116,16 @@ init python: return - def wait_packet(): + def wait_packet(fg=True): global tr_load, tr_val, tr_busy timeout=0.0 print("Now waiting for packet!") while not tr_load: - sdelay() # FIXME: This can cause errors in mobile? + if fg: + sdelay() # FIXME: This can cause errors in mobile? + else: + time.sleep(0.02) timeout+=0.02 if timeout >= TIMEOUT_INTERVAL: @@ -161,11 +164,11 @@ init python: return - def send_packet(packet, args=""): + def send_packet(packet, args="", fg=True): global tr_cmd, tr_busy, tr_load schedule_packet() send_packet_now(packet, args) - return wait_packet() + return wait_packet(fg) # In past, this would keep running, in hopes of catching the program quit # and being able to kill the threads... But well, it worked poorly. diff --git a/game/misc.rpy b/game/misc.rpy index a37d779..27659dc 100644 --- a/game/misc.rpy +++ b/game/misc.rpy @@ -299,7 +299,7 @@ image spinner: init python: def ap_restore(): # Request AP Data from websocket - raw=send_packet("apdata") + raw=send_packet("apdata", fg=False) apdata=json_decode(raw) try: Player["ap"]=apdata["ap"] diff --git a/game/script.rpy b/game/script.rpy index ad0ced0..4bd7081 100644 --- a/game/script.rpy +++ b/game/script.rpy @@ -243,8 +243,6 @@ label quit: pass # Data cleaned up - # Destroy the socket - $ persistent.ws = None $ print("Sockets closed and data flushed!") return -- cgit v1.2.3-70-g09d2