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

FSX Dynamic array in C gauge

Messages
368
Country
unitedkingdom
I'm working on a radar gauge to display shipping near the user aircraft. What I'd like to do is take the data SimConnect is giving me, do a couple of calculations to get range and bearing and then put it in an array. Once that's done the drawing routine can work its way through the array to draw all the objects before starting again.
The problem I've got is that the number of objects is varying over time so either I make an array large enough to hold the data on as many boats as I'm likely to come across (~300 with full boat and shipping traffic near the coast). Or create a new array the right size every time and delete it at the end of the drawing cycle.
The first seems inelegant and wasteful, unfortunately I can't figure out how to create a dynamically sized array in a dll gauge.
Does anyone know if this is possible and if so how to go about it?
 
well, you could use one of the Standard Template Library (STL) generic container classes, vector being the most likely for your scenario. Or you could use a linked list style data structure.
 
First of all, you need to use C++, I don't think there are any dynamic arrays structures in C, unless you write your own, or search some kind of 3rd party library.

In C++, as Beatle pointed out, you have Standard Template Library, which supports containers, that are different ways of dealing with dynamic data structures.

For an AI radar, the most convenient data structure is the Map, which is what I've used in the MS F/A-18 radar Gauge. It's an associative array, where you have unique keys associated to data. This is very fitting for the Simconnect AI model, since you ARE getting your unique key for every AI objects, both when requesting all the objects around you initially, and when new objects appear or disappear.

Having the object id, you simply insert it in the Map structure, using the insert command, or remove it when it goes away.

This way, your memory is always in synch with the AI situation. Removing objects from your Map when Simconnect notifies of this, is very easy, since you simply pass the id of the object that has been removed to the Map "by key".

Then, drawing AI objects should be very easy, since it's just a matter of using an iterator on it. All C++ STL containers supports iterators, which is an easy way to get a loop and a pointer to an object inside a container at the same time.

Using containers, you don't need to worry about memory management, because it's all done by the container itself.

Have a look at the Wikipedia page on the std::map container:

http://en.wikipedia.org/wiki/Map_(C++)
 
Last edited:
Many thanks for the pointers, I've spent the last couple of days refining the display element while using a static array to store the object data. I think the Map data structure looks like the way to go.
 
Back
Top