P3D v4 Value change delay in XML gauge

#1
Hi,
in several gauges I use rotating drums as described in the wiki here: https://www.fsdeveloper.com/wiki/index.php?title=XML:_Macros_-_Extracting_Digits
I never needed any kind of delay until I tried to display the DME distance using a rotating drum.
P3D updates the variable slowly so that the fraction of the distance drum jumps 3 or even more digits instead of rolling smoothly.
I can't see how the delay tag can help, because a pixel delay or a value delay causes the vertical number strip image not to jump immediately from upper 0 to lower 0 but to scroll down slowly. Bad.

So I delayed the change of the variable itself. Unfortunately I still do not understand how to use stack operators properly, so I came up with the solution below which looks somehow ugly to me. Because recently I promoted myself from totally dumb beginner to mostly dumb beginner, I start now creating standard code blocks and this code should be one of those.
So I'd like to ask: Is it possible to solve this problem better/more elegant?

Code:
<Macro Name="DME1">
// 10 * to get rid of fractions, so that I can always copy&paste the value tag line below without changing anything but the macro name
// near is just personal taste, looks better to me
  (A:NAV1 DME, nmiles) 10 * near sp0

// Start condition: If a distant DME starts being received, digits shouldn't rotate slowly from 0 to 200...
  l0 (G:Var2) - abs 5 &gt; if{ l0 (>G:Var2) }

// This is the delay, inc and dec steps can be different. If equal, don't change
  l0 (G:Var2) &gt; if{ (G:Var2) 0.01 + (>G:Var2)  }
  l0 (G:Var2) &lt; if{ (G:Var2) 0.01 - (>G:Var2)  }

// This one I really hate. This could be solved better, couldn't it?
  (G:Var2)
</Macro>

// The rest below is copied from the rotating drum example, nothing to optimize
<Macro Name="ExtDigit">
  @1 sp0
  @3 0 > 
  if{ l0 10 @3 pow * sp0 }
  l0 int 10 @2 pow % 10 @2 1 - 0 max pow / int 
</Macro>

<Image Name="number_strip.bmp" />
<Shift>
  <Value>@DME1 1000 % s1 999 >= l1 999 - * @ExtDigit(@DME1,4,0) + </Value>
  <Scale Y="14"/>
</Shift>
Thanks for your comments
Frank
 
#2
For the 10ths / fraction try not to use the @ExtDigit macro. I believe that has a built in "snap" to it.
Instead, try just a plain old "rolling" style formula, not completely sure. Wouldn't hurt to try -

XML:
<Image Name="number_strip.bmp" />
<Shift>
  <Value>(A:NAV1 DME, nmiles) 10 * 10 %</Value>
  <Scale Y="14"/>
</Shift>
 
#3
Oh sorry, this is exactly what I do. I didn't include this part of the code because I wanted to keep my post short and well-arranged.
In the meantime I managed using stack registers - but the result is neither better nor shorter but less readable...
And it seems that you didn't roll your eyes when you saw my code, so I consider it as acceptable.

By the way, I reduced the ExtDigit macro to my needs. @2=1 now returns second right digit of @1. The macro cannot return decimal places of @1 anymore.
Code:
 <Macro Name="ExtDigitLite">
  @1 abs 10 @2 pow / flr 10 %
</Macro>
Thanks
Frank

PS: No, I think my post is not useful without the full code. Here is the code to display DME1 and DME2 distance using rotating drums. In order to demonstrate the issue if you don't delay the value itself, DME2 uses the standard code I use for speed, altitude etc.
Fly quickly (around 300kts) towards a DME station and you will see the difference.

Code:
 <Macro Name="DME1">
    @DMEx( (A:NAV1 DME, nmiles),(L:DME1d) ) (>L:DME1d)
  </Macro>

  <Macro Name="DME2withdelay">
    @DMEx( (A:NAV2 DME, nmiles),(L:DME2d) ) (>L:DME2d)
  </Macro>

  <Macro Name="DMEx">
     @1 10 * near sp0
     @2 sp1
     l0 l1 - abs 5 &gt; if{ l0 sp1 }
     l0 l1 &gt; if{ l1 0.01 + sp1 }
     l0 l1 &lt; if{ l1 0.01 - sp1 }
     l1 d
  </Macro>

  <Macro Name="DME2">
    (A:NAV2 DME, nmiles) 10 * 
  </Macro>

  <Macro Name="ExtDigit">
    @1 abs 10 @2 pow / flr 10 %
  </Macro>

  // DME 1
  <Element>
    <Position X="12" Y="-118"/>
    <Image Name="DME_strip10.bmp" />
    <Clip Left="12" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME1 1000 % s1 999 >= l1 999 - * @ExtDigit(@DME1,3) + </Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
  <Element>
    <Position X="22" Y="-118"/>
    <Image Name="DME_strip10.bmp" />
    <Clip Left="12" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME1 100 % s1 99 >= l1 99 - * @ExtDigit(@DME1,2) + </Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
  <Element>
    <Position X="32" Y="-118"/>
    <Image Name="DME_strip10.bmp" />
    <Clip Left="12" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME1 10 % s1 9 >= l1 9 - * @ExtDigit(@DME1,1) + </Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
  <Element>
    <Position X="44" Y="-118"/>
    <Clip Left="12" Top="22" Width="40" Height="12" />
    <Image Name="DME_strip1.bmp" />
    <Shift>
      <Value>@DME1 10 %</Value>
      <Scale Y="14"/>
    </Shift>
  </Element>

