Hacker News new | ask | show | jobs
by Kiro 3219 days ago
Stupid question: Why can't you just take an array of all the pixels, randomize it and then iterate it to draw?
4 comments

Because with ideal packing it would take 150 kB (320·240·log2(320·240)/8). Wolf3d needed 640 kB of RAM and using quarter of it just to display death animation wouldn't be a good idea.
because this would take a huge amount of memory. something like xy(sizeof x + sizeof y). not only memory wasn't available cheaply at the time. it would be slow to generate, write to memory, then fetch back to draw.
This was written in assembly and to do that you'd have to make a new register of all the references while randomizing. Your approach works great in modern, high level languages where there's no issue copying an array in memory and calling array_shuffle or something, and doubling the memory requirement for the effect is no problem. This approach however seems to only require 17 bits of additional memory.
1) That's a lot of memory

2) Accessing memory is the slowest thing you can possibly do on a computer, other than IO