• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

XML vs C

Messages
95
Country
malta
okay, this is crucial.

Is XML flexible as C? I mean, is it possible for example to do a fly-by-wire gauge in XML instead of C?

Regards.
 
okay, this is crucial.
Is XML flexible as C? I mean, is it possible for example to do a fly-by-wire gauge in XML instead of C?
Regards.

Nope. You need C to get at SimConnect or FSUIPC to build a fly-by-wire outfit.

Doug
 
Why not just use the fly_by_wire = 1 :) No idea what it does but its in the sdk
C++ is the way to go just wish it wasnt so hard to learn you can fudge a lot of the stuff in xml but its messy and wont talk to simconnect
Wozza
 
Hi,

Forget about XML as quickly as possible and work in c++ (yes ++), XML may seem "easier" (well not to me, but to many apparently) but it actually isn't.

Björn
 
Hi,

Forget about XML as quickly as possible and work in c++ (yes ++), XML may seem "easier" (well not to me, but to many apparently) but it actually isn't.

Björn

Well, as you yourself have pointed out, if one is both a modeler and a programmer, or at least if one's a programmer who works with a modeler...

...then some knowledge of XML and its idiosyncrasies is crucial, if for no other reason than that the gauge/panel system must interface with the model's embedded XML scripts! :rotfl:
 
Hi Bill,

Off course I agree with you, I was just stating things a bit polarized to make my point ;) It's exacly those idiosyncrasies which drive me crazy!

Björn
 
Hi Bill,

Off course I agree with you, I was just stating things a bit polarized to make my point ;) It's exacly those idiosyncrasies which drive me crazy!

Björn
Better going crazy than blood boiling mad trying to work out the setup for the C++ gauge compiler, not to mention if you have no past coding experience
the C++ syntax looks like gobbly gook.....xml may have its limitations but if your standing on your head it has some sort of logic ;) :D
Wozza
 
Hi there,

Out of curiosity I recently counted the lines of code I produced for my Lockheed Electra. The numbers are:
  • 22,205 lines of code in XML, that includes the added sections in the modeldef.xml
  • 2,793 lines of code in C++

there is hardly anything you can't do with XML and once you got your head around the "reverse polish sausage" the process of programming your systems and let them interact with your instruments is very straight-forward.
For my project the C++ module just kicks in when I need to set variables that can't be accessed via XML, like the payload for instance.
Another point is that if you want to design a VC seriously, you have to look at XML anyway, otherwise you are stuck with the limited number of stock animations.

Cheers,
Vitus
 
One of the "tricks" I use when working with modeldef.xml is to create a unique <AnimationGroup> section for my project. This collection of GUIDs are a combination of custom XML scripts I've written, as well as the GUIDs from other project's and default XML scripts.

This makes selecting the ones I wish to use much easier, since I don't have to sort through the very l o n g "complete listing..." :teacher:

