[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Multiple lua instances
- From: David Given <dg@...>
- Date: Tue, 19 Jan 2010 16:03:45 +0000
-----BEGIN PGP SIGNED MESSAGE-----
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:
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.
┌─── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ───── 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/
-----END PGP SIGNATURE-----