Hacker News new | ask | show | jobs
by Waterluvian 1273 days ago
How?! How did you get PyGame not to be so brutally slow? Is it basically that all the graphics are done separately and pygame only offers up IO and game loop?

This is just brilliant and wonderful and beautiful. The premise of this game is just amazing.

4 comments

If you offload graphics to the GPU (which is what shaders are), there's surprisingly little CPU work left in a 2D platformer game.

Think of (fragment) shaders as programs that run in the GPU per-texture-pixel. There is some initial CPU/memory-bound work setting everything up (e.g. uploading textures to GPU RAM, compiling the program, sending vertex buffers...) and then per-frame you just call the shader with some parameters (e.g. character's current position) and the GPU does the rest.

In-CPU you mostly do the non-parallelizable work such as collisions, game logic, keyboard input, etc. which can be very light for a simple 2D platformer.

The original PyGame used software rendering and thus was very slow, but I believe a relatively recently released new version uses hardware (GPU) rendering. That's probably where the shader support comes in too.
The author made a video about optimizing pygame performance here: https://youtu.be/3hGcW77M-84
pygame isn't that slow if you use pygame 2 that depends on SDL2 (2D hardware acceleration, yay!) or go with OpenGL directly.

I used to do a lot of amateur gamedev with Python (pygame and pyglet). If most of the work happens on the GPU or external libraries, it is usually OK if you aren't doing anything stupid.