744 Forum

Apron => Accessories => Topic started by: Lashrathius on Fri, 23 Sep 2022 04:29

Title: Partial success - PSX rendering as a gauge in P3D
Post by: Lashrathius on Fri, 23 Sep 2022 04:29
Hey all,

As the title says, I've managed to get PSX rendering as a gauge within Prepar3D v5. In the screenshot below, you can see the gauge in the top left, which is an actual C++ gauge rendering the PSX window within Prepar3D. The original PSX window is located bottom right.

Hardy - before you panic - no, I did not do any reverse engineering of PSX or any of its assets. I can render ANYTHING on Prepar3D v5 - including my desktop or a Spotify window. This is using a certain rendering function found within the Windows API. I just set the target to PSX.

This shows me that it may be possible to render the PSX displays (PFD, ND, EICAS, Lower DU, FMS screens, etc.) onto a 3D model within Prepar3D. (imagine - a 3D 747 model with PSX displays rendering on the displays)

I am currently working with the 2D display, as I have to find a way to draw onto the screens in the virtual cockpit (find the HWND of the draw surface, as it's drawing to the HWND of the active window at the moment)

The limitation is that this is RENDERING ONLY - which means you will not be able to click a button on the 3D model and have those changes appear in PSX - it is purely for visuals only.

And I know someone will ask - no, this will not work in Microsoft Flight Sim. It will only work in Prepar3D because Asobo / Microsoft disabled the ability to reference the Windows API in the MSFS SDK.

Disclaimer - this is all a proof of concept, showing that it is entirely possible to render PSX within Prepar3D v5. However, it does not mean I am promising this will work, as I need to drill into the simulator to find the HWND for a 3D surface. It is only rendering on a 2D surface's HWND at the moment. If there are any programmers in this forum who know how to locate a specific HWND (and save me the time of researching), please let me know!

(https://media.discordapp.net/attachments/949770506901524540/1022709456334749726/PSX_rendering_in_P3Dv5.png?width=917&height=542)
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Gary Oliver on Fri, 23 Sep 2022 15:19
Henry,

It looks like the same kind of thing can be done using a WASM module in MSFS which is exactly how the Fenix gauges appear to be working.

Exciting stuff...
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Hardy Heinlin on Fri, 23 Sep 2022 16:35
Quote from: Gary Oliver on Fri, 23 Sep 2022 15:19... can be done using a WASM module in MSFS which is exactly how the Fenix gauges appear to be working.

Fascinating. If that is true, it's easier than I've thought. Some weeks ago I got an inquiry from Fenix. They'd like to buy the copyright on PSX and integrate it in MSFS. I declined for several reasons; one being the expected high technical efforts (ProSim code is MSFS oriented, PSX code isn't), and because of the very low mass market street price of Fenix add-ons which would kill my existing business. I would lose my independence and thus my creative freedom and motivation. So I suggested them to use PSX just as a "panel provider" in the background, free of charge; the user still had to be a legal owner of PSX which would still be sold separately and not by Fenix. Fenix would just provide the add-on that transfers the "pixels" from PSX to MSFS. -- Well, they declined that suggestion :-)


|-|ardy
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: evaamo on Fri, 23 Sep 2022 18:54
Quote from: Gary Oliver on Fri, 23 Sep 2022 15:19Henry,

It looks like the same kind of thing can be done using a WASM module in MSFS which is exactly how the Fenix gauges appear to be working.

Exciting stuff...

I think TDS does the same with the GTN 750/650 and the Garmin Trainers. The rest is just manipulating the controls / LVARs.

Quote from: Lashrathius on Fri, 23 Sep 2022 04:29If there are any programmers in this forum who know how to locate a specific HWND (and save me the time of researching), please let me know![/i]

It's been a while since I did some MFC programming, but I think you're looking for something like this:

https://stackoverflow.com/questions/64256501/how-to-get-a-list-of-window-rectangle-from-enumchildwindow-and-store-them

--
Along the lines of this post...

There was a conversation on an X-Plane developer channel on Discord the other day about doing something similar. Some options came up, including using platform-independent options such as vnc, but I don't think that'd be elegant nor practical.

This weekend I'll get back to work on my X-Plane plugin in substitution of Xview now that XP12 is out. If only there were more hours in a day ;-).
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Lashrathius on Fri, 23 Sep 2022 20:45
Quote from: Gary Oliver on Fri, 23 Sep 2022 15:19Henry,

