Game Scripting With Python
P. Staurou writes "There is very interesting article about game scripting with Python over at Sylphis3d.com. It talks about how game engines should be structured as operating systems with actors being the processes. The proposed design is based on a special version of Python called Stackless and already successfully implemented in their own Sylphis3D game engine."
... is already using stackless Python, so it's a proven, successful multiplayer online game platform. EVE has upwards of 10,000 players most of the time.
This article presents the idea relatively well, but this is NOT A NEW IDEA.
I'm not sure if Epic invented it, but I can certainly tell you that microthreading, latent functions (such as the sleep in the door example, or a playanimation method that takes game time to complete), and this general idea has been around since at least the original Unreal Engine in UnrealScript (which is now a rather mature scripting language).
http://brandonbloom.name
It didn't make the front page, but the recent article on extending games with Lua is also worth a read. My personal preference is still for Python (I love all of the libraries that it has), but Lua is good if you need some small scripting engine.
In that article, I was asked about this book, which covers Lua, Python, and Ruby for games. Despite having all of the "right languages," the book is awful. For people wanting to extend games with python, I suggest Game Programming with Python. This book is a wonderful overview.
EA/Dice currently use Python scripts in the latest Battlefield 2 game. You will actually find quite a few games that currently use python already. I dont know why it should be news when game developers already do so and have for a while now.
As for the language, we used Python in Unity http://www.otee.dk/ for the initial preproduction of GooBall. It was soooo slow. After that we switched to Mono. CPU usage in the scripting logic went for >40% to app. 5%... If you like the Python syntax, you can always include boo http://boo.codehaus.org/ which mimics Python very closely, but uses type inference to get type safety automatically. On another note: the article states that Unreal does not use microthreads. That is not correct.
The point of using Stackless Python (as opposed to ordinary Python) is that it provides a particularly good system for handling multiple threads and communcation for threads via tasklets and channels. If your game engine works by creating actors as threads then using a scripting language that has a simple to use, efficient, and platform independent threading model is likely of great importance, and Stackless Python offers that.
If you're generally interested in better threading models, and being able to think and reason about threads and their interactions more easily then you really ought to check out CSP. Multithreading is actually easy if you do it right - it's just that most languages don't.
Jedidiah.
Craft Beer Programming T-shirts
Stackless is a completely different implementation from CPython, and has extremely different performance characteristics.
Consequently, your experiences with CPython simply don't apply here -- Stackless is largely focused around doing this kind of thing (microthreads and such) extremely well.
Another game-related Python activity is the PyWeek competition, where entrants have one week to write a game. Unfortunately you've just missed this year's competition; it's held in August, and the winners were just announced.
There are many, many games using python for scripting. Battlefield 2 being the most recent I've noticed.
.py files, you may be surprised.
Search your game folders for
Battlefield 2 uses Python too (look around in the game's directories, you'll find lots of *.py files). In fact, I'd guess that it's the most widely played game right now that uses Python.
What's interesting to me is that they were able to utilize Python and still develop a state-of-the-art, performant 3-D FPS. (People with slightly older computers might argue about "performant", but it does actually run very well even with the Pythion compiler/interperter baked in.)
I use Emacs for editing both C and Python. With Python, it is just a matter of marking the block you'd like to indent/dedent (CTRL-space at the beginning of the block, and ALT-w at the end), and then use "CTRL >" or "CTRL <" to indent/dedent the whole block. This saves a few keypresses compared to C, where the extra braces have to be inserted/removed.
Freevo - Linux Multimedia Jukebox
See the Unreal Tournament Community Bonus Pack, and the SuperStorm fan-made patch for Earth 2160. Both hosted on official download sites. The UT2003 community pack was actually included on the UT2004 DVD.
These are just the two examples I've played today...
Slashdot - Mutual Assured Discussion
I don't like that code either; I'd write
(define (gnc:leap-year? year)
(cond ((= (remainder year 400) 0) #t)
((= (remainder year 100) 0) #f)
(else (= (remainder year 4) 0))))
As the other poster pointed out, Python can be written moronically too.
You know, tools such as StackGuard, ProPolice, Valgrind, Splint...
how to invest, a novice's guide
With Cell (which I've worked on for 3.5 years until last month), its Power core supports virtualization feature (or "hypervisor" mode as IBM likes to call it) as documented in Power Architecture V2.02.
This allows companies (I won't be surprised see if all 3 game consoles will support this) to allow game programmers to create RTOS (real-time operating system) like programs so that they have very refined control over program behavior (even OS like control) while the hypervisor SW (like Xen) will prevent any critical resources of games from clobbering each other (just as hypervisor supported OS will not hurt other OS running under hypervisor). Virtualization will give more control to the game programmer (more power and more responsibility) while the game console maker would retain minimal but critical control over the resources (mainly IO and memory). Pretty exciting world ahead for game developers in my opinion....
Danny Kumamoto
FWIW, it's also trivial to do the same thing under Eclipse using PyDev. Mark a block of text, then hit tab or shift-tab to indent/unindent. If you're an Emacs user, turn on Eclipse's built-in Emacs keybinding set and it's home away from home...
Not a knock against Stackless Python, though. In fact, I agree with the author that preemptive threading in the context of scripting a game probably causes more problems than it solves. In a game, you can be more trusting of its processes/threads(aka scripts) than a general pupose OS would be. On the other hand, with games like UT where you can have have multiple "mutators" running simultaneously that were created by the modding community and not an inhouse designer, maybe preemptive threading would be a good idea.
Eve online (crowd control software) is the main user of stackless python. Most of the patches are either contributed by them or requested for them. BF2 also uses python for most of its non engine work. (not sure about the AI though.)
Rock on python.
Official GOD FAQ.