7. File System

Source: Internet
Author: User

I haven't updated it for a long time, mainly because I'm too lazy to write this article.ArticleIt usually takes a few hours. Sometimes you need to configure images orCodeI feel tired. I really admire those guys who can write a lot at will. However, since the beginning, we should continue. This article writes the file system used in the engine, The main reason why the engine needs a file system is that the game data needs to be packaged when the game is released. The number of files in a large game may reach tens of thousands or more than 100,000, these files are slow to install or uninstall, and occupy extra space. Therefore, you need to put them in one or more large files. however, during development, we do not want to store game data in the form of packaging, because various operations on files are inconvenient. this leads to different storage methods for game data during the staging and development phases. Therefore, we need a file system to encapsulate this difference and expose it to the upper layer with a Unified File Read/Write interface, its underlying implementation can process different file access methods. for example, you need to open a file File "C: \ ixengine \ data \ texture \ AAA. DDS ", this file may exist in the operating system during the development period, and c: \ ixengine \ data may exist in the preparation period. the position in the package is texture \ AAA. DDS. we handed the string to the file system. The file system can automatically search for each node in the path. If there is a package file on the node, the corresponding file will be further searched in the package. this is no different for the upper layer, which can simplify the design of the upper layer. As for how to package a lot of tricks, you can consider compression or something, but there is only one simple implementation in this engine, that is, to sort the added files one by one, then, the file location is indexed Based on the simplest hash table (with the path name as the hash Key), and no compression technology is used. one problem is that the file package must have the patch function, that is, to replace the data of a file. If the data volume of this file is larger than the original one, the original location will not be able to be placed, it can only be placed at the end, so that after many patches, there will be a lot of holes in the package, and the package will grow bigger and bigger. I want to add an incremental package cleanup function. Each time a game is running, some holes are cleared so that the player is unaware. The file system mentioned above corresponds to the file system of the operating system and is a tree structure, but it is not suitable for a type of data in the game, that is, map data, because our engine must support a large game world, maps must be dynamically loaded. Tree file systems are not suitable for MAP access, therefore, the engine implements a mapfile file system. Basically, its data organization is as follows:

 

 

Map Data is divided into many channels, each channel stores a certain type of data, such as channel 0 stores surface data, Channel 1 Stores vegetation information, and channel 2 stores surface information, in this way, each module in the game is completely independent in data, and each channel is divided into a two-dimensional block array, each block stores data in a small block in the game world. For example, a block corresponds to a 4x4 m square area in the game world. The main purpose of using this method to save map data is to dynamically load maps. Since the storage of game object data is block-based, the game object itself is also block-based, currently, game maps can be detached/loaded in blocks. That is to say, maps of a block can be detached/reloaded without affecting other blocks. This is of great benefit to editing, for example, undo/Redo has become easier because of this map storage method (you only need to back up the data of several modified blocks ). in addition, you can easily implement Version Control of Map Data (checkin/Checkout a plot). The benefit of dividing the map into channels is that the map sizes of different channels can be different, for example, the earth surface may have a range of 1024 m/m, while the vegetation may only have a range of x512. They can dynamically load data in their respective channels without interfering with each other. another technology suitable for this map storage method is that you can add some pre-read windows in the mapfile system (the specified range of blocks to be pre-read ), then, the underlying layer can transparently load the data using multi-thread pre-reading. We can set up multiple pre-reading windows at the boundary of the map to make the dynamic loading of the map smoother. The structure of the mapfile system is still very simple, but it is still a little troublesome to implement. First, it is impossible to store a file in a block. There will be no number of files, but the whole map cannot store only one file, because we need to take into account the version control of each block. therefore, the concept of field is introduced in the implementation of the mapfile system. A field is a large area and is currently 256 m x 256 m, that is, 64x64 blocks, the data of a field is saved as a file, so the checkin/Checkout block is also carried out in field units. because a field contains multiple blocks, and each block requires independent data writing, the specific code implementation is still a bit difficult. The field file is divided into clusters, dynamically allocates the required Cluster Based on the Data size of each block and links these clusters. please note that the reading efficiency of this storage method is very low, because the data of a block is not stored in the file in a continuous manner, read a block It may cause the head to jump in and out of different locations on the hard disk. in addition, although field is used to reduce the number of files, the number of files on a large map is still too large. Therefore, I finally wrote a new mapfile system, the whole map is packaged into a map file, which is used by the mapfile system to read the map file. this package is only used when the game is released. Because the package is read-only, block data in the package can be stored in a continuous manner, improving the reading speed. the old mapfile system is only used for editing. of course, the interfaces of the two mapfile systems are consistent with those of the upper layer. The file system is like this. Next, let's talk about the string.

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.