lua-users home
lua-l archive

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


Hi, Dan

>From my experience - just avoid calling scripts EVERY frame (eg onTick()
handler). Usually most scripting is required for special situations:
dialogs, taking damage, mission start etc., times for running those scripts
will not affect performance much (even if they are relatively complex)
because they are not called often.

Just for example, you can refactor this code:

function unit:onTick()
    self.pos = self.pos + self.speed
    local enemy = self:SeeEnemy()
    if enemy then self:Fire(enemy) end
end

into this:

unit.speed = speed
function unit:onSeeEnemy(enemy)
    self:Fire(enemy)
end

Best Regards,
Grisha

----- Original Message ----- 
From: "Dan East" <dan@naxs.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, June 10, 2004 7:50 PM
Subject: RE: LUA Shell inside my application


>   Roughly what is the performance difference from say calling 100 scripts
> (from C), verses calling a single script that performs the same work as
the
> 100 individual calls?  In other words how bad is the penalty for turning
> execution over to LUA (assuming everything is precompiled).
>
>   I am also in the process of incorporating LUA into my game engine for
> similar use - where the content creators can write script handlers that
> process every entity instance.  The actual scripts will be short and
> simplistic, but they would be called often.  It best suites my object
> oriented paradigm to have lots of calls - that is how my current C++
> handlers function.  However I can arrange things differently if there is a
> substantial penalty just for calling into LUA.
>
>   This is mainly for Pocket PC use, so I've been hesitant to provide any
> scripting at all because performance is incredibly important (most of my
> critical routines are hand-written ASM), so it is a huge step in the other
> direction to support scripting.  However my thought is to allow content
> creators to design a game via scripting, and once they have things
finalized
> I could then rewrite their scripts in C purely for performance.  3rd-party
> mods could still be done in LUA, however there would be some performance
> penalty.
>
>   Dan East
>
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Grisha
> Sent: Thursday, June 10, 2004 10:36 AM
> To: Lua list
> Subject: Re: LUA Shell inside my application
>
>
> Hi, Andreas
>
> I can't advise calling any script for every object per frame, but if your
> object count is small probably it'l work fast enough. Generally Lua is ten
> times slower than C code (which is good for scripting language), but
> probably you will need to benchmark your scripts yourself.
>
> Lua does have the ability to precompile scripts, you can take a look at
the
> luac.c file in your lua distribution. Note that scripts are compiled on
> load, so compiling in advance will reduce only load time, not execution
> time.
>
> regards,
> Grisha
>
> ----- Original Message -----
> From: "Andreas Volz" <lists@brachttal.net>
>
> > Another reason I like to embed LUA is because I want to give users the
> > ability to write LUA scripts which are executed every frame, give data
> > to LUA, do some "things" and give them back to C++. Is LUA fast enough
> > to so this (25fps)? It's not much data, only 5-10 objects with some
> > x/y/z/angle data. Perhaps LUA has the ability to precompile scripts or
> > cache them if they're used very often?
>
>
>