Is doom objective c? I'm no programmer but the code for checking an odd number ( if (gametic & 3) ) looks weird. Someone explain pls.
Doom is C. that is a bitwise AND operation, it's less cycles than modulus division:
It performs a bitwise AND operation on every bit of the bitstring "Gametick," an unsigned 32-bit integer. You only need to examine the lower 2 bits of a bit string (xxxx-xx00, xxxx-xx01, xxxx-xx10, xxxx-xx11) for this purpose. an AND expression equates to 1 if both bits being compared are 1. In this case, the expression only evaluates to true if the lower 2 bits are 0x11 (binary 3), which is the same as doing x%4 only faster. 1 is the same as true. It's not checking to see if it's an odd number, it's a gate that only opens every 4 game ticks. This is because the lower 2 bits of any binary value will loop every 4 iterations:
0 = 0x0000
1 = 0x0001
2 = 0x0010
3 = 0x0011 (= &3 = %4 = true)
4 = 0x0100
5 = 0x0101
6 = 0x0110
7 = 0x0111 (=&3 = %4 = true)
8 = 0x1000
9 = 0x1001
10 = 0x1010
11 = 0x1011 ( = &3 = %4 = true)
etc
"3" as a 32-bit number is actually 0000-0000 0000-0000 0000-0000 0000-0011 so the upper 30 bits are always 0. 0 AND 0 is 0, 0 AND 1 is 0, 1 AND 1 is 1. By using bitwise and operations, you reduce the complexity of the check.