"Game design Mode" of "Game Programming mode" Content refining summary

Source: Internet
Author: User
Tags abstract shallow copy

Turn from Light ink choobies cloud: http://blog.csdn.net/poem_qianmo/article/details/53240330


This is a more than million words of reading notes, summed up "game programming Patterns" (Chinese version of the Games programming mode) a book of all chapters and content of the knowledge outline.

We know that the game industry has been very short of a system introduced game programming advanced skills of the book, and the "Game Programming Mode" appeared, just make up for this point.

Previously mentioned, unlike traditional publishing methods, the book is web-published, and then the Web version is completely free, and it has a rare 5-star rating on Amazon, which shows readers ' high level of praise. In addition to the vivid and interesting contents of the book, it is the conscience of the industry to explain the various experiences.

Book Home: http://gameprogrammingpatterns.com/

Web version Full text read: http://gameprogrammingpatterns.com/contents.html Chinese translation: http://gpp.tkchu.me/




Before this article, I have written three related reading notes, but feel a mode of introduction, rhythm is too slow, use this summary of the article to the 19 design patterns once introduced.



Short version of the article: The book Content mind map



The following is the "game programming model" of the content of the book, the contents of the 19 modes of mind Mapping:






This article read the description


According to the Order of "game Programming Mode", this article introduces the following three aspects of the 19 modes of the book:

Main points of application and reference

After the introduction of 19 modes in turn, some more reference and learning resources are finally given.

It is important to note that the design pattern itself is more abstract in understanding. Because this article is the design pattern Content Summary Introduction, therefore understanding the slope naturally will be relatively steep. If the part of the summary is not quite understood, suggest that you read the original (in each mode "extension and Reference" part of the link has been given), this article on the original text of the summary and the original combination of understanding, so that the mastery will be more smooth.





first, the common Gof design pattern




This section introduces six kinds of GOF design patterns that are commonly used in game development:

Command mode Enjoy META Mode Observer pattern prototype mode Singleton mode State mode




1. Command Pattern


The command pattern encapsulates a request into an object to parameterize other objects with different requests, queues, or logs, while supporting undoable operations.


Key points

Abstract a set of behaviors into objects, which can be stored and passed like other objects, thus allowing loose coupling between the requester of the behavior and the implementation of the behavior, which is the command pattern. The command pattern is an object-oriented version of the callback mechanism. The essence of the command pattern is to encapsulate the command, separating the responsibility for issuing the command from the responsibility of executing the command. The advantages of the command pattern are: Decoupling between classes, strong extensibility, easy command combination maintenance, easy to combine with other patterns, and the disadvantage of causing the expansion of the class. There are many kinds of subdivision of the command pattern, which should be used to find the right design method according to the current need.

Use occasions

The command mode is ideal for functions such as undo, redo, replay, and time reversal. The function of recording and replaying based on the command mode is to execute and parse a series of ordered command sets of each player operation after pre-recorded serialization.

extension and Reference

Eventually we may get a lot of different command classes. To make it easier to implement these classes, it is often helpful to define a specific base class that contains some high-level methods that define the behavior. You can move the main body of the command execute () to a child-like sandbox. An object can respond to a command, or give a command to its subordinate object. If we do this, we have completed a chain of responsibility model. For equivalent instances, you can use the enjoy meta-mode to improve memory utilization. Unity version Implementation of command mode: Https://github.com/QianMo/Unity-Design-Pattern/tree/master/Assets/Behavioral%20Patterns/Command %20pattern This section is related to the original English: http://gameprogrammingpatterns.com/command.html This section of the relevant Chinese translation: http://gpp.tkchu.me/ Command.html



2. Enjoy meta mode Flyweight pattern


Enjoy meta-mode to effectively support a large number of fine-grained objects in a shared manner. Reduces the performance consumption of system-created object instances by reusing objects that already exist in memory.

Key points

There are two states in the enjoy meta mode. The intrinsic state (the Internal state) and the outer States (External). The intrinsic state, which is not changed with the environment, is the state information stored inside the object, so the intrinsic state can be shared. The value of the intrinsic state is exactly the same for any one of the objects of the privilege. The state of the outer Yun will change with the change of the environment. Therefore, it is a non-shareable state, and its value may be different for different objects of enjoyment. The shared meta-mode is a way to isolate the changing and invariant parts of the system by sharing the intrinsic state and distinguishing the state of the outer aggregates.

