In this assignment we start to explore lua and the ways it can be used to help us in the build process. We aren’t writing too much code in this assignment, we will be offloading the shader build process to a lua file with the help of code provided by our Professor John-Paul (JP). Therefore the learning in this assignment will come from understanding the build process and where lua fits into this.
First we needed to get the Lua compiler and Lua executable projects compiled into the right folder with the right name so that we could use it to compile the lua files that are being added to the project. Secondly we had to import the new files that JP provided which use the Lua apis to expose functions that the Lua script can call. Part of the assignment was to “fill in the blanks” in these files with the right code to get the project working. Finally I had to add code in the lua script to make sure that it builds the right shader files.
The file that actually does the building is “AssetBuildFunctions.lua”. To make it faster to load and process, we use the Lua compiler to create a binary file when we make a Release build of the application. This is what the insides look like post lua compilation.
As I mentioned earlier, compiling the lua files before leads to faster loading times because the byte code is smaller than text and is faster to execute. Additionally, compiling helps catch any errors. However, compiling doesn’t prevent run time errors, therefore any time we need to change the code we cannot do it easily, we have to recompile the file to use it which can be time consuming.
The last part of the assignment was to use the all the knowledge we gained to create a settings.ini file that would allow the user to change the application resolution at runtime. This part took me longer to figure out than the rest of the assignment. Creating the actual ini file and making sure it was getting copied into my output folder was pretty straight forward. But I could not, for the life of me, figure out why the lua script that was supposed to copy it into my game folder was failing to execute the command. After wrestling with it for about half an hour I realized that I had to call the “CopyFile” function declared in the C++ file instead of trying to execute the windows copy command using the “ExecuteCommand” function. After I got everything copied correctly, the file worked like a charm. Here is the comparison between the original window (512x512) and the new one which is 800x600.
The settings.ini file allows flexibility in allowing the user to choose the resolution they want without having to recompile the game. The player would want to do this for many reasons, I remember doing it for certain games because my measly graphics card couldn’t handle higher resolutions and I always had to run my games in 800x600. We also copy the file as it is without compiling it because that would be unreadable gibberish and hence not easily editable.