Game Scripting With Python 186
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."
EVE Online (Score:5, Informative)
This is not a new idea (Score:5, Informative)
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).
A quibble (Score:1, Informative)
Lua, Books (Score:5, Informative)
In that article, I was asked about this book [amazon.com], 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 [amazon.com]. This book is a wonderful overview.
Not new (Score:2, Informative)
Python? For 100s of game entities? Try Mono... (Score:4, Informative)
Re:Python is nice but consider LUA for game script (Score:5, Informative)
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 [usingcsp.com]. Multithreading is actually easy if you do it right - it's just that most languages don't.
Jedidiah.
There's a REASON they're using Stackless (Score:4, Informative)
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.
Re:This is not a new idea (Score:2, Informative)
Go back even further than that. The idea of building a game engine that acts as a virtual machine for scripts defining a game is a very old idea. For example, way back in 1987, LucasArts developed SCUMM [wikipedia.org] (Script Creation Utility for Maniac Mansion), which is little more than an engine that runs scripts the define a game. All of LucasArts' adventure games from Maniac Mansion to The Curse of Monkey Island used SCUMM. After that, they built a new engine (GrimE [wikipedia.org], Grim Edit) that was used in Grim Fandango and Escape from Monkey Island and followed the same ideas they first built in SCUMM. This time they used Lua [wikipedia.org], which is a popular scripting language used by many other commercial game engines (such as Bioware's Infinity Engine [wikipedia.org] used for the Baldur's Gate games, the Icewind Dale games, and Planescape: Torment).
Unreal's UnrealScript is a very powerful language within the scope of the Unreal engine, but it's certainly not the first implementation of the "game engine as an abstract operating system for scripts" idea. The technology of the scripting language may change, but the core idea is very old (and very good). There's nothing inherently special about using Python as the scripting language for a game, but it's neat that Python is now capable of doing so.
Python game programming competition (Score:3, Informative)
Python Already in Use for Commercial Games (Score:2, Informative)
Search your game folders for
Don't forget that Battlefield 2 uses Python (Score:2, Informative)
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.)
Re:Python whitespace indentation (Score:3, Informative)
Re:Civilization 4... (Score:5, Informative)
These are just the two examples I've played today...
Comment removed (Score:3, Informative)
Re:Lisp instead of Python (Score:3, Informative)
(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.
Re:Either I forgot to do something, or Python is.. (Score:1, Informative)
Anyway, just like most programs written in other languages, python programs often require dependencies.
These can often be found in that really useful "README" or "INSTALL" file in the project's top-level directory. You *did* read them, didn't you?
Almost all python stuff I've used was correctly installed by a meagre "python setup.py build && sudo python setup.py install". Occasionally I'll need to install a 3rd-party package. In which case I repeat the steps above for it.
Re:Python is nice but consider LUA for game script (Score:2, Informative)
You know, tools such as StackGuard, ProPolice, Valgrind, Splint...
Virtualization and Game as OS (Score:3, Informative)
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....
Re:Python whitespace indentation (Score:3, Informative)
just a nitpick to counter... (Score:3, Informative)
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.
Re:just a nitpick to counter... (Score:3, Informative)
I have to admit that I'm not clear on what the original article means when they talk about using non-preemptive multithreading (do they mean somehow overriding the Stackless tasklet scheduler?). They seem to be worried about the need for locks on shared-state variables. However, the correct approach to building a Stackless-based system would probably be to follow the CSP paradigm of avoiding shared-state completely - such systems are lock-free and can be completely deterministic. But perhaps I am completely misinterpreting what they are trying to get at.
Eve Online and BF2 (Score:2, Informative)
Rock on python.
Re:Python Already in Use for Commercial Games (Score:2, Informative)
http://www.codemasters.com/severance/eng/ [codemasters.com]
Re:Python is nice but consider LUA for game script (Score:1, Informative)
Battlefield 2, Blade of Darkness, Eve Online used Python.
These are real-world examples you can mess with right now, rather than speculating about which is better.
I kind of like Python more than Lua because the syntax is more straightforward, which is good for non-technical level designers. I'm sure programmers will have other opinions, but what's the point of using scripting if it's going to be as difficult as C++? Does it really save that much time?
Re:Oooh! (Score:1, Informative)
A "more sensible" implementation would involve using type declaration/inference to allow compile time resolution of member functions. Even if it only managed to resolve a pointer to a pointer, it would still be at least several times faster. Unfortunately, that would defeat one of python's major selling points: dynamic classes. Thus, it's not really such a sensible option.
So in conclusion I can't really suggest a solution, but I thought I'd at least try to explain the problem.