• 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 Bubble Sort utilizing XMLVARs

Status
Not open for further replies.
Messages
1,564
Country
thailand
Recently, a question about sorting came up. The context was an ICAO Search of Facility types which returns ICAO strings in alphabetical order. However, each ICAO represents a Facility that is a certain distance from the user's aircraft, and proper display of the Facility information required a sort according to distance from the user's aircraft rather than alphabetical order of the ICAO strings.

Acknowledgements are owed to Robbie McElrath who provided the Bubble Sort XML (thank you, Robbie) and Tom Aguilo, for providing XMLVARs. The sort script that follows makes use of the array-forming capabilities of XMLVARS. Thanks, Tom.

Code:
<!-- @sort('array_name', array_length) -->
<Macro Name="sort">
  @2 (>L:sort_len, number)
  :127
     0 (>L:sort_swapped, bool)
     0 sp0
     :128
        l0 ++ s0 (L:sort_len, number) &gt;= if{ g129 }
        @1 l0 -- scat s10 (>C:XMLVARS:SearchVarName, string) (C:XMLVARS:NumberValue, number) s11
        @1 l0    scat     (>C:XMLVARS:SearchVarName, string) (C:XMLVARS:NumberValue, number) s12 &gt;
            if{
              l11 (>C:XMLVARS:NumberValue, number)
              l10 (>C:XMLVARS:SearchVarName, string) l12 (>C:XMLVARS:NumberValue, number)
              1 (>L:sort_swapped, bool)
            }
        g128
     :129
     (L:sort_swapped, bool) if{ g127 }
</Macro>

<Macro Name="store">
  @1 @2 scat (>C:XMLVARS:StoreVarName, string) (>C:XMLVARS:NumberValue, number)
</Macro>

<Update Frequency="18" Hidden="No">
(L:StoreInit, bool) 0 ==
    if{
        2 @store('sort_test', 0)
        1 @store('sort_test', 1)
        4 @store('sort_test', 2)
        8 @store('sort_test', 3)
        7 @store('sort_test', 4)
        0 @store('sort_test', 5)
        1 (>L:StoreInit, bool)
    }

    'sort_test0' (>C:XMLVARS:SearchVarName,string) (C:XMLVARS:NumberValue,number) (>L:SortTest0, number)
    'sort_test1' (>C:XMLVARS:SearchVarName,string) (C:XMLVARS:NumberValue,number) (>L:SortTest1, number)
    'sort_test2' (>C:XMLVARS:SearchVarName,string) (C:XMLVARS:NumberValue,number) (>L:SortTest2, number)
    'sort_test3' (>C:XMLVARS:SearchVarName,string) (C:XMLVARS:NumberValue,number) (>L:SortTest3, number)
    'sort_test4' (>C:XMLVARS:SearchVarName,string) (C:XMLVARS:NumberValue,number) (>L:SortTest4, number)
    'sort_test5' (>C:XMLVARS:SearchVarName,string) (C:XMLVARS:NumberValue,number) (>L:SortTest5, number)
</Update>

<Area Left="150" Top="130" Width="16" Height="16">
    <Cursor Type="Hand" />
        <Click Kind="LeftSingle+RightSingle">
            @sort('sort_test', 6)
            (L:SortMacroExecuted,enum) ++ (>L:SortMacroExecuted,enum)
        </Click>
</Area>

Notes:
  • (L:sort_len, number) is the array length. For example, IcaoSearchMatchedIcaosNumber
  • The StoreInit sequence was used for testing purposes only. It stores 2, 1, 4, 8, 7, and 0 into XMLVARs named 'sort_test0' through 'sort_test5'. In a real application, GeoCalcDistance information, for example, would actually generate the values to be stored in these XMLVARs and a StoreInit sequence would probably never be used.
  • The bottom 6 lines in the Update section simply read the XMLVARs and store them into traditional L:Vars so that BlackBox can display them (so you can see what is happening before and after the sort is applied). Again, for testing purposes.
  • A Mouse Area 'click area' is used to execute the sort macro, @sort('sort_test', 6). The number 6 is the array length to be sorted. In the real example I postulated, it would be written @sort('sort_test',C:fs9gps:IcaoSearchMatchedIcaosNumber). (L:SortMacroExecuted,enum) ++ (>L:SortMacroExecuted,enum) was included for test purposes to verify operation of the mouse click. Obviously, it isn't necessary.
  • The sort macro requires use of XMLVARs. Specifically, the array-forming capability of XMLVARs in which an array of variables can be named dynamically, such as, sort_test0, sort_test1, sort_test2, ... sort_testn, is needed. Without XMLVARs, it is not straightforward to represent the data in the first place.
  • The algorithm sorts in ascending order. To sort in descending order, change the &gt; to &lt; in this line:
