Game Engineering-II |Assignment – 8
This assignment focuses on converting our user readable Lua file into a binary file during build time and making changes to our cMesh class such that it now reads data about vertices and indices from this new binary file.
Here is the executable MyGame_
- F1 – F2 — Move camera up – down
- F3 – F4 — Move camera left – right
- directional keys — move sphere
- SPACE — remove plane
The biggest plus of this assignment was that it decouples the graphics engine from relying on Lua to get Mesh data. (Also my cMesh.cpp looks much cleaner without any unnecessary Lua code!). This opens up the opportunity to use any kind of data format I need without having to change my engine code.
First off here is a screenshot of the game with data extracted from a binary file at run time.
Here is a binary representation of a mesh file.
There are various advantages of using binary file formats, but the two major ones that I can think are –
- Binary files are smaller than human readable files. The difference becomes visibly noticeable when the file sizes are large.
- Reading a binary file at run time is much faster than reading a human readable file.
For my solution the binary files do not vary from platform to platform (OpenGL/DirectX) since I handle winding order inside my Graphics engine itself i.e. after the mesh data has been read in during run time.
Here is the code which handles extracting data from the binary file.
Testing with a helix for measuring size differences between a binary and a human readable file, I created a helix mesh with 30000 vertices which brought the file size to 2.6mb. On converting it to binary the file size became 470kb. Now imagine hundreds of file like this with sizes > 10mb. The amount of space we save is very large.
Comparing the build times as expected the new configuration took about 7 seconds longer to build than before (when we did the parsing at run time)