I’m studying software development and am currently studying up on threads and concurrency. As I read through such materials I get excited and start wondering about game development. Eventually I’d like to endeavor in small personal game projects to help solidify my personal understanding of coding methodology, and I can definitely foresee the most daunting task would be planning out multi-threading for pseudo-A.I.
Perhaps this is the wrong board to post to, or even the wrong forum, but the community here is awesome and I feel like if I can get a solid answer I could understand how StoneHearth works under the hood a little better - and thus multi-threading as well.
I guess my question is to what extent should you multi-thread for A.I.? To elaborate what I’m trying to understand, consider the various needs of the Hearthlings:
Individual stats and states.
With just those 4 things it seems like you have what is necessary to have a relatively complete A.I. But how do you break those up on a technical level?
The way my nubile mind would attempt to tackle these are:
Pathfinding: 1 thread for pathfinding that receives the location of the Hearthling and the requested destination, maps it out, and passes back vector information to the Hearthling in an array that he/she can work through.
Tasking: 1 thread for job tasking that hands out jobs to the most proximate/available Hearthlings.
Stats&States: 1 thread for Hearthling management that iterates through each Hearthling and updates their stats and animation states based on their tasks.
Environmental Awareness: 1 thread that iterates through an array of special objects that ping nearby Hearthlings for pseudo-awareness. For example, a Hearthling is killed by a goblin and its corpse (the object in question) is on the ground… and every 200 milliseconds the body would attempt to “ping” the nearest Hearthling within a certain radius and either delegate a task or change the state of said Hearthling - maybe sending the Hearthling into a state of alarm or caution, or take the corpse to a graveyard.
How acceptable or not is this line of thinking?
Should each Hearthling have their own thread instead?
How many threads would be too many for a game?
I’ve tried to do some reading online on multi-threading and A.I. but I’m not entirely sure what it is I’m actually looking for as I search … and the answers aren’t as specific as I’d like, leaving me ruminating over this
Any thoughts or resources the community can chime in with would be helpful!