views:

514

answers:

4

What are some of the more common design patterns used when developing 3D games? Are there any high-level architectural design patterns that are commonly used? What about general software patterns within the architecture?

A: 

Variations on the state pattern are useful for modeling game state. The Enginuity series of articles is a good overview of some of the low level aspects of game engine design. It is incomplete, but good. The Guff framework's designers outlined the use of state hierarchies for handling game state. The hierarchy concept is good, although their view of a game state is limited (it encompasses the entire game loop instead of just state). They also have a paper on real-time game loops.

When implementing scripting, is is extremely useful and powerful to use a scripting language that supports some kind of cooperative multithreading. Stackless Python offers this. Since Mono 2.6, you can do this in C# using continuations, but only on the Mono platform (not .NET), as it required changes to the VM.

There are common solutions for 2D and 3D graphics, animation, input, etc. Many of them are handled by DirectX, SDL or similar frameworks.

Matt Olenik
+5  A: 
  • Composite for doing everything per update step (eg. rendering) (And indeed common amongst all UI libraries).
  • Flyweight for drawing many of the same item type on the screen (trees/bushes/bullets)
  • Observer for a lot of UI libraries (again, not game specific)
  • State for transitioning between game/menu/console/pause/etc. states
  • Abstract factory in some beat-em-up type of games for creating mobs/NPCs (the games with ridiculous amounts of AI characters at a time - ie. Left 4 Dead).
  • Strategy for the swapping heuristics in path finding algorithms like A*
  • edit> Command for games like MMO's that have an actionbar with interchangeable buttons that you can click to cast spells and whatnot.

That's all that I can think of seeing right now.

SnOrfus
+1  A: 

I don't think there are any particularly game-specific software design patterns. Games use the same languages, libraries, platforms as everybody else and face pretty much exactly the same problems at the software level.

There are certain methods or approaches that seem to be popular, but which aren't formalised at code level in the way that classic design patterns are. One example is component-based actors, often not even aggregated in the same object but via sharing an ID, communicating via a signals/slots type mechanism. Another would be the embedding of a second language for scripting purposes, such as Lua, Python, or Javascript.

Kylotan
I'm really looking for some general architectural patterns - like how to organize all the different components of the game into something that is understandable and maintainable from a high level. Something like the game development equivalent of an MVC type architecture or a layered architecture.
Hooray Im Helping
They don't exist, I'm afraid! This sort of question comes up again and again over on GameDev.net but there is actually no standard approach or anything resembling one. Everything has an input-update-render/output loop, and often there is a game state system similar to that described by Matt Olenik, but beyond that, it's an ad-hoc arrangement of various small-scale systems and patterns. I could give some advice, but I'd be lying if I claimed my suggestions were "common".
Kylotan
A: 

I found this PDF detailing possible game architectures. Although, it might be 'disagreeable to readers who are more inclined to think in terms of object-oriented design.'

Hooray Im Helping