Code:
  <AnimationGroup name="C310" guid="0x5F42FD3B,0x9C9F4168,0x8E55D265,0x8E7410D0">
    <AnimationRef guid="48b310a9-9adf-4499-95a0-7272f7def351"/>
    <AnimationRef guid="7b04f5f5-bdc6-4851-b73b-66972dbcffd2"/>
    <AnimationRef guid="1061f2df-6299-4bae-bc49-1121ef0c1ed9"/>
    <AnimationRef guid="1061f2df-6299-4bae-bc49-1121ef0c1ed9"/>
    <AnimationRef guid="37f0d3cc-067d-455c-afa0-ddef334297ec"/>
    <AnimationRef guid="c9e581fa-14d6-463f-a94f-433e59b19493"/>
    <AnimationRef guid="77ca3943-92e5-4595-9f12-ba029b9b30b2"/>
    <AnimationRef guid="4f5eef73-3279-46c4-90c4-1f9a161e2f28"/>
    <AnimationRef guid="29046b9a-9f33-4887-b905-196d4a46371b"/>
    <AnimationRef guid="93bbe639-3689-4bad-8821-8d96f20b9d65"/>
    <AnimationRef guid="36f5398f-4aa7-4db4-b057-3ce17f8cc01b"/>
    <AnimationRef guid="17692ab3-ffa6-46eb-9fd1-cbdd1f68d49a"/>
    <AnimationRef guid="a86ef078-bf84-4314-b60e-21694dafb490"/>
    <AnimationRef guid="85b0b556-baea-4b48-a924-d930f82b3ea6"/>
    <AnimationRef guid="35869fd3-a65f-433b-ace8-86531b16e934"/>
    <AnimationRef guid="9383d131-5576-4f23-a6dc-b1e966c1e354"/>
    <AnimationRef guid="de38ec88-1713-45cd-8a29-8c7e99e17c41"/>
    <AnimationRef guid="881c736b-08b5-40d5-beca-0ef791f330bf"/>
    <AnimationRef guid="7374bc73-868b-4975-8034-3f3f2ca7537b"/>
    <AnimationRef guid="7f1b7336-8c47-4527-94b5-243a6e50c0bf"/>
    <AnimationRef guid="dee5e9ec-0919-4e1e-8dfd-b2e774ab0de7"/>
    <AnimationRef guid="127f8156-7ff6-46dd-a27c-3fef57acad90"/>
    <AnimationRef guid="24bf724d-108e-47a4-9552-f4ee3c023c8a"/>
    <AnimationRef guid="92224b34-748f-4e53-8b4f-23761c7158bd"/>
    <AnimationRef guid="505017d6-ccfe-499b-be1c-8c3339293080"/>
    <AnimationRef guid="87f8ec54-ec98-4b9d-b276-4b98016e468f"/>
  </AnimationGroup>
 
Out of curiosity I recently counted the lines of code I produced for my Lockheed Electra. The numbers are:
  • 22,205 lines of code in XML, that includes the added sections in the modeldef.xml
  • 2,793 lines of code in C++

Well, this should already be a more than enough argument in favour of C++ :)

For my project the C++ module just kicks in when I need to set variables that can't be accessed via XML, like the payload for instance.

I always try to follow the exact opposite approach: keep the XML code as dumb as possible ( up to a point that's it's ONLY 1 line of <Code> ), and doing everything in C++


Another point is that if you want to design a VC seriously, you have to look at XML anyway, otherwise you are stuck with the limited number of stock animations.

You only need to know just enough XML to write 2 lines:

1) a single line to tie an animation to an L: variable

2) a single line to generate an event with a mouse click, which can also be a custom event ( with a direct hex number, instead of a KEY_something name )

Once you can do this in XML, there's nothing else you need, and everything can be done, just much more efficently, in C++ since, from C++, you write what you need to write to the L: variable, to trigger the animation, and you just intercept the mouse events (including custom ones) with an handler, so you get asynchronous notifications of every possible user action.

Nothing more is needed to create "serious" VC programming, and there's no need to write any more XML than that.

An example, this is the "Bingo" bug knob of the F/A-18 Acceleration:

Code:
  <PartInfo>
    <Name>knob_bingo_bug</Name>
    <AnimLength>360</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:knob_bingo_bug,number)</Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftDrag+Wheel</MouseFlags>
      <CallbackJumpDragging>
        <XMovement>
          <Delta>2</Delta>
          <EventIdInc>0x11001</EventIdInc>
          <EventIdDec>0x11002</EventIdDec>
        </XMovement>
      </CallbackJumpDragging>
    </MouseRect>
  </PartInfo>

As you can see, the XML code is as dumb as it gets, it's almost all empty tags, except for 1 <Code> line, and 2 <EventID> lines. Yet, this is a fully custom animation, which is driven just with 1 line, here:

Code:
<Code>(L:knob_bingo_bug,number)</Code>

This is the link from C++ to FSX in the bottom-up direction, where C++ drives the model.

And this, of course, the other way around, when the model controls the C++ code:

Code:
<EventIdInc>0x11001</EventIdInc>
<EventIdDec>0x11002</EventIdDec>

Once C++ is able to intercept these 2 custom events, which is done with an handler using the register_key_event_handler() function of the SDK, the whole communication is done.

You can do everything using just this pattern, or very little variations of it, without having to write XML longer or more complex than this, for each part...
 
