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