MVC Game Design - Controller Architecture

Reading artile on gamasutra made me think about how a controller in an MVC game should be designed as:

Option 1: The controller should act on the model,

For example: whenever a key is pressed, the controller calls the model:

On KeyPress Left SuperMario.StartWalking(Left) On KeyRelease -Left or Right- SuperMario.StopWalking() 

Option 2: the model asks the controller what to do

For example: each update ticket model calls GetDesiredXSpeed ​​():

 On KeyPress Left speedX = -SuperMario.MaxSpeed(); On KeyRelease -Left or Right- speedX = 0; int GetDesiredXSpeed() return speedX; 

Which of the two constructions for the controller gives the greatest advantages in terms of the possibility of changing the controller to support alternative input methods. For example, a joystick or mouse, network player, or even AI? What should I teach another. If you have any personal experience in game design, please give me 2 cents on this.

+4
source share
1 answer

There is more focused on the game http://www.koonsolo.com/news/model-view-controller-for-games/

The main idea is to separate the model, render the model according to the presentation and manage the model (user and / or other objects). For example, it means that your model code is a representation of the world within the country, does not know specifically how it will be displayed in the view. Consequently, the entire graphics engine can be changed without touching the code of the base model. A controller is a part of your code that deals with user input, and then calls in the model to do something. The controller code is also quite carefully separated from the model code and can be replaced with various control devices without changing the model.

As a rule, everyone tries to minimize function calls by the model on something else. The controller typically uses model function calls to modify it, and the view uses different model calls to access what is needed to create a (user-visible) model view.

This becomes more and more attractive when you start trying to make a formal separation between domain objects and the object management code in the model, and it can be difficult to place certain code in the model, in business logic (in applications that formalize it) or in the controller code. However, for small games this is not so important.

The short answer to the question is that, in general, the model will not request controllers or view generation code.

+9
source

Source: https://habr.com/ru/post/1481625/


All Articles