Hi Bill,

I am intrigued by the animation groups. They never came to my attention but it seems like they are reaaaaaaally useful. One question though: what's the story behind the guid entry in the <group> section? It's obviously a different type of guid but why are there four of them? How to set up this header?


Hi Umberto,

Wow, interesting how different our approaches are!

Well, this should already be a more than enough argument in favour of C++
What I really wanted to say is that, apart from some minor things, almost everything can be done using XML only. ;)

And if you look at XML code, it isn't more "bulky" than C++, except of course the variable names:
Code:
if (number == 1) { anothernumber = 2 }
Code:
(L:number,number) 1 == if{ 2 (&gt;L:anothernumber,number) }

For myself, I just don't see any advantages in using C++. XML feels more "direct", no need to trigger any events to activate your systems, because everything can be done in the code section of your animated part.

Cheers,
Vitus
 
Hi Bill,

I am intrigued by the animation groups. They never came to my attention but it seems like they are reaaaaaaally useful. One question though: what's the story behind the guid entry in the <group> section? It's obviously a different type of guid but why are there four of them? How to set up this header?

Okay, here is a brief(er) example, showing just one entry in it's entirety. I tend to keep all three sections close to each other while developing, since "order" isn't important at this stage, just efficiency!

Let's start with this GUID:
6EDE437E-ADD3-4bfe-AB44-E73AB6BCB013

The Animation Group's GUID is separated every 64bits (8 characters) and connected by comma.

So first separate into 8 character blocks (delete the - sign)
6EDE437E
ADD34bfe
AB44E73A
B6BCB013

Next , add 0x on the front which means written in hex
0x6EDE437E
0xADD34bfe
0xAB44E73A
0xB6BCB013

And connect by comma:
0x6EDE437E,0xADD34bfe,0xAB44E73A,0xB6BCB013
Now before the math purists hammer me to death, mathematically speaking these two are not the same number if compared in decimal, but...

...that doesn't matter one bloody bit! It is still a unique GUID number!!! :rotfl:

Okay, now that we have this in hand, we simply need to create an entry for our new Animation Group:
Code:
  <!-- C310 Custom Animations -->
  <Animation name="C310_needle_asi" guid="48b310a9-9adf-4499-95a0-7272f7def351" type="Sim" typeParam="AutoPlay" length="260" typeParam2="C310_needle_asi" />

  <AnimationGroup name="C310" guid="0x6EDE437E,0xADD34bfe,0xAB44E73A,0xB6BCB013">
    <AnimationRef guid="48b310a9-9adf-4499-95a0-7272f7def351"/>
  </AnimationGroup>

  <PartInfo>
    <Name>C310_needle_asi</Name>
    <AnimLength>260</AnimLength>
    <Animation>
      <Parameter>
        <Sim>
          <Variable>AIRSPEED INDICATED</Variable>
          <Units>knots</Units>
        </Sim>
      </Parameter>
    </Animation>
    <MouseRect>
      <TooltipID>TOOLTIPTEXT_AIRSPEED_KNOTS</TooltipID>
    </MouseRect>
  </PartInfo>

Of course, it wouldn't make a lot of sense to have only one item in a sorted "Animation Group," but the beauty of this system is that you can put any GUID in the list at all. It's only purpose is to display a grouped list of all the animation scripts you're using in any project so you don't have to sift though all the entries looking for the one you need.

I keep a copy of modeldef.xml loaded in Visual Studio, and every time I find a script I can reuse, I use "Find" to locate it's <Animation.../> entry, then copy/paste the GUID into my custom <AnimationGroup>. Then when I go back to Max to use the Animation Manager, I simply click on my C310 "Group List" to find it quickly!

The Acceleration SDK's "modeldef.xml" file has many pre-built Animation Group "categories," such as:

Wing Flex
Carrier Specific
EH-101 Specific
Flight Controls
Flaps and Spoiler
TrimTabs
PistonEngine
Jets and Turboprop Engine
Gears
Tire
Doors
 
Last edited:
:eek: This is brilliant! Although copy and paste of the guids is really painful, but the result is excellent. Thanks for sharing!
 
