PirlKnighte | 25 May 19:40 2015
Picon

Pyglet and Sockets

I'm running into a problem where it won't send data while pyglet.app is running, even when added as a schedule_interval.  After I close the window it seems to read that data was sent.  Here is my code:

Sever.py
#!usr/bin/python

import socket, thread, time, json

currentUsers
= {}
collidables
= json.loads(json.dumps(""))
map_size
= 100
maxPlayers
= 50
current_IP
= socket.gethostbyname(socket.gethostname())

def Timer():
       
global waiting
       
while True:
                waiting
= False
                time
.sleep(0.05)
               
print "-"
                waiting
= True
                time
.sleep(0.1)

def Admin():
       
print "Creating Admin port %s" % str(4999)
        s
= socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create new socket
        s
.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1) # set to reusable
        s
.bind(('',4999)) # bind said socket
        s
.listen(1)
        client
, address = s.accept() # wait for new connection
       
while True:
                data
= client.recv(size)
               
if data == "/UserList":
                        client
.sendall(str(currentUsers))
                       
print currentUsers

def Thread(port):
       
global host, size, nextPort, waiting, maxPlayers
       
print "\r                                                                       \rCreating User ports %d/%d" % (port-5000, maxPlayers),
       
while True:
               
try:

                       
# Create socket and wait for connection
                        s
= socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create new socket
                        s
.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1) # set to reusable
                        s
.bind(('',port)) # bind said socket
                        s
.listen(1)
                        client
, address = s.accept() # wait for new connection
                        username
= client.recv(100)
                       
print "Port %s connected to \"%s\" %s" % (str(port), username, str(address))
                        currentUsers
[str(port)] = str(address) + " | " + username
                        client
.sendall(str(map_size))

                       
# Main loop, adds point to hashmap
                       
while True:
                                data
= client.recv(size)
                               
print data+"+"
                               
while waiting:
                                       
pass
                               
if data:
                                       
# print "Recieved from port  %s (%s)" % (port, str(address[1]))
                                        data_json
= json.loads(json.dumps(data))
                                        collidables
.append(data_json)
                                        client
.sendall(str(collidables))
                                       
print collidables+"."
                               
while not(waiting):
                                       
pass

                        client
.close()
                        s
.close()
                       
break
               
except socket.error:           # Add something to check for timeouts \ Quitters
                       
print "\"%s\" in port %s left %s" % (username,str(port),str(address))
                        client
.close()
                        s
.close()

               
except:
                       
print "\nFailed to Create port %s" % str(port)
                        client
.close()
                        s
.close()
                        time
.sleep(1)
                        nextPort
-=1
                       
NeedNewThread = True
                       
break


host
= 'localhost'
nextPort
= 5000
size
= 1000000
hashMap
= {}
waiting
= True
print current_IP
thread
.start_new_thread(Admin,())
thread
.start_new_thread(Timer,())
time
.sleep(0.5)

while nextPort < 5000+maxPlayers+1:
        thread
.start_new_thread(Thread,(nextPort,))
        time
.sleep(0.1)
        nextPort
+=1
print ""

while True:
       
pass




Client.py
from pyglet.window import Window,key
from pyglet import app
from pyglet.text import Label
from pyglet.clock import schedule_interval
import random, socket



Keys = [False,False,False,False,False] # [W,A,S,D,FIRE]
last = Keys

bullets
= []
bullet_speed
= 3
bullet_life
= 5


point
= {'x':0,'y':0}
size
= 100 # query server for size
map_size
=10

username
= "Lemonilla"


# Game Setup
print "Enter IP of the server you with to connect to."
server_IP
= raw_input(">")

port
= None
while port == None:
       
for x in xrange(0,50):
               
try:
                       
print "\r                                    \r  Attempting socket %d" % (5000+x),
                        server
= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                        server
.connect((server_IP,5000+x))
                        port
= 5000+x
                       
break
               
except:
                       
pass

server
.sendall(username)
print "\n  Waiting for server to respond. . ."
size
= server.recv(10)
print   "  Launching Game. . ."

win
= Window()
ScreenMap = Label("")


def move():
       
global Keys,point,last
       
if Keys[0] == True: # W
                point
['y']+=1
       
if Keys[1] == True: # A
                point
['x']-=1
       
if Keys[2] == True: # S
                point
['y']-=1
       
if Keys[3] == True: # D
                point
['x']+=1
       
if Keys[4] == True: # SPACE
               
Fire()
       
last = Keys

