The scene file is a formal interface between the game engine and its client because it triggers a sequence of function calls to create a playable game level. With a game level defined in a scene file, the game engine must first initiate asynchronous loading, wait for the load completion, and then initialize the client for the game loop.
These steps present a complete functional interface between the game engine and the client. By examining and deriving the proper support for these steps, the interface between the game engine and its client can be refined. The Scene File Project This project uses the loading of a scene file as the vehicle to examine the necessary public methods for a typical game level. You can see an example of this project running in Figure 4-4. This project appears and interacts identically to the previous project with the only difference being that the scene definition is asynchronously loaded from a file. The source code to this project is defined in the Chapter4/4.4.SceneFile folder.
Keep in mind the ultimate goal of this project is to define the public interface methods between the game engine and a game level, or the client. While the definition/loading of a scene file is interesting, in this case it is but a vehicle. The following describes the definition and parsing utility for the scene file. It is important to remember these are only the tools for examining the required public methods for interfacing to the game engine.
The Scene File Instead of hard-coding the creation of all objects to a game in the initialize() function, the information can be encoded in a file, and the file can be loaded and parsed during runtime. The advantage of such encoding in an external file is the flexibility to modify a scene without the need to change the game source code, while the disadvantages are the complexity and time required for loading and parsing. In general, the importance of flexibility dictates that all game engines support the loading of game scenes from a file.
Objects in a game scene can be defined in many ways. The key decision factors are that the format can properly describe the game objects and be easily parsed. Extensible Markup Language (XML) is well-suited to serve as the encoding scheme for scene files. 1. Create a new folder at the same level as the src folder and name it assets. This is the folder where all external resources, or assets, of a game will be stored including the scene files, audio clips, texture images, and fonts.