[…]
This is a great lesson to learn. I started programming many years
ago, but never really made it my career, and only recently began
looking at C++. With machines now running at 2-3GHz instead of
8-25MHz (like when I started learning C), it makes more sense to
only look at optimation when it’s needed.
Yes indeed.
Back then, there was no such thing as real-time code. Games didn’t
look at the clock of your computer and synchronize gameplay with
real-time. The programmers simply tried to make their programs run
as fast as they possibly could, which often required a LOT of
optimization.
Here, I have to disagree.
Actually, many games from the 8 and 16 years were not just real time,
but hard real time applications. They didn’t have to look at the
RTC (if there was one), simply because their clock was the video
frame rate, which was either 50 or 60 Hz depending on version. (Games
had to be tuned once for PAL and once for NTSC, and then released as
two versions, or two-in-one.)
These games never missed a frame, because the code was fast enough
to meet the deadlines at all times, and because there was no stupid
"general purpose" OS to screw up scheduling all the time.
The fact that you usually had to optimize pretty much anything that
was called from the main loop was an effect of a different
graphics/logic CPU time balance. Graphics bandwidth was low thanks to
low resolutions, text generators and hardware sprites, but game logic
wasn’t that much simpler than in modern games. You had to control
those NPCs, even if it meant you had to code the whole AI in asm and
spend weeks optimizing it.
I think the compilers we use today make many of
those optimizations automatically, and the CPU’s run much much
faster, with less need for other optimizations.
I think it’s worth noting that compilers are able to do many of these
optimizations only because we write relatively plain and simple high
level code now. There isn’t much bit fiddling going on. No fixed
point calculations where you make use of the double word size
capabilities of MUL and DIV instructions. No CPU specific shortcuts
that you can’t even express in a mid or high level language.
The need for these tricks started going away when the 16 bit machines
arrived, and that made life easier, even if you were still coding
mostly or entirely in asm. This made it possible to use high level
languages for more than the highest level stuff, and thus, opened the
path towards writing real applications entirely in high level
languages.
Better optimization and faster CPUs are just further steps in the same
general direction; towards a higher bandwidth/complexity ratio.
Consider this example:
We have a 2D shooter game with full screen scrolling at 50
pixels/second. There’s one player ship and five enemies on the
screen. Now, let’s consider two implementations of this:
C64:
* 1 player ship (X, Y, h/w collision bit)
* 5 enemiy ships (X, Y, h/w collision bits)
* H/w scrolling multicolor text (40x25; 3 bytes/char)
PC/VGA:
* 1 player ship (24*21 pixels ==> 504 bytes)
* 5 enemiy ships (2520 bytes)
* S/w scrolling 256 colors (320x200 ==> 64000 bytes)
The C64 would have shuffle around about 20 kB of data per second to
keep the graphics alive. (Hardware scrolling means you only have to
repaint the screen every 8th frame.) Meanwhile the PC would have to
deal with 3.35 MB/s to produce essentially the same display! Of
course, the PC has enough CPU power to do that.
Now, if both machines have about the same amount of spare CPU time
left after the graphics is done, it turns out that the PC has about
170 times the bandwidth of the C64. This does not strictly map to CPU
power, but it does suggest that implementing the AI isn’t exactly
going to be a matter of hacking fast code on the PC.
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —On Saturday 17 May 2003 07.46, Chris Palmer wrote: