views:

778

answers:

13

Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.

If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do things out of habit!

Any information would help satisfy my curiosity.

Edit:

Would the GIL post a major issue on 3d client performance? And what is the general performance penalty for using say, OpenGL or DirectX bindings vs natively using the libraries?

+11  A: 

Yes. How it will perform is another question.

A good development pattern would be to develop it in pure python, and then profile it, and rewrite performance-critical bottlenecks, either in C/C++/Cython or even python itself but with more efficient code.

nosklo
Actually, that would be a bad development pattern. Not a single successful game has been developed like that. There's plenty of science about what performs well and doesn't in games, without hitting the development cost of major re-writes. For example, you wouldn't write your networking, collision or graphics modules in python.
Justicle
A: 

Because Python is interpreted there would be a performance hit, as opposed to C/C++, but, you would want to use something like PyOpenGL instead of DirectX though, to run on more operating systems.

But, I don't see why you couldn't write such a game in Python.

James Black
Judging by the context, I'm guessing that you mean couldn't rather than could?
Emil H
Thank you, corrected. :)
James Black
+5  A: 

Technically, anything is possible in any Turing Complete programming language.

Practically though, you will run into trouble making the networking stack out of a high level language, because the server will have to be VERY fast to handle so many players.

The gaming side of things on the client, there should be no problem, because there is nothing too complicated about GUIs or quests or keyboard input and what have you.

The problems will be in whatever is computationally intensive up on the server. Anything that happens in human-time like logging on will probably be just fine, but if somemthing needs to be instantaneous over ten thousand users, you might want to go for an external library done up in C.

Now some Python guru is going to come out of the woodwork and rip my head off because, as I said at the top, technically, anything can be done with enough effort.

Karl
Blizzard has more than one server, one server doesn't have to handle every player.
Malfist
On one hand your first talking about a language, and on the other hand, on implementation. Don't mix them up. You cannot do anything in Turing complete language if there's no implementation.
egaga
"Practically though, you will run into trouble making the networking stack out of a high level language, because the server will have to be VERY fast to handle so many players." - the thing about this is that you can throw better hardware at the server-side. That's a bit more difficult to do on the client side.
Jason Baker
"Technically, anything is possible in any Turing Complete programming language." Well, anything that is possible on a universal Turning machine, at least. :)
mipadi
+3  A: 

Yes, you could write it in assembly, or Java, or Python, or brainfuck. It's just how much time you are willing to put into it. Language performance's aren't a major issue anymore, it's more about which algorithms you use, not what language you use.

Malfist
Someone's never tried to write a detailed physics sim in phython then, or run a complex computer vision algorithm in MATLAB. We're not quite at the stage where all languages are comparable performance-wise, believe me!
Ed Woodcock
-1 for mentioning brainfuck.
shoosh
Find an old TRUESPACE download site. I believe that's python.
ryansstack
@shoosh, it was an example. If you was really determined, you could. It might take you all your life, but you _could_ do it.
Malfist
+1 for mentioning brainfuck, because I'm contrary
Joel Mueller
+11  A: 

While I don't know all the technical details of World of Warcraft, I would say that an MMO of its size could be built in Stackless Python.

EVE Online uses it and they have one server for 200,000 users.

Robert S.
from what I remember, max users online at a time was about 50k.
praavDa
Why Stackless Python, in particular?
Edmund
+5  A: 

The game Minions of Mirth is a full MMO more or less on the scale of WoW, and was done mostly in Python. The client side used the Torque Game Engine, which is written in C++, but the server code and behaviours were all Python.

Tim Sullivan
+3  A: 

Since your main question has already been answered well, I'll answer your latter questions:

Would the GIL post a major issue on 3d client performance?

In Python 2.6, the multiprocessing library was introduced, so you can take advantage of multiple processor cores without worrying about the GIL. Stackless Python also has some pretty cool related stuff.

And what is the general performance penalty for using say, OpenGL or DirectX bindings vs natively using the libraries?

I don't have any benchmarks to back it up, but the penalty for using the bindings vs. the native libraries is small enough that you don't need to worry about it.

musicfreak
A: 

Just because it might give an interesting read, Civilization is partly written using Python. A google on it returns interesting reading material.

Led
Why not give a link?
fiXedd
because there's more than one interesting link, and I assume everyone knows how to use Google :)
Led
+3  A: 

There are some additional real industry examples in addition to Eve Online. The server backend on the Ultima Online 2 project at Origin in the late 90's was mostly Python over a C++ server infrastructure, and the late Tablua Rasa game from NCSoft (with most of the same dev team) had the same architecture.

The Twisted Matrix python server framework was created originally with this exact goals - actually from a developer on the UO2 project at the time, and there was a company called Ninjaneering that attempted to commercialize that code-base through MMO projects.

There has been a move towards lua as a scripting engine (eg EQ2) as is easier to embed and instance.

The problems with python in this environment tend to be in the interface between languages. When you do the inevitable optimization of moving some high performance system from python to C/C++, then pushing data back and forth across language boundaries and calling functions across language boundaries becomes an issue. The cost of serialization can be high if done poorly. For example, using early versions of SWIG would serialize pointers into their string representation and then parse the string back into a pointer on the other side!!

Check out this paper from the mid-90's:

But, in the long term, i think it is possible.

sean riley
A: 

Python is not interpreted - it is tokenized/'just in time' bytecode 'interpreted' and it doesn't have a VM like Java does. This means, in english, it can be daaaaaamnfast. Not all the time though, it depends on the problem and the libraries, but python is not slow, this is a common misconception even among knowledgable people (and that includes deep java engine folks who have just not gone and tried python).

I think commenting on this is "above your pay grade." Your answer makes no sense. Re-read it. I mean "it's not interpreted" "but it is" is a little strange. Guess the bong hits kicked in, huh?
xcramps
+4  A: 

The answer to what I think your specific question is, "... in pure Python ..." the answer is NO.

Python is not fast enough to call OpenGL or DirectX efficently enough to re-create World Of Warcraft at an exceptable frame rate.

Like many others have answered, given some high level frame work, it would be possible to use Python has the scripting language but at a minimum you'd need some kind of graphics system written in another language like C++ to handle the graphics. For networking, given that WoW is not an action game, you might be able to get away with pure python but most likely that part as well would need to be some non-python library.

gman
+2  A: 

I have been trying my hand at writing 3D games in Python, and given a good rendering framework (my favourite is OGRE) and decent bindings, it is amazing what you can get away with. However, especially with games, you are always trying to squeeze as much as you can out of the hardware. The performance disadvantage of python eventually will make itself felt.

The main problem I ran into using python is its massive call overhead. Calling python functions, even from other python functions is very expensive. In a way, it's the price you pay for the dynamic nature of python. When you use the function call operator "()" on a symbol, it has to work out whether it's a function or a class, look over the method resolution order, handle the keyword arguments, etc etc. All these things are done ahead of time in less dynamic (compiled) languages.

I have seen people trying to overcome this problem by manually inlining function calls. I do not have to tell you that this medicine is worse than the ailment.

Ranieri
A: 

as a technologist i know: if it can be written in C\C++ it can be written in assembly (though it will take longer) if it can be written in C\C++ and is not a low-level code - it can be written in any managed environment. WoW is a high-level program that is written in C\C++ python is a managed environment

There for: WoW can be written in python and so any other MMORPG in 3D...


the hardest part will be the 3d engine for it is the "heaviest" part of code - you will need to use an outside engine (written in C\C++\Assebly) or to write one and optimize it (not recommended)

good luck

accesomat