• 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++ Tutorial - A class to handle L: variables in C++

Thank you both for your responses.

I am thinking Toms Solution might be a better one as std::map has a performance hit as the number of items increase (talking about 100+ vars here) where as enums is resolved at compile time which essentially generate no hit.

Thanks though for this map example. It has helped me thought of other users of it already...
 
I am thinking Toms Solution might be a better one as std::map has a performance hit as the number of items increase (talking about 100+ vars here) where as enums is resolved at compile time which essentially generate no hit.

Yes, that's true, although 100 variables is still considered not too much, because the performance of the [] operator on a std::map is Log(n), which means 2 operations to access a 100 elements map, and 3 operation to access a 1000 elements map. And you could use the std::unordered_map, which is even faster, because the cost would be 1 operation on average, and Log(n) in the worse case.

But yes, I agree that nothing beats compile time, it doesn't make sense to calculate at runtime something that can be evaluated at compile time. The only case where a map could be useful, might be in a situation where your program doesn't even know the name of the L: variables to be used, for example if they are being read from a configuration file, but that's not very common (perhaps an airplane editor to create animations...)

Thanks though for this map example. It has helped me thought of other users of it already...

the std::map data structure could be used very efficiently for any kind or "radar" or TCAS gauge, anything that would have to update its content at run time, you might use the Object ID returned by Simconnect when querying for all AI around you as the key, and an object containing AI data like position, speed, altitude, etc, as the value, and iterate over the map using the iterator method, to draw the radar/tcas gauge.

That's how the F/A-18 radar is made, of course, and it was very easy to code using the std::map method.
 
Back
Top