Comments on: X-Plane 10 Instancing Compatibility Wrapper https:/code-sample/x-plane-10-instancing-compatibility-wrapper/ Developer resources for the X-Plane flight simulator Sun, 28 Jan 2018 15:17:36 +0000 hourly 1 https://wordpress.org/?v=6.6.1 By: Ben Supnik https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-25032 Sun, 28 Jan 2018 15:17:36 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-25032 In reply to Saar.

You don’t need to hide the object for performance reasons – we do that.
If a script is going to show and hide the object, I’d suggest positioning, not deleting the instance, because the script could “thrash” it. But it’s a hard call – if the script hides it permanently a delete would be ideal.
The coordinate changes happen at specific times – you have to monitor the lat_ref and lon_ref datarefs to detect jumps. IF the coordinate system jumps back to how it was before, your old coordinates may seem okay. But you can definitely be at one airport in two different coordinate systems depending on flight direction.

]]>
By: Saar https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-25029 Sun, 28 Jan 2018 12:48:33 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-25029 In reply to Ben Supnik.

Hi Ben,

Thanks for the clarifications, here are some explanations from my side:
1 and 2. When I tried “instancing” I started with the original example: “https:/code-sample/instanced-drawing-sample/”.
Unfortunately I failed to load “physical” files from HDD.
This is when I tried the code in this page, but I was surprised it was a set of functions and not a full plugin.
Once I understood it was a snippet of code from “XPLMInstance.h” which is part of XPSDK300 version I was able to load my custom object or any object file.
This is why I wrote that I do not understand why the name holds wrapper in it since it is the only correct way to load a 3D Object and create an instance in XP11, I neglected XP10.

3. Regarding coordination location refresh. I currently use static objects that are placed in certain location. I expected that if My plane will be position far away (more than 1000nm) from the object and then I position back in same place I’ll have to re-calculate local world coordination.
The tests that I did prove me wrong, the 3D Objects where visible in the exact same place.
I haven’t conducted other tests, but I remembered from XP10, If a 3D Object was located in adjacent DSF, and there was a scenery load, I had to re-calculate the 3D Object local coordinate, or it will disappear.
I might need more test to prove my point, but so far it just works without recalculation.
I’ll update if I will prove my self wrong.

4. Regarding hiding an Object – this is only for cooling reasons. Back in XP10 I gave a designer the option to place a simple 3D Object in the XP World. This was useful when a mission designer wanted to use “show/hide” object to drive the mission.
Other reasons to use show/hide:
1. Save drawing if plane is far away, or at certain distance (mission designer decide).
If I understand correctly, it is automatic when using instancing ?
2. Part of mission, example: a passenger that waits for a plane(show), and passenger get on a plane(hide).

My rule for this feature was: if you can’t do it from WED, you should try “dynamic 3D Objects”.
My intension’s are the same for XP11.
So, there are not many “show/hide” actions and it is only for specific driven ones.

My next implementation will probably be – moving objects. In this case, I’ll have to re-position the instance every frame to make the “movement”. Of-course I prefer to use XPSDK for this task, but as I understand from your answer, it is not implemented.

Last, I have no idea how ATTR_hide is manipulated from a plugin and I’ll consider it if it is simple to implement.

Thanks
Saar

]]>
By: Ben Supnik https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-25015 Sat, 27 Jan 2018 20:21:06 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-25015 In reply to saar.

First, let’s be totally clear. The point of this code sample is NOT to show you how to use the new XPLMInstancing API. It is to give you utility code to replicate the new SDK function in OLDER versions of the SDK, so that you can write a plugin using the new API and have some compatibility with XP10 and XP11.05. With that in mind:

1. This doesn’t make any sense. You can load ANY OBJ you want at any time – you are responsible for providing a loaded object to XPLMCreateInstance, and you would get it fro XPLMLoadObject[Async] – any physical or virtual library path is fair game.

2. This doesn’t make sense to me either – I think you’re confused about the point of this code. The only future-proof way to draw objects is via the XPLMInstancing API – the old way (calling XPLMDrawObject from a draw callback) is going to be incompatible with future drawing APIs like Vulkan and Metal.

So you should rework your code to use the new instancing API, and use these utility functions if you need 11.05 and earlier compatibility.

If there is a use case for XPMDrawObject that is not covered by this API, we’d like to know what you were doing, but I fear it was probably illegal.

3. This is still necessary – since your coordinates are in OpenGL coordinates, you have to reset your position when the coordinate system changes. This isn’t fantastic, and we may revisit it. (For dynamic objects, you’re going to have to cope with shifts because you’re telling us the position a lot. For relatively static objects it would be nice if the SDK would rotate it for you. But if you are going to update the object, that’s wasted work.

4. You can use ATTR_hide or XPLMInstanceSetPosition. Generally you should destroy the instance if it’s going away for a while, but move it ‘far away’ if you need a high frequency effect.

What are you doing that requires you to show/hide the object so much? Note that X-Plane will skip drawing if it detects that the object is off-screen – you get this ‘for free’.

]]>
By: saar https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-25011 Sat, 27 Jan 2018 19:36:36 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-25011 Hi,

