Game Development Reference
In-Depth Information
6.3M ODEL V IEW C ONTROLLER (MVC)
A model view controller (MVC) pattern is useful when developing user interface systems
because it separates the data being presented to and manipulated by the user from the user's
control or input and the presentation of said data.
AnMVCpatternconsistsofthreeobjects,themodelisthemostlivedatasuchastheplayer's
inventory or a tech-tree. The view is the object that will render or present the information on
thescreenbyqueryingthelatestsnapshotofthemodel.Andthecontrollerisresponsiblefor
providing an interface between the user and the model, communicating user input that will
modify the model's state.
By decoupling the view from the model, we gain the advantage of providing multiple views
for any given model, this allows us to create different ways to visualize the state of the data
without rewriting or duplicating the model's code. For example in an MMORPG auction
house,thousandsofplayerswillhaveadifferentviewofthelargedatabaseofitemsdepend-
ing on what they wish to buy. Player's do not own a local copy of this data, they only see a
snapshot of it.
Thesameappliestothecontroller,beingdisconnectedfromthemodel,wecanhavemultiple
controllers,orswapcontrollersasneeded,effectivelychangingthewaythemodelreactsde-
pending on the type of user input it receives. A great example is the case of multiplatform
games,agamethatrunsonaPCtypicallywillhaveaphysicalkeyboardfortheusertoinput
text, if the game is then compiled to run on a console or a mobile device, the input is still
available but it will come from a gamepad or a virtual keyboard displayed on-screen, in this
situation we can detect the platform and use the corresponding controller.
Search WWH ::




Custom Search