Tweaked the networking code to try and make pygame work - still not working...
This commit is contained in:
parent
7abef7b37d
commit
e7d29696f1
|
@ -34,6 +34,7 @@ class GTPSocket:
|
|||
|
||||
while msg is None:
|
||||
try:
|
||||
select.select([self.socket], [], [])
|
||||
msg = self.socket.recv(4096)
|
||||
if msg[0] == '?':
|
||||
print "Error: GTP response: " + msg
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# The board is also wrapped in a mutex, even though only this thread should modify it
|
||||
# if it exists.
|
||||
|
||||
import select
|
||||
import threading
|
||||
import gtpsocket
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class GUI:
|
|||
def __init__(self, goban, settings):
|
||||
# Basic screen init
|
||||
pygame.init()
|
||||
pygame.fastevent.init()
|
||||
# screen = pygame.display.set_mode((1000, 800))
|
||||
self.screen = sgc.surface.Screen((1000,800))
|
||||
pygame.display.set_caption('pyGo')
|
||||
|
@ -71,13 +72,12 @@ class GUI:
|
|||
self.wait_dialog = sgc.widgets.Dialog(title="Please wait...", widget=wait_label)
|
||||
self.wait_dialog.rect.center = self.screen.rect.center
|
||||
|
||||
# Generate a spurious event once a second, just to
|
||||
# force an update
|
||||
pygame.time.set_timer(USEREVENT, 1000)
|
||||
# Generate a spurious event 5 times a second, to force an 'fps' of 5
|
||||
pygame.time.set_timer(USEREVENT, 200)
|
||||
|
||||
|
||||
def do_event(self):
|
||||
event = pygame.event.wait()
|
||||
event = pygame.fastevent.wait()
|
||||
sgc.widgets.event(event)
|
||||
|
||||
if event.type == QUIT:
|
||||
|
@ -86,10 +86,7 @@ class GUI:
|
|||
if self.network_mode:
|
||||
# This set of events should only be called if we can currently play
|
||||
if self.goban.to_move == self.our_color:
|
||||
print 'Processing an event while it is our turn: {}'.format(event)
|
||||
|
||||
# Hover a transparent stone over our
|
||||
# cursor position, assuming play is legal
|
||||
# Hover a transparent stone over our cursor position, assuming play is legal
|
||||
if event.type == MOUSEMOTION:
|
||||
with self.net_thread.goban_lock:
|
||||
self.do_hover(event)
|
||||
|
@ -150,6 +147,7 @@ class GUI:
|
|||
except socket.error as exception:
|
||||
print 'Error: Socket creation failed: {}'.format(exception.args)
|
||||
else:
|
||||
sock.setblocking(0)
|
||||
self.socket = gtpsocket.GTPSocket(sock)
|
||||
self.net_thread = networkthread.NetworkThread(self.goban, sock)
|
||||
self.net_thread.start()
|
||||
|
@ -167,6 +165,7 @@ class GUI:
|
|||
sock.bind(("127.0.0.1", 6859))
|
||||
sock.listen(1)
|
||||
conn, addr = sock.accept()
|
||||
conn.setblocking(0)
|
||||
sock.close()
|
||||
except socket.error as exception:
|
||||
print 'Error: Socket creation failed: {}'.format(exception.args)
|
||||
|
|
Loading…
Reference in New Issue
Block a user