« Globals underrated - fight! | Main | Australian Notation - Globals And Multicore »

July 25, 2009

Comments

Soren Johnson

For Civ4, we completely separated the game code from everything else, so much so that you can compile the game/AI logic separately into its own DLL. This allowed us to release the game code so that modders could create their own game DLL to overwrite the default, leading to total conversions like Fall from Heaven. (You can find the code here: http://www.2kgames.com/civ4/downloads.htm)

And, yes, we used globals too...

Mat Noguchi

Heh, I'll throw even more fuel onto the fire and state that you don't need smart or shared pointers if you have a strict enforcement of lifetime plus some constraints on what you use pointers for. I prefer the same model as http://misko.hevery.com/2009/04/15/managing-object-lifetimes/ : you store references to other objects if they have a longer lifetime, otherwise, pass it via the stack. So I don't use smart or shared pointers for that, just raw pointers. Whee!

It works out pretty well for our caching system, although you get some weirdness when dealing with legacy code. (And yes, that kind of blows the ideal out of the water.)

Bryan McNett

read/write globals are dubious in single-core, and prohibited in multicore - unless it's a simple game and it's OK to let cores sit idle.

this is because multiple frames are processed in parallel across multiple cores. if there were read/write globals, maintaining data coherency across frames becomes costly or impossible.

except wii, all console and PC platforms are multi-core already, and the number of cores is scheduled to grow faster than moore's law.

don't say nobody warned you.

Grumpy

Are any of the people who are raging about global variables good game programmers, by which I mean, specifically, developer/artists/designers who happen to make novel or interesting content that has a code component, particularly for games of new or ambiguous genres? I'm sure many of you are brilliant systems and engine programmers, which is great in the right contexts.

My own personal experience has been that global variables (and, in general, ditching all notions about aggressively constraining what can access what and dealing with "architecture") are really useful for fiding novel game play in an iterative context. I'll readily concede that these practices are bad for big teams, high performance requirements (especially multicore), client/server issues, persistence, and blackbox reuse... but when it comes down to "how hard is it make and evolve novel, innovative, surprising interactivity, particularly at a large scale, between elements of the game that players weren't expecting", my personal experience has been that there is a direct and specific correlation between "good engineering practices" and "high performance, beautiful, astonishingly predictable and tedious game designs".

New and novel game styles thrive on unexpected (to the player) interactions. Code is how we describe interactions and correlations. Unexpected interactions are specifically the sorts of things good engineering practices are designed to eradicate or make extremely irritating to explore.

If, on the other hand, your job is to make the next Madden or another Iraq colored FPS, where performance and asset quality is most of what you're shooting for... well... yeah! Down with globals!

Mat Noguchi

> Code is how we describe interactions and correlations. Unexpected interactions are specifically the sorts of things good engineering practices are designed to eradicate or make extremely irritating to explore.

Umm... I will argue to the death that code that has unexpected consequences is the very thing that prevents you from composing it with any degree of sanity. One way code can have unexpected consequences is by accessing mutable global data explicitly. If it happens to be global but the code never knows that, then it doesn't matter.

Emergent behavior does not require crappy code. In fact, good emergent behavior requires quite robust code, as it is less likely to cause real problems by stressing it in unexpected ways.

Jake

If you are a good programmer you dont need global variables. Here http://www.rapidsloth.com shows how you can program without the use of global vairables.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name is required. Email address will not be displayed with the comment.)

Jamie's Bragging Rights

  • Spider-Man 2
    The best superhero games of all time Game Informer
    Top five games of all time Yahtzee Croshaw
    Top five superhero games of all time MSNBC
    Top 100 PS2 games of all time Official Playstation 2 Magazine
    1001 Games You Must Play Before You Die Nomination for Excellence in Gameplay Engineering Academy of Interactive Arts & Sciences
  • Schizoid
    Penny Arcade PAX 10 Award
    Nominated for XBLA Best Original Game
    Nominated for XBLA Best Co-Op Game