views:

347

answers:

3

Is the MVC design pattern used in commercial computer games?

Particularly with regard to high performance games I am curious if there have been any commercial users of MVC in the games industry?

+4  A: 

I don't know of any commercial games that use it; there may be some. However, I was able to find a paper (PDF) that mentions the MVC pattern being used in computer games. This may give you a little bit of insight.

Vivin Paliath
Nice link, thanks.
topright
+13  A: 

It's rarely used in games. It took me a while to figure out why, but here's my thoughts:

MVC exists to make a distinction between two representations. The Model is the abstract representation of your data. It's how the machine views the state of your application. The View (and Controllers) represent a more concrete visible instantiation of that system in a way that's meaningful to humans.

In most business apps, these two worlds are pretty different. For example, a spreadsheet's model is simply a 2D grid of values. It doesn't have to think about how wide the cells are in pixels, where the scrollbars are, etc. At the same time, the spreadsheet view doesn't know how cell values are calculated or stored.

In a game, those two worlds are much closer to each other. The game world (model) is typically a set of entities positioned in some virtual space. The game view is also a set of entities positioned in some virtual space. Bounding volumes, animation, position, etc., all things you would consider part of the "view" are also directly used by the "model": animation can affect physics and AI, etc.

The end result is that the line between model and view in a game would be arbitrary and not helpful: you'd end up duplicating a lot of state between them.

Instead, games tend to decouple things along domain boundaries: AI, physics, audio, rendering, etc. will be kept as separate as possible.

munificent
Good answer. I would add to this that it's easy and sensible to separate the view from the model when creating a view is not time-critical and is done every few seconds. When you start needing to have a view that updates 60 times a second with no more than 10-20ms of latency you have to start arranging it alongside the model data for efficiency reasons at least.
Kylotan
That's also a good point. Hard performance requirements often lead to a less decoupled architecture than you might otherwise have.
munificent
+1  A: 

That will depend a lot on the game.

For example, a first-person shooter, probably not.

A flight simulator, MVC is very likely (X-Plane and FlightGear both actually do use MVC, you can tell from their plugin APIs). SimCity, you certainly could do that way and make sense (no idea if they actually did). Real-time strategy, perhaps. Bejeweled, who knows.

Andrew McGregor