def Fire():
       
global last
       
# bullet = [x, y, distance to travel, direction]
                                       
#     (W, A, S, D, FIRE)
        bullets
.append((point['x'], point['y'], bullet_life, list(last)))

def decay():
       
global bullets
        index
=0
       
for b in bullets:
                bullet_x
=b[0]
                bullet_y
=b[1]

               
if b[3][0] == True:
                        bullet_y
=b[1]+bullet_speed
               
if b[3][2] == True:
                        bullet_y
=b[1]-bullet_speed
               
if b[3][1] == True:
                        bullet_x
=b[0]-bullet_speed
               
if b[3][3] == True:
                        bullet_x
=b[0]+bullet_speed
               
if b[2]-1 > 0:
                        bullets
[index] = (bullet_x, bullet_y, b[2]-1, b[3])
               
else:
                        bullets
[index] = None
                index
+=1
       
while bullets.count(None) > 0:
                bullets
.remove(None)

def check_crash():
       
return
        send
= "{\'"+str(username)+"\':"+str(bullets)+"}"
        server
.sendall(send)
       
print send
       
# Query Server for Colidables list
        collidables
= server.recv(1000000)
       
print collidables

def buildScreen():
       
global ScreenMap, win, point, map_size
        screen
= ""
       
for y in xrange(point['y']+map_size+1,point['y']-map_size,-1):
               
for x in xrange(point['x']-map_size-1,point['x']+map_size):
                       
if not(x == point['x'] and y == point['y']):
                                printed
= False
                               
for b in bullets:
                                       
if x == b[0] and y == b[1]:
                                               
if not(printed):
                                                        screen
+="  +"
                                                        printed
= True
                               
if not(printed):
                                        screen
+="  . "
                       
else:
                                screen
+=" <at> "
                screen
+="\n"
       
ScreenMap = Label(str(screen), x=0, y=win.height, width=win.width, multiline=True)


<at> win.event
def on_key_press(symbol, modifiers):
       
global Keys,ScreenMap
       
if symbol == key.A:
               
Keys[1] = True
       
if symbol == key.S:
               
Keys[2] = True
       
if symbol == key.W:
               
Keys[0] = True
       
if symbol == key.D:
               
Keys[3] = True
       
if symbol == key.SPACE:
               
Keys[4] = True
        win
.clear()
       
ScreenMap.draw()

<at> win.event
def on_key_release(symbol, modifiers):
       
global Keys,ScreenMap
       
if symbol == key.A:
               
Keys[1] = False
       
if symbol == key.S:
               
Keys[2] = False
       
if symbol == key.W:
               
Keys[0] = False
       
if symbol == key.D:
               
Keys[3] = False
       
if symbol == key.SPACE:
               
Keys[4] = False
        win
.clear()
       
ScreenMap.draw()
       


def update(dt):
       
global Keys,ScreenMap,point

        buildScreen
()
        move
()
        decay
()
        check_crash
()

        win
.clear()
       
ScreenMap.draw()

        point_label
= Label("%d,%d" % (point['x'],point['y']))
        point_label
.draw()
 

schedule_interval
(update, 0.1)

app
.run()




--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
lhc29tb | 22 May 18:20 2015
Picon

ctypes behavior changed by pyglet?

i found my program could not run if i imported pyglet.media.  an example:

windll.user32.GetCursorPos(int)

(where int is a memory address in python process)

raised TypeError: LP_POINT instance expected instead of int.
but it ran correctly without importing pyglet.media.
i may still make the program work, but pyglet is affecting a built-in module of the official Python and the way a programmer does programming, is this really necessary?
software version: python 2.75, pyglet 1.2.2/1.2.3a1 32bit

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Mark Weyland | 18 May 19:26 2015
Picon

Drawing circle with triangles (BUG?!)

Hello, could anyone run these snippets?
TEST 1
import pyglet
from pyglet.gl import GL_TRIANGLES
from itertools import chain

C
= 0.707
def octagon (x, y, r, c, b, g):
   
""" Returns a vertex list of regular octagon with center at (x, y) and corners
    distanced r away. Paints center and corners. Adds to batch b in group g. """

    i
= list(chain.from_iterable( (0, x+1, x+2) for x in range(8) ) )
    i
.extend( (0, 1, 8) )
    p
= x, y
    p
+= x-r, y, x+int(-C*r), y+int( C*r), x, y+r, x+int( C*r), y+int( C*r)
    p
