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

Generate AI Outside the Reality Bubble

Messages
26
Hi All,

I'd like to be able to generate traffic around the globe, outside of the players reality bubble.

Is it possible to do this? Using the create Parked/Enroute I'm not able to - is nonATC different, would that allow me to do that?? (But then I'm responsible for that aircraft's positioning aren't I? Or can I tell it to head to a specific airport and land for example?).

Has anyone tried this before? Or should I be interrogating the players position and updating the AI aircraft based on that so they are generated when they would be present within the bubble?

Cheers,
S.
 
Messages
42
Country
wales
Hi Slopey,
I ran some experiments with SimConnect nonATC flying waypoints quite some time ago. As far as I recall, when they reach the last waypoint they just keep on flying in a straight line. I don't recall whether they were deleted by FSX when they reached the edge of the bubble. However I have a feeling they will survive, as certainly they were still flying at time acceleration 8x.

Later, I think I saw a tip that suggested if you make your last waypoint at zero feet above ground, the aircraft will land. You need to allow a lot of airspace for turns, the AI piloting was less than impressive. Since you are not under ATC, I guess you would have to handle all the parking yourself through additional waypoints.

Maybe you could create the AI inside the bubble then move it outside by directly updating the coordinates?

Remember that even when AI is not in visible range for the model to be rendered (10nm), just having FSX doing the state and position management carries a cost. For instance, SuperTrafficBoard has an "Optimise" function that deletes all AI except for those at a chosen airport. Let says you delete 200 "out of sight" aircraft like that, it might earn you an extra 5 fps. When I'm fighting the bar at 20, that's a big gain.

UT2 is using an "external" scheduling engine to create and remove (ATC) traffic through SimConnect. As a result, they have an articifical reality bubble much smaller than FSX but that can be a good thing for performance. STB does some similar things in certain airspace management situations.

The two drawbacks I've found using SimConnect for AI are:
- If your client disconnects, FSX kindly deletes the AI objects.
- There is little context information concerning your flight stored in FSX. You can see this with UT2 for example. Neither STB nor TrafficToolBox have information concerning departure/arrival airports and scheduling times, because FSX does not have that information either. You end up with a departures/arrivals board with a list of flights, but no idea where they are going to/coming from or at what time.

If you do go down the path of AI management, please do consider other "add-ons" like STB and the provision of some kind of API that would supply the missing scheduling information. My customers tell me there are few things more frustrating than applications that don't work well together, something I hope UT2 will remedy in the not to distant future. I'd be glad to do anything I can to help out in this area.

Give me a shout if there's anything more I can help with.

Regards
Simon
 
Messages
1,360
Country
scotland
Hi Folks

Slopey -
Yes simconnect can generate an object outside the user's reality bubble,
and do so anywhere within FSX's global environment.

Tested with user aircraft located in the UK
and placing an satellite at 30,000 km above equator
i.e. just short of geostationary orbit.

Objects are visible in Traffic Explorer,
though can't remember if it showed in Traffic Map.

Traffic Explorer also allows switching to a view of the object's location.



HTH
ATB
Paul
 
Last edited:
Messages
26
Excellent - I'll try that - thanks.

I can create the Parked/Enroute aircraft and for now, I just check periodically if the object is within the player's reality bubble - if it is, the object is created, if not, it fails and I'll try again later.

Is there an easy way to know when SimConnect removes an object? For example, if I create 2 parked aircraft at Airport A, then moved to Airport B which is distant from A, the 2 aircraft are now outwith the bubble and are removed by FSX.

Is there an event (or type of event) which fires when this happens, or do I need to poll SimConnect with the objectId and see if I get something back?

Cheers,
S.
 
Messages
317
Country
unitedkingdom
Is there an event (or type of event) which fires when this happens, or do I need to poll SimConnect with the objectId and see if I get something back?

Subscribe to the "ObjectAdded" and "ObjectRemoved" events by using "SimConnect_SubscribeToSystemEvent" and you will receive SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE messages. These contain the ID of the object and whether it was added or removed.

Regards

Pete
 
Messages
26
Mmmm, not quite as straight forward as I'd hoped - I'm having trouble getting the Add/Remove events.

I'm using the .net Wrapper and VB.net 2005.

I can successfully create AI aircraft at a specific airport without any issues as "Parked" aircraft, however, if I then fly away from there, and bump the accelerated time up to x8, those AI aircraft are removed.

What I'd like to do is trap their removal, or even query to see if they still exist.

For trapping the removal, I had hoped it would be as easy as registering for Add/Remove events (SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE) with something like:

Code:
        AddHandler fsx_simconnect.OnRecvEventObjectAddremove, New SimConnect.RecvEventObjectAddremoveEventHandler(AddressOf fsx_simconnect_OnRecvObjectAddRemove)

And when the event fired, I could process it in my OnRecvObjectAddRemove procedure, however this never seems to fire.

I can successfully trap ObjectIDAssigned messages (SIMCONNECT_RECV_ASSIGNED_OBJECT_ID), and I can trap requests for info on a specific ObjectID without issue however.

So I'm a little stuck. Does anyone have a VB or C# code snippet using AddRemove?


The other way to do it would be to try to request info from FSX based on the ObjectID I guess and look for any failure/lack or data, however, given the asynchronus nature of SimConnect, I'm a little confused about how to go about it.

How do I know that the exception received relates to the approrpriate ObjectID (which I have stored in an array) as I can't guarantee that SimConnect responses for ObjectID's will be returned in the order requested, or that another SimConnect call from another thread in my application won't fire during the request/response cycle.

Anyone have any pointers??

Cheers,
S.
 
Messages
317
Country
unitedkingdom
Mmmm, not quite as straight forward as I'd hoped - I'm having trouble getting the Add/Remove events.

Hmm. Strange. i simply subscribe to them, as with all the other System Events, and I get them all. I have to filter them to just get the aI aircraft.
I'm using the .net Wrapper and VB.net 2005.

don't know those. Are you able to subscribe to and receive any of the system events? There shouldn't be any difference.

For trapping the removal, I had hoped it would be as easy as registering for Add/Remove events (SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE) with something like:

Code:
        AddHandler fsx_simconnect.OnRecvEventObjectAddremove, New SimConnect.RecvEventObjectAddremoveEventHandler(AddressOf fsx_simconnect_OnRecvObjectAddRemove)

Well, I don't know your languages, but creating a handler to handle something doesn't automatically make them happen, now, does it? Not in my world, anyway. Surely you need to Subscribe to the events you want to handle somewhere previously, as I said originally?

Anyone have any pointers??

Why not first subscribe to the "ObjectAdded" and "ObjectRemoved" events by using "SimConnect_SubscribeToSystemEvent", exactly as I suggested. Or does the language you are using prevent you using the necessary SimConnect procedures?

Regards

Pete
 
Messages
26
Hi Pete,

It's all kept from me with the managed VB wrapper.

According to the docs, I can do:

Code:
 fsx_simconnect = New SimConnect(" VB Managed Data Request", Me.Handle, WM_USER_SIMCONNECT, Nothing, 0) 

Protected Overrides Sub DefWndProc(ByRef m As Message) 
   If m.Msg = WM_USER_SIMCONNECT Then 
      If fsx_simconnect IsNot Nothing Then 
         fsx_simconnect.ReceiveMessage() 
      End If 
   Else 
      MyBase.DefWndProc(m) 
   End If 
End Sub

Which sets up the SimConnect connection, and returns events via the handle back to my form. I can then use AddHandler to handle the appropriate message type.

I don't need to subscribe to specific events per se - as far as I understand it that's already done, and I just need to handle them.

What's confusing me is that it works for the assigned object Id, and the request data on object - but not for the Add/Remove events.

Back to the documentation for me.....
 
Messages
317
Country
unitedkingdom
I don't need to subscribe to specific events per se - as far as I understand it that's already done, and I just need to handle them.

I find that a little hard to believe. The system events all have specific string names. Where do your handler routines get those from?

What's confusing me is that it works for the assigned object Id, and the request data on object - but not for the Add/Remove events.

But you actively requested that data, didn't you? That's why you get the responses. And they really are responses more than "events" in the sense of something spontaneously occurring and you being notified.

I don't see how you'll get any events you don't ask for! It would make the system pretty inefficient. I mean, look at them all:

"1sec"
"4sec"
"6Hz"
"AircraftLoaded"
"Crashed"
"CrashReset"
"FlightLoaded"
"FlightSaved"
"FlightPlanActivated"
"FlightPlanDeactivated"
"Frame"
"Pause"
"Paused"
"PauseFrame"
"PositionChanged"
"Sim"
"SimStart"
"SimStop"
"Sound"
"Unpaused"
"View"
"WeatherModeChanged"
"ObjectAdded"
"ObjectRemoved"
"MissionCompleted"
"CustomMissionActionExecuted"
"MultiplayerClientStarted"
"MultiplayerServerStarted"
"MultiplayerSessionEnded"
"RaceEnd"
"RaceLap"

I think you must be missing something. You need to request events, not expect them as a right.

Regards

Pete
 
Messages
324
Country
us-virginia
Yep, Pete is correct, you have to call the SubscribeToSystemEvent function to enable SimConnect to send you those specific events, which then will be passed to the .Net event handler you have registered.

If you are just starting out with SimConnect under .Net, you might also want to check out my new Managed SimConnect SDK (see the blog link in my signature), I've been looking for some VB devs to try it out :-> I will warn you, in advance, that the docs are pretty much non existent at the moment and the SDK doesn't currently include any VB samples (just haven't had time to port/write any yet). My SDK does do away with the need for any files to be installed in the GAC or WinSxS folders, but only supports SP2/XPack/ESP.

Also, you might want to consider updating to VB 2008 (or even the current Beta 2010) from the 2005 version, lots of additional features/class libraries/etc have been added (and support for .Net v2 seems to be slowly being dropped by some folks already, although I do currently include a v2 version of my library, albeit with somewhat limited features because there's no Named Pipe support in v2).
 
Messages
26
Ah ha!!! Ok - gotcha.

I was missing the subscribe to - the previous examples I've found on the net have only dealt with request rather than waiting for an event to fire.

Doh!

I'm sticking with VS2005 just now, because I don't want to have to re-licence a load of 3rd party controls for 3.5 ;)
 
Messages
324
Country
us-virginia
I'm sticking with VS2005 just now, because I don't want to have to re-licence a load of 3rd party controls for 3.5 ;)

I can understand that, although you can still build .Net 2.0 apps within VS2008 (it supports multi-targetting, you can build 2.0, 3.0, or 3.5 compatible apps) when you need to use the 3rd party controls, and you can use 3.5 along with WPF/XAML when you don't :->
 
Messages
26
Yes, but I'd also have to buy a copy of 2008, which as a cash strapped hobbyist, I'm not too bothered about.

I use VS2008 in the office, and it's ok, but I find the IDE quite slow on large projects (which granted should be split up anyway), and there's not enough of a driver for me to move up right now. Not with 2010 round the corner.
 
Messages
26
Just to let you know - all working now :)

Only question left is should a create Enroute or create Parked call to SimConnect result in an AddRemove event being fired? Does'nt seem to, but I can get the ID from the AssignedID call anyway so it's not an issue.
 
Top