Thank you so much for your answer, that's awesome!
I've begun to suspect that anything requiring pure OpenGL is going to be a pain since I'll have to get someone to check everything I do, so I've just begun to focus my efforts on running the Pyglet event loop from within WX.
I have the code for the tiles - which even works (surprisingly), and it'll give me the added benefits of game controler support et al.
Have you managed to integrate the two libraries? I could just use a thread... but I already have twisted running inside of a further thread, and having three running consecutively seems extraneous.
Thank you again for all the info, it's been really helpful!
Take care,
Chris
--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Hi, yes, Twisted, specifically twisted.protocols.basic.NetstringReceiver.
The client I am making is for Mindspace, which is my VR idea:
https://github.com/chrisnorman7/
I have never heard of Coiterate... a quick google shows it's something to do with iterators?
If you have an example that would be amazing!
At this point I've pretty much resigned myself to using Pyglet for the whole project.
I actually don't mind using Pyglet - I love it! It's just that I know more about presenting information with WX, and I'd written me a very nice (and pretty much indespensible remote Python shell for building things on the fly within the Mindspace server instance).
I'm planning to do the unthinkable and have a third (or second if I can make your code work for me) event loop for WX, and just leave a frame around to keep the main loop chugging away.
All in all, I'm actually quite excited because I'd love to use game controller support, and I find the keyboard handling q lot nicer.
Cheers,
Twisted you say? Hmm. As I said, I've only just started playing around with wxpython recently, other than the script I linked to i'm not sure how to integrate them at this point. I have however managed to integrate pyglet with twisted before using Twisted's coiterate function, I have an exampleof that around if you like.
Working with OpenGL may be a bit tricky, I know of a few tools available that may help if your not aware of them already. There's Peter Meijers [The vOICe] sotware, which you could use to scan the active window and convert it into sound. Another option would be the accessible paint tool [BrushTone], you could take a screenshot of the window with the print screen key, paste and save it as an image in something like mspaint and run it through BrushTone to look at the results.
Sorry, forgot to say that I'd definitely love to see your example please! :-)
Twisted you say? Hmm. As I said, I've only just started playing around with wxpython recently, other than the script I linked to i'm not sure how to integrate them at this point. I have however managed to integrate pyglet with twisted before using Twisted's coiterate function, I have an exampleof that around if you like.
Working with OpenGL may be a bit tricky, I know of a few tools available that may help if your not aware of them already. There's Peter Meijers [The vOICe] sotware, which you could use to scan the active window and convert it into sound. Another option would be the accessible paint tool [BrushTone], you could take a screenshot of the window with the print screen key, paste and save it as an image in something like mspaint and run it through BrushTone to look at the results.
import pyglet
from pyglet.window import mouse
from pyglet.window import key
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.internet.protocol import Protocol
from twisted.internet.protocol import Factory
from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor
from twisted.internet import task
import pickle
import zlib
pyglet.options['debug_gl'] = False
#pyglet window
class example(pyglet.window.Window):
def __init__(self):
super(example, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
#connected user variable, when someone connects the Echo Class will add itself into it.
#then just call self.user.sendData to transmit to the connected user or self.user.dataRecieved to get data.
self.user = []
self.server = None
#since the Reactor is in control, to properly run the main game loop you have to manually call the clock.
#this variable is to keep track of the last time the clock was ticked.
self.old_dt = pyglet.clock.tick()
self.fps_display = pyglet.clock.ClockDisplay()
#main game loop
def update(self):
while not self.has_exit:
#Make sure events are timed properly while coiterating with network layer. That and tick clock events like the fps counter and game pacing.
dt = pyglet.clock.tick()
self.old_dt = self.old_dt + dt
#draw to screen
self.draw()
#manually dispatch window events (since twisted reactor is in control)
self.dispatch_events()
#return control to twisted Reactor
yield 1
#draw and manually flip frame buffers
def draw(self):
self.clear()
self.fps_display.draw()
self.flip()
#mouse click
def on_mouse_press(self,x,y,button,modifiers):
if button == pyglet.window.mouse.LEFT:
if len(self.user) != 0:
data = ['left_press',x,y]
for a in self.user:
a.sendData(data)
if button == pyglet.window.mouse.RIGHT:
if len(self.user) != 0:
data = ['right_press',x,y]
for a in self.user:
a.sendData(data)
def on_mouse_release(self,x,y,button,modifiers):
if button == pyglet.window.mouse.LEFT:
#if someone has logged in, transmit if you click the mouse
if len(self.user) != 0:
data = ['left_release',x,y]
for a in self.user:
a.sendData(data)
if button == pyglet.window.mouse.RIGHT:
#if someone has logged in, transmit if you click the mouse
if len(self.user) != 0:
data = ['right_release',x,y]
for a in self.user:
a.sendData(data)
def on_key_release(self,symbol, modifiers):
if symbol == key.S:
self.server = TCP4ServerEndpoint(reactor, 8007)
self.server.listen(QOTDFactory())
print "server initializing"
if symbol == key.C:
reactor.connectTCP('localhost', 8007, EchoClientFactory())
print "connecting"
if symbol == key.ESCAPE:
self.close()
#shutdown program gracefully
def shutdown(self, result):
reactor.stop()
#system error shutdown
def bailout(self, reason):
reason.printTraceback()
reactor.stop()
#twisted network classes
class Echo(Protocol):
#data reciever class
def connectionMade(self):
data = "An apple a day keeps the doctor away\r\n"
data = pickle.dumps(data)
compressed = zlib.compress(data)
self.transport.write(compressed)
window.user.append(self)
def dataReceived(self, data):
#have the Echo Protocol class representing the connection to the currently connected user add itself
#to the window.user variable so we can comminicate with the connected user in the game loop.
data = zlib.decompress(data)
data = pickle.loads(data)
if data[0] == 'left_press':
print '1'
if data[0] == 'left_release':
print '2'
if data[0] == 'right_press':
print '3'
if data[0] == 'right_release':
print '4'
#data transmitter class
def sendData(self,data):
data = pickle.dumps(data)
data = zlib.compress(data)
self.transport.write(data)
#this monitors the port and automatically calls Echo() when someone connects, passing their address to it.
class QOTDFactory(Factory):
def buildProtocol(self, addr):
print addr, "connected."
return Echo()
#This class establishes a connection to a server.
class EchoClientFactory(ClientFactory):
def startedConnecting(self, connector):
print 'Started to connect.'
def buildProtocol(self, addr):
print 'Connected.'
return Echo()
def clientConnectionLost(self, connector, reason):
print 'Lost connection. Reason:', reason
def clientConnectionFailed(self, connector, reason):
print 'Connection failed. Reason:', reason
if __name__ == '__main__':
#initialize main window
window = example()
#coiterate between the reactor and the window
task.coiterate(window.update()).addCallback(window.shutdown).addErrback(window.bailout)
#start main reactor loop
reactor.run()
You're in, thank you so much!
Take care,
Well, I can't take all the credit. Nathan posted the gist of it [here] ages ago, I came across it a few years later and based my own example on it. For reference though, just magurp244 would suffice.