Erik Hofman wrote:
What method would you recommend for a script that basically has to run forever.
What I'm trying to do is add continuous motion to the sailship by interpolating between +10 and -10 degrees pitch, but I haven't found a clue on how to do this with Nasal.
Probably the best way to do this is with interpolate(). This code should swing the pitch linearly between -10 and +10 and back 5 times over 10 seconds, and then set a timer to do it again:
rockBoat = func { # Arguments: property, value, delta, value, delta, ... # Start at 10 degrees immediately, then back and forth five times: interpolate("/sim/ai/wherever/boat/pitch-deg", -10, 0, 10, 1, -10, 1, 10, 1, -10, 1, 10, 1, -10, 1, 10, 1, -10, 1, 10, 1, -10, 1); # When we're done, start it again: settimer(rockBoat, 10); }
I tried this with a linear interpolation table but I think a problem right now is the fact that the timer is frame rate dependent. And since I'm running at a frame rate of about 5 frames per second this can be a problem.
With a little work, you could populate that table with random numbers, etc... This avoids the need to run a Nasal script every frame to iterate your animation; the interpolator is a C++ module.
A useful feature that doesn't yet exist would be the ability to register a callback function for the end of an interpolation; this would eliminate the need for the settimer call and any race conditions that result from slightly different timeouts.
That would be really nice.
BTW. No need to hurry on this, I was just experimenting with Nasal a bit and (although I would get something like this implemented sometime) the code to add an AI model using Nasal isn't available either.
What you are asking for, the ability to run a script in a loop forever, will require more work. This would essentially be a multithreaded interpreter, and the NasalSys subsystem would have to maintain separate execution contexts for each thread. That is, by design, supposed to work in Nasal, But for this kind of animation problem, it's probably not the right solution. The per-thread overhead is rather high.
Agreed, an event method would be best, but I couldn't find the right solution.
Erik
_______________________________________________ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