@1 l0 scat (>C:XMLVARS:SearchVarName, string) (C:XMLVARS:NumberValue, number) s12 &lt;

The following is a screen shot of results. On top are the initial values of (L:SortTest0, number) through (L:SortTest5, number). On the bottom are the values after the bubble sort. Tested in FS9 but also works in FSX (XMLVARs has a FS9 module and a FSX module)

SORT_TEST.png


Bob
 
Last edited:
Bob,

I was hoping to get away with not coding that bit and blame the capabilities of the simulator...I can no longer do that now. Thank you...I think.:rotfl: Now to learn this.

In all seriousness this is impressive. Somehow XML seems to be getting more and more powerful in FS particularly by the dedication of a few members here.
 
In all seriousness this is impressive. Somehow XML seems to be getting more and more powerful in FS particularly by the dedication of a few members here.
I agree with you. For gauges that many people in here work on, even complex FMS systems such as yours, XML has little disadvantage to C++, or so I have been told (but I do not know C++). XML has all the math and string operators I need.

I know it comes up short in its ability to generate graphics and to communicate with other systems in FS. But, that's where XML tools that have become available in the past several years really boost capability, like Pete Dowson's FSUIPC, Doug Dawson's sound module, Arne Bartel's FS9 Traffic Radar, Robbie's LOGGER (XML>HDD>XML) module and Tom Aguilo's XMLVARs module. I realize in advance that I have missed many other good examples, so maybe readers of this thread will add some more.

Anyway, I encourage people to take a look at Pete Dowson's web site, Doug Dawson's web site, or Robbie McElrath's BlackBox web site for other tools and ideas. The link to Tom Aguilo's XMLVARs is here. And, the Wiki section in this forum keeps growing, too.

Bob
 
Last edited:
I agree with you. For gauges that many people in here work on, even complex FMS systems such as yours, XML has little disadvantage to C++, or so I have been told (but I do not know C++). XML has all the math and string operators I need.

Well, perhaps if you knew C++, you wouldn't say that...there were several discussions here, and sometimes XML developers comes out with this "math and string operators", as if the power of a language might be expressed just with that.

Every programming language has a fairly complete set of math and string operators today, what makes a language different is its structure, the ability to use powerful programming patterns, the object orientation, the integration between all of them. With this regard, XML for gauges can't even be classified as a "language". It's an RPN expression evaluator with some glue added to interact with FSX.

In fact, if I had to indicate a use case where C++ would be the clearly better choice over XML, is precisely for such "complex FMS systems", using specific programming patterns (such as the "Command Pattern") it would be very straightforward and incredibly speed and memory efficient in C++, while it would be slow, unreadable and very difficult to maintain and to grow in XML.

Some comments about this sorting routine:

If I understood correctly, you are relying on an C++ .DLL module ( XMLVARS ) in order to give you access to a data structure (the array) which you don't normally have in XML, then you use XML to add a sorting algorithm on top of it, because you need data sorted by distance, that the ICAO search function doesn't provide.

Since you ARE relying on an external C++ .DLL, perhaps a better approach would have been using C++ to SORT the array for you too, maybe passing a parameter from XML, to indicate which "field" you want the sort be based.

Sorting in C++ is so straightforward that it wouldn't even require to *code* anything, just use a standard C++ container (like a List) to hold data, and call the Sort() method on it.

Maybe, you can suggest to the author of the XMLVARS module, to add a sorting function for its own arrays, it might be useful for many applications. But even if this doesn't happen, you could always write a separate C++ module that interacts with it, for example to add sorting, since the XMLVARS module will likely use registered variables, it should be fairly easy to exchange data with it, even without any changes to that module.

BTW, if you find C++ too complex and/or difficult to setup, AT LEAST consider using C#! That's a decent language, and will interact with FSX and Simconnect just fine, it's reasonably easy to get started with, and it offers basically the same object-oriented power as C++, without the headaches.
 
Very thoughtful answer Umberto. Thanks, and I really appreciate it. I can see you must understand C++ and have a passion for it. I know it's what the professional gauge programmers use. Maybe you are one.

You're saying C++ is better. I'm saying XML is good enough for gauges that many people in here work on. I think we are both right but I guess you wouldn't agree. But surely you would agree that many of us that make FS gauges as a hobby use XML, like it or not, and the bubble sorting macro, and XMLVARs and the other things I mentioned above are for them. This forum is for those of us stuck in low XML orbit as well as those that use a real programming language. Room for us both.

Bob
 
You're saying C++ is better. I'm saying XML is good enough for gauges that many people in here work on. I think we are both right but I guess you wouldn't agree.

