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.


MVC and the in-betweens for game development


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
2 replies to this topic

#1 BlinksTale   Members   -  Reputation: 315

Like
1Likes
Like

Posted 13 February 2013 - 01:54 PM

Hello GameDev! I'm starting work on a new project now, and I want to fit it as nicely into MVC as possible. I feel comfortable distinguishing game logic from graphics from input, but I want to get better/cleaner at this. A couple edge cases still confuse me, for example, where do I put cutscenes? Is the timing between shots in game logic, even though it has no impact on the rules, or should it be 100% in graphics, since it's all visuals and no engine or interaction?

 

More what I'm trying to figure out (part 2) though is how to share information between the three. In my last game, I gave everything access to the game logic main file, and had things passed through a couple files to go up/down the hierarchy (from keyboardHandler to controller/input to model/game logic to playerHandler) but that felt sloppy to have things jump through so many steps. Any advice on this?



Sponsor:

#2 flodihn   Members   -  Reputation: 254

Like
0Likes
Like

Posted 13 February 2013 - 05:49 PM

I made my game client with a slightly modified MVC.

 

The MVC you think of with the database as model usually found in web development does not really suite a game engine, according to my own beliefs.

 

Here is what I did:

MVC+L (Model/View/Controller/Logic) because standard MVC does not state where your logic would fit into the architecture.

 

The model stores all persistent data, such as game objects, mouse pointer, open windows. A game object is a unique id with a number of properties. Like this

{

    id: 1231234

    mesh: "GruntyOgre.mesh"

    pos: 1, 3, 0

    speed: 0

    hp: 100

}

 

{

    id: 231231

    window: "MenuScreen.xml"

}

 

{

    id: 23123156

    mouse_pointer: "green_arrow.png"

    pos: 100, 231

}

It has no functionality other that creating, destroying game objects and adding/removing properties on game objects.

 

The view registers itself on the model and gets notified with game objects are created/destroyed or properties changed. When a game object with a graphical representation (for example having the property mesh) is created, it creates its own graphical object with the same id used to display stuff on the screen (including GUI).

 

The controller listens for input from keyboard, mouse, network etc, translates them to events and forwards them to the logic.

 

The logic is a state machine that does all logic (duh) in the game. It creates, destroys, changes properties in the model.

 

All 4 different layers are completely decoupled and only communicates with callbacks registered in each other.

 

This gives my engine flexibility and some interesting properties such as:

- I can choose not to create a view, thus I can make it easy to create a multiplayer game (if add the feature for the layers to registers themselves on remote machines).

- I can choose to switch resultions and even graphics implementations (opengl/directx) during runtime without having to shut down the game

- I can make any type of game with the engine by just replacing the logic layer.

- I can dynamically upgrade/restart all parts of the game but the model without loosing any game data (since the model is just a stupid container chances are low I would have to update it).

 

On a side effect, this architecture makes it also easy to add and remove features since changes can not cause shockwaves of changes outside their own layers.


Edited by flodihn, 13 February 2013 - 05:55 PM.


#3 thedevsykes   Members   -  Reputation: 336

Like
0Likes
Like

Posted 14 February 2013 - 02:53 AM

I have discussed this methodology with my professors at University. Essentially the reply was, MVC doesn't fit exactly into a game system. Mike McShaffery, writer of Game Coding Complete uses something similar to it, and it could be worth reading his book (I'd reccomended either the third or fourth edition) in order to get an idea. Essentially, the way I see it, you have your game screens, intro, main menu, level 1, level 2, etc. But you define your logic completely seperately and use controllers to CONTROL the gamer as it were. Sometimes you just need to have the rendering and the logic closely tied together, games are awesome like that.... yeah. One method Mike uses is an event based system. The view (being the screen lets say) accepts input, handles rendering and playing sound. Events will trigger, for example, player is shot which will be sent to the logic which will update and if required return player is dead, and the screen will update accordingly.

 

Thats a pretty rough explanation, but should set you on the right track. Essentially what flodihn is saying.


'Knowledge isn't key, but understanding...'

My qualifcations are not here to showcase, but for those I answer and ask, to get a better idea on my knowledge.

BCS Level 2 Certificate for IT Users (ECDL Part 2)
OCR Level 2 National Award in Business
Level 2 First Diploma in Media
Level 3 Diploma in Games Design and Development Extended
BSc Hons in Computer Games Programming (Current - 1st Year)




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