Unity Interview Easy Exam Questions - Framework Concept
MVC framework
MVC is a design framework that divides code functions. The main principle is to separate game data, user interface and business logic, so as to enhance code scalability, reusability, maintainability and flexibility, and reduce coupling.
Model - Data Layer Data Management
View - view layer view interaction
Controller - control layer business logic
Approximate process:
M -> Add data update event M -> Send data update event
V -> Add data change event V -> Send view interaction event
C -> Add view interaction event C -> Send data change event
ECS framework
Entity entity
Component component
System system
Entities and components have a one-to-many relationship. What functions an entity has depends entirely on which components it has. By dynamically adding or removing components, the behavior of the entity can be changed when the game is running.
Components are general-purpose components. Once any entity mounts the component, it can have the functions of the component.
A system is a tool for working with collections of entities that have one or more common components
https://gameinstitute.qq.com/community/detail/114516
The principle of ECS improving the cache hit ratio:
The data stored in ECS will determine the Archetype according to the Component owned by the Entity. The Archetype represents all the Components owned by this type of Entity. The data of the same Archetype will be stored in 8k chunks. Generally, the L1 cache is more than 16k, which means that 2 chunks or more can be stored. The arrangement of the Archetype in the memory is continuous. Read and write by offsetting bytes until the required chunk exceeds L1, and the commonly used object-oriented method uses pointers. Its arrangement in memory is not continuous, which will cause random flying in memory and the problem of cache miss. ECS is arranged continuously through the sequential layout of struct, so it will not have cache loss.
Unity Interview Easy Exam Questions- Data Structure
Array
A linear data structure that stores the same type of data in a contiguous storage space
Applicable to situations where there is little requirement for storage space and few additions and deletions
advantage:
Querying elements by index is fast
It is convenient to traverse the array according to the index
shortcoming:
After the size of the array is fixed, it cannot be expanded
Arrays can only store one type of data
It is inconvenient to insert and delete data
A stack
is a linear data structure for data storage and retrieval only by accessing its top.
Data is stored according to the first-in-last-out principle.
stack storage structure
To avoid stack overflow, use a linked list to store data in the stack
Stack space capacity can be dynamically expanded
Need to pre-define or apply for stack storage space
Stack space capacity is limited
When data is pushed into the stack, it is necessary to judge whether the stack is full. If the stack is full, an exception will be thrown.
Sequential stacks are generally implemented through arrays, and dynamic expansion is not recommended, as deep copying will occur
sequential storage
chain storage
A
queue is a first-in, first-out linear data structure
Only allow pop data at the front of the queue, and push data at the rear of the queue
Queue storage structure
The judgment condition that the queue is empty is that the values of the head pointer and the tail pointer are the same, and both point to the head node
Linked list stores queue data, which can be dynamically expanded to avoid queue overflow
The sequential queue is assumed to be a ring structure, called a circular queue
Array space can be recycled
When the queue is full, pop up the head of the queue, which can be used for structures such as caching
Need to pre-define or apply for the storage space of the queue
The capacity of the queue space is limited, when the queue tail pointer reaches its upper limit, the queue is full
Use a group of storage units with continuous addresses to store the data in the queue
When an element enters the queue, it only modifies the pointer at the end of the queue, and when an element leaves the queue, only the pointer at the head of the queue is modified.
sequential storage
cycle storage
linked list storage
Two stacks implement a queue
- Entering the queue: just push it directly into the stack 1
- Dequeue: If stack 2 is not empty, pop the top data in stack 2 directly; otherwise, pop all the data in stack 1 and push it into stack 2, and then pop the top data in stack 2
Linked list
Non-contiguous and non-sequential storage structure in physical storage unit
It can represent both linear structures and nonlinear structures
Linked list data storage is realized through the pointer link order in the linked list
linked list type
singly linked list
circular linked list
doubly linked list
Tree
Basic Concepts
A tree is a nonlinear ordered data structure
Each node has zero or more child nodes
A node without a parent node is called a root node
Every non-root node has one and only one parent node
In addition to the root node, each child node can be divided into multiple disjoint subtrees
Tree (Tree) is a finite collection of n (n ≥ 0) nodes, n = 0 is called an empty tree
In any non-empty tree, there is only one specific node called root
Root node: the top node of a tree Parent node, child node: If a node is connected to multiple nodes, then the node is called a parent node, and the node below it is called a child node Leaf node: a node without any child nodes Brother nodes: Nodes with the same parent node are called sibling nodes Node degree: The number of subtrees owned by a node
For each node at the same depth in the tree, their heights are not necessarily the same, depending on the depth of the leaf nodes under each node
Binary tree
A binary tree is a tree structure in which each node has at most two subtrees, usually subtrees are called "left subtree" and "right subtree"
Binary trees are often used to implement binary search trees and binary heaps
Binary tree classification
Full binary tree
All branch nodes have left and right nodes, and the leaf nodes are concentrated in the bottom layer of the binary tree
Features of a full binary tree: 1. Leaf nodes are all at the bottom level 2. Depth = maximum number of layers 3. Leaf node tree = Math.Pow(2, number of layers - 1) || odd number
complete binary tree
All nodes on each level have two child nodes except the last level, which is a leaf node
balanced binary tree
The absolute value of the height difference between the left and right subtrees does not exceed 1
red black tree
A tree with a color for each node, the node color is either red or black
A red-black tree is a search tree
The longest path from the root node to the leaf node is no more than twice the length of the shortest path
Heap A
heap is a special tree data structure in which each node has a value. Usually the data structure of the heap refers to the binary heap. The characteristic is that the value of the root node is the smallest (or the largest), and the two subtrees of the root node are also a heap
picture
A graph is composed of a set of vertices and a set of edges connecting two vertices
path, ring
A path is a sequence of vertices connected sequentially by edges, and the length of a path or cycle is the number of edges it contains
A simple path is a path with no repeated vertices
A cycle is a path that has at least one edge and has the same start and end points
A simple cycle is a cycle with no repeated vertices and edges (except that the start and end must be the same)
connected graph
There exists a path from any vertex to any other vertex
hash table (hash table)
conflict handling
Create a special storage space to store conflicting data
Suitable for cases with less data and conflicts
Open Customization
chain address method
Public Spill Area Act
rehashing
Prepare several hash functions, if there is a conflict using the first hash function, then use the next one
expansion
If you need to add data frequently, it is best to open the space in advance