:eek: This is brilliant! Although copy and paste of the guids is really painful, but the result is excellent. Thanks for sharing!

It's just me paying forward. I learned this from some time spent on the POSKY forums some years ago.

Actually, the process is really not all that painful once you've got the hang of it...

Do you know about the <Copy> feature? It's also quite handy at times:

Code:
  <PartInfo>
    <Name>switch_fuel_boost</Name>
    <Copy>switch_fuel_pump</Copy>
    <AnimLength>50</AnimLength>
  </PartInfo>

Instead of copy/pasting the entire switch_fuel_pump script, I've simply added <Copy>switch_fuel_pump</Copy> and then added in the only entry that's different from the linked script, which is the <AnimLength> entry!
 
An example, this is the "Bingo" bug knob of the F/A-18 Acceleration:

Code:
  <PartInfo>
    <Name>knob_bingo_bug</Name>
    <AnimLength>360</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:knob_bingo_bug,number)</Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftDrag+Wheel</MouseFlags>
      <CallbackJumpDragging>
        <XMovement>
          <Delta>2</Delta>
          <EventIdInc>0x11001</EventIdInc>
          <EventIdDec>0x11002</EventIdDec>
        </XMovement>
      </CallbackJumpDragging>
    </MouseRect>
  </PartInfo>

As you can see, the XML code is as dumb as it gets, it's almost all empty tags, except for 1 <Code> line, and 2 <EventID> lines. Yet, this is a fully custom animation, which is driven just with 1 line, here:

Code:
<Code>(L:knob_bingo_bug,number)</Code>

This is the link from C++ to FSX in the bottom-up direction, where C++ drives the model.

And this, of course, the other way around, when the model controls the C++ code:

Code:
<EventIdInc>0x11001</EventIdInc>
<EventIdDec>0x11002</EventIdDec>

Once C++ is able to intercept these 2 custom events, which is done with an handler using the register_key_event_handler() function of the SDK, the whole communication is done.

Hi Umberto,

Now I am intrigued. We have been struggling to use left/right mouse click events in the VC, mostly because of my lack of understanding of XML. Looking at your code I could imagine that you can trap exactly which mouse button was clicked and respond differently?
Is this correct and could you show how this is done ?

Thx,
Björn
 
Now I am intrigued. We have been struggling to use left/right mouse click events in the VC, mostly because of my lack of understanding of XML. Looking at your code I could imagine that you can trap exactly which mouse button was clicked and respond differently?
Is this correct and could you show how this is done ?

Thx,
Björn

Detecting mouse events via XML in the model is really simple. Consider the following example:

Code:
      <MouseFlags>LeftSingle+MiddleSingle+RightSingle+WheelUp+WheelDown+DownRepeat</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle'  scmi 0 == if{ (&gt;K:HEADING_BUG_DEC) }
        (M:Event) 'RightSingle' scmi 0 == if{ (&gt;K:HEADING_BUG_INC) }
        (M:Event) 'WheelUp'     scmi 0 == if{ (&gt;K:HEADING_BUG_INC) }
        (M:Event) 'WheelDown'   scmi 0 == if{ (&gt;K:HEADING_BUG_DEC) }
        (M:Event) 'MiddleSingle' scmi 0 == if{ (A:Plane heading degrees gyro,degrees)  (&gt;K:HEADING_BUG_SET) }
      </CallbackCode>

In the <MouseFlags> entry you simply list the mouse actions you wish to test. The "DownRepeat" flag tells FS to repeat whatever command is assigned to continuously send the event as long as a button is held down.

The 'key to understanding' is the (M:Event) entry...

(M:Event) 'Flag' scmi 0 == if{ some_command }

In the FSX SDK you will find a HUGE list of possible mouse flags. If I remember correctly, it would be possible to have a single mouse rectangle perform up to seventeen different commands! :eek:

In the example above, the mouse area for the HDG knob allows left/right click, mouse wheel up/down, and mouse wheel click (sets the HDG bug to a/c heading). ;)
 
What I really wanted to say is that, apart from some minor things, almost everything can be done using XML only. ;)

