CodeSOD: Do You Think This is a Game? |
Weve passed Christmas and made our way through a Steam sale with our wallets mostly intact, and now most of us have a pile of games that well probably never actually play.
Game programming is hard. Setting aside the cultural problems in the industry- endless crunches, compensation tied to review scores, conflicts between publishers and studios, and a veneer of glamour over unglamorous work- the actual work of developing a game is a hard job.
Building a game engine is even harder. Not only do you have to build highly performant code, you have to build a system flexible enough so that game developers can build a game on top of it. You need to provide a set of high-level abstractions that make it easy for them to build a game, and this is where the problems come in.
For example, I went through a brief period of playing Frozen Cortex, an interesting approach at a turn-based sports game. I was stunned at how badly it performs, though. Weirdly, its not during gameplay that performance stinks, but when staring at the menus. I was puzzling over this for some time, when Anonymous sent us a message.
You see, Frozen Cortex is build on the Torque engine, and our anonymous submitter is working on a different game that also uses the Torque engine. And theyve encountered a few… special warts.
First, take a look at this code:
a = getWords("The quick brown fox jumped over the lazy programmer.", 3);
b = getWords("The quick brown fox jumped over the lazy programmer.", 3, 5);
c = getWords("The quick brown fox jumped over the lazy programmer.", 3, 2);
getWords is a substring function, taking a string, the starting index and the ending index. Now, what would you expect to happen if the ending index comes before the starting index? Would you expect it to throw an exception? Well, bad news- TorqueScript has no concept of exceptions. It just crashes the entire game. This is a great tool to teach you how to be a better defensive programmer.
Now, you could argue that prohibiting exceptions is a pretty clever optimization- exceptions and stack unwinding are expensive operations. We have to wonder though, because heres a performance comparison between calling a function and in-lining the operation:
==>%r=getRealTime();for(%i=0;%i<999999;%i++)%d=getMin(getRandom(),getRandom());echo(getRealTime()-%r);
7040
==>%r=getRealTime();for(%i=0;%i<999999;%i++)%d=(%a=getRandom()
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |