TestExternalSim Sample Problems

smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Fri Jun 03, 2011 5:20 pm

I'm new to Prepar3D development and want to evaluate using it as a rendering engine for pre-recorded time history data. The TestExternalSim sample looked like a good place to start but I'm not sure I'm smart enough to fully understand how it is supposed to work.



In order to simplify debugging (and trying to understand how it works), I did convert it to a *.exe (instead of a *.dll).



So I start Prepar3D with the default configuration/aircraft/location, then launch the TestExternalSim application and step through it. It does receive the SIMCONNECT_RECV_ID_OPEN event and executes the OnRecvOpen method and the associated menus are added. Those do function so the appropriate events are received; however, it never appears to receive any EXTERNAL_SIM events and therefore never executes the OnRecvExternalSimEvent method. So what causes Prepar3D to send the external sim events and what am I missing to make that happen?





Thanks

beatle
Posts: 88
Joined: Thu Sep 16, 2010 8:34 pm

Postby beatle » Mon Jun 06, 2011 11:21 am

Hey smguest,



You have to create a SimObject that uses the external sim (instead of one of the internal sims). You also have to decide if you want to create a primary sim (which does all the simulation for a SimObject) or a secondary sim (more useful for adding additional subsystem simulations, mostly to drive custom animations).



Creating a SimObject using an external sim can be done in several ways:



* Create a SimObject container which includes additional items in the aircraft.cfg/sim.cfg file (I'll hunt up an example and post in a seperate reply) and then just load that SimObject with the Select Aircraft dialog



Use one of the 3 new API functions added to allow using existing SimObjects with an external sim:



* SimConnect_AttachExternalSecondarySimToSimObject - used to attach a secondary external sim to any existing SimObject (either AI object or user's object) - this option is also useful to create a record flight data type addon (just as an easy way to get called every sim frame and passed a structure of SimVars for a specific SimObject, could also record any events that you have mapped).



* SimConnect_AICreateObjectWithExternalSim - used to create an AI object based on any existing SimObjects in your sim (specified using the title= string from the aircraft.cfg/sim.cfg) but using the specified external sim (this is the option you would most likely use for doing recording playbacks, unless you specifically want to playback using the user's simobject - ie good if you want to playback a bunch of objects to create your own AI system say, or to create a "side-loading" Multiplayer system (like VatSim/IVAO use))



* SimConnect_ChangeVehicleWithExternalSim - loads any existing SimObject as the User's SimObject using the specified external sim (you would want to use this one for your recording playback if you want to only playback one objects recording using the user's aircraft)



So in your EXE version of the code, after the code registers the external sim using SimConnect_RegisterExternalSim (or SimConnect_RegisterExternalSecondarySim for secondary sims), you can use one of the above API calls to create one or more objects using your external sim (in fact, you could register several different external sim GUIDs in the same addon if you had a need for that and create objects using specific external sims).



Use the SimConnect_MapClientEventToSimEvent to register which events you want your external sim to be able to receive (ie every SimEvent you map to a ClientEvent code will be passed along to your external sim when they occur, those you haven't registered/mapped won't be sent to you)



Yell if you have any other questions, glad to have an external guenea pig trying this stuff out to determine where additional functionality needs to be hooked up in future releases to make this more useful - I'm fairly certain everything you will need to do a recorded path playback system is in there somewhere, that was one of my primary target uses for this feature :->



Tim


smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Wed Jun 08, 2011 9:15 am

Tim,



It is starting to make more sense now and I'll certainly appreciate any more demo material that you can provide. It does look like SimConnect_ChangeVehicleWithExternalSim will be my starting place. I'm sure I'll have more questions and do thank you for the details as I don't think I was ever going to find these answers on my own.





smguest

beatle
Posts: 88
Joined: Thu Sep 16, 2010 8:34 pm

Postby beatle » Wed Jun 08, 2011 10:59 am

Hey smguest,



Yep, I need to write up a few overview/introductory articles on the APIs added in v1.1 (and then roll those back into the SDK docs) so feel free to yell if you have any more questions/issues.



Tim

smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Thu Jun 09, 2011 10:02 am

It looks like I've gotten a test case to work with the SimConnect_ChangeVehicleWithExternalSim, very cool and thanks. I've just modified the TestExternalSim sample code so that it sends the position and attitude that I want and it works.



Now for the next step, what are your recommendations for the best way to use SimConnect so that I can set all the surface deflections/landing gear positions for the visuals? Again, I have a time history file that has these values and I'm wanting to play them back.





Thanks,

smguest

beatle
Posts: 88
Joined: Thu Sep 16, 2010 8:34 pm

Postby beatle » Thu Jun 09, 2011 11:20 am

Hey smguest,



At the moment, SimVar support is the main deficiency with the current External Sim support. We need an updated SimVar subsystem that automatically provides the backing store for variables (currently each sim type (aircraft, helocopter, boat, etc) has to provide its own support for SimVars) and allows defining new SimVars on the fly in several ways (keyed from the aircraft.cfg/sim.cfg file, via SimConnect, within an XML or C++ gauge, etc).



With the current code, what's available is a single SimVar "External Primary Sim Vars Value" which is an indexed variable and currently supports a max of 1000 vars (index 0 - 999) which can be used for anything you want, but in order to drive animations in the visual model, the visual models animations would have to be redone to use the indexed external primary sim var value SimVar. The count of these indexed vars that is supported is specified as the dwExternalSimVarCount param on the ChangeVehicleWithExternalSim call.



I don't believe we'll be able to replace the SimVar system for the next release, but I can look into adding support for more of the standard SimVars to the External Sim anchor code. I'll post a list of the SimVars that are currently supported by the External Sim (mostly provided by the base class that all Sim Modules inherit from) later today.



Tim


Return to “SimConnect Interface Questions”

Who is online

Users browsing this forum: No registered users and 12 guests