Yes, but there's an important detail: you said yourself you don't know C++. So, you don't have the means to be able to make an informed judgement.

But surely you would agree that many of us that make FS gauges as a hobby use XML, like it or not, and the bubble sorting macro, and XMLVARs and the other things I mentioned above are for them. This forum is for those of us stuck in low XML orbit as well as those that use a real programming language. Room for us both.

My point is that you are making your life more difficult, not less, by trying to do things (like sorting a list) that every normal program will need to do sooner or later, in a language that wasn't designed to do that, when there are several options using languages that solved this issues long ago.

If you are feeling the need to have a sorting routine in your gauge, it's because your project has approaching enough complexity that you are starting to outgrow XML! You can use C#, you can even use Visual Basic for that, all of them can be interfaced with FSX using Simconnect, and doing that in any of those languages would be *easier* and more efficient than XML.

The real issue is, FSX (and FS9 before) never had a "real" script language, something that could be used easily by anyone, but with the power of a "real" language. That's why we developed an entire scripting system based on Python.

MS Flight was a step in the right direction, because its SDK allowed LUA scripting (while I believe Python is better than LUA, LUA is light years better than XML), and the .MDL animation system (the modeldef.xml) got rid of the RPN notation, making way easier to write complex expressions but, unfortunately, it didn't turned out so well in the end...
 
You're saying C++ is better. I'm saying XML is good enough for gauges that many people in here work on.

Bob,

Not only is good enough but in my opinion is the best option for developing panels and aircraft in FS. MS really nailed it on when they included XML-style options in models and gauges, bringing FS to the incredible success we are seeing today. Without XML you probably wouldn't find so many freeware and commercial addons out there as it is easiest, fastest and simplest to debug than any "real" language to be used in FS, like C++.
Leaving appart complex graphics, and with the aid of custom libraries (like XMLVars) almost everything in gauge coding can be programmed using XML scripts, including complex systems like EICAS and FMS.

And I am not saying it doesn't have limitation, because it has, of course, but they are not comparable to the benefits, like HTML scripting "language" has them as well and it does not prevent its use by MILLIONS of people across the world. Would you think for a while that HTML is "worst" or "less efficient" than C++, from an INTERNET user pov?.

Tom
 
Not only is good enough but in my opinion is the best option for developing panels and aircraft in FS

It's the best AVAILABLE (meaning, you don't have so many other choices...) option to start learning about doing gauges or modify existing one and learn something in the process.

MS really nailed it on when they included XML-style options in models and gauges, bringing FS to the incredible success we are seeing today. Without XML you probably wouldn't find so many freeware and commercial addons out there

Freeware, yes, I agree with you.

For Commercial, yes/no, meaning the quantity might have been improved compared to old times, but it hasn't do anything to improve the quality. And the best commercial developers are divided between those that always used C++, and those that are redoing all their existing stuff with it. For the Commercial market, the only thing that XML has achieved, is both lowering the entry barrier for new developers, but it also lowered the general quality of the offering. The only thing "good" is that, by bringing more developers to FSX, one can only hope new talents will eventually rise, which is surely good for everybody.

as it is easiest, fastest and simplest to debug than any "real" language to be used in FS, like C++.

I find XML to be cumbersome and fiddly to debug. Once you have Visual Studio properly setup to debug FSX, C++ is very straightforward. The debugger is one of the BEST features in Visual Studio, I would rate it as a reason to NOT use XML.

Leaving appart complex graphics, and with the aid of custom libraries (like XMLVars) almost everything in gauge coding can be programmed using XML scripts, including complex systems like EICAS and FMS.

This very thread had a suggestion to rely on SEVERAL external .DLL modules (FSUIPC, a sound module, xmlvars, other tools, ALL made in C++, of course...), just to do what is not possible using plain standard C++ and the official SDK.

Again, while I can fully support this suggestions for someone developing as an hobby, to offer some freeware, I would never, ever, suggest that anyone would BUY anything based on such suggestions.

Is someone asking money for his work, lacking the basic ability to set-up a C++ compiler and do something as trivial as a sort routine ? What's the point discussing about fps and resource optimization, when there might be *commercial* developers ( I don't know if this was the case, but maybe someone else reading this thread might seriously think to use such approach ) using XML to sort data??

And I am not saying it doesn't have limitation, because it has, of course, but they are not comparable to the benefits, like HTML scripting "language" has them as well and it does not prevent its use by MILLIONS of people across the world. Would you think for a while that HTML is "worst" or "less efficient" than C++, from an INTERNET user pov?.

