I thought that maybe the # of active sound channels had been exceeded, even after adding my sound culling code the other day to remove far away / quiet non-looping sounds.
When I added some code to print out the # of active channels, it was never going beyond 12, even in the most extreme conditions.
Early this morning I finally found & fixed the issue. Every frame, I loop through my sound instances, and query the sound library to see if they are still playing, If not, I queue them for deletion.
On deletion, I stop the sound ( in case it was requested to stop and hadn't stopped on its own ), and then delete the sound instance.
Turns out the issue was that, using SDL_mixer, looping sounds will return that they are not playing if you catch them right before they loop around again, causing me to delete a sound that was about to loop again. So, the fix was simply to not delete looping sounds if they say they have stopped playing.
I verified this works by logging the issue about 30 times over several hours of testing while I went to sleep. What a relief - I can't stand those intermittent issues - so hard to isolate & debug.
Here is an older shot of a cavern level, without the new lighting fixes, with a very busy battle ensuing.
Yesterday I re-factored part of the AI to support target selection based on teams. The plan is to have the player able to walk in on or observe battles, and also initiate them between different factions from time to time.
Each sentient AI has a team tag, and every second or so, will scan its nearby environment for enemy entities, and add it to the list of known active enemies. Every so often, the AI will re-evaluate its target selection from this list. For now, the AI will pick the nearest target to attack, while giving its last target a 20% bonus to keep it from switching targets too often.
This should reduce the # of raycasts done and also allow for cool gameplay scenarios.
Once this is working, I plan to extend it by having the AI creatures have a more realistic field of view, and having them turn their head from side to side on occasion. I want them to look around as if bored while wandering or when on patrol, and look aggressively while aggro.
Also added some more level editor options, so that you can directly rotate & scale a selected set of triangles without making it a mesh first, and also a button to force tris to keep their tex coords and not regenerate them when you are manipulating them in this way.