[Summary of game development post 5] (The difference between face-to-face object and face-to-face process, polymorphism, CG, design mode, process thread coroutine, memory area storage, principle of coroutine)

I found that a lot of things really know the general idea of ​​this thing in their heads, but if you are asked to say it, you really can’t hold back a sentence,
so we still have to be down-to-earth. One problem is that we can’t look at it well.

The difference between the face object and the face process

1. The face-to-face process is a process-centric programming idea, and the face-to-face object is a programming language with the object as the basic program structure unit.
2. The face-to-face process is to analyze the steps to solve the problem, and then implement it step by step, calling the
face object one time at a time. Have a unique static type, and possibly multiple dynamic types, share data and operations
3. The face-to-face process does not support the characteristics of face-faced objects (polymorphism, inheritance) It is not allowed to mix persistent state and logical
face-faced objects to be represented internally A pointer, any operation on this object is through this pointer to manipulate the properties and methods of the object

What is polymorphism?

Polymorphism is: the reference of the parent type points to the object of the child type.
Popular version: the same operation acts on different objects and produces different effects

Benefits: 1. Improve the reusability of the program (modifying the parent class can make the derived class change)
2. Improve the scalability and maintainability (the function of the derived class can be called by the base class)

How did it happen?
Add the virtual keyword in front of the function of the base class to override the function in the derived class. The function will be called according to the actual type of the object at runtime.
If the object is a derived class, use the function of the derived class. If it is a base class, use the function of the derived class. Use base class functions

GC

GC is the
role of the garbage collector :
1. Improve the abstraction of software development
2. Programmers can not worry about memory management
3. Make the modules clearer and reduce the coupling
4. Reduce the bugs caused by improper handling
5. Memory usage is more efficient

Common design patterns and application scenarios

Singleton mode

The singleton mode is a commonly used design mode.
Its core structure warranty includes a special class called a singleton class. Through the singleton mode, it can be ensured that there is only one instance of a class in the system
and that the instance is easily accessible to the outside world. Control of this instance to control and save resources

Scenario : If you want only one object of a certain class in the system, singleton mode is a good solution

Factory mode

The factory pattern is mainly to provide an interface for creating objects

Scenario: It is not possible to foresee which type of instance needs to be created when coding. The
system should not rely on the details of how the product class instance is created, combined and expressed

Strategy mode

The algorithm family is defined and packaged separately so that they can be replaced with each other. The algorithm changes in this mode are independent of the customers who use the algorithm

Scenario:
One thing, there are many solutions that can be implemented.
I can decide which method to implement at any time. Many solutions may
be added in the future. The
strategy model can make the change of the solution not affect the customers who use the solution.

Observer mode

Also known as the publish/subscribe model defines one-to-many dependencies between objects.
When an object changes, the state of all dependents will be notified and automatically updated

Scenes

To update the state of an object, other objects need to be updated synchronously, and the number of other objects is dynamically variable. The
object only needs to notify other objects of its own update without knowing the details of other objects.

Iterator mode

Provide a way to sequentially access the various elements of an aggregate object without exposing the internal representation of the object

Scenes

When you need to access an aggregated object, no matter what these objects are and need to be traversed, use the iterator pattern. The
stl container is a good example of the iterator pattern.

The difference between process, thread, and coroutine

Process: Has its own independent stack, neither shared stack nor shared heap, and is scheduled by the operating system.
Thread: Has its own independent stack, shared heap, and is scheduled by the operating system. Coroutine
: Shared heap and independent stack like threads , The programmer manually schedules the coroutine

An application generally has a main thread and multiple auxiliary threads. The threads run in parallel. The coroutine can be opened in the thread to allow the program to run at a specific time.

Processes and Threads difference
1. process is resource allocation smallest unit, the thread is executing the smallest unit
2. The process has independent space, no thread, the process of resource independent, threads are sharing the
big 3. process execution overhead, thread execution overhead Small
4. Thread is the basic unit of processor scheduling. Process is not

The difference between coroutine and thread: coroutine avoids meaningless scheduling, which can improve performance, programmers must bear the responsibility of scheduling,
and threads lose the multi-CPU capability of standard threads

Principle of coroutine:

During the execution of the coroutine in unity, through yield return xxx, the program is suspended, and the following content is executed.
Note that the coroutine is not a thread. Before encountering yield return xxx, the coroutine method and the general method are the same. That is, after the program execution encounters yield return xxx,
the program after the startcontinue() method will be executed. It is still in single-threaded mode. It just temporarily suspends the content after yield return xxx and waits for execution at a specific time.

Dynamic batching, static batching

Dynamic batching:
Unity comes with dynamic batching, which needs to be turned on in unity, which will cause CPU consumption.
Limitation: the
object's transform must have the same zoom factor,
use the same material
, and render the
static batching together one by one
. Mark the object as static in unity and then turn it on Static batching
Restriction: you
need to keep static and cannot change
the objects of the same material in the transform to be
batched. One batch is online with ~15K vertices

What are the blocks in the memory area and what are stored separately

There are five memory areas in total:
1. Stack area: It is mainly automatically allocated and released by the compiler to store function parameter values ​​and local variables. The operation method is similar to the stack in the data structure.
2. Heap area: allocated and released by the programmer, and stored new Or the instance from malloc is released by the programmer (allocation method is similar to linked list)
3. Global area (static area): global variables and static variables are stored together, initialized global variables and static variables are placed in RW
uninitialized global variables and static Variables are automatically released after the ZI program ends.
4. Text constant area: stores constant strings, and automatically releases after the program ends.
5. Program code area: stores binary codes

The difference between static global variables and global variables

1. The storage area of ​​both is the same as the global area (static area)
2. Ordinary global variables affect the entire source program. If a source program has multiple source files, then this global variable is valid for all source files
3.static The global variable limits its scope to the source file defined by the variable, and can only be used by the function of this file, and other source files cannot use this static variable.

The principle of coroutine

When unity is running, calling the coroutine is to start an IEnumerator (iterator), and the coroutine starts to execute.
Before the execution reaches the yield return, the coroutine is no different from other normal applications, but it will return immediately after encountering the yield return.
And temporarily suspend the function. After the next frame encounters FixedUpdate or Update, it is judged whether the yield return condition is satisfied.
If it is satisfied, execute it downward, otherwise continue to hang

Guess you like

Origin blog.csdn.net/weixin_44302602/article/details/113664307