Use occasions


Use the enjoy meta mode when all of the following are true:

When there are many instances of an object type in the system. Because of the large number of objects used, there is a large storage overhead.  Most states of an object can become an outer state. In the system design, when the object instances are categorized, it is found that there are very few real differences in classification.


extension and Reference

In order to return an already created share, we need to make contact with the objects that have already been instantiated, and we can work with the object pool. When using the state mode, it is often possible to use the same object instance on different state machines with the enjoy meta mode. Unity version implementation of the enjoy meta-mode: https://github.com/QianMo/Unity-Design-Pattern/tree/master/Assets/Structural%20Patterns/ Flyweight%20pattern the contents of this section are in English: http://gameprogrammingpatterns.com/flyweight.html the relevant Chinese translation of this section: HTTP// Gpp.tkchu.me/flyweight.html

3. Observer Pattern Observer pattern



The Observer pattern defines a one-to-many dependency between objects, and when an object's state changes, all objects that depend on it are notified and automatically updated.


Key points


The Observer pattern defines a one-to-many dependency between objects, and when an object's state changes, all objects that depend on it are notified and automatically updated. We know that splitting a system into a class with some kind of collaboration has a bad side effect, which is the need to maintain consistency among related objects. We do not want to be tightly coupled in order to maintain consistency, which can cause inconvenience to maintenance, expansion, and reuse. The observer is the solution to this kind of coupling relationship. The MVC pattern, which is widely used at present, is based on the observer pattern. The observer pattern is widely used, and Java even puts it into the core library (Java.util.Observer), and C # directly embeds it in the syntax (event keyword).

Use occasions

When an abstract pattern has two aspects, one of which relies on another, it is necessary to encapsulate these two aspects separately into separate objects, changing and reusing each other independently. When a change in one object in a system needs to change the contents of other objects at the same time, it is not known how many objects are to be changed. When an object changes it must notify other objects to make corresponding changes, but cannot determine who the object of the notification is.

extension and Reference

Unity version implementation of the Observer pattern: https://github.com/QianMo/Unity-Design-Pattern/tree/master/Assets/Behavioral%20Patterns/ Observer%20pattern This section is related to the original English: http://gameprogrammingpatterns.com/observer.html This section of the relevant Chinese translation: http://gpp.tkchu.me/ Observer.html



4. Prototype Mode Prototype pattern


Use the prototype instance to specify the kind of object to create and create a new object by copying the prototypes.

Key points

Prototype mode: Specifies the kind of object created with the prototype instance, and creates a new object by copying the prototypes. Prototype mode is a relatively simple mode, it is very easy to understand, implement an interface, rewrite a method to complete the prototype mode. In practical applications, prototype patterns rarely appear alone. Often mixed with other patterns, his prototype class prototype also uses abstract classes instead. When copying objects using prototype mode, be aware of the difference between a shallow copy and a deep copy. Prototype patterns can be used to build prototypes of data models in conjunction with data interchange formats such as JSON.

Use occasions

The process of producing objects is complex and requires a lot of resources when initializing. When you want the frame prototype to separate from the resulting object. The same object may be available to other callers at the same time to invoke access.

Reference and Extension

Unity version implementation of prototype mode: https://github.com/QianMo/Unity-Design-Pattern/tree/master/Assets/Creational%20Patterns/ Prototype%20pattern the contents of this section are in English: http://gameprogrammingpatterns.com/prototype.html the relevant Chinese translation of this section: HTTP// Gpp.tkchu.me/prototype.html


5. Singleton pattern Singleton pattern



Guarantees that a class has only one instance and provides a global access point to access the instance.


Key points

The singleton mode has many applications in the development process because of its convenient characteristics. The singleton pattern has two points, guaranteeing that a class has only one instance and provides access to the instance's global access point. Minimize the use of single-case mode. Singleton mode as a global variable, there are many global variables of the malady. It makes the code more difficult to understand, more coupled, and less friendly to parallelism.

Use occasions

When a particular class object instance in the system only needs to have a unique one. The singleton pattern should be used sparingly, and the use of incontinence will bring about various ills. To ensure that the instances are single, static classes can be used simply. You can also use a static identity bit to detect whether only one instance was created at run time.


Reference and Extension

The sub-class sandbox mode described below gives the instance access to the class without having to make it globally available by sharing the state. The service locator mode described below not only makes an object globally available, but also provides some flexibility for setting objects.

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.