The second task for the flocking simulation is to create a tool for handling configuration of the simulation. We are given a list of options that need to be configurable. The data also needs to be saved so that the simulation can be recreated between computers.
One of the suggestions in class was to use C# Windows Forms to create the configuration tool. Since my only experience with C# so far is within Unity it seemed like a good opportunity to learn how C# works outside of Unity. My initial plan going into this task is to create a form that can save/load settings as an external file (.xml or possibly .csv) and launch the Flocking Simulation. The simulation itself will need to be altered to read in this file and use the data it contains when starting.
To start with I looked into how to actually launch an external program from within C#. This ended up being fairly straightforward (Process.Start()). The issue however was passing the data entered into the form to the flocking sim when it was started. On the C# side it was simple, add the arguments to a string and put that string in the Process.Arguments variable. This meant that data was passed to the flocking sim in the same way you add parameters when launching a program from the command line.
The C++ side was a different story. At first I tried receiving the data as a string and converting that into an array of input variables. When this didn’t work I did some research and learned that I need to use argc and argv in order to get the input (int main(int argc, char** argv)). Now that I had the data i needed to convert it into a format that would be easily usable within the code. My first thought was to create a struct that contained all the relevant variables, meaning they could be accessed with inputData.agents.The issue with this idea was the amount of code required to manually convert each varaible into its specific variable in the struct. My alternative solution was to create an enum that named each variable we needed. By using the same enum on both the c++ and c# sides of the program we can ensure that values are in the correct order.
Once we convert the data from the form into an array:
Because the argv data also contains the name of the application (in argv) we have to take the value +1 to place it in the write element of our data array. With the data in the array I can then call it wherever I need in the main function with inputData[enum name]:
With that working I just need to get the rest of the data inputs placed on the Form itself and then add the relevant points to the c++ code.