Application of MVC pattern in game development

Source: Internet
Author: User

Original address:

Http://www.cocoachina.com/gamedev/2012/1129/5212.html

MVC is the abbreviation for three words: Model, view, and control controller, respectively. MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application into three core parts: models, views, controllers. They each handle their own tasks, relationships:

The model is the data layer, the view is the presentation layer, the controller is the logical layer, also corresponds to the program running in the data input, data processing, output basic three steps. In fact, MVC pattern development is also suitable for game development.

Data-driven

Recently saw a blog write the driving method of the use of experience, this blog is always emphasizing the contradiction between data and logic, the realization of the technology is the table drive. And the sublimation of this technology is data-driven technology. And this technology is used in the game, is the data-driven game development. Before the game is developed, the definition defines its data elements in a certain format, leaving the art resources and technology separated.

Hierarchical Design

Since the object-oriented program design approach is called mainstream, the concept of encapsulation is very popular. Class encapsulates the properties of an object with a method, which is then a modular design. The communication between modules is realized by opening the corresponding interface. Modular design can be said to be a major step forward in programming. The hierarchical design method can also be said to be modular design, but the module between the use of a certain sequence relationship. The MVC pattern focuses on the hierarchical design of data in different states (data layer, logic layer, Presentation layer) in program running

Hierarchical design has two key issues: tiering and integration. In the process of design, how to define the whole design layer and the defining norm between layers and layers. When each level of the module has been developed, how to integrate them to achieve a seamless connection on the whole.

The MVC pattern solves both of these problems well. According to the MVC pattern, the game can also be divided into three layers: data layer, logic layer, presentation layer. It is defined as follows:

Data Layeris a collection of objects formed in the game engine by various resources (pictures, sounds, animations). The art offers these are the most primitive, requiring the game engine to be packaged into a set of controllable code. In Cocos2d, the corresponding objects are used to initialize these primitive resources directly, such as Sprit,menu,simpleaudioengine and so on. These objects can be divided into the data layer throughout the game. The best example of this is the Cocosbuilder generated CCB file class that is parsed by the engine. When the most primitive resource files are organized by a certain file format, the object collection is formed by the engine, which is the most desirable method of data layer generation. In fishing 2, multiple functional modules are designed to use this method. such as localization of multiple languages. The translation of all the fields is stored by a plist file, forming a two-dimensional table. When you need to switch languages, just change the value of a key relative to the line. The logic layer does not need to make any changes.

Logical LayerCan be divided into Data interface layer, game AI layer, Operation control layer. The data interface layer is responsible for encapsulating the corresponding data objects from the data layer. At this level, similar to the property definition of the object-oriented class, and provides the control (Set/get) interface. This layer can be either unstructured (the original data type definition) or structured (table, tree, collection). The game AI layer is the core of the logic layer, defining the changes in the state of the various data elements below it (number of coins, weapon level, animation playback ...). )。 According to the different state variables, control the state of the data elements, is the game of the Brain, Command and control center. The Operation control layer is responsible for processing the user input and registering or binding the corresponding AI event. In the logical layer, the data interface layer faces down to the data layer, and the manipulation control layer faces up to the user behavior events, while the game AI Layer co-ordinates the two layers.

Presentation LayerLike direct and scene in the cocos2d, it controls the big background of the game and is responsible for displaying the various states of each data element in the program in a timely manner.

Hierarchical design is widely used in software design, such as TCP/IP network model (physical layer, link layer, network layer, Transport layer, application layer), database technology (physical data layer, conceptual data layer, logical data layer). Its common feature is hierarchical, while database technology emphasizes the independence of data and logic.

Summary

Data-driven game development is to achieve the separation of data and logic, so that game development from the data level independent, focus on design, AI processing, to achieve rapid development of the game. When the logic layer matures, just to change the different style of data layer, is another kind of game, can quickly meet the needs of users of the fashion aesthetic. Perhaps the MVC model can be used for reference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.