Game file system solution

xiaoxiao2021-03-06  21

Analysis and establishment of game file system

I Objective:

Implement a highly integrated, easy-to-operate file management system, can work closely with other engines.

The emergence of II:

When establishing an engineering, you will often use a large number of WAV BMP JPG MP3 X and other resource files, as well as Script script files, configuration files, and more. We are facing so many files that don't care about the complexity of the project's document management (or habits ). But considering the user and the security mechanism, you do not want other resources to make changes to some resources. (Such as scene configuration, task script). Or a lot of resources will spend a lot of space inside the hard disk. (Small, zero-scattered). As well as other issues (copyright, etc.). Therefore, there is an urgent need for effective management of resources, and try to reduce the complexity of the use. Most games are doing this of.

III solution:

Using a file package, when you need it, it is necessary to determine the required file in the resource package (which is assumed to be a PAK file), and then convert to the MemoryStream supplied to DirectX or other engine.

IV concrete implementation: The above seems to be very simple, but it is really difficult to achieve the expected goal. If you adapt to Game, you should meet at least the following conditions.

1 basic packaging, extraction function

2 Structured directory management, to clearly understand the file inside that package

3 The difficulty of use is not too complicated, close to the complexity of direct reading

4 Consider the update problem of network GAME

5 Because it is the file system you created, you have to do management tools yourself.

6 Since it has been updated, then the version control is also considered.

A relatively large engineering ...

V There are currently two solutions.

1 Simple packaging package file (hereinafter referred to as A-Type)

Advantages: simple, small code quantity. High efficiency, simple architecture, strong expansion, and earth people do this.

2 Implement with a small database (hereinafter referred to as B-TYPE)

Advantages: More rich control, and relatively sound security mechanisms, compatibility, and security.

The above two mechanisms are to simulate the physical operation of the disk, avoiding the direct operation of the file in the future. It is only the media that reads and writes is different when the final implementation is different. If you are interested, you can do an abstract class and then implement it. These two mechanisms. (But I am not interested)

VI Let's talk about the steps

Read operation:

1 Create a ClassDatacenter

2 Put the required bag loadpak into Datacenter

