MVC Design

Overview of the MVC Pattern

A game is an interactive application that requires a medium to receive user-inputs, a way to provide feedback, such as a view, and a mechanism to make decisions.

In game development, user-inputs, view, and game logic are implemented through the use of a Design Pattern known as the Model-View-Controller (MVC) pattern.

The MVC pattern implements the logic of a game through the Model Component. It implements what you see in a game through the View Component. And it implements user-inputs through the Controller Component.

The image below illustrates the components of the MVC pattern.

image

A game engine interacts with the MVC pattern through the components specified. For example, all game characters are submitted to the engine’s scenegraph through the View Component.

image

User-inputs are directed to the engine through the Controller Component. And if desired, the state of a character is updated through the Model Component.

image

An overview of the MVC architecture is illustrated in the image below:

image

Each of these components is loosely-coupled. Meaning that they can communicate among themselves, yet don’t depend, nor do they know about each other. Furthermore, each component can extract information about the state of the game.

For example, the Model Component can ask the View Component how many characters are in the engine’s scenegraph. Similarly, the Model Component can ask the Controller Component which button was pressed. This interaction between the engine and the MVC allows for the development of modular, clean games.

Untold Engine MVC Implementation

The Untold Engine represents each of the MVC Components as Objects. For example:

  • The U4DEngine::U4DGameModel object represents the Model Component.
  • The U4DEngine::U4DWorld object represents the View Component.
  • The U4DEngine::U4DControllerInterface object represents the Controller Component.

The image below illustrates the MVC representation in the Untold Engine:

image

Subclassing MVC Objects

To make use of the Untold Engine MVC architecture, you must create subclasses for each of the MVC components. For example, the Untold Engine comes with the following objects:

  • Earth
  • GameLogic
  • GameController
  • GamePadController
  • KeyboardController

The Earth object is a subclass of the U4DWorld parent class. The GameLogic object is a subclass of the U4DGameModel parent class. And the GameController, GamePadController, KeyboardController objects are subclasses of the U4DControllerInterface.

The image below illustrates the subclass of the MVC objects:

image