- Joined
- Dec 9, 2008
- Messages
- 52
Ok here's a problem I came across that I've solved, but I'm pretty sure is just some crude hack. I'm looking to see if any experienced people have a more kosher way of solving this.
I have some basic AI for a couple dozen units, and I have to check on them every second to make sure they're not being stupid. That's not the issue. The issue is how do I stagger my calls so I don't have 99% of the game time not being used to compute their AI, and then 1% of the game time being lagged by having to do a lot of work in a few microseconds.
My solution is to assign each unit a random number between 1 and 100, and then I make a call every 1/100th of a second. And then I check each unit's random number, and if it matches which 100th of a second it is, it does the action. This way everything is staggered. I realize, however that this is a pretty ghetto way of doing things and would like input on perhaps a more standardized method for solving my problem.
Thanks!
I have some basic AI for a couple dozen units, and I have to check on them every second to make sure they're not being stupid. That's not the issue. The issue is how do I stagger my calls so I don't have 99% of the game time not being used to compute their AI, and then 1% of the game time being lagged by having to do a lot of work in a few microseconds.
My solution is to assign each unit a random number between 1 and 100, and then I make a call every 1/100th of a second. And then I check each unit's random number, and if it matches which 100th of a second it is, it does the action. This way everything is staggered. I realize, however that this is a pretty ghetto way of doing things and would like input on perhaps a more standardized method for solving my problem.
Thanks!