+= x+r, y, x+int( C*r), y+int(-C*r), x, y-r, x+int(-C*r), y+int(-C*r)
   
return b.add_indexed(9, GL_TRIANGLES, g, i, ('v2i', p), ('c3B', c))

WIN
= 900, 900, 'TEST'
CENTER
= WIN[0] // 2, WIN[1] // 2
RADIUS
= 100
SPEED
= 0.1 # in seconds
WHITE
= (255, 255, 255) # for center
RED
= (255, 0, 0)       # for points

# Variables
win
= pyglet.window.Window(*WIN)
batch
= pyglet.graphics.Batch()

def on_step(dt):
   
global batch
    batch
= pyglet.graphics.Batch()
    octagon
(CENTER[0], CENTER[1], RADIUS, WHITE+RED*8, batch, None)

<at> win.event
def on_draw():
    win
.clear()
    batch
.draw()

pyglet
.clock.schedule_interval(on_step, SPEED)
pyglet
.app.run()

TEST 2
import pyglet
from random import randrange
from pyglet.gl import GL_TRIANGLES
from itertools import chain

C
= 0.707
def octagon (x, y, r, c, b, g):
   
""" Returns a vertex list of regular octagon with center at (x, y) and corners
    distanced r away. Paints center and corners. Adds to batch b in group g. """

    i
= list(chain.from_iterable( (0, x+1, x+2) for x in range(8) ) )
    i
.extend( (0, 1, 8) )
    p
= x, y
    p
+= x-r, y, x+int(-C*r), y+int( C*r), x, y+r, x+int( C*r), y+int( C*r)
    p
+= x+r, y, x+int( C*r), y+int(-C*r), x, y-r, x+int(-C*r), y+int(-C*r)
   
return b.add_indexed(9, GL_TRIANGLES, g, i, ('v2i', p), ('c3B', c))

WIN
= 900, 900, 'TEST'
RADIUS
= 60
WHITE
= (255, 255, 255) # for center
RED
= (255, 0, 0) # for corners

win
= pyglet.window.Window(*WIN)
batch
= pyglet.graphics.Batch()

def on_step(dt):
    x
= randrange(RADIUS, WIN[0] - RADIUS)
    y
= randrange(RADIUS, WIN[1] - RADIUS)
    octagon
(x, y, RADIUS, WHITE+RED*8, batch, None)

<at> win.event
def on_draw():
    win
.clear()
    batch
.draw()

pyglet
.clock.schedule_interval(on_step, 1)
pyglet
.app.run()

I posted this question on Stack Overflow too. The code seems to be correct but on the shape is incorrectly drawn. Is this reproducable on your machine? What causes this behaviour?

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Ben Albrecht | 16 May 02:52 2015
Picon

Shapes in class in Pyglet

I am curious, why not have some high level classes for drawn common shapes, like rectangles, circles, triangles, etc. built on top of pyglet.gl? Is there some technical barrier preventing this? 

I imagine many people are deterred from Pyglet when they realize they will have to write some nasty looking opengl calls to draw some simple shapes. At least this is a common comparison I notice when people compare Pygame vs. Pyglet.

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Salvakiya | 14 May 09:08 2015
Picon

optimizations?

Hello everyone. I seem to be having performance issues with my pyglet project. can someone take a look at it and tell me what I can do? It has to do with how I handle the sprites.

https://github.com/Salvakiya/PyGM3

any additional tips or advice is welcome!

thanks!

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Rob | 9 May 13:09 2015
Picon

New test framework

Hi all,

For pyglet 1.3.x I've been working on a new test framework to make it easier to run all tests during development and while preparing for a release. This week I migrated the last test to this new framework and created the documentation for it. The framework still relies on the built-in unittest module in Python plus the mock library (builtin since Python 3.3, but also included in the pyglet source tree).

What does this mean? Well, to start the old tests/test.py no longer exists, instead there is the module tests.run. The tests have been split into unit, integration and interactive tests. For the interactive tests a new base class is introduced to handle the user verification and screenshots. Also support for coverage (if installed) is added.

To find more details about the new test framework, please see the documentation at: http://pyglet.readthedocs.org/en/latest/internal/testing.html

There is still some work in progress, which includes increasing the coverage and testing on all platforms, but the basic gist is there.

Kind regards,
Rob

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Sandeep Bhat | 8 May 20:08 2015
Picon

Audio recording using pyglet

I need to know how to record audio using pyglet. Couldn't find any documentation regarding it. I tried using PyAudio but it's highly unstable. So would like to know how to do the same using pyglet.
Thanks in advance.

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Rob | 1 May 22:26 2015
Picon

