r/PirateSoftware • • Jul 17 '25

I showed a professional 2D game engine programmer Pirate's lighting code and he said it's fit for purpose

I saw a video online talking about Pirate's lighting code, it just seemed off to me. I sent it to a professional 2D game dev and he told me the following:

The developer reviewed the code and found that the criticism in the video (claiming it's O(n^3)) is exaggerated and misleading. He mentioned that the code, written in GameMaker's GML, uses a pixel-by-pixel approach to avoid shaders, which is better for non-career programmers as it massively reduces complexity.

He also confirmed the time complexity is likely O(n) or O(x*y) (x = number of lights y = number of pixels) due to iterating over pixels and light sources, not O(n^3) as claimed. He pointed out that Pirate's method, while not perfectly optimized (e.g using case switches instead of clean math for directions and repeating diffusion steps), is a valid approach for a non-programmer game dev.

The video's suggested fixes, like using pre drawn light PNGs or surfaces, were wasteful in memory and not visually identical, offering no real performance gain. He also debunked the video's claims about redundant checks, noting they’re functionally intentional and O(1) with GameMaker’s collision grid.

Overall, he felt Pirate's code is decent for its purpose, and the video’s analysis and testing was wrong, as he had an "If true" statement which is a total blunder, running the code constantly, making his benchmarking completely wrong.

Edit:
If anyone has any questions for the dev, leave it in the comments and I'll forward it to him and I'll post his reply

103 Upvotes

424 comments sorted by

View all comments

Show parent comment

2

u/TheMrFluffyPants Jul 17 '25

By your logic, you could also represent every pixel as a fixed total if you knew the resolution of the game. If the game were 128 x 128 pixels, you could argue it’s in constant time since you know the exact number of operations you’d need for 1 light source (16,384), but that’s not how algorithm analysis works.

The input for Thor’s algorithm isn’t number of pixels, it’s resolution. When you double the resolution, you aren’t just doubling either height or width. You’re doubling both of them, and the resulting number of operation quadruples.

Either way, whether it’s linear or quadratic, it doesn’t change the fact that Thor’s claims that this implementation is ‘highly performant’ is incredibly misleading. This is a brute force algorithm with no optimization for efficiency whatsoever.

1

u/CorrectTechnicality Jun 24 '26

By your logic, you could also represent every pixel as a fixed total if you knew the resolution of the game.

This is kinda a strawman and a stretch. What OP advocates for is to use the correct terms and sizes for the input, which is num_pixels, not width and height.

Everyone doing image processing uses the correct terms. The fact you can access image data by x and y in two loops is a convenience, you can just as good use one single loop and do the calculations to convert x and y to the array index (which is done for you in the other case) yourself.

The input for Thor’s algorithm isn’t number of pixels, it’s resolution.

Resolution IS the number of pixels...

When you double the resolution, you aren’t just doubling either height or width. You’re doubling both of them, and the resulting number of operation quadruples.

You CAN change each of them independently and the algorithm will work fine. In a true O(n^2) algorithm if you double the n for one loop, but not the (SAME) n in the other loop, your algorithm will break.

Think of a naive duplicate search or bubble sort. And then try to understand the difference to the image algorithm.