I need some clarification regarding Instancing:
1. The instancing example, not the wrapper, is only good for LR libraries that are probably being loads on X-Plane start up and used by LR team. Is this true or am I missing something (can we do the same?)

2. The only way to load custom 3D Objects is just through the Wrapper, I’ll appreciate if there is other option. I mean it is not just for compatibility staff, it should be the only way to load custom 3D Objects in xp11.10 when using instancing, so why use the term “wrapper” ?

3. On X-Plane 10 and I believe 11 prior to 11.10 to draw 3D Objects we had to call XPLMWorldToLocal when certain events occur, like: “XPLM_MSG_SCENERY_LOADED” so 3D Objects will keep their visibility.
When I use instancing, I do not use “draw call backs” anymore, and it seem that the call to XPLMWorldToLocal is not needed in the case of “XPLM_MSG_SCENERY_LOADED”.
If that is true, any other hidden benefits ?

4. If I want to show/hide an instanced object, should I only use: “XPLMInstanceSetPosition” and “XPLMDestroyInstance”. I mean in X-Plane 10 if I wanted the “cool” 3D Objects that rendered far away from plane, I just skip them in the “draw” call back.
In XP 11.10 there is no such option. So, from performance perspective, should I keep an instanced object all the time without “cooling” logic? is there no performance price to code “position”/”destroy”/”position” repeatedly ?

Thanks
Saar

]]>
By: saar https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-21576 Sun, 03 Sep 2017 17:03:39 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-21576 In reply to Steve.Wilson.

Too hard core for me…

]]>
By: Ben Supnik https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-21560 Sat, 02 Sep 2017 22:59:01 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-21560 In reply to Steve.Wilson.

Drawing to the _panel texture_ (which ends up in the 3-d cockpit) is 2-d drawing to X-Plane, so we are hoping to wrap it in compatibility, just like 2-d window overlays.

The main issue is that we don’t see a way to share _depth buffer_ information between any of the modern drivers (metal, vulkan) and legacy GL, and this means we can’t correctly integrate 3-d plugin drawing with our content.

Our current expectation is to run a GL context and composite 2-d plugin content in place; we are not planning to ‘intercept’ the calls. But if an OpenGL 2.x or 3.x layer on top of Vulkan or Metal became available we could run plugins on top of that. Molten-GL has the problem of beign payware and (more importantly) GL ES 2.0, while plugins can basically assume full GL 2.1 on desktop (and 3.x + compatibility on windows).

]]>
By: Steve.Wilson https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-21555 Sat, 02 Sep 2017 18:31:10 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-21555 Tyler & Ben: Will there need to be a similar compatibility layer added for things like drawing on the 3D cockpit, namely the panel.png as SASL is frequently used? I see the potential for lots of products breaking if this gets gnarly as Vulkan/Metal are integrated.

Or is it possible that there will be a compatibility layer added within the SDK libraries themselves so that OpenGL calls are automatically translated on build, allowing current drawing routines to remain valid throughout the transistion?

]]>
By: Steve.Wilson https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-21553 Sat, 02 Sep 2017 18:24:39 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-21553 In reply to Ben Supnik.

ANSI C forever. The other stuff needs it’s *own* letter of the alphabet. 😉 Nothin’ like the classics.

]]>
By: Ben Supnik https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-21550 Sat, 02 Sep 2017 16:57:09 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-21550 In reply to saar.

If I had done the examples and not Tyler, they would have been pure C.

]]>
By: saar https:/code-sample/x-plane-10-instancing-compatibility-wrapper/#comment-21541 Sat, 02 Sep 2017 10:26:54 +0000 http://developer.x-plane.com/?post_type=code-sample&p=7835#comment-21541 I am not criticizing, but the code is so pre C++11 times 🙂
Since you defined the new OSs and Compilers as your base line, whty not use “auto” in your examples, can me easier and cleaner. Something like:

Instead of:
for(vector::iterator it = s_instances.begin(); it != s_instances.end(); ++it)
{
xplm_instance_t * i = *it;
for(int d = 0; d data.size(); ++d)
XPLMSetDataf(i->datarefs[d],i->data[d]);
XPLMDrawObjects(i->model, 1, &i->position, 1, 0);
}

We could write:
for(auto it : s_instances )
{
xplm_instance_t * i = *it; (not sure if you need the “*” in this case)
for(int d = 0; d data.size(); ++d)
XPLMSetDataf(i->datarefs[d],i->data[d]);
XPLMDrawObjects(i->model, 1, &i->position, 1, 0);
}

I believe we should let the new compilers “work” for us too. I mean I hate these all iterator overhead…

Cheers and keep the great work
Saar

]]>