Re: [Flightgear-devel] timer help
eagle monart wrote: > i am tryng to add a delay in seconds before activation/ > deactivation of cockpit functions. my aim is to declare > specific drag according to time within component cycle time. i > am trying to add an example decleration for that purposebut > function goes too..infinite!!! or totaly > frezes sim . Well, first, we seem to be talking about different things. I thought the question was about how to use settimer() in a Nasal script, whereas these are modifications to the C code in LaRCsim. Second, as a more general suggestion: please get your whitespace under control. Different programmers have different ideas about where braces go, how many spaces to use for indentations, whether tabs are legal, whether whitespace should be used around parentheses, etc... But no one should be forced to read stuff like you posted. I honestly had to read through your (non-code) text several times just to be sure it wasn't a joke. :) Third, the clock() function you are calling is not what you think it is. It does not "wall clock" time, but CPU time used by your current process. These aren't likely to be well synchronized. And finally, trying to wait like this is never going to work well. FlightGear has a main loop that it needs to execute every frame. When you block waiting on something to happen, you are blocking the entire simulator. The proper way to implement this kind of feature is to "poll" for changes every frame, and set some kind of "state" to know what to do each update. Honestly, my suggestion is to leave the C/C++ code alone, study the existing aircraft to learn how they are configured using XML and Nasal, and try to implement your feature at that level. Andy ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
RE: [Flightgear-devel] timer help
eagle monart wrote > > > > >And, as always, posting the code you are having trouble with is much > >more useful than simply announcing that different versions start > >infinite loops. :) > > > >Andy > > i wrote different functions here is few examples. by the way i am writing > these to the larcsim c172aero also added time.h under msvc7.1. > > i am tryng to add a delay in seconds before activation/ deactivation of > cockpit functions. my aim is to declare specific drag according to time > within component cycle time. i am trying to add an example decleration for > that purposebut function goes too..infinite!!! or > totaly frezes sim . > > my first try > // travel time speedbrake drag coeff=1 after travel comp drag=1 // itt > logic checker to break loop > > if( Speedbrk) { if (itt==0) > start_time = clock(); > while((clock() - start_time) < 3 * > CLOCKS_PER_SEC) > { speedd=1 ;itt=1; > } } >speeddd=1.7; } > > > another try > > > double delwait ( double seconds ) > { > double checker1,result1 ; > checker1= clock () +seconds * CLK_TCK ; > result1= checker1-clock(); > return (result1); > } > if( Speedbrk) { if ( itt==0 ) {ni=delwait(2); > while (ni>0) { speedd=1; itt=1; } > } > else { speedd=1.7 ;} > } > > > another try but frezes whole sim > > wait ( int seconds ) > { > clock_t endwait; > endwait = clock () + seconds * CLK_TCK ; > return(endwait-clock()) > } > > if( Speedbrk) { if ( itt==0 ) { while ( wait (2)>=0) { speedd=1; > itt=1 }} > speedd= 1.7 ;} > You will find an example of a time delay function in ~/Aircraft/Spitfire/models/spitfire.nas. Look for the code following # Coffman starter stuff == This particular fragment was written by Melchior Franz. Regards, Vivian ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
Re: [Flightgear-devel] timer help
eagle monart wrote: > i am totaly lost. i ve tried different declarations of delay > functions but they starts infinite loops. i tihnk nasal expalined > only for xml usage but i didnt find a source to declare settimer() > in a source code . I need a reference... The documentation for the function is at http://plausible.org/nasal/flightgear.html (at the bottom of the file). It explains how to write Nasal in XML files as well as how to write stand-alone files. The settimer() function is a C++ extension function, it is defined in src/Scripting/NasalSys.cxx in the source code. And of course you can look at the existing Nasal code, all of which uses settimer() extensively. You can grep through all the existing nasal files with something like: cd $FG_ROOT find . -name '*.nas' | xargs fgrep settimer And, as always, posting the code you are having trouble with is much more useful than simply announcing that different versions start infinite loops. :) Andy ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
Re: [Flightgear-devel] timer help
On Saturday 11 June 2005 14:15, Roy Vegard Ovesen wrote: > > settimer(foo(...), time) > > where foo(...) is the function to call and time is the delay in seconds. > This will call foo(...) in time seconds from when settimer() is called. > > Here is a function that repeats, or calls itself every 5 seconds. > > foo = func > { > # Do something really neat > > settimer(foo(), 5.0); > } > > This is of course an infinite loop. If you want to stop the loop you have > to check for some condition and simply not call the settimer function: > > foo = func > { > # Do something really neat > > if (stopTheLoop) > { > # Do nothing > } > else > { > settimer(foo(), 5.0); > } > } Whoops! Replace foo(*) with foo wherever it appears above. -- Roy Vegard Ovesen ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
Re: [Flightgear-devel] timer help
On Saturday 11 June 2005 13:44, eagle monart wrote: > > i am totaly lost. i ve tried different declarations of delay functions but > they starts infinite loops. i tihnk nasal expalined only for xml usage > but i didnt find a source to declare settimer() in a source code . I need > a reference... settimer(foo(...), time) where foo(...) is the function to call and time is the delay in seconds. This will call foo(...) in time seconds from when settimer() is called. Here is a function that repeats, or calls itself every 5 seconds. foo = func { # Do something really neat settimer(foo(), 5.0); } This is of course an infinite loop. If you want to stop the loop you have to check for some condition and simply not call the settimer function: foo = func { # Do something really neat if (stopTheLoop) { # Do nothing } else { settimer(foo(), 5.0); } } -- Roy Vegard Ovesen ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
Re: [Flightgear-devel] timer help
eagle monart wrote: > > > are there any references to use time delay in functions. i am trying to > delay speedbrake for 1.5 scnds everytime activated or deactivated in > larcsim . i tried to use sleep() functions in msvc71 but makes the > whole sim sleep:) > > i am looking for example time delays in fg source and would be happy if > anyonepoints... > > _ > Is your PC infected? Get a FREE online computer virus scan from McAfee® > Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 > > > ___ > Flightgear-devel mailing list > Flightgear-devel@flightgear.org > http://mail.flightgear.org/mailman/listinfo/flightgear-devel > 2f585eeea02e2c79d7b1d8c4963bae2d > You could easily do it in NASAL using settimer(). Josh ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d