// DME 2
  <Element>
    <Position X="64" Y="-118"/>
    <Image Name="DME_strip10.bmp" />
    <Clip Left="64" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME2 1000 % s1 999 >= l1 999 - * @ExtDigit(@DME2,3) + </Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
  <Element>
    <Position X="74" Y="-118"/>
    <Image Name="DME_strip10.bmp" />
    <Clip Left="64" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME2 100 % s1 99 >= l1 99 - * @ExtDigit(@DME2,2) + </Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
  <Element>
    <Position X="84" Y="-118"/>
    <Image Name="DME_strip10.bmp" />
    <Clip Left="64" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME2 10 % s1 9 >= l1 9 - * @ExtDigit(@DME2,1) + </Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
  <Element>
    <Position X="96" Y="-118"/>
    <Image Name="DME_strip1.bmp" />
    <Clip Left="64" Top="22" Width="40" Height="12" />
    <Shift>
      <Value>@DME2 10 %</Value>
      <Scale Y="14"/>
    </Shift>
  </Element>
 
Last edited:
#4
Hi,
because I'm still not fully satisfied, I continued searching and found someting really cool in one gauge from @n4gix :
Code:
<Text  Color="%('#AA0000' '#FF5A5A' (L:AlternativeColor,bool) ?)" >
So I hoped that this might work for the Delay tag, too. But both tries didn't set any delay:
Code:
<Delay PixelsPerSecond="%('1' '10' 0 ?)" />

<Delay PixelsPerSecond="%(1 10 1 ?)" />
Is this caused by wrong syntax or doesn't this work at all?
If it doesn't work, can I assume that there is no other way to change a Delay dynamically?

Thanks again
Frank
 
#5
The ('#AA0000' '#FF5A5A' (L:AlternativeColor,bool) ?) section of the original code represents: if (L:AlternativeColor, bool) is true, then use color #AA0000 else use color #FF5A5A... unless they made the two variables reverse polish as well, and then it would mean if (L:AlternativeColor, bool) is true then use color #FF5A5A else use color #AA0000. In short... it's not a delay and you've hard coded the possible return by forcing either a 0 or a 1 as the final value. The % sign at the beginning is probably not appropriate either.
 

n4gix

Resource contributor
#6
The % symbol definitely not. In the context of a "Text ..." element, it is used as a formatting symbol for a text display.
 
#7
Although I understand that you tell me, that my attempt will never work, I must admit that I don't understand the reason. The % symbol is of course part of Bill's code. Here the original line from Bendix KR-87 in the Socata TB20 panel - it's lousy 16 years old...:
Code:
<Text X="150" Y="35" Bright="Yes" Length="6" Fixed="Yes" Font="Quartz" Color="%('#AA0000' '#FF5A5A' (L:PanelLight_Flight,enum) 0.5 &gt;= ?)" Adjust="Left" VerticalAdjust="Center" Multiline="No">
Seeing this, my thinking was:
There is an element. This element can have different attributes like X, Y, Color or PixelsPerSecond. The attributes have values written in quotes. So the general syntax is <Element_Name Attribute_Name="Value">stuff</Element_Name>
An example for text therefore is <Text X="1" Y="2" Color="#AA0000">stuff</Text> For delay, this would be <Delay PixelsPerSecond="10" >nothing</Delay>
What excited me was that Bill changed the value of an attribute within the <> brackets.
Using %(something) somewhere between <Text> and </Text> or between <Tooltip> and </Tooltip> wouldn't have surprised me, this does the well known text formatting things.
Using %(something) within Attribute=" " is very different and would open so many possibilities!

But obviously color attribute is a special case and this technique seems to work nowhere else. What a pity.

Anyway thanks a lot for checking
Frank
 

tgibson

Resource contributor
#8
Hi,

There are two different things here - Attributes, which are included inside the tag and surrounded by quotes, and Values, which are placed between the beginning and end tags. You cannot mix the two.
 
Top