Jump to content

Recommended Posts

Hi Tom,I want to use your technique for IAS rolling numbers and want the 10's and 100's to roll over. Your example formula to date did not show a formula for 10's.I have(A:Airspeed select indicated or true, knots) sp9 l9 int 10 @2 pow % 10 @2 1 - @1 1 - - 0 max pow / intthen(A:Airspeed select indicated or true, knots) 10 % for the units@E1IASDigit(1,1) s3 8 >= l3 8 - 2 / * @E1IASDigit(1,2) + for the 10's@E1IASDigit(2,2) s2 80 >= l2 80 - 20 / * @E1IASDigit(1,3) + for the hundredsI cannot get the 10's to work properly. When the units are rolling from 8 to 10, the 10's flick, say, from 5 to 5.5 then flick to 6. They do not roll smoothly from 5 to 6. What's wrong with,@E1IASDigit(1,1) s3 8 >= l3 8 - 2 / * @E1IASDigit(1,2) +cheers,nick

Share this post


Link to post
Share on other sites

Nick,I'll let you solve this by yourself :-)BUT, with a little hint:@E1IASDigit(1,1) s3 8 >= l3 8 - 2 / * @E1IASDigit(1,2)@E1IASDigit(1,1) reaches 8 and then?..goes to 9 directly and then to 0 again..No "fractionals" to help the rolling.When @E1IASDigit(1,1) is 8, @E1IASDigit(1,2) returns, say, 5 Then @E1IASDigit(1,1) goes to 9 so "s3 8 >= l3 8 - 2 / *" gives 0.5and @E1IASDigit(1,2) returns 5.5 ...etcGood luck! Tom

Share this post


Link to post
Share on other sites

Thanks Tom, I'm now pulling me hair out:-) So @E1IASDigit(1,1) is not giving any decimals.>and @E1IASDigit(1,2) returns 5.5 ...etc does work with decimal, so I tried,@E1IASDigit(1,2) s3 8 >= l3 8 - 2 / * @E1IASDigit(1,2)but now flicks with no roll whatsoever.Tried various combinations in the first @E1IASDigit(1,2 with no joy. Could you be a little more generous with the clues please,cheers,nick

Share this post


Link to post
Share on other sites

Hi Tom, something else that's interesting, @E1IASDigit(x,x) s3 8 >= is saying, when @E1IASDigit(x,x) is equal to or greater than 8, do l3 8 - 2 / *. How does this manage to do away with any 'if{ }' statements?cheers,nick

Share this post


Link to post
Share on other sites

Nick,How about @E1IASDigit(1,1) l9 d int % + s3 8 >= l3 8 - 2 / * @E1IASDigit(1,2) + Note: l9 is coming from s9 used in the macro. Test it and let me know :-)CheersTom

Share this post


Link to post
Share on other sites

