With the deadline to push for a polished beta build of our game closing in fast, I really want to bring my focus back to fixing the MT-D*-Lite issue. But of course, things rarely go my way. With the multithreading system in, I managed to integrate A* with ACO into our game without any major performance hits. However, upon further testing, multiple issues arise.
The first being the game would lock up on occasion when there are many enemies alive and turrets are placed which then causes all the enemies to try and re-path (an unfortunate drawback for A*). While this seems relatively harmless, since I have moved the A* calculations onto threads so it does not hold-up update calls, I have forgotten that I had also multithreaded physics collision. With the previous threading system setup, I have a job queue that threads pull jobs from. I start threads at the start of our engine and the thread waits until there are available jobs in the queue or shutdown is called. But therein lies the problem. I push both A* calculation jobs and physics jobs into the same queue. There is a limited amount of threads that can be running simultaneously. Thus, if the queue is first flooded with A* calculation jobs, it has to first process all those jobs before it gets to the physics jobs that are pushed in later on in the queue, and therefore, causing updates the wait and hangs the game.
To resolve this issue, I have decided to create two separate queues. One for critical game stopping jobs and one for other jobs that are not essential for the game to run smoothly. Additionally, I set aside a percentage of threads to dedicate only to process critical jobs to avoid the chance that all threads be occupied by non-critical jobs which we also cause the game to hang.
Another major issue this week is our game freezing during restart while there are still enemies alive. This poses a similar issue as the previous where the game hangs because it needed to first complete all the running jobs. More precisely, on restarting, all active enemies call a function that destroys themselves. However, this logic does not execute and resolve until our game goes through a late update, which gave enemies the time to continue adding jobs to the queue for pathing. By the time the enemies are actually destroyed, the job queue is flooded with these pathing requests which the threads continue to process until the queue is empty, thus, causing a performance spike with the game. To address this issue, I implemented a mechanism so that the queue will stop accepting jobs as soon as the restart is called and additionally, it also clears all jobs in the queue as they are no longer valid. While further testing is required, our game runs quite smoothly now.