Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » MVC in game development

This thread is locked; no one can reply to it. rss feed Print
MVC in game development
decepto
Member #7,102
April 2006
avatar

I come from a web programming background. My first language was basic, then c++. But I really didn't start diving deep into programming until Perl. Then I moved onto PHP with a custom framework. Finally, and currently, I use Ruby on Rails.

I'm in love with the Model-View-Controller pattern. I'd love to be able to apply it somehow to game development. Have any of you tried?

--------------------------------------------------
Boom!

Archon
Member #4,195
January 2004
avatar

Quote:

I'm in love with the Model-View-Controller pattern. I'd love to be able to apply it somehow to game development. Have any of you tried?

Yes.

Johan Henriksson
Member #11
April 2000
avatar

ideas from MVC can be applied to games but in general it is just a waste of time. encapsulation helps portability between some (obscure) platforms but going all the way to MVC is overkill.

any use of a "programming pattern" just for the sake of using a pattern is gonna do more bad than good for whatever you are working on. choose the tool based on the problem, not the reverse.

monkeyCode
Member #7,140
April 2006

I never try to apply a design pattern, but inventories often end up having a model-view design, but yeah guess my point is, use patterns where they are logical to use ;)

axilmar
Member #1,204
April 2001

Actually every game is an MVC application: the game's entities is the model, the game's graphics classes is the view, and the main loop is the controller. The only difference with classic MVC is that in a game, the graphics data, logic and game algorithm is fused together.

gillius
Member #119
April 2000

MVC works well with games, and I have used it to much success. In fact, on my game you can find an example for this -- in 2D class my team did a game called Super Isobomb, a bomberman clone. We did the game in MVC style such that all of the rendering code was completely separate from the model. When we wanted to port it to 3D, all I did is change the view portion of the game. If you look at Mega Monkey Mayhem, you'll notice that it is very much like Super Isobomb -- in fact the model part was much unchanged.

MVC is also could be used in professional games -- I suspect this is the case where you have a game with a OpenGL engine and a DirectX one.

MVC is also helpful in net games. If you design it properly, using the same model you should be able to just modify the controller portion to implement net games. Of course, sometimes gameplay/logic has to change to be appropriate to net play, but the MVC will get you a lot closer by limiting the change required and highlighting the sections that need changing. I have also done this, and one of my teammates in 2D class tried to do this using the MVC in super isobomb -- it worked but was not completed.

And to complete the circle with a replacement model approach -- this one I've never done but it has been done in the real world -- a common rendering engine that you can use with any model. Really most 3D libraries (like OGRE or OpenLayer) are basically this, but from a pure MVC standpoint they are reversed as you usually push to the view (in pure MVC, the view pulls from the model). However, to make an engine pure MVC you could define interfaces for the renderables in the game. To convert these to a more "pure" MVC approach (taking Allegro as an example), you would make a glue layer such as a Sprite interface that any object implementing it will be drawn in the world (to flip push/pull models).

Gillius
Gillius's Programming -- https://gillius.org/

Go to: