Eighth back string Library A lot of strings are used in game development. The most common is various texts on the game interface (such as buttons ), in addition, during the development process, the editor user will edit a variety of Game objects and usually give them an intuitive name, so that when these objects are used, you can easily identify them. there are also some strings similar to XML tags that can be used to define some formats (such as <font: 12, color: 255, 0, 255>, used to describe a font format ). user-defined messages can also be represented by strings. wait. Extensive use of strings is crucial to a user-friendly editor. however, some features of a string are not very good. The worst thing is that it is a piece of variable-length data, which is inconvenient for copying or storing data. then it has a large amount of data, which can be used to compare or make hash keys, which will affect the performance. another point is that the string is prone to errors, which may cause unnecessary troubles. wait.
However, I always think that the intuitive and easy-to-use of the editor is the first, so I still use a lot of strings in the engine. later, I came up with a way to reduce the inconvenience of using strings, that is, creating a string library and throwing all the strings used in the game into this library, A four-byte ID is used to represent this string. This library can be accessed throughout the system. Therefore, if you have a string ID, you can pass it to any part of the system or copy it to save it. This is more convenient and reliable than maintaining a const char * or STD: string, more efficient. of course, to use such a string library, we still need to have enough editor support. first, you must write a dialog box for editing the string library. It is the string edit box in the engine. (You can easily see its functions on the interface ):
Second, you need to enable users to use this edit box to edit the game object data. this is not a very troublesome task for our engine, because most objects in the engine have object description information (see the previous article ). <Fifth re-Object Description Description: makes it easier to use an object.> ), All we need to do is add a string ID semantics (Sementic) to modify a DWORD string ID variable, and add the corresponding semantics to the property grid. is the property list of a button object:
The red box is the name of the button, represented by a string ID. Click... to edit it in the string editing box that just appeared:
The blue box contains four other string IDs, which correspond to the font formats of buttons in different States. Note that the string ID is used, therefore, these format strings can be easily shared by buttons of similar styles. (You can also find them in the preceding dialog box) Note that in a multi-person development environment, the problem of mutex edit must be solved. Therefore, when the edit box is displayed, the string library is checked out automatically, after the edit box is closed, check in automatically to ensure that only one computer can edit the string Library at the same time. since string editing is generally a very short process, there is little chance of conflict. this is a concise solution, which is much easier than trying to remove several strings from merge. Finally, another potential benefit of using string ID is that it can provide international support for the game. The string library is a simple concept, but I still like it very much. So here I will introduce it and hope to inspire you. Next I will talk about a very important thing in the system: stub.