HTML IS the tool designed to do what is usually used for: creating hypertext documents that links to each other. It has obviously grown a lot over the years, it has added support for many script languages, is now way more flexible in rendering, but is STILL the right tool for THAT job, C++ has never been an alternative to HTML, as your sentence seems to suggest.

XML, on the other hand, is NOT a scripting language, and it has never been designed for that. It's a STORAGE format, designed to allow easy interchange of data and structured parsing. Which means, is NOT the "right tool for the job" for this application, which is modeling the BEHAVIOUR of real world systems like gauges, flight computers, etc. The "right tool for the job" in this case, would be an Object Oriented programming language.

Your "Leaving apart complex graphics" comment is quite telling, and you are really missing the point here: the ability to drive DirectX, DirectSound, GDI+, which is of course much suited to C++, it's NOT the main point of using it. That's something that could be replaced by helper .DLL modules, as discussed here. But that's just a tiny fraction of what a complete simulation of a system, like an fmc, or other airplane systems is.

The kind of questions I'm seeing here (and sometimes I try to help, when I have time), asking where is the best place to put this and that, where to initialize things, how to share variables, etc., indicates that many developers don't have a very clear idea of basic programming patterns (or what "patterns" are in the first place), but that's something that an OOP language would have forced to do, and it comes very naturally with it.

Since the Flight sim SDK always allowed to use C++, that would be the most logical choice, but it's not the only one, C# is almost as good as C++, but without all the pain involved in having to deal with pointers, memory, while still allowing to apply proper programming practices, with no limitations I can think of.
 
A certain amount of XML scripting is unavoidable, since that is the only option in a modeldef.xml file... :stirthepo
 
A certain amount of XML scripting is unavoidable, since that is the only option in a modeldef.xml file... :stirthepo

Of course. That's why I always suggested to keep the XML in the modeldef.xml file as simple and "dumb" as possible, just generating an event (standard or custom), to be catched by a C++ Event Handler, that will do all the actual work.
 
It's the best AVAILABLE (meaning, you don't have so many other choices...) option to start learning about doing gauges or modify existing one and learn something in the process.

Yes, it's the best but not only to start learning. If you take a look at the vast universe of freeware and commercial aircraft and panels released for FS (9&X) you'll find that a huge majority use XML files as a source for standard gauges. Even the latest commercial projects, some with highly advanced Virtual Cockpits, are handling complex code within their modeldef XML files.

For Commercial, yes/no, meaning the quantity might have been improved compared to old times, but it hasn't do anything to improve the quality. And the best commercial developers are divided between those that always used C++, and those that are redoing all their existing stuff with it. For the Commercial market, the only thing that XML has achieved, is both lowering the entry barrier for new developers, but it also lowered the general quality of the offering. The only thing "good" is that, by bringing more developers to FSX, one can only hope new talents will eventually rise, which is surely good for everybody.

Commercial developers have been using C++ to model standard systems since FS' first days, in one way to protect their work from piracy and competitor's watch. Since Virtual Cockpit has become the standard view mode, most of them are programming their gauges directly as animated objects controlled by modeldef XML scripts, as I stated before. Some of them still use C++ in extensive graphical displays and system's control, but even in those cases you'll find basic 2D gauges (like COMMs,Airspeeds, etc) coded in XML and defined in VC sections within panel files. I find this very reasonable because I don't see a true reason to program otherwise; I can develope gauges and or modules in C++, with or without Simconnect, and I wouldn't ever think of writing an analogic Airspeed in anything but XML, for obvious reasons that you resist to accept. And it is not because of any kind of technical limitation I may have, such being the case you might think so.

Regarding what you noticed of a lowering in some addon's quality, it has nothing to do with XML but it's basically related to market strategy. Most of aircraft addon's customers don't care too much about system's fidelity to rw, and this conduct has been expanded lately after the "FS native limitation in handling real flight parameters" tale (which is true in some aspects) is more often heard. So it has become more profitable to build aircraft that are visually perfect, with acceptable flight models and systems, able to be released in a short period of time than to invest months, even years, in developing an almost "systems perfect" model that counts single in a store's shelf. There are of course few exceptions that do nothing more than confirm the rule.

I find XML to be cumbersome and fiddly to debug. Once you have Visual Studio properly setup to debug FSX, C++ is very straightforward. The debugger is one of the BEST features in Visual Studio, I would rate it as a reason to NOT use XML.

Really it's a shame that you have such difficulties with XML. I, on the other hand, find it simple, easy to understand and easy to code. But maybe it's just me.

This very thread had a suggestion to rely on SEVERAL external .DLL modules (FSUIPC, a sound module, xmlvars, other tools, ALL made in C++, of course...), just to do what is not possible using plain standard C++ and the official SDK.

