Bright Worlds postmortem, Part I – The Betrayal of Python/Pygame
ahem.
I love Ludum Dare!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Okay. Glad we got that out of the way. Now, let’s talk about my most recent game. Since I’m sure you all are raring to hear about it! I can see the look of intense excitement in your eyes. Good. Sit down in a nice comfy armchair and smoke one of these fine cigars while I tell you a tale of betrayal and rapscallion-ry.
Python. Python is one of my favorite languages. It’s just so easy to bust out code. It instantly alerts you to where any errors are. The code is so much shorter than equivalents in C++ or Java. There’s practically nothing wrong with it.
Or so I thought.
See, turns out Python is actually really slow. (‘What?!’ you exclaim from your armchair. ‘I had no idea!’) Generally, it doesn’t matter. Computers are usually fast enough to compensate for the approximate 30-50x slowdown that python entails, at least for 2D games. The last game I made, Escape Artist, for LD21, was written in python/pygame and it was zippy and smooth.
But what I didn’t anticipate was that the game I was making – Bright Worlds – was going to be really computationally expensive. Bright Worlds in a nutshell is a game involving light simulation. It has radial lights (they go in all directions) and directional lights (go in a single direction). (Incoming technical stuff – feel free to skip to the next paragraph if you don’t understand.) This means that for each light I need to raycast to every point on the map, then calculate the light delta values for that light, then sum up all the deltas across the whole map. This is an O(n^3) operation for those of you familiar with big-O notation. If you’re not, what I’m saying is: this takes a lot of time!
Long story short: Python could only handle about 2 lights on a scene before very visibly lagging.
That’s without doing anything else. I had a sweet particle system that I essentially dumped because python was just too darn slow.
It got even worse, though. From the comments that I’m seeing on my game, the game speed is all over the place. On windows, it runs really fast. On OSX, it’s pretty slow. Lag sucks, and I’m pretty sure that some people are getting a disappointing playing experience.
What a pain.
I love python, and I still do, but this was a huge disappointment.
I didn’t know this, and I couldn’t have anticipated it without actually coding out the game. In the future, I’ll use a faster language. Scala looks pretty promising, so I’ll probably buff up on Scala for the next LD. Another nice benefit of Scala – no porting worries.