Python Support


allanlw

Still Fresh
Joined
Dec 13, 2009
Messages
2
I was wondering what kind of python support the pandora will have out of the box. Mostly I was wondering whether the python SDL bindings (pygame) would be available as well as whether there is going to be some kind of python GL bindings (do python bindings for OpenGL ES even exist?).

Thanks.
 
I think CPython 2.6 is currently in, but I don't think pygame is currently bundled. If they're not in there, it should not be hard to bundle the needed libs in your pnd-files and likely will get patched into the OS officially.

jeff
 
atomicthumbs said:
I hope we can get Unladen Swallow to work well on this once it's done.
Unladen Swallow is a fork of Python 2.6 with some general performance improvements + a llvm-based JIT. It is however meant to be merged back into python mainline.

So it's not a separate interpreter, just a temporary fork. Also, LLVM on ARM is not quite supported yet, so the jit wouldn't be very useful.
 
Last edited by a moderator:
CPython isn't really a good choice for devices like this. It's a little bit too slow for being useful. It probably won't matter for the next generation of hardware, but with the current one it doesn't really look all that good.

For example if you do some math in a loop... then it performs even worse than IE6's JavaScript engine. And IE6's JS engine is famous for being outrageously slow. And trust me, it really is.

For being able to write any kind of classic 2D game, you probably need something which is about 5-10 times faster than CPython. V8 (Chrome's JS engine) for example is about 10 times faster. I'm sure there are other Python implementations with similar performance characteristics.
 
aho said:
CPython isn't really a good choice for devices like this. It's a little bit too slow for being useful. It probably won't matter for the next generation of hardware, but with the current one it doesn't really look all that good.

For example if you do some math in a loop... then it performs even worse than IE6's JavaScript engine. And IE6's JS engine is famous for being outrageously slow. And trust me, it really is.

For being able to write any kind of classic 2D game, you probably need something which is about 5-10 times faster than CPython. V8 (Chrome's JS engine) for example is about 10 times faster. I'm sure there are other Python implementations with similar performance characteristics.
Synthetic benchmarks aren't realistic. For most python games, the speed of interpreter is not the bottleneck. Also, bottlenecks are easy to work around with a bit of Cython (C extensions).

That said, PyPy is quite fast nowadays, even though it isn't yet production ready (nor does it have an ARM JIT).
 
Last edited by a moderator:
aho said:
CPython isn't really a good choice for devices like this. It's a little bit too slow for being useful. It probably won't matter for the next generation of hardware, but with the current one it doesn't really look all that good.

For example if you do some math in a loop... then it performs even worse than IE6's JavaScript engine. And IE6's JS engine is famous for being outrageously slow. And trust me, it really is.

For being able to write any kind of classic 2D game, you probably need something which is about 5-10 times faster than CPython. V8 (Chrome's JS engine) for example is about 10 times faster. I'm sure there are other Python implementations with similar performance characteristics.
Wasn't there someone who wanted to create a game engine based on V8 for the Pandora? I would really like to see how that would work, especially since I've gotten quite a lot of experience with Qt's declarative API recently which is rendered entirely in WebKit using JS and QML, and let me tell you, it's REALLY nice.

A declarative game engine using hardware-accelerated rendering and functional-style JS, oh man, that would be great for sure. Dunno about Python, though; if you want to use it for declarative stuff, it might be difficult since you can't really track property dependencies with the bare Python implementation...
 
Last edited by a moderator:
sindbad said:
[...]
Synthetic benchmarks aren't realistic. For most python games, the speed of interpreter is not the bottleneck. Also, bottlenecks are easy to work around with a bit of Cython (C extensions).

That said, PyPy is quite fast nowadays, even though it isn't yet production ready (nor does it have an ARM JIT).

Well, I tried CPython/Pygame on the Wiz... and you really need something which is about 10 times faster. While the Pandora got a better CPU, it also got a bigger screen, which means you have to draw more tiles to fill it. It really doesn't look very good.

But as I said, with a better Python implementation this wouldn't be an issue anymore.

dflemstr said:
[...]
Wasn't there someone who wanted to create a game engine based on V8 for the Pandora? I would really like to see how that would work, especially since I've gotten quite a lot of experience with Qt's declarative API recently which is rendered entirely in WebKit using JS and QML, and let me tell you, it's REALLY nice.

A declarative game engine using hardware-accelerated rendering and functional-style JS, oh man, that would be great for sure. Dunno about Python, though; if you want to use it for declarative stuff, it might be difficult since you can't really track property dependencies with the bare Python implementation...


I want to create something like that for the Wiz. Problem is, so far I didn't manage to make it do math correctly. It will probably fix itself soonish (just like the other issues). Also, creating a snapshot on ARM is currently very difficult.

[Snapshot: The runtime includes a fairly big chunk of JS code, which needs to be compiled on startup. With a snapshot you've done that ahead of time, which improves startup drastically. But even without one it starts up in about 2 seconds on the Wiz.]

Actually, the plan isn't to create an engine. It's something way simpler: a subset of HTML5 canvas (+image, +audio, +input). No paths, no text... just the ability to draw transformed images or parts thereof. Just the bare minimum for being useful.

The big advantage of this strategy is the ability to test/develop the game with any (good) browser. And there are also a few additional benefits like being able to try the game right away without having to install it first. And you can also put it on some website and generate some ad revenue. Since homebrew handhelds aren't very attractive from a commercial point of view, this kind of strategy might allow people to spend more time and resources on their projects. Of course it also makes game development for these platforms far more accessible.

Another problem with the Wiz is the lack of FBOs. And while pbuffers appear to be sorta kinda there, no one figured out how to use them yet.

Well, the subset canvas is step one. Simple 2D stuff. The next logical step is WebGL. The draft specs were finally released a few days ago. WebGL is a binding for OpenGL ES 2.0 - something the Pandora happens to support (the Wiz can only do 1.1).

WebGL/V8 already runs on some mobile phones and it really looks pretty promising so far.
 
Last edited by a moderator:
Speaking of python, I want to learn it. And in the process of learning it, I think that I will try to implement a game inspired by one of my favourite board games from the childhood: "Voyage of the B.S.M. Pandora". (really, it has "Pandora" in its name ;)). It would be a bit bigger perhaps, with more and different random encounters.

Do you guys have some python example suitable for a game:
  • display 2D sprites & pictures loaded from image files
  • dividing display into separate buffers of display
  • handling keyboard, and dpad events
  • font handling and putting text on those buffers

I am proficient in C++ and I have never ever before programmed python. My goal is not to write a game, but to learn python by writing something - eg. a game.
 
cosurgi said:
Do you guys have some python example suitable for a game:
  • display 2D sprites & pictures loaded from image files
  • dividing display into separate buffers of display
  • handling keyboard, and dpad events
  • font handling and putting text on those buffers

I am proficient in C++ and I have never ever before programmed python. My goal is not to write a game, but to learn python by writing something - eg. a game.
Everything you want (and more!) is covered in the Pygame tutorials (the Chimp tutorial is a particularly good starting point). However, all of those tutorials assume some familiarity with Python; for that, Dive Into Python is a pretty good place to start (though it's more of a learning book than a reference book, but that's what makes it a good place to start).

Edit: I should point out that Dive Into Python was last updated in 2004, so it's a little out of date. However, everything it says is still applicable to Python 2.6 (which I guess will be the one on the Pandora). Still, some newer references (including the official ones) will show some newer, fancier features and improved idioms.
 
Last edited by a moderator:
Tempel said:
Everything you want (and more!) is covered in the Pygame tutorials (the Chimp tutorial is a particularly good starting point). However, all of those tutorials assume some familiarity with Python; for that, Dive Into Python is a pretty good place to start (though it's more of a learning book than a reference book, but that's what makes it a good place to start).

Edit: I should point out that Dive Into Python was last updated in 2004, so it's a little out of date. However, everything it says is still applicable to Python 2.6 (which I guess will be the one on the Pandora). Still, some newer references (including the official ones) will show some newer, fancier features and improved idioms.
Thanks a lot for the pointers, I'll check out pygame and chimp.

I already printed 'dive into python' and started reading it - and I must admit - I cannot bear reading it, for me it's too boring, annoying and long. I rather need a quick syntax reference, because I already know programming constructs that are language independent. Except for C++, I also programmed saturn & x86 assembler and even enough ocaml/lisp to grasp functional programming too.

I only need to know what the python syntax is. A short, concise reference. I'm sort of a parasite now, because I'm too lazy for searchig for such a reference myself, I hope that someone of you already knows it! :D
 
Last edited by a moderator:
heh, ok. what I actually need are ass-hours spent in front of python :) keep fingers crossed.

EDIT: But any pointers to some short syntax reference for C++ people will be greatly appreciated.
 
cosurgi said:
heh, ok. what I actually need are ass-hours spent in front of python :) keep fingers crossed.

EDIT: But any pointers to some short syntax reference for C++ people will be greatly appreciated.
http://www.ibm.com/developerworks/library/l-cheatsheet3.html
 
Last edited by a moderator:
cosurgi said:
I only need to know what the python syntax is. A short, concise reference. I'm sort of a parasite now, because I'm too lazy for searchig for such a reference myself, I hope that someone of you already knows it! :D
As mentioned, there are the official docs (including the language reference, though I often find them a little hard to follow. Still, you'll probably return to that frequently just because of the standard library reference.

A bit nicer is the wikibook on the subject. Also starts kinda simple, but you can always skip the easy bits.

I've never seem dflemstr's link, but it seems quick and accurate, except that it uses old-style classes. That's okay for Python 2.x, but not for 3.x, but it's bad form anyways, but I'm sure you'll see more about it soon.
 
Last edited by a moderator:
Tempel said:
<...>

Thanks a lot! One more question - how do I handle localization? My game will have text to display, I want to make it localizable to any language in the way that everyone does it. Do you have a simple 'hello world' example for python, which is localized, and prints different text depending on user's locale? (I guess it should depend on LC_MESSAGES=, or LANG= )
 
Last edited by a moderator:
cosurgi said:
One more question - how do I handle localization? My game will have text to display, I want to make it localizable to any language in the way that everyone does it. Do you have a simple 'hello world' example for python, which is localized, and prints different text depending on user's locale? (I guess it should depend on LC_MESSAGES=, or LANG= )
Never used it myself, but a quick search in the standard library reference gives internationalization modules. To get the values of environmental variables, use os.environ.

Python has what they call a "batteries-included" philosophy. If you have a common problem, chances are there's something in the standard library to solve it.
 
Last edited by a moderator:
cosurgi said:
Tempel said:
<...>

Thanks a lot! One more question - how do I handle localization? My game will have text to display, I want to make it localizable to any language in the way that everyone does it. Do you have a simple 'hello world' example for python, which is localized, and prints different text depending on user's locale? (I guess it should depend on LC_MESSAGES=, or LANG= )
You could even use gettext.
 
Last edited by a moderator:
Back
Top