It's been an interesting month. I've not made much progress on new features but once I started adding AI cars into the game it uncovered a few issues.... so I've been focusing on fixing those.
1, 2, 3 ... er
As I'm now able to add AI cars to the game I thought I'd add some code to show the current race order. Unfortunately that's where things went awry...
The main issue was that the lap counter would sometimes lose count, particularly for the player car. Obviously being able to count the number of laps a car has done is fundamental to circuit racing. The AI cars accurately keep track of the number of laps completed but the player car would value would drift and end up one to two laps off. Fortunately the issue turned out to be fairly simple and one that was only triggered when more than one car was on track. This was why I hadn't spotted the issue when I'd written the lap counter code and it only came to light at this stage. Easily fixed though.
The second issue was that there was a bug in the code that works out the split times between the player car and the car ahead and the one behind (as appropriate). This worked reasonably well but there was an intermittent issue whereby the time for the split to the car behind would occasionally be calculated as over 20 seconds when the gap was actually much, much lower. This turned out to only happen when cars were on different laps. So, when the lead car crosses the start/finish line it's a lap further on than the following car. At this point the code should look to the previous sector entry times to determine the split. Instead it was using the current sector of the lead car and looking back a lap to when the following car entered the same sector - which explains the discrepancy. By the time the split was next calculated the cars had often moved to another track section and the code got the comparison correct and showed the correct split time.
I'll be back working on the AI code for rival cars.