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?
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).
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.
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.
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.)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With