lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Coroutines are well suited for this kind of problem. You can easily create 10000
coexisting coroutines that yield. Using a manager that keeps track of all
coroutines and which executes coroutines that should be executed in this frame.
If the coroutine yields it could return when it should be called next (i.e.
returning 100 for getting called in 100 ms again).

Creating a thread for each AI would be inefficient, but you could use schedulers
(4-8) which run threaded. But this is really only required if your AI scripting
is the bottleneck. Otherwise it is a waste of time and a source of concurrency
errors. And it is not even said that it would improve the execution speed.

> I have designed the AI scripting for my project in the following way: 
> for each entity I execute the AI script every X ms. This works fine for 
> very simple scripts, but for more complex scripts I expect the program 
> to repeat a lot of basic tasks, like checking if entity is fighting, if 
> has to heal itself, etc. So, it is much better to suspend execution and 
> continue on next refresh turn that to spend CPU cycles on something 
> already done 100 ms ago. I thought in coroutines, but then I noticed 
> that i have to deal with 200-300 entities, which  represents 200-300 
> different scripts executed one after another.
> Is there some way to do this? Or perhaps I should redesign my AI system?
> 
> 
> -- 
> http://dsgp.blogspot.com | Linux, programación, juegos
> Have no place I can be since I found Serenity
> But you can?t take the sky from me
> 
> 		
> ______________________________________________ 
> LLama Gratis a cualquier PC del Mundo. 
> Llamadas a fijos y móviles desde 1 céntimo por minuto. 
> http://es.voice.yahoo.com
>