Sorry for the delay in responding. I was trying out ClanLib and wanted
to see how it did.
I fairly quickly had ClanLib scrolling smoothly (1440x900, 16x16
tiles), a parallax background layer, 40 sprites moving around, all of
them emitting light through a black overlay layer, all at 145fps on my
windows machine with a gts250.
I also fairly quickly remembered why I quit using C++. I really want
to get this working in Python even if I have to do some of the guts in
a C extension.
The main requirement other than smooth scrolling, is that I can't
build the whole level in memory. It has to build dynamically from an
array of tile indexes as you scroll through. I can get the rest of it
working if I can do the scrolling at a decent fps.
Here is what seems to work best so far (only the important parts):
#a pre-built list of tex_coords for each tile
tilePointers=[(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0) for i in range(1024)]
for tdKey in tileDict.keys():
tileTextures[tdKey]=tileAtlas.add(tileDict[tdKey].img.get_image_data())
tilePointers[int(tdKey)]=tileTextures[tdKey].tex_coords
#make a map of a repeating pattern (tile 0,1,2,3,0,1,2,3...)
tileMap=[ [i%4 for i in range(0,mapWidth/TILE_WIDTH)] for i in
range(0,mapHeight/TILE_HEIGHT)]
@window.event
def on_draw():
glEnable(tileAtlas.texture.target)
glBindTexture(tileAtlas.texture.target, tileAtlas.texture.id)
tileBatch.draw()
glDisable(tileAtlas.texture.target)
fps_display.draw()
#when the player moves:
#tw/th = tile width/height
#px/py = player x/y
textureData=[]
vertexData=[]
tIdx=0
vIdx=0
tx=int(px/tw)
ty=int(py/th)
y1 = -(int(py)%th)
for row in range(tileYCnt):
y2 = y1 + th
x1 = -(int(px)%tw)
for col in range(tileXCnt):
x2 = x1 + tw
vertexData.extend([x1, y1, x2, y1, x2, y2, x1,
y2])
textureData.extend(tilePointers[tileMap[ty+row][tx
+col]])
x1 = x2
y1 = y2
tileVertexList.tex_coords=textureData
tileVertexList.vertices=vertexData
I've tried re-writing this loop in a C extension, and using Cython and
the best I can get is about 85fps, but it's jerky and ticks a lot, and
this is just one layer with no sprites or game logic. In straight
Python, I get a max of about 40fps.
Am I doing something fundamentally wrong? In ClanLib, the example I
based my test from used a sprite to hold all the tiles, then looped
through the tileMap, changing the sprite frame and redrawing it at
each tile location. I did not have much success with this in Pyglet.
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.