WPF World Editor for my DirectX engine

I am working on a small game and C ++ game engine using DirectX. The purpose of educational and recreational.

My next goal is to create a simple world editor that uses the game engine. To do this, I will need to move the engine to the DLL so that it can be used in the game and / or editor. The world editor will be a standalone tool, not part of the game. The main goal of the world editor will be reading and displaying my (user) scene file, as well as the ability to annotate / modify the properties of objects (objects) of objects, clone objects, collect and move objects and drop them, scale objects, etc., and then save a modified scene so that later it can be read in the game.

It was recommended to use wxWidgets for the editor. A bit of research makes me feel that wxWidgets is a bit outdated and awkward, although I'm sure very good GUIs can be written using it. This is just a steep learning curve that I do not expect. I got samples to build and run, but it was a headache.

A bit more research, and I found that I can integrate DirectX into a WPF application using D3DImage. I did a little work with WPF and I don't find it too scary, and there are a lot of good books (there is only one old one for wxWidgets), as well as a lot of information on the Internet. I got an example of a rotating triangle, and it seemed pretty simple.

So my question is:

Will WPF let me create a decent big world editing application that reuses my game engine?

My game engine currently uses RawInput for mouse and keyboard; How will this work with WPF?

How does WPF affect my message pump?

It looks like I will need to write a lot of functions (facade scheme?) So that WPF can interact with my engine. Is there an easy way to do this so that it does not compile into the game?

Any advice or ideas on how to proceed will be greatly appreciated!

Thanks.

+4
source share
1 answer

You need to create a wrapper class that provides certain functions to your game.

For instance. This function is in my shell of the editor of the engine for C ++ files.

extern "C" _declspec(dllexport) void SetPlayerPos(int id, const float x, const float y, const float z); 

Then in your C # wpf application you can create a static class that allows you to use these functions

 [DllImport(editorDllName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetPlayerPos(int id, float x, float y, float z); 

You will need to have functions for your basic functions of the game engine through dll. such things as

EditorMain RenderFrame / DXShutdown Update

So you can call editormain in your wpf app constructor

 System.IntPtr hInstance = System.Runtime.InteropServices.Marshal.GetHINSTANCE(this.GetType().Module); IntPtr hwnd = this.DisplayPanel.Handle; NativeMethods.EditorMain(hInstance, IntPtr.Zero, hwnd, 1, this.DisplayPanel.Width, this.DisplayPanel.Height); 

You will need to create a message filter class and initialize it also in the constructor

 m_messageFilter = new MessageHandler(this.Handle, this.DisplayPanel.Handle, this); 

here what the message filter class looked like

 public class MessageHandler : IMessageFilter { const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; IntPtr m_formHandle; IntPtr m_displayPanelHandle; EngineDisplayForm m_parent; public MessageHandler( IntPtr formHandle, IntPtr displayPanelHandle, EngineDisplayForm parent ) { m_formHandle = formHandle; m_displayPanelHandle = displayPanelHandle; m_parent = parent; } public bool PreFilterMessage(ref Message m) { if (m.HWnd == m_displayPanelHandle || m.HWnd == m_formHandle) { switch (m.Msg) { case WM_LBUTTONDOWN: case WM_LBUTTONUP: { NativeMethods.WndProc(m_displayPanelHandle, m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32()); if (m.Msg == WM_LBUTTONUP) { m_parent.SelectActor(); } return true; } } } return false; } public void Application_Idle(object sender, EventArgs e) { try { // Render the scene NativeMethods.RenderFrame(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } 

to create win forms and wpf interop http://msdn.microsoft.com/en-us/library/ms742474.aspx

+3
source

Source: https://habr.com/ru/post/1369440/


All Articles