>Hi Tom, something else that's interesting,>> @E1IASDigit(x,x) s3 8 >= is saying, when @E1IASDigit(x,x) is>equal to or greater than 8, do l3 8 - 2 / *. How does this>manage to do away with any 'if{ }' statements?>cheers,>nickI am using "bool maths" here. You know that any time "s3" is < 8 a 0 is placed on the stack, else is placed a 1. So, what I do is multiply the result of "l3 8 - 2 /" by that "stack factor" of 0/1 and add it to the macro's return. When s3 < 8 I add nothing (0).A way to do with if{ structure would be@E1IASDigit(x,x) s3 8 >= if{ l3 8 - 2 / } els{ 0 } Tom

Share this post


Link to post
Share on other sites

>Hi Tom, now that is VERY interesting,>many thanks,>nickYou can save a lot of "if{ els{" by using bool maths. The * factor gives 0/1 which is stored on the stack like any other value, maybe a float64 (as of Ron's tests); Any bool Lvar or bool value is placed with the same float structure, so there is no difference of using bools or * factor values. BUT, if{ els{ are stack's jumps, which have to consume extra cycles. Even there seems to be a limit of nested if{ as Jon did find in his test. The cost of using bool maths? less readability for sure. But, hey, maybe I'm going too far here..:-)Tom

Share this post


Link to post
Share on other sites

Yes. Happy to report it worked.Instead of your macro and the code line, that is,(A:Airspeed select indicated or true, knots) sp9 l9 int 10 @2 pow % 10 @2 1 - @1 1 - - 0 max pow / int@E1IASDigit(1,1) l9 d int % + s3 8 >= l3 8 - 2 / * @E1IASDigit(1,2) + I formulatedl3 10 % s4 8 >= l4 8 - 2 / * l3 10 / flr +and l3 coming from a previous line,(A:Airspeed select indicated or true, knots) s3 10 % This looks more lean to me.>But, hey, maybe I'm going too far here.. Not at all. I have a complex gauge here and from yours and other messages here I have been able to make it a lot leaner.Now, I can see the use of macros where the same code is repeated many times, but are there other advantages with calculation speed, for example. I had a macro but scrapped it in favour of just plain code.For example,Before,(A:Airspeed select indicated or true, knots) 10 / flr 10 * %(@E1IAS 30 +)%!3d!n%(@E1IAS 20 +)%!3d!n%(@E1IAS 10 + )%!3d!n%(@E1IAS)%!3d!n%(@E1IAS 10 - 0 max)%!3d!n%(@E1IAS 20 - 0 max)%!3d!Now,%((A:Airspeed select indicated or true, knots) d 10 / flr 10 * s0)%( l0 30 + )%!3d!n%( l0 20 + )%!3d!n%( l0 10 + )%!3d!n%( l0 )%!3d!n%( l0 10 - 0 max )%!3d!n%( l0 20 - 0 max )%!3d!and I use l0 in subsequent lines.Are macros handled in a different way to plain code which give advantages?BTW, with l3 10 % s4 8 >= l4 8 - 2 / * l3 10 / flr +Is there a way to rid of s4 and l4. The stack would have a 1 (or zero) after >= and the required value for 8 - before >=, that is,x >= 1(0)Therefore 1(0) is on top of the stack and x the next value down. I have tried reversing, duplicating/reversing but to no avail.cheers,nick

Share this post


Link to post
Share on other sites

>Yes. Happy to report it worked.>Good news!>>l3 10 % s4 8 >= l4 8 - 2 / * l3 10 / flr +>and l3 coming from a previous line,> (A:Airspeed select indicated or true, knots) s3 10 %>>This looks more lean to me.>Even better news. There's always something more to pull from the bag when you put your creativity to work.:-)>Before,> (A:Airspeed select indicated or true,>knots) 10 / flr 10 * > >%(@E1IAS 30 +)%!3d!n%(@E1IAS 20 +)%!3d!n%(@E1IAS 10 +> )%!3d!n%(@E1IAS)%!3d!n%(@E1IAS 10 - 0 max)%!3d!n%(@E1IAS 20>- 0 max)%!3d!>>Now,>%((A:Airspeed select indicated or true, knots) d 10 / flr 10 *>s0)%( l0 30 + )%!3d!n%( l0 20 + )%!3d!n%( l0 10 + )%!3d!n%(>l0 )%!3d!n%( l0 10 - 0 max )%!3d!n%( l0 20 - 0 max )%!3d!>>and I use l0 in subsequent lines.>Are macros handled in a different way to plain code which give>advantages?The second option is for sure more efficient. In the first, the compiler is pasting the macro code into the stack each time it is referenced.Macros should tend to be used: 1-As fine constants, (see GPSNN.XML) easier to reference than the original var.2-Whenever there is a repetitive code in a gauge, in different elements, and it is a complex source. (Ie when handling polinomies, extracting data from tables, etc)Using macros gives no advantage in performance than not using them, its only a code saving aid to the programmer, and sometimes an easier path to undertand what the code means. >>BTW, with l3 10 % s4 8 >= l4 8 - 2 / * l3 10 / flr>+>Is there a way to rid of s4 and l4. The stack would have a 1> (or zero) after >= and the required value for 8 - before >=,>that is,>x >= 1(0)>Therefore 1(0) is on top of the stack and x the next value>down. I have tried reversing, duplicating/reversing but to no>avail.>Duplicating/reversing should work:l3 10 % d 8 >= r 8 - 2 / * l3 10 / flr +Tom

Share this post


Link to post
Share on other sites

Thank you Tom, you have been most helpful in this entire matter, and I've learnt a great deal.cheers for now,nick

Share this post


Link to post
Share on other sites

>Thank you Tom, you have been most helpful in this entire>matter, and I've learnt a great deal.>cheers for now,>nickWas my pleasure Nick. Have you thought of making another wonderful tutorial like those you made before, from all this gathered info? Tom

Share this post


Link to post
Share on other sites

I'd love to, but it's finding time at the moment. I'm working on 3 panels at the moment for a certain development group. We could do with a good tutorial regarding the use of macros, modulus and an understanding of stack manipulation and how it works, and the use of operators like 'd', 'r', etc. Do you fancy putting pen to paper? Be nice to have a tutorial on formatted text as well, but that's another story.cheers,nick

Share this post


Link to post
Share on other sites
Guest Ron Freimuth

<...>We could do with a good tutorial regarding the use of macros,>modulus and an understanding of stack manipulation and how it>works, and the use of operators like 'd', 'r', etc. Do you>fancy putting pen to paper? Be nice to have a tutorial on>formatted text as well, but that's another story.>cheers,>nick What would be good is a set of XML examples for all the typical things required. Rolling Numbers, Display Formats, Input devices, Creating Tables, Macros.... A few dozen would be a start. ;) I've only worked on Aerodynamics calculations. Dynamic pressure, q, is a useful parameter for setting things that basically depend on it. Generally much better than 'IAS', etc. It took some time to find the best way to calculate this. I am also able to calculate Drag in XML, though it's a bit tricky. Ron

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...