lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 19/01/10 15:42, ingmar wirths wrote:
[...]
> My questions now is: how efficient is this solution? How does it scale?
> Is this approach still sound, when the user controls severel hundred
> or maybe even
> thousends of units, all with there own lua instance to be evaluated every frame?

Lua instances are reasonably lightweight. It's feasible to run thousands
of concurrent Lua states; it's a rather extreme thing to want to do, and
you'll need hefty memory requirements, but it *can* be done.

Incidentally, you probably want to look at Lua Lanes:

http://luaforge.net/projects/lanes/

It's a library for running multiple concurrent Lua states, together with
lots of nice IPC mechanisms for communicating with them. Each state is
run in its own thread.

> What is generally done in computer games concerning this problem?
> (Even if the user
> is not permitted to modify the AI)

It's possible to run all your AI routines in a single Lua state, using
Lua's own sandboxing facilities to isolate them from each other. This is
the lightest weight approach. The big disadvantage of this is that an AI
routine can, say, loop infinitely or use too much memory, which will
upset your entire program. (There are some hacky workarounds, but
they're still quite hacky.) This isn't an issue in most code but if
you're letting the user write their own AI scripts you'll want to think
about it. Running each one in a separate Lua state (and thread) avoids this.

- -- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "Money is a sign of poverty." --- Iain Banks
│
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktV194ACgkQf9E0noFvlzj7xACdFHuuJoJg6mV1viwVu6ODZNfR
d5sAoID8EIrQqbdOKkEi+EPE5dQlmfVH
=LofO
-----END PGP SIGNATURE-----