From the perspective of someone who generally writes far fewer comments than this, I find that this code has a number of comments which is well-justified due to the complexity of the subject, poor availability of external documentation describing the interface it implements, and the nature of the code. However, the code can be written in a manner which is still readable with fewer comments.
Here's a sample from the file:
// For sprites, color 0 is transparency so don't draw anything.
if color == 0 {
continue;
}
This comment is probably not necessary: it would be equally clear if it were written as something like the following: if color == SPRITE_COLOR_TRANSPARENT {
continue;
}
A few lines up is another comment: // Is this specific pixel not on the screen? We already check that x_pos is not off
// the left side earlier, so only need to check that it's not off the right side.
if x_pos + p >= 160 {
continue;
}
If the code were written with a constant, then it would only need to clarify why we don't check the left side here (the only non-obvious thing about the code), so: // Note: bounds testing on the left side is handled earlier
if x_pos + p >= SCREEN_WIDTH {
continue;
}
One last example: // We want to iterate through 160 pixels to draw one scanline.
for col in 0..160u8 {
No comment, similar level of readability: for col in ppu.iterscanlines() {