ctpug / pygame_cffi Goto Github PK
View Code? Open in Web Editor NEWA cffi-based SDL wrapper that copies the pygame API.
License: GNU Lesser General Public License v2.1
A cffi-based SDL wrapper that copies the pygame API.
License: GNU Lesser General Public License v2.1
Python 2.7.10 (f3ad1e1e1d62, Sep 07 2015, 21:46:51)
[PyPy 2.6.1 with GCC 5.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import pygame
>>>> pygame.init()
(5, 0)
>>>> pygame.time.set_timer(pygame.USEREVENT,1000)
From cffi callback <function _timer_callback at 0x00007fedc97ec098>:
Traceback (most recent call last):
File "/opt/pypy/site-packages/pygame_cffi-0.1.0-py2.7-linux-x86_64.egg/pygame/time.py", line 115, in _timer_callback
event = ffi.new("SDL_Event")
TypeError: expected a pointer or array ctype, got 'union SDL_Event'
>>>>
Consider using "SDL_Event *" instead.
I'm using pygame.mask to detect object in TMX please update it
While most of the files we've imported from pygame (excluding those in tests) have the appropriate LGPL license notices, we've been rather lack about adding them and appropriate copyright holder notes to the rest of the project. This should be fixed.
My game uses pygame.mixer.music.set_endevent()
to register an event type to be used when music playback is complete. Running my game with pygame_cffi
and PyPy, the following traceback was logged when the queued music file finished playing, and the registered event was never observed. I don't get this traceback with standard pygame
in cPython.
Traceback (most recent call last):
File "/home/josh/.local/lib/pypy2.7/site-packages/pygame/mixer_music.py", line 207, in _endmusic_callback
event.post(event.Event(_endmusic_event))
File "/home/josh/.local/lib/pypy2.7/site-packages/pygame/event.py", line 226, in post
raise RuntimeError("event post blocked for %s" % event_name(event.type))
RuntimeError: event post blocked for Unknown
Hi!
So have been using pygame_cffi for a while and one day noticed that one of my programs using pygame_cffi would segfault once in a while.
I figured out what causes it and how to reproduce:
import pygame
import time
pygame.init()
surface = pygame.display.set_mode((800, 800))
color = [255, 127, 0]
pos = (656, 800)
radius = 0
width = 0
pygame.draw.circle(surface, color, pos, radius, width)
objects in my program would get smaller with distance sometimes their radius would reach zero, not often though. so initially i did not pick it up.
if width > radius it throws width greater then radius.
and if radius > width it would work fine.
so it is only in the case of radius = width = 0
that it would segfault.
for me it's an easy fix i can live with
if radius == 0:
radius = 1
but it shouldn't segfault.
A lot of games written with pygame uses functions like this:
@staticmethod
def display_single_line(line, x, y, screen):
"""Displays a single line of text on Battle screen"""
txt = pygame.font.Font(None, 36)
render = txt.render(line[0:13], 0, (255, 255, 255))
screen.blit(render, (x, y))
So font file being opened every time when function is called. But this error doesn't happen in PyGame.
Maybe we should add caching or something like it?
Which is a bit unexpected.
To reproduce: clone pypy, go to directory (like rpython/jit/metainterp)
and run py.test --view test/test_loop.py
then once pygame pops in press "/" to search
Clearly this is not implemented yet. Is there an eta on this?
pygame.event.get and pygame.event.clear support restricting the events pulled or removed by type.
pygame_cffi currently doesn't.
A bunch of different people have now contributed to pygame_cffi. We should give them credit.
pygame_cffi currently doesn't support
There's also a TODO item in the surface checks that should be completed.
CFFI 1.0 allows pre-building the necessary C modules which massively reduces import times. on slower machines (e.g. Raspberry Pis).
Currently there's no support for this object.
I seem to have a problem with this module on Mac OS X 10.11 Golden Master.
Running "import pygame" causes the following error:
Python 2.7.10 (f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559, Sep 21 2015, 15:59:29)
[PyPy 2.6.1 with GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/pypy/2.6.1/libexec/site-packages/pygame_cffi-0.0.1-py2.7-macosx-10.11-x86_64.egg/pygame/__init__.py", line 3, in <module>
from pygame.color import Color
File "/usr/local/Cellar/pypy/2.6.1/libexec/site-packages/pygame_cffi-0.0.1-py2.7-macosx-10.11-x86_64.egg/pygame/color.py", line 3, in <module>
from pygame._sdl import ffi, sdl
File "/usr/local/Cellar/pypy/2.6.1/libexec/site-packages/pygame_cffi-0.0.1-py2.7-macosx-10.11-x86_64.egg/pygame/_sdl.py", line 1, in <module>
from pygame._sdl_c import ffi
ImportError: No module named pygame._sdl_c
>>>>
To install it, I ran:
brew install pypy cairo jpeg
git clone https://github.com/CTPUG/pygame_cffi.git
cd pygame_cffi
pypy setup.py build build_ext -n -I/usr/local/include
sudo pypy setup.py install build_ext -n -I/usr/local/include
I included "/usr/local/include" because it couldn't find "jpeglib.h"
Currently we don't have this module.
with stock pygame:
>> pygame.surface.Surface((120.0, 122.8)) <Surface(120x122x32 SW)>
With pygame_cffi
``>> pygame.surface.Surface((122.0, 122.8))
....
TypeError: expected tuple of two integers but got <type 'tuple'>`
This causes problems with programs that pass floats (usually created by some mathematical operation) when creating surfaces
Pygame appears to have a .version
attribute in the top-level package that, e.g., pyknic, relies upon.
Currently it appears to not be installed by pip install pygame-cffi
.
In pygame proper, pygame.image.load() accepts any file-like object (e.g., a StringIO object), but this results in a TypeError in pygame-cffi.
i encountered this error/bug when running my pygame code.
i think it happens where a to big value for x is entered and can not be stored in a int16_t.
in my case it was a entity in my code going far offscreen.
this is the full traceback:
http://pastebin.com/hf1g75Fn
to reproduce:
>>> import pygame
>>> pygame.init()
(5, 0)
>>> screen = pygame.display.set_mode((300, 400))
>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (((2**16)/2), 0), 1)
<rect(32767, 0, -32466, 2)>
>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (((2**16)/2)+1, 0), 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/duality/.pyvenvs/pypyvenv/site-packages/pygame/draw.py", line 375, in circle
_fillellipse(surface, pos, radius, radius, color)
File "/home/duality/.pyvenvs/pypyvenv/site-packages/pygame/draw.py", line 587, in _fillellipse
c_x - k, c_x + k - 1, c_y - h - 1)
File "/home/duality/.pyvenvs/pypyvenv/site-packages/pygame/draw.py", line 127, in _drawhorizline
sdlrect.x = start_x
OverflowError: integer 32768 does not fit 'int16_t'
integer 32768 does not fit 'int16_t'
>>>
The following functions from pygame.transform aren't complete
We should convert to using cffi-1.4's Extern “Python” syntax for callbacks, to avoid the issues with the ffi.callback approach.
Since one of the goals is to provide pygame for pypy, we really should run the test suite against pypy.
Since travis only has horribly outdated versions of pypy available, this will require rolling our own logic for setting up pypy.
We should also try using the travis OSX target sometime.
Anyone have any plans to implement?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.