It looks like the same kind of thing can be done using a WASM module in MSFS which is exactly how the Fenix gauges appear to be working.

Exciting stuff...

If I had access to the source of PSX, then yes, it would be very possible with WASM. But... the method I'm using - I don't need the source of anything. I rendered my Spotify window in P3D, for example.

The methodology I'm using, which is universal for any software, is using the Windows API, which is banned from MSFS due to its closed state. No VNCs, no streaming services / APIs.

The idea of this project is so Hardy can do what he does best without any interruptions and zero software modifications, while I can bring this over to a 3D perspective for many of us looking for a virtual 3D cockpit. The requirements to run the addon would, of course, be that the user owns a legal copy of PSX.
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Ton van Bochove on Fri, 23 Sep 2022 21:36
QuoteThey'd like to buy the copyright on PSX and integrate it in MSFS. I declined for several reasons

One of your better ideas  ;)

Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Lashrathius on Mon, 26 Sep 2022 08:45
Hi Hardy,

Just an update - I think I've got it. We may very well see PSX screens in a 3D Prepar3D 747 virtual cockpit this coming week if I can sort out one small thing...

A showstopper currently - what is the name of the PSX window?

I require the name of the window title in order to pass it through my rendering code.

For example, the title of the Instructor window is "SEVER | BOOST | Instructor - Precision Simulator". When I put this title in my rendering program, it successfully renders the Instructor window within the Prepar3D cockpit display.

However... the window title for PSX itself shows on my screen as "SERVER | BOOST | Captain Flying [1] - Precision Simulator". The problem is - if I input this title into my rendering program, I get a blank grey window.

I then wrote some additional C++ code to render whatever window my cursor is pointed to. I pointed it to PSX and it renders perfectly fine on the cockpit displays (no blank window), but the window title, when ran through the debugger, says something like "0x018ff21c", which is a memory address.

My question is - is PSX running each render instance on a memory address that is different each time the program is open? Is there any fixed window title that I can pass through my rendering program?

If this talks too much about the internal workings of the simulator (for competitive reasons), please feel free to delete this reply & we can email about this privately. I'm happy to sign an NDA.
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Hardy Heinlin on Mon, 26 Sep 2022 10:10
Hi Henry,

I know nothing about memory addresses. My world is pure Java :-)

You can set the frame titles yourself on Instructor > Layout > Settings in the 9 edit fields.

You can make all 9 frame titles equal, if you like.

I remember a similar question from Gary some years ago; it was about linking the PSX frame titles with Simfest's Twitch video stream window system or something. He asked me do add something to the title, but I don't recall exactly what it was. Anyway, after the modification the link worked. Gary, do you remember?


Regards,

|-|ardy
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Lashrathius on Mon, 26 Sep 2022 10:21
Hi Hardy,

After experimenting, I'm guessing the way that PSX puts the frames together is that there is a master window, similar to a puzzle canvas, and the frames are like pieces of a puzzle that are put together and shown on top of the window / canvas.

That would explain why my code sees blank - it's only seeing the canvas, and not the pieces of the puzzle. That would also explain why I'm getting a memory address for the window title - because it's picking up on a frame, rather than the actual window.

(The code that I am using is FindWindow() in C++, for anyone who has done this before or may know how to.)

Thanks all in advance!
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Hardy Heinlin on Mon, 26 Sep 2022 11:54
Maybe it's blank in your system because PSX uses the "volatile memory" graphics function in the background to get hardware acceleration. Without that, the frame rate would drop below 20 fps.
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Gary Oliver on Mon, 26 Sep 2022 12:27
Quote from: Hardy Heinlin on Mon, 26 Sep 2022 10:10Hi Henry,

I know nothing about memory addresses. My world is pure Java :-)

You can set the frame titles yourself on Instructor > Layout > Settings in the 9 edit fields.

You can make all 9 frame titles equal, if you like.

I remember a similar question from Gary some years ago; it was about linking the PSX frame titles with Simfest's Twitch video stream window system or something. He asked me do add something to the title, but I don't recall exactly what it was. Anyway, after the modification the link worked. Gary, do you remember?


Regards,

|-|ardy

Can't remember I am afraid.. however I do know it now works!
Title: Re: Partial success - PSX rendering as a gauge in P3D
Post by: Hardy Heinlin on Mon, 26 Sep 2022 18:15
Just found it in this thread from 2015:

https://aerowinx.com/board/index.php/topic,2525.msg24806.html#msg24806