Handling AI
What is the best way to handle massive amounts of spawned monster's AI?
The current way I have is a linear handling of a list of mobs. In a seperate thread, I search for "awake" monsters. If they are awake, a doAI() function is executed. Otherwise the mob is skipped. Whenever a player walks into a room with a monster, that monster wakes up. If the monster is idle for a set amount of time (10-20sec), it goes to sleep.
The problem is a monster at the beginning of the list will get it's AI run faster, then one at the end. Also the more mobs spawned, the longer AI takes to complete.
The other solution would be to have each monster run their AI in a separate thread. But having 500 threads running at the same time would be a terrible idea right?
|