Yes, but with 10x number of lines, of "unreadable" code.


And if you look at XML code, it isn't more "bulky" than C++, except of course the variable names:

Code:
if (number == 1) { anothernumber = 2 }

Code:
(L:number,number) 1 == if{ 2 (&gt;L:anothernumber,number) }

Yes, but writing a whole program, it's not just expressions. In fact, if we should be precise, you are not comparing the C++ language with the XML "language" (quotes on XML being a language, are intentional...), you are only comparing their expression evaluators, which are just a very small aspect of any language.

The only comparison you made here, is between a post-fix and in-fix notation...both have their merits, but a whole programming language is way more than that.

For myself, I just don't see any advantages in using C++. XML feels more "direct", no need to trigger any events to activate your systems, because everything can be done in the code section of your animated part.

We are talking about very simple things here, which is appropriate in a forum. But, what about if that "something" that needs to be happening when you click the mouse, is too complex to do in XML ?

You'll end up with an hybrid project, with lots of complex code in the XML section, and lots of complex code in C++ as well, which is a recipe for disaster, especially for maintenance, becase you are breaking one of the fundamental programming rules, which is "keep all the complexity as close as possible". If you figure it out you are going to use C++ anyway, it would be better to simply stick to it, and write as much as possible in C++, which will keep you the XML code simple in return.

Of course, we shouldn't forget performances. You can't even PROFILE XML which means, if your gauge is slow, you can't even check where, and why. When I use a code profiler, I know exactly how many micro-seconds each line of my code takes, and I have a report of which routines my program is spending most of its time.

An interesting story about this, that I mentioned at the MS Devcon in Seattle in 2007, is that, when profiling the F/A-18 Gauges, to squeeze the last possible bit of speed (the gauges are GDI+, which means you *have* to optimize), I found that, the most costly function, of ALL, was to simply CLEAR THE SCREEN, using the standard GDI+ call. It took more time to clear the screen, than to draw the whole gauge, even in case of the most complex one, which is the HSI with moving map+navaids. Yet, clearing the screen was quite costly, but of course you wouldn't suspect that, unless you run through a profiler. I was considering to play hardball, and replace the GDI+ clear screen function, with a custom one written in x86 ASM, perhaps even using SSE2 instructions to "kill" bits 128 bits at time, at a blazing speed. But it was maybe overkill, and luckily I found out that, if I cleared the screen using the regular GDI command insead of the GDI+ one, it would have worked the same, just 4-5 times faster and, since this was happening at every frame, on 4 gauges at the same time (3 MFD's + 1 HUD), and this was the most costly action of the whole gauge, the frame rate improvement was very noticeable!

No way you can do this with XML.

Let's not even start discussion how bad is to *debug* XML code. The VC++ debugger is so powerful, and work so well, that I wouldn't dream to do anything without it, except for the really trivial things.

When you are going into the more complex things, you'll find that XML simply can't cut it. Some things will not just be possible, but others might be so cumbersome and difficult to maintain, that your project might just fail because of that, or you simply find yourself writing and re-writing thousand of lines of code for EACH project, because the only "code reusability" that XML offers to you, other than the puny macro commands, it's copy&paste...

C++ superiority doesn't even show up in a single project, because this might be small enough that would have been doable in XML anyway. But should be evaluated over the course of several projects, that lies its main strenght.

Of course, this means using C++ to its fullest, very different from what you might have seen in SDK samples, and most of the fightsim-oriented tutorials, which are basically C, with almost no notion of OOP whatsoever.

Concept like using Class hierarchies, inheritance, methods, virtual functions, accessors and Templates, of all. And this is the low level.

At an higher level of abstraction, you'll use Patterns, which are not strictly related to C++, but can be applied to any OOP language (like C#, Java, Python, etc.), that are common ways to solve usual programming problems.

Read an older post of mine, that would give you more insight about what I mean:

http://www.newsite.fsdeveloper.com/forum/showpost.php?p=119515&postcount=5

None of this, of course, it's possible with XML, which is not really a language in the first place, but it's more an expression evaluator.
 
Last edited:
Back
Top