Again, while I can fully support this suggestions for someone developing as an hobby, to offer some freeware, I would never, ever, suggest that anyone would BUY anything based on such suggestions.

Well, you can suggest, or not suggest, whatever you want. In the end will be nothing but your personal opinion, which some people might consider valuable and some other might not.

Is someone asking money for his work, lacking the basic ability to set-up a C++ compiler and do something as trivial as a sort routine ? What's the point discussing about fps and resource optimization, when there might be *commercial* developers ( I don't know if this was the case, but maybe someone else reading this thread might seriously think to use such approach ) using XML to sort data??

Anyone has the right to ask money for his work, and there will be someone who will probably buy his product. Succeeding in sales will depend on how much customers liked the product, not the level of C++ expertise the developer has. I've never seen a customer ask in a support forum whether the gauge programmer knows how to setup a compiler, or build a sort routine.

HTML IS the tool designed to do what is usually used for: creating hypertext documents that links to each other. It has obviously grown a lot over the years, it has added support for many script languages, is now way more flexible in rendering, but is STILL the right tool for THAT job, C++ has never been an alternative to HTML, as your sentence seems to suggest.

But in the very begginings of the Net, its developers have to choose the proper language/tool that would fit in the schema they were thinking, that should be simple, reliable, easy to code for the most universe of programmers, and also fast to transmit. Surely C++ was not an option, as you correctly stated. They chose HTML and that was, obviously, a clever decision.
Now, MS at one point faced with kinda same dilemma: to choose a language/tool that, being simple, reliable and rather easy to program should bring more developers to the Flightsim arena, meaning more future sales. Indeed they had already C# and C++, but that wasn't enough. So they included XML and that was, obviously, a clever decision as well.

XML, on the other hand, is NOT a scripting language, and it has never been designed for that. It's a STORAGE format, designed to allow easy interchange of data and structured parsing. Which means, is NOT the "right tool for the job" for this application, which is modeling the BEHAVIOUR of real world systems like gauges, flight computers, etc. The "right tool for the job" in this case, would be an Object Oriented programming language.

You're right, XML is not a scripting language though it can support scripts. And FS, when building gauges, uses similar functions both when reading their structures from an XML file and when reading them from a compiled .gau/dll. The main difference lies in XML files being compiled by FS at run time, and C++ coming already compiled and thus, (allegedly) better optimized. Using XML source files FS builds gauge classes that also have equivalent to C++ module init/deinit, gauge callback, mouse callback and event_handler functions/routines.

Your "Leaving apart complex graphics" comment is quite telling, and you are really missing the point here: the ability to drive DirectX, DirectSound, GDI+, which is of course much suited to C++, it's NOT the main point of using it. That's something that could be replaced by helper .DLL modules, as discussed here. But that's just a tiny fraction of what a complete simulation of a system, like an fmc, or other airplane systems is.

I wouldn't dare to talk about a tiny fraction. Just do a search on this forum and you'll discover very interesting projects that were developed by using advanced XML scripts combined with external modules like those named by Bob (the OP). Fortunately MS was smart enough to include XML to C++ interaction via those modules, which expanded XML possibilities to a level hard to imagine years ago. Another clever decision for sure, whether you accept it or not.

Since the Flight sim SDK always allowed to use C++, that would be the most logical choice, but it's not the only one, C# is almost as good as C++, but without all the pain involved in having to deal with pointers, memory, while still allowing to apply proper programming practices, with no limitations I can think of.

MS brought XML to developers. Developers (mostly) made a choice. Customers also. And FSX blossomed, still being current after so many years since released. Reality is the only valid truth.

Tom
 
Last edited:
It's hard to read about sorting methods without thinking about the different algorithms available, especially Bogosort: check cards to see if sorted, if not throw them into the air, pick up from floor, check if sorted, repeat if not sorted. Cracks me up every time!
 
Yes, it's the best but not only to start learning.

It's the best for learning, and one will learn fast how limited it is. If he hasn't yet, it's only because he still have tackled something *really* complex.

If you take a look at the vast universe of freeware and commercial aircraft and panels released for FS (9&X) you'll find that a huge majority use XML files as a source for standard gauges.

You keep mentioning "quantity", while I was more concerned about QUALITY. And this, I'm afraid, is sorely lacking. Yes, even the most famous FSX developers out there, could do MUCH better.

Even the latest commercial projects, some with highly advanced Virtual Cockpits, are handling complex code within their modeldef XML files.

Again, the quantity of XML used doesn't say much. And I've said in my previous reply to Bill, of course XML will be used inside .MDL files, but what I don't agree with, is precisely the usage of it for "complex code", because it makes for LESS efficient code and it's NOT any faster to develop, because it's just wrong trying to shoehorn something that XML has never designed to do, and does it in an inherently messy way.

Commercial developers have been using C++ to model standard systems since FS' first days, in one way to protect their work from piracy and competitor's watch.

That's just a very minor reason for using C++. Again, if someone uses C++ JUST to protect from piracy, he's missing the WHOLE point of using C++ in the first place...

Since Virtual Cockpit has become the standard view mode, most of them are programming their gauges directly as animated objects controlled by modeldef XML scripts, as I stated before. Some of them still use C++ in extensive graphical displays and system's control, but even in those cases you'll find basic 2D gauges (like COMMs,Airspeeds, etc) coded in XML and defined in VC sections within panel files.

Doing an hybrid approach it's even worse. Once you took the pain to setup a C++ compiler, it's way easier to do everything in C++.

I find this very reasonable because I don't see a true reason to program otherwise; I can develope gauges and or modules in C++, with or without Simconnect, and I wouldn't ever think of writing an analogic Airspeed in anything but XML, for obvious reasons that you resist to accept.

I wouldn't ever think of writing an analogic Airspeed in anything but C++, instead, if I were doing a 2D panel. On a VC-only panel, instead, I would probably model the needle in 3D, link it to an animation with modeldef.xml which doesn't do *anything* other than rotate the needle, and drive the variable from C++, so it would be properly integrated in the bigger picture of a larger, probably more complex, system simulation.

