Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Model–view–controller pattern


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 ms75214   Members   -  Reputation: 143

Like
0Likes
Like

Posted 07 September 2013 - 06:54 PM

I know the Model–view–controller pattern is popular in general programming.
 
But what about in games?
 
Is it used in games much?
 
Anyone here ever used it?
 
Thanks.
 


Sponsor:

#2 Norman Barrows   Crossbones+   -  Reputation: 2308

Like
1Likes
Like

Posted 07 September 2013 - 07:52 PM

M-V-C is one of many "patterns" from the non-game software industry that folks sometimes apply to games.

 

Th general problem with such approaches is that they come from the non-game software industry, and may or may not be applicable to games.

 

MVC is a business app model as i recall. 

 

Game software, otoh, is modeling and simulation software.  so one would expect "patterns" from modeling and simulation to be applicable, and "patterns" from other types of software to be perhaps less so. if you want to think of the game's data as the model, render as the view, and process_input and update as the controller (or would update be part of the model? i'd have to look up MVC again), i see no major harm. as long as it doesn't lead to unnatural code organization, and therefore unnecessary complexity.

 

me personally, i'd stick with "patterns" that come from game development- such as the "main game loop" pattern! <g>.

 

or the "render all" pattern, or the "update all" pattern.  or the "process_input" pattern.   or the "entities list" pattern, or the "world/level map" pattern.

 

THESE are the "patterns" one sees in games, not stuff like MVC.


Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

 

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

 

 


#3 CJ_COIMBRA   Crossbones+   -  Reputation: 831

Like
0Likes
Like

Posted 07 September 2013 - 08:46 PM

me personally, i'd stick with "patterns" that come from game development- such as the "main game loop" pattern! <g>.

 

or the "render all" pattern, or the "update all" pattern.  or the "process_input" pattern.   or the "entities list" pattern, or the "world/level map" pattern.

 

 

I am curious about this. Is there any source you could indicate about design patterns for games?



#4 Norman Barrows   Crossbones+   -  Reputation: 2308

Like
0Likes
Like

Posted 07 September 2013 - 09:04 PM


I am curious about this. Is there any source you could indicate about design patterns for games?

 

check my journal

 

i'm about to add an entry!


Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

 

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

 

 


#5 Kaptein   Prime Members   -  Reputation: 2178

Like
0Likes
Like

Posted 07 September 2013 - 09:05 PM

-


Edited by Kaptein, 07 September 2013 - 09:08 PM.


#6 cardinal   Members   -  Reputation: 902

Like
4Likes
Like

Posted 07 September 2013 - 09:36 PM

Maybe I'm a little rusty on model view controller (although it is one of the first things I learned at university), but games are a very good example of it as far as I'm concerned.

 

The model is your "data set" or the game simulation.

 

The view is the rendering of your simulation.

 

The controller is the input mechanism used to feed the simulation to effect change on it (controllers/mouse/keyboard and input processing feeding into your game simulation).

 

MVC is all about separating and enforcing responsibility, so that you don't have GUI or rendering code affecting your data set, and that you can display your data set as many ways as you want (i.e. different camera settings).



#7 adam4813   Members   -  Reputation: 667

Like
0Likes
Like

Posted 07 September 2013 - 10:17 PM

You can get my take on it, in my article MVC and CBES as it Relates to Game Programming



#8 frob   Moderators   -  Reputation: 22692

Like
4Likes
Like

Posted 07 September 2013 - 11:05 PM

Actually it is frequently used in games.

One ubiquitous example is online games where processing is done on the server. The authoritative model is kept on the server. The view is shown on the client machine, and many different views can exist. The controller transmits clicks into events that get fed back to the model.

It applies for the whole gambit of online games. Everything from Words With Friends to WoW follow the MVC idioms.

Many large games follow the pattern. Although you don't need to follow it, it absolutely simplifies things. You have a game simulator that does the work. You have a decoupled rendering engine. And you have a decoupled user interface that generates events for processing.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#9 LorenzoGatti   Crossbones+   -  Reputation: 2762

Like
2Likes
Like

Posted 08 September 2013 - 10:15 AM

Game software, otoh, is modeling and simulation software.  so one would expect "patterns" from modeling and simulation to be applicable, and "patterns" from other types of software to be perhaps less so. if you want to think of the game's data as the model, render as the view, and process_input and update as the controller (or would update be part of the model? i'd have to look up MVC again), i see no major harm. as long as it doesn't lead to unnatural code organization, and therefore unnecessary complexity.

 

me personally, i'd stick with "patterns" that come from game development- such as the "main game loop" pattern! <g>.

 

or the "render all" pattern, or the "update all" pattern.  or the "process_input" pattern.   or the "entities list" pattern, or the "world/level map" pattern.

But MVC and its variants are perfectly suitable patterns for modeling and simulation software, including games. Compared to typical business software there's only a slight shift from independent views of separate UI elements to consolidated (but often hierarchical) views of the whole game and from controllers related to user interaction with UI elements to various types of controllers (remote network players, AI agents, etc.) related to important model objects.

 

The mentioned game-related patterns are easily combined with a good model-view-controller separation: the main game loop ties together all steps of model, view and controller processing in the correct order and with the correct timing; rendering updates the view from the model; simulation updates involve only the model, which is very important; processing input is the job of some of the controllers ; lists of entities and maps are possible internal structures of the model.


Produci, consuma, crepa

#10 rwtwm   Members   -  Reputation: 129

Like
0Likes
Like

Posted 08 September 2013 - 03:26 PM

 

me personally, i'd stick with "patterns" that come from game development- such as the "main game loop" pattern! <g>.

 

or the "render all" pattern, or the "update all" pattern.  or the "process_input" pattern.   or the "entities list" pattern, or the "world/level map" pattern.

 

 

I am curious about this. Is there any source you could indicate about design patterns for games?

 

 

I've been following Bob Nystrom's in progress web book on this http://gameprogrammingpatterns.com/. It's easy enough to follow even as an amateur and there are already a lot of handy chapters online.



#11 TheChubu   Crossbones+   -  Reputation: 4754

Like
0Likes
Like

Posted 08 September 2013 - 05:32 PM

I'd say that MVC pattern in enterprise stuff is applied because the need of having different views over the same model and persistent data. Whereas in games you'd apply it to have a clear distinction between systems as other users said said before (input, render, data).

 

It is a very "natural" pattern (like the layered architecture) so probably many apply it to some extent, knowing about it or not.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#12 wintertime   Members   -  Reputation: 1861

Like
0Likes
Like

Posted 09 September 2013 - 06:52 AM

MVC got such an ambiguous and watered down high level concept you can apply it to nearly anything, even retroactively. Imo the main takeaway from it is to not intermingle presentation, business logic and data storage so refactoring stays easier, other than that you probably wont gain much from it.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS