MultiClient: signal an event when receiving item data to improve responsiveness
This commit is contained in:
parent
b36c981eb4
commit
f843c401c7
|
@ -24,6 +24,7 @@ class Context:
|
||||||
self.server_address = server_address
|
self.server_address = server_address
|
||||||
|
|
||||||
self.exit_event = asyncio.Event()
|
self.exit_event = asyncio.Event()
|
||||||
|
self.watcher_event = asyncio.Event()
|
||||||
|
|
||||||
self.input_queue = asyncio.Queue()
|
self.input_queue = asyncio.Queue()
|
||||||
self.input_requests = 0
|
self.input_requests = 0
|
||||||
|
@ -647,6 +648,7 @@ async def process_server_cmd(ctx : Context, cmd, args):
|
||||||
if start_index == len(ctx.items_received):
|
if start_index == len(ctx.items_received):
|
||||||
for item in items:
|
for item in items:
|
||||||
ctx.items_received.append(ReceivedItem(*item))
|
ctx.items_received.append(ReceivedItem(*item))
|
||||||
|
ctx.watcher_event.set()
|
||||||
|
|
||||||
if cmd == 'LocationInfo':
|
if cmd == 'LocationInfo':
|
||||||
for location, item, player in args:
|
for location, item, player in args:
|
||||||
|
@ -655,6 +657,7 @@ async def process_server_cmd(ctx : Context, cmd, args):
|
||||||
item_name = replacements.get(item, get_item_name_from_id(item))
|
item_name = replacements.get(item, get_item_name_from_id(item))
|
||||||
print(f"Saw {color(item_name, 'red', 'bold')} at {list(Regions.location_table.keys())[location - 1]}")
|
print(f"Saw {color(item_name, 'red', 'bold')} at {list(Regions.location_table.keys())[location - 1]}")
|
||||||
ctx.locations_info[location] = (item, player)
|
ctx.locations_info[location] = (item, player)
|
||||||
|
ctx.watcher_event.set()
|
||||||
|
|
||||||
if cmd == 'ItemSent':
|
if cmd == 'ItemSent':
|
||||||
player_sent, location, player_recvd, item = args
|
player_sent, location, player_recvd, item = args
|
||||||
|
@ -822,7 +825,11 @@ async def track_locations(ctx : Context, roomid, roomdata):
|
||||||
|
|
||||||
async def game_watcher(ctx : Context):
|
async def game_watcher(ctx : Context):
|
||||||
while not ctx.exit_event.is_set():
|
while not ctx.exit_event.is_set():
|
||||||
await asyncio.sleep(2)
|
try:
|
||||||
|
await asyncio.wait_for(ctx.watcher_event.wait(), 2)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
pass
|
||||||
|
ctx.watcher_event.clear()
|
||||||
|
|
||||||
if not ctx.rom:
|
if not ctx.rom:
|
||||||
rom = await snes_read(ctx, ROMNAME_START, ROMNAME_SIZE)
|
rom = await snes_read(ctx, ROMNAME_START, ROMNAME_SIZE)
|
||||||
|
@ -857,12 +864,6 @@ async def game_watcher(ctx : Context):
|
||||||
assert SCOUT_LOCATION_ADDR == RECV_PROGRESS_ADDR + 7
|
assert SCOUT_LOCATION_ADDR == RECV_PROGRESS_ADDR + 7
|
||||||
scout_location = data[7]
|
scout_location = data[7]
|
||||||
|
|
||||||
if scout_location > 0 and scout_location not in ctx.locations_scouted:
|
|
||||||
ctx.locations_scouted.add(scout_location)
|
|
||||||
print(f'Scouting item at {list(Regions.location_table.keys())[scout_location - 1]}')
|
|
||||||
await send_msgs(ctx.socket, [['LocationScouts', [scout_location]]])
|
|
||||||
await track_locations(ctx, roomid, roomdata)
|
|
||||||
|
|
||||||
if recv_index < len(ctx.items_received) and recv_item == 0:
|
if recv_index < len(ctx.items_received) and recv_item == 0:
|
||||||
item = ctx.items_received[recv_index]
|
item = ctx.items_received[recv_index]
|
||||||
print('Received %s from %s (%s) (%d/%d in list)' % (
|
print('Received %s from %s (%s) (%d/%d in list)' % (
|
||||||
|
@ -879,6 +880,12 @@ async def game_watcher(ctx : Context):
|
||||||
|
|
||||||
await snes_flush_writes(ctx)
|
await snes_flush_writes(ctx)
|
||||||
|
|
||||||
|
if scout_location > 0 and scout_location not in ctx.locations_scouted:
|
||||||
|
ctx.locations_scouted.add(scout_location)
|
||||||
|
print(f'Scouting item at {list(Regions.location_table.keys())[scout_location - 1]}')
|
||||||
|
await send_msgs(ctx.socket, [['LocationScouts', [scout_location]]])
|
||||||
|
await track_locations(ctx, roomid, roomdata)
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--snes', default='localhost:8080', help='Address of the QUsb2snes server.')
|
parser.add_argument('--snes', default='localhost:8080', help='Address of the QUsb2snes server.')
|
||||||
|
|
Loading…
Reference in New Issue