{Class internal implementation: Each additional PAK is loaded with the list to memory

Put together each file list into a full file list, at this time, the true needed file is filtered by the version control mechanism.

Implement the generation of directory trees based on a complete list.

3 Return to data stream with classdirectory.getfile (namespace)

{Internal implementation mechanism:

If Namespace has no path, and then it is directly returned.

If the Namespace has a path, remove the current directory, recursively implementing getfile (namespace) knows the return

After finding the file, it is a ClassFile object, and use the object's classfile.getStream to get a data stream.

}

It can be seen that in addition to the initialization of the start, use it with a general file operation complexity.

Write action:

1 Create a PAK object (Classlibrary)

2 Create a ClassFile object, set the object properties

3 Classlibrary.createFile (classfile)

Final Dispose

In addition to the initialization, the write operation is comparable to the complexity of the direct write file.

VII uses database operations

1 Using the database to meet most of the target proposed, after actual testing, insert a large file binary data, it will cause considerable burden to the system, but the massive small-scale data is excellent. You can easily complete the modification and delete work. (In terms of Atype, the insertion and deletion is indeed simpler) is not as good as ATYPE.

2 Decide to use the database to operate still need to solve it by many problems.

A Data Inventory Take all configuration information, so you must make your own response tool to read and write configuration, and the text file can be used with NotePad.

B Upgrade control is inconvenient, if all inserted into the main library, this library will become very large, or a CD can not be installed, and it cannot be downgraded (a special downgrade tool) is very poor, it becomes difficult to maintain, if there is Players customize the task, using this method of frequent rewriting the database is unrealistic.

The solution is that each package, similar to the ROMS mechanism of the simulator, except for the main library, and the public library, other things are placed under the ROMS directory, and when you need it, you also have the shortcomings, every time Before you begin, you must first scan all registered libraries, which means there will be a lot of connections and adapters, and with the increase of the number of libraries, the cost of complete random access consumption is not anger. At the same time, you can find that except for the first In order to ensure integrity scan, the file reads after the game is generally required to support the support of two or three libraries (otherwise indicating that your resource organization is unreasonable). And some libraries (such as the main library) After reading is complete, you can completely release it immediately, save resources, and load all the configuration information into memory.

D In short, don't try to load all the libraries, you can't imagine what extent slowly.

3 If the overhead is so large, it is necessary to establish an adapter buffer pool (that is, the connection buffer pool)

VIII file system needs to complete the task

1 File list summary.

When using the file system, it is as simple as using a Windows file, and must contain version control, and ultimately needs to be converted into stream and Windows file system interaction.

2 multi-storey "class distribution" system

Perhaps this hat is a bit big, but this is indeed close to the data warehouse. Manage multiple libraries and their interactions, you need to understand the contents of each library (otherwise you can't achieve local files)

In the primary library or memory built-in, a table is used to describe the index of all library files (maybe a collection or dataset) and then look up the binary file stream according to the index.

Such physical layer participating file structures are completely separated from the logical layer directory structure (Tian !! We made a set of drivers)

3 view

When the user reads the scene, you can use the view to get the data. Due to the characteristics of the database, some security mechanisms can be easier to implement, such as access access rights, etc. Here, the purpose of using the view is to reduce data lookup work, security Second, after all, this is not very important.

IX structure relationship diagram

X object description

XDATACENTER

Inheriting Hashtable

Convergence used to manage library files and complete the list of original files

.addlibrary (Key as object, FileName As String)

.addlibrary (Key As Object, Targetlibrary As Xlibrary)

Add a library while giving together all of his files list

.removelibrary (key)

Remove a library while removing the list of files he contained

.items library list.

FileList As XfileList The current list of all libraries.

CreatedIRectory () As XDirectory

Class XFileList

File list, each member is a XFile object

Inheriting Hashtable

AddFile (Key, TargetFile As Xfile) Allows dynamically add XFile objects

Removefile (key) allows dynamic deletion of XFile objects

Item Xfile Collection

getFile (Namespace As String) AS XFile

Return XFile according to Namespace

GetStream (Namespace As String) AS MemoryStream

Return to the stream according to Namespace

Xlibrary

Used to indicate library files, can be a PAK file or to represent a database. Can be used to physical operation on the file. Other object file operations are actually made by it.

Inherit Object

Createfile (TarfileStream As FileStream, Tarfile As Xfile)

The file exists on a disk, file extension information from TARFILE

Deletefile (Namespace) // database support, file operation is more complicated

Delete the file of the library namespace location

getFile (Namespace As String) AS XFile

Return XFile according to Namespace

GetStream (Namespace As String) AS MemoryStream

Return to the stream according to Namespace

Getlist () as xfilelist

Returns all files lists in the current library

XDirectory

It is used to represent a directory structure, which is convenient for enumeration. Of course, this class is not necessary, using it to be convenient to enumerate Object

New (xdatecenter)

New (xfilelist)

New (xlibrary)

Transform the list to the tree

Parent parent directory

Name own name

Items (Namespace AS String) Returns XFile

DIRS (Namespace AS String) Returns XDirectory

Path Current Full Path

Dispose destructure, release all of its Directory and File

Class XFile

Used to represent files

Inherit Object

method

GetStream gets the stream of files

UPDATE Update Record // If it is direct file access, then this is still

Delete Delete Record // If it is a file access, this will not be necessary.

CreateNew (Namespace, FileStream)

CreateNew (Namespace, FileName)

Establish a new file

Extract (filename as string) export file

Attributes:

Library specifies the Library sitting, and finally calls Xlibrary to return data stream.

Author author

The location of the Namespace file in the library

Version file version

Filename raw file name

... .. Content inside other data sheets

Xi usage

You can use Xlibrary's direct NAMESPACE modification to protect the use of xdirectory.

For atype

You can allocate two files, one is the index file specifically used to store the index, and the other is a Data file for storing data.

A Index file contains a structure for random access

For example Struct Sfile

{

SSIZE structure length

VER version

Beginpos start position

Endpos end position

INFO Other Information

}

Then read a piece according to the size of SSIZE, traverse all blocks to the memory general

For databases, recommended table structure

Three sheets

The configure table is used to store the information of the library. For the main library, the game configuration information, etc., the game is different, and the content stored is different.

Files table is used to store file information, which is equivalent to all content of Atype's INFO field. Since database processing is more convenient, it can be completely separated and mapped to the XFile class (add his attribute after inheritance)

The DATA table is used to store binary data, associated with FILES's NameSpace or other keys, determine when using the xlibrary.getStream () method.

转载请注明原文地址:https://www.9cbs.com/read-43535.html

New Post(0)