Melchior FRANZ wrote:
> But only if the animation was triggered and as long as the movement
> lasts, which is a time where the "operator" watches the animation,
> anyway, and couldn't care less about a few extra cycles. Apart from
> that there should be zero overhead. Have I misunderstood the
> settimer command?

Your code works just fine.  But if settimer() was the *only* method
for doing animations via scripts, then *every* animation would be done
with a timer handler and we'd potentially have many timers going off
every frame.  It's easy to see every model (maybe a few dozen around a
busy aircraft) having many timers (blinking lights, rotating beacons,
rolling wheels...).

That's slow.  For numeric work, Nasal is hundreds of times slower than
equivalent C code; for string handling, it's more like 5x, and for big
allocation/hashtable work like dictionary searching it's probably only
twice as slow.  But still, thrashing at a script 20 times a second is
going to be suboptimal. :)

And honestly I find the interpolate() interface to be simpler and
cleaner than timers; what's supposed to be happening is smooth change,
but a "timer" represents a discrete event.

This is the (untested) replacement code I wrote for bo105.nas as a
sample of the interpolator stuff.  It goes inline in the -set.xml
file, rather than living in its own file:

 <input>
  <keyboard>
   <key n="67">
    <name>C</name>
    <desc>open/close rear door</desc>
    <binding n="0">
     <command>nasal</command>
     <script>bo105.toggleDoor()</script>
    </binding>
   </key>
  </keyboard>
 </input>

 <nasal>
  <bo105>
   <script><[CDATA[
    prop = "/controls/rear/door";
    swingTime = 2.5; # Time to swing from open to closed
    target = 1;      # Start closed, so initial target is "open"

    # Utility, put this in globals...
    abs = func { if(arg[0] < 0) { -arg[0] } else { arg[0] } }

    toggleDoor = func {
        val = getprop(prop);
        time = abs(val - target) * swingTime;
        interpolate(prop, target, time);
        target = !target;
    }
   ]]></script>
  </bo105>
 </nasal>



_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to