Game Design MVC - Controller Architecture -


reading artile on gamasutra had me thinking of how should controller in mvc game designed as:

option 1: controller should act on model,

eg: whenever key pressed controller calls model:

on keypress left  supermario.startwalking(left)  on keyrelease -left or right-  supermario.stopwalking() 

option 2 : model queries controller

eg: each update tick model calls getdesiredxspeed():

on keypress left   speedx = -supermario.maxspeed();  on keyrelease -left or right-   speedx = 0;  int getdesiredxspeed()     return speedx; 

which of 2 designs controller provides benefits in terms of being able change controller support alternative input methods eg, joystick or mouse, network player or ai? should preffer on other. if have personal expirience in game design please give me 2 cents on this.

there's more game-focused breakdown @ http://www.koonsolo.com/news/model-view-controller-for-games/

the basic idea divide model, rendering of model view, , control of model (by user and/or other entities). means, example, model code - representation of world internally, doesn't know how it'll displayed view. hence, entire graphics engine swapped out without touching of core model code. controller portion of code deals user input , calls model have something. controller code pretty thoroughly separated model code, , swapped out different control devices without needing change model.

generally 1 trying minimize function calls model else. controller uses model's function calls change it, , view uses different model calls access needed build (user-visible) representation of model.

this gets more involved when 1 starts trying make formal division between domain objects , object control code in model, , can hard place code in model, in business logic (in applications formalize it), or in controller code. however, smaller games, isn't critical.

the short answer question model not query controllers, nor view generation code.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -