• 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.

C++ and XML

Messages
240
Country
switzerland
I was trying to reply to a question in the other thread, but it was closed while I was typing it...let's try again here.

Let me just illustrate an example:

Get Engine N1 Parameter:

XML-Use A: Vars and that's it.

C++-Add variable into Simconnect Data Structure, more keystrokes to add to data definition, Finally access the struct to get N1 data.

You can clearly see the steps and number of key strokes is way more.

That's not how you do it in C++. Not the only way, at least...I would probably use Simconnect ONLY if I had to program an EXTERNAL Simconnect client (an out-of process .EXE which runs together with FSX), because an external client doesn't have any other choice than using the Simconnect client-server model to access simulation variables.

However, a Gauge or a module, which runs in-process with FSX ( a .DLL loaded by FSX ), can access to the simulation variables directly, using the function from Panels.dll, with no Simconnect needed, and a more straightforward way of using it. Your example would look like this in C++

Code:
n1 = aircraft_varget( aircraft_varget( get_aircraft_var_enum( "ENG N1 RPM" ), get_units_enum("rpm") , 0 )

That's NOT the most efficient of doing it, it's just to show you how it would look like and that it CAN be an easy to read one-liner.

In a real program, I would have it wrapped in a C++ class, instead, that would call get_aircraft_var_enum and get_units_enum only once when the sim starts, since their token won't change while FSX is running, so there's no reason why you would call it every time you need to read the variable. But that's the optimization part...

Really, if you don't get into the mindset of REALLY using C++, which means using it properly, with the things that MAKE what C++ is about, namely Object-oriented programming, with classes and templates, you are entirely missing what makes C++ more productive, and are in fact using C.

I believe that THESE kind of tutorials are probably more needed.
 
I was trying to reply to a question in the other thread, but it was closed while I was typing it...let's try again here.
That's NOT the most efficient of doing it, it's just to show you how it would look like and that it CAN be an easy to read one-liner.

Right, I forgot about this. However, that still potentially requires more keystrokes then XML. (ignoring efficiency of code as you said)

Obviously XML is not OOP and that's the point, its simplistically simple (especially for beginners). Sometimes you really do not need OOP for simple things. That simplicity can help quickly build low to mid complexity aircraft. OOP is only powerful to those who understands and know how to use it, those who don't will find it bloated.

Now that I am coding multithread C++ complex gauges, obviously C++ and OOP is much better appreciated here. (Think arrays/vectors, pointers in classes etc)
 
On the topic of tutorials of advanced gauge drawing:

However, for the rest of people that already have basic to medium knowledge in C++ (and I include myself in the medium group), there is a real lack of information on how to deal with advanced GDI+ and DirectX drawing technics in FS, like those referenced by Umberto.

Many tutorials on GDI+, Direct2D is covered on MSDN. A google search will bring results.

I am currently using direct2d and may share some of the common code/functions that I use in drawing.

Maybe we can build a code library if everyone contributes a little snippet of their code.
 
I was trying to reply to a question in the other thread...

Now that you have properly started a new thread, please continue. We could use some proper pointers here, and I don't mean the *pointer kind! :duck:
 
Actually *pointer represents the value that's being pointed to and is not actually the pointer itself.... just saying. *runs!*
 
Right, I forgot about this. However, that still potentially requires more keystrokes then XML.

In my purposely "inefficient" (but still way faster than XML would have been) example, which was made for the clarity sake.

My "real" code would have looked more like this:

Code:
// Declaration, somewhere in the panel initialization
CFSVar<SIMVAR_ENG_N1_RPM, Units::percent> EngineN1;

// Usage, in the gauge loop.
EngineN1.Update();

Or, in case you want to read from multiple engines:
Code:
// Declaration
CMultipleFSVar<SIMVAR_ENG_N1_RPM, Units::percent, 4> EngineN1;

// Usage
for( int i = 0; i < 4; ++i )
{
  EngineN1.Update( i );
}

Now, before you say "it still requires more keystrokes than XML" yes, if you wanted to read ONLY ONE variable, it might. But, what kind of airplane project will need to read just one variable ? Even the simple airplanes will have the need to read many variables, and NOW C++ will start to become *shorter* than XML.

For example, imagine we have a 4 engine airplane simulation, and there's some instrument that will have to display all engine values. Somewhere, the code will have to update all those variables, and somewhere else, it will display them, either as text or by driving needles, animations, whatever.

Assuming we declared all the variables we need this way:

Code:
// declarations
CMultipleFSVar<SIMVAR_ENG_N1_RPM, Units::percent, 4> EngineN1;
CMultipleFSVar<SIMVAR_ENG_N2_RPM, Units::percent, 4> EngineN2;
CMultipleFSVar<SIMVAR_ENG_OIL_PRESSURE, Units::psi, 4> EngineOilPress;
CMultipleFSVar<SIMVAR_ENG_OIL_TEMP, Units::celsius, 4> EngineOilTemp;
CMultipleFSVar<SIMVAR_ENG_VIBRATION, Units::number, 4> EngineVibration;
CMultipleFSVar<SIMVAR_ENG_PRESSURE_RATIO, Units::ratio, 4> EngineEPR;
// this continues with all needed variables

We could then create a vector with all of them, like this, we are still in the gauge *initialization* part:

Code:
// init a vector engine data
std::vector<CMultipleFSVar> EngineData;

// fill the vector with data
EngineData.push_back( EngineN1 );
EngineData.push_back( EngineN2 );
EngineData.push_back( EngineOilPress );
EngineData.push_back( EngineOilTemp );
EngineData.push_back( EngineVibration );
EngineData.push_back( EngineEPR );

We created a vector that contains objects of the CMultipleFSVar type, which means that now, in the gauge main loop, where it counts, we can be REALLY concise, clear and have a code very EASY to maintain and upgrade, like this:

Code:
// Inside the simulation loop, we update all engine variables in one go:

for( int i = 0; i < EngineData.length(); ++i )
{
  for ( int j = 0; j < 4; ++j )
    EngineData[ i ].Update( j );
}

How beautiful is that ? Two lines, very easy to understand, to update all the variables we need in one go. And the beauty of it, this code is EASY to MAINTAIN. If you find the need to add other variables, you only need to add them to the declaration and initialization parts, for example:

Code:
// add this line in the declaration
CMultipleFSVar<SIMVAR_ENG_TURBINE_TEMPERATURE, Units::celsius, 4> EngineTurbTemp;

// add this line in the initialization
EngineData.push_back( EngineTurbTemp );

And your code to update them will STILL WORK...the code updates were trivial and easy to understand (even reading at it months/years later), and the code that "does stuff" hasn't changed...

So yes, if you need to do ONE thing, XML might be shorter, but nothing really ends up being "one thing", code grows and C++ is designed to handle code growth in a manageable way. Of course, using proper OOP methods, like these.

Sometimes you really do not need OOP for simple things. That simplicity can help quickly build low to mid complexity aircraft. OOP is only powerful to those who understands and know how to use it, those who don't will find it bloated.

No, it's only STARTING your own framework that is more complex. But after you have it, OOP would make you simpler things even simpler than XML, I'll try to demonstrate it here, but it will take several steps to get there...
 
Last edited:
Wanted to add that, some of the things I've posted here don't exists in C++, by default. They are part of what I indicated as "your framework" of classes, that are supposed to be part of your toolset for gauge programming. Something you will have to write once, and reuse many times.

In this example, the CFSVar and CMultipleFSVar classes and the Units namespace, which I'll try to cover in a dedicated tutorial.
 
To all those who are interested, the precursor to this thread can be found here, starting with post #4 -- with appreciation to Dick (Forum Moderator), who steered the discussion into a new thread and to Umberto, for starting this one.

Bob
 
Last edited:
Arno, Jon, would it be possible to fork the previous thread and merge it to this one? personally i think it would make a better structured discussion.

As for the topic, I had a blast over this last year with C++, and I am very happy that I was pushed to use it by circumstances. I don't much dabble in gauges, but for what I do, I can't imagine using XML code...
 
Back
Top