A sample of something that, as of today, is still unbeaten in speed, smoothness and quality, using ANALOG gauges on a 2D panel (yes, 2D panels are passè today, but I did this in 2005...), I suggest having a look or at least read some reviews of the Cloud9 MB339 and the Cloud9 Phantom. These were using a framework (100% C++, of course) that allowed me to use GDI+ for ANALOG gauges, dispelling the common knowledge that GDI+ was "slow" (it's not, if you know how to use it) and only useful for glass cockpits, because nobody figured it out how to have a background with smooth GDI+ needles on top of it.

The Cloud9 Phantom was released in 2006, see some comments here on Avsim from 2012 (6 YEARS later!!) commenting on a newly released F4, that still couldn't match it:

http://forum.avsim.net/topic/381357-newly-released-f4-phantom/

A sample of something that instead uses the approach of a fully 3D VC (with no 2D panels), was of course the F/A-18 we made for Microsoft to be included in FSX Acceleration. This uses the approach I think it's the best of two worlds: there's a LOT of XML modeldef.xml animations, but the XML inside is as DUMBEST as it can possibly be. The real work is done entirely in C++, and the interesting fact is that, the whole airplane code is just 800K... The result, of course, is that the F/A-18 is one of the smoothest airplanes ever made for FSX, which is even more interesting, considering it's made with 4 ( 3 DDI + 1 HUD ) GDI+ glass gauges, which are usually considered very "slow".

This a discussion of the famous "Petraeus Index", a benchmark which was made to test AIRPLANE relative performances, all other things being equal:

http://forum.avsim.net/topic/242828-the-petraeus-index-version-2-feb-2009/

Unfortunately, the actual graphics is not available anymore on the internet, but if you read the comments in that thread, BOTH the F/A-18 AND the EH-101 (the other airplane I made for MS), were at the TOP of the benchmark. The F/A-18 was released in 2007, and it was even fps *limited*, by default, but it includes tweaks to make the fps even better, so with a today's fast machine, the gauges can refresh at 60+ fps, if your system can handle it.

Regarding what you noticed of a lowering in some addon's quality, it has nothing to do with XML but it's basically related to market strategy.

This might be true, but it doesn't have anything to do with the choice of using XML vs C++. I'm not even happy with the quality of some that are considered the best products out there. There must be something *wrong* if an airplane lowers your fps in half, and takes 1GB of RAM, and I simply don't buy the explanation that "it models complex systems", there might something else going on, because C++ code on modern CPUs can't really slow down a system, regardless how "complex" it is. Either the developer doesn't do his job properly, or there's a fundamental problem in the overall approach.

BECAUSE an airplane .MDL is "complex", that's PRECISELY why you want to keep the XML in it (in the modeldef.xml file) as simple as possible, and do the "real" work in C++. An airplane with hundreds or even more ( I think the PMDG 737 has more than *thousands* draw calls = part animations ), moving part, will benefit more and more from moving away from XML, because nothing is slower than string processing, and XML parsing is the showcase piece of string processing!

Really it's a shame that you have such difficulties with XML. I, on the other hand, find it simple, easy to understand and easy to code. But maybe it's just me.

This can be easily reversed: if you can't see how FASTER and BETTER is debugging with C++ and the excellent Visual Studio debugger, compared to the clumsly and limited debugging options you have with XML, the only possible explanation is that you never tried doing a real comparison.

Well, you can suggest, or not suggest, whatever you want. In the end will be nothing but your personal opinion, which some people might consider valuable and some other might not.

The whole point of this forum is to share opinions. It has been years since I've made an airplane product, and I'm really too busy right now managing my company, to have any hope of doing another airplane project again.

But precisely because many years has passed, I think I can now share some of the things I've learned in those 20 Years of professional Flight sim development, and I don't considered them to be business secrets anymore, so maybe someone might find it useful and research on his own.


Anyone has the right to ask money for his work, and there will be someone who will probably buy his product. Succeeding in sales will depend on how much customers liked the product, not the level of C++ expertise the developer has. I've never seen a customer ask in a support forum whether the gauge programmer knows how to setup a compiler, or build a sort routine.

Of course users don't care how something is done, but they WILL notice when something has good performances and doesn't take too much memory. It's not user's role to question development languages, but they will surely notice when something works better than something else.

Now, MS at one point faced with kinda same dilemma: to choose a language/tool that, being simple, reliable and rather easy to program should bring more developers to the Flightsim arena, meaning more future sales. Indeed they had already C# and C++, but that wasn't enough. So they included XML and that was, obviously, a clever decision as well.

And they started to move away from it, because they introduced LUA (which I'm not particularly love, but at least IS a script language...) in the MS Flight SDK, and got away with RPN notation in modeldef.xml! While still not the best possible solution, at least they knew what the biggest XML shortcomings were. Note that, if MS Flight SDK ever reached the release stage, it would have meant an "earthquake" for XML developers, since they would have had to REDO all their existing XML code (the more complex, the more rework needed), since the "new" XML in MS Flight wasn't backward compatible, in the most painful way, in the expression evaluator, the core of it...

Of course, someone that used my preferred approach, of making the XML code as simple as possible and doing everything with C++, would have been spared from such pain...that's another very good reason to prefer C++ to XML. XML is not a standard, it can be anything, depending how it's parsed. Something changes in the sim and how it processes XML, and your precious code might become useless. Just see what happened with P3D, which only accepts &gt; and doesn't accept the > sign. It's very *minor* thing, but it's enough to stop lots of code from working.

Of course, if you have your own routine coded in standard C++, nobody will ever take it away from you, your time investment is preserved, even if you would need to eventually move away from the FSX "family".

If a developer made a complex airplane entirely using standard C++ code and libraries, and linked it to FSX only in the thinnest way possible (as I've suggested), compared to another developer who made incredibly complex things in XML "code", who do you think will ever had any chance to move to, let's say, X-Plane, in case FSX and/or P3D would eventually "fail" ?

And FS, when building gauges, uses similar functions both when reading their structures from an XML file and when reading them from a compiled .gau/dll. The main difference lies in XML files being compiled by FS at run time, and C++ coming already compiled and thus, (allegedly) better optimized. Using XML source files FS builds gauge classes that also have equivalent to C++ module init/deinit, gauge callback, mouse callback and event_handler functions/routines.

"(allegedly) better optimized" ??? A WORLDS AWAY BETTER OPTIMIZED!! But again, that's not the whole point, the whole point is that with XML code, you are forced to do something that it would have been very *easy* (and very fast) in C++, more complex that it would have been. So, it's slower for two reasons: both because XML parsing is inherently slower, and it scales very badly, but also because the code logic itself becomes more complex because it's limited by what is really a glorified expression evaluator, not really a "language".

I wouldn't dare to talk about a tiny fraction. Just do a search on this forum and you'll discover very interesting projects that were developed by using advanced XML scripts combined with external modules like those named by Bob (the OP). Fortunately MS was smart enough to include XML to C++ interaction via those modules, which expanded XML possibilities to a level hard to imagine years ago. Another clever decision for sure, whether you accept it or not.

Doing something just because it can be done, doesn't automatically means it's a good idea doing it. Yes, I could go off-road with a sport car, but why would I ?

MS brought XML to developers. Developers (mostly) made a choice. Customers also. And FSX blossomed, still being current after so many years since released. Reality is the only valid truth.

You just made my point. Customers, without even knowing, grant with commercial success the developers who use mostly C++, just look what the best selling airplanes are.

Yes, someone might enjoy very good commercial success with a product that doesn't use C++ at all, why not ? But this doesn't prove your point that *because* it can be done, it's always the best choice, maybe it was for a particular product, but you will never know if it could have been an even better in C++, your argument that because there are developers having success using XML or that the FSX platform has blossomed because of that, it's not enough to prove that XML is the automatically the "best" choice.

I might say that, instead, without any support for C/C++ and 3rd party modules with very extensive access to the platform, FSX would have been JUST like any other "moddable" game out there, something that might be nice for users having fun modding stuff, but not nearly enough to start a (small) *industry*.

Many games have some kind scripting technologies, similar to what you could do in FSX XML, most of the times even better using more powerful languages like Python, LUA, etc. but very, very FEW allows full development of proper (and potentially dangerous) .DLL modules using C++ and guess what, NONE of these games has so much commercial development available.

So, the only fact I see here, when comparing FSX to other games, is that FSX has C++ and full blow support for plug-in modules and if it only had XML, it wouldn't be much better (in relationship to having started an "industry" of add-ons, which of course keep users interest high) than all those other games with scripting abilities.

As I've said, it's not that having XML included was a "mistake". Offering a development environment geared towards beginners has ALWAYS been a successful strategy for MS, some argued it was Visual Basic which really kicked off Windows, and the ability to develop something with an easier starting approach DOES bring value to the "platform", and this will in turn attract better developers, or will simply turn beginners into better developers, and those will soon enough realize how much better they will work with a better programming language.

There IS room for both kind of developers, but for exactly the same reason, it's just wrong insisting that you can do "everything" that C++ can do in XML so, there's no point using C++ because XML can do "everything". Yes, it can do lots of stuff, but C++ would do the same stuff way better and more efficient and even consuming LESS developer's time. It will take more time to LEARN C++, but once you learned what it really MEANS programming in C++ (which doesn't mean compiling a gauge, it means using proper classes and programming patterns), and you have all your base framework in place, you will proceed FASTER with C++.

While XML was designed to exchange data, C++ was designed to increase programmers productivity.
 
Last edited:
I did believe XML was easiest until I caught on to C++. Suddenly XML became really clunky and troublesome to work with....whereas C++ became so much easier that I cannot help but adore it.
 
I did believe XML was easiest until I caught on to C++. Suddenly XML became really clunky and troublesome to work with....whereas C++ became so much easier that I cannot help but adore it.

Yes, that was my point: C++ has a bad reputation to be hard, and yes, it might be daunting at first, if only to learn the complexity of the Visual Studio environment and setup a compiling and debugging environment. But once you "get it", it becomes very clear and logical, and everything clicks back in place.

I think a problem with C++ in the Flight-sim community, has always been the lack of proper tutorials, because those using C++ were very protective of their business secrets, and I might even put myself in that group, because some of the things I tried to explain here, were approached many years ago, so I will try to be more helpful from now on.
 
...
I think a problem with C++ in the Flight-sim community, has always been the lack of proper tutorials, because those using C++ were very protective of their business secrets, and I might even put myself in that group, because some of the things I tried to explain here, were approached many years ago, so I will try to be more helpful from now on.

Umberto, it's a huge problem. In fact, this situation is the single biggest practical advantage to developing gauges with XML. With XML, you can get help if you need it. With C++, you're on your own.
 
Well, once upon a time we had the likes of Arne Bartels & others who were quite helpful in the AVSIM "Panel and Gauges" forum. There is also Dai Griffith's Magnum Opus on gauge development. Unfortunately none of that really covers C++, GDI+ or DirectX gauge development.

Perhaps a new forum here dedicated to a series of "How to" type articles beginning with the very basic essentials of getting one's Visual Studio set up, as well as how to create a rational development pipeline would be useful. :teacher:
 
Perhaps a new forum here dedicated to a series of "How to" type articles beginning with the very basic essentials of getting one's Visual Studio set up, as well as how to create a rational development pipeline would be useful. :teacher:

That would be really great to open a own forum for this matter.

Edi
 
Actually, we have the wiki for just such an educational project.

The topic is meandering faaaaaar off the original post. Why not start a new thread discussing an FS-specific tutorial of C++ and advanced gauge development?

Dick
 
There is a pretty good tutorial out there....The ESP GDI+ example. It shows a basic OOP'ed gauge callback, along with everything needed to set up the gauge's link with the panel system. It also shows how to set up a basic SimConnect callback, retrieve variables using SimConnect, as well as handle events. The FSX SDK while not always as clear as I would like it to be still is good enough to get you going with everything else SimConnect related. Combine that with Prof John Smiley's book on C++ is how I learned things. I decided to try comparing the example and the book's explanations to try and see if I could find a pattern and that's when the basics of functions, classes, variables, pointers etc all suddenly fell into place. Granted my first project used a rather brute force style and could be way cleaner but even then C++ was suddenly faster and easier. Its a slightly modified ESP GDI+ gauge project that I have been using as a template to build on for every single C++ project I have done so far.
 
Last edited:
Status
Not open for further replies.
Back
Top