in reply to OOP, ".NET", Perl, and all that

Gaming systems often have complex object systems in practice (landscapes, monsters, players, projectiles, missions, etc), but for some reason most games that I know about are written in C.

Does anyone know how thye manage complex object management without an object-oriented language?

Replies are listed 'Best First'.
Re: Why dont games use OOP?
by Dominus (Parson) on Dec 15, 2001 at 02:10 UTC
    You may enjoy this article. Here's the introduction:

    Tim Sweeney co-founded Epic Games in 1991, providing the coding expertise that helped push the company forward over the next decade to become a leader in the computer 3D engine marketplace. The original Unreal was a major success in the states and especially abroad, thanks to an amazing array of engine features that attracted gamers and engine licensees alike. The sequel, Unreal Tournament, was all of that plus a year's worth of mutliplayer and network code painstakingly developed with extensive Internet playtesting. At the center of it all was Tim Sweeney, cranking away at the code. Tim's essay, "A Critical Look at Programming Languages," takes a hard look at the tools developers are using nowadays, and their shortcomings in the field of high-tech intensive 3D entertainment.

    --
    Mark Dominus
    Perl Paraphernalia

Re: Why dont games use OOP?
by Masem (Monsignor) on Dec 15, 2001 at 01:33 UTC
    Look at the code for Nethack. While there are several 'objects', there is very little inheritence, thus, they only need to keep a 'monster' array, a 'object' array, etc. In such a flat OOP system, C is very easy to use to mimic a true OOP language. The benefits of 'switch' become highly apparent here.

    Mind you, you *can* rewrite Nethack to use true OOP. As an example, you could easily use Java Interface-equivalent classes to describe all the attrbiutes that monsters may have (say, "class Large", "class Intelligent", etc). Then you can create new monsters by simply creating a new class and 'inheriting' those attributes ("class Tiamat implements Large, Intelligent, Flying, FireBreathing, PitA { ... }" ).

    There's even sort of a meta-OOP floating with Nethack; one can define which interface they want at make/build time; this allows the Nethack team to actually do a primative MVC architecture so that those running the game on more 'graphic' terminals can chose an interface that's more suited for that.

    But just because you can doesn't mean it will work. I know of numerous attempts to OOP'ive the classic Rogue-like games with no luck.

    Just remember, any OOP structure/intherience tree/class diagram can be flatted to a procedural structure. (Initial versions of C++ did just this; they preprocessed code to munge class names and methods to unique C names) In most cases, this will be messy and filled with lots of switch blocks, but it can do the same thing. However, the flatter the object structure starts, the simplier the underlying C code, and this typically can be optimized further to get speed gains.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important