Pyglet 1.2.3a2

Hi all,

I created a new package with the latest fixes. Still need to test it thoroughly though.

As always it is available from PyPI:
http://pypi.python.org/pypi/pyglet/1.2.3a2

Or:
pip install pyglet==1.2.3a2

Kind regards,
Rob

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Noah A | 29 Apr 18:59 2015
Picon

Pyglet without X Windows and other questions

I'm in the early phases of trying to decide between Pyglet and PyGame. I have very little GUI programming experience. I write web applications but for my current needs web interfaces are too heavy and have too much latency.

I bought a book on PyGame and started trying to make something with it but I found the API wasn't very Pythonic (in my opinion) and felt like I might as well be using C++ for the performance gains since it was already a pain to use. But I looked at Pyglet and the API seems much better to me. I'm just unsure if it can do what I need.
  1. Can Pyglet be used to create applications which run from the console (ie direct to frame buffer) without X Windows to avoid overhead.
  2. Is Pyglet hardware accelerated on most computers?
  3. Is Pyglet hardware accelerated on the Raspberry Pi 2?
  4. Can you point me to any projects which use Pyglet so I can gauge performance?
  5. In a windowed environment can Pyglet get and set the window location so that when it launches the Window can be put back where it was last time?
I have two main kinds of applications I want to make. One is simple touch screen (non-multi touch) interfaces with big buttons and sliders for gloved fingers on industrial equipment. Standard GUI toolkits don't work well for this because they all seem to be built assuming you have a keyboard and mouse. The other is to display gauges on industrial equipment which requires several layers of overlapping transparent images. For example think about the face of a sophisticated watch with a date dial, power meter, and such. This page has examples of the kind of complex dials. http://www.luxurybazaar.com/subcategories/subid_1285_Classique_Moonphase.html




--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
claudio canepa | 27 Apr 07:26 2015
Picon

[ANN] cocos 0.6.3 released

Besides small bugfixes, this release brings

- support to load (some) .tmx maps with hexagonal tiles
- compatibility break: HexMapLayer and HexCell changed __init__ signature
- support collisions between CircleShape and AARectShape in collision_model,
thanks Daniel Gillet
- support to read .tmx (Tiled Editor) object layers and objects
- deprecated do_not_scale and do_not_scale_window, use autoscale

Full Changelog at https://raw.githubusercontent.com/los-cocos/cocos/master/CHANGELOG

available from pypi https://pypi.python.org/pypi/cocos2d/0.6.3
or github https://github.com/los-cocos/cocos


What is cocos2d:
A framework for building 2D games, demos, and other graphical/interactive applications.
Draws using OpenGL, which is hardware accelerated.
Targets the Operating Systems linux, mac or windows on Pc-like hardware.
Provides some conventions and classes to help you structure a "scene based application".
A cocos2d application consists of several scenes, and a workflow connecting the different scenes.
It provides you with a "director" (a singleton) which handles that workflow between scenes.
Each scene is composed of an arbitrary number of layers; layers take care of drawing to the screen (using the pyglet and OpenGL APIs), handling events and in general contain all of the game/application logic.

cocos2d simplifies the game development in these areas:

* Flow control: Manage the flow control between different scenes in an easy way
* Sprites: Fast and easy sprites
* Actions: Just tell sprites what you want them to do. Composable actions like move, rotate, scale and much more
* Effects: Effects like waves, twirl, lens and much more
* Tiled Maps: Support for rectangular and hexagonal tiled maps
* Collision: Basic pure python support for collisions
* Transitions: Move from scene to scene with style
* Menus: Built in classes to create menus
* Text Rendering: Label and HTMLLabel with action support
* Built-in Python Interpreter: For debugging purposes
* Access to OpenGL functionality
* and much more! http://python.cocos2d.org

enjoy !

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
Florian Höch | 26 Apr 15:32 2015

Current development version of pyglet steals menus when used with wxPython under Mac OS X

Hi,

I'm using pyglet devel (122cf30) together with wxPython (3.0.2 cocoa) in an application. This works well, except that under Mac OS X (Yosemite), after application startup pyglet replaces my menus with just an app menu with "Quit!" and "Hide!" entries. The way I've worked around it for now is by overriding the platform event loop with a dummy one in pyglet.app.__init__ (I only use pyglet to play sound), but a better solution is probably needed.

--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to pyglet-users <at> googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Gmane