Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the MVC design pattern used in commercial computer games

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?

like image 970
acheo Avatar asked Feb 05 '10 20:02

acheo


People also ask

Is MVC used in games?

One useful architecture pattern in game development is the MVC (model-view-controller) pattern. It helps separate the input logic, the game logic and the UI (rendering).

Is MVC good for game development?

MVC describes how to organize your code in such a way that is easy to maintain, and helps in improving code readability. Without structure, your code can get messy very easily and look like “spaghetti code”. To avoid this, developers should separate the game logic from the display code.

What is the MVC pattern used for?

MVC (Model-View-Controller) is a pattern in software design commonly used to implement user interfaces, data, and controlling logic. It emphasizes a separation between the software's business logic and display. This "separation of concerns" provides for a better division of labor and improved maintenance.

What is an example of MVC design pattern?

Car driving mechanism is another example of the MVC model. Every car consist of three main parts. View= User interface : (Gear lever, panels, steering wheel, brake, etc.)


2 Answers

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.

like image 110
munificent Avatar answered Sep 20 '22 08:09

munificent


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.

like image 28
Andrew McGregor Avatar answered Sep 20 '22 08:09

Andrew McGregor