Home » Community » Forums » » Continuous Updating in MFC
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Continuous Updating in MFC
Post Reply 
I will definitly have to give this a try! In my current OpenAL testing model in my profile, I had this bug where nothing would work after the first time I used it. I finally tracked it down to the fact for some reason in VS7, my timers were not being triggered at all. I have yet to figure that out. If this works well, I will get back and let you know .

- Drew

[edit] Great article, but my project is just FUBAR'd. i can't even overload the default functions in VS7...VS6 here I come! Thank you Mr. Mantle for spending the time to write this.

[Edited by - Drew_Benton on February 16, 2005 3:39:51 AM]

 User Rating: 1933   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Great Article, I will defiantly use those tips for the level editor I am currently creating for my project at University using MFC and Directx. On a side note has anybody got any tips on using Swapchains with MFC?

My idea is to have 4 swapchains which correspond to the 4 views I have created in MFC. That way the 4 views all can share the same resources such as Vertex Buffers.

Quote:
[edit] Great article, but my project is just FUBAR'd. i can't even overload the default functions in VS7...VS6 here I come! Thank you Mr. Mantle for spending the time to write this.


If you are talking about the functions to deal with size and on drawn messages for example, in VS .NET click on the classes tab on the solution explorer, then select the class where you want to add the overloaded method. the go to the properties pane(usually just below the solution explorer) there are three icons just below the class name called Events, message and overrides. Select one of those and a list of all the functions, messages etc that you can change is displayed. Select the empty box and a drop down menu appears that will say add <method name> click on this and it will add the method to your .h and .cpp file, this will also update the message map for you if you override a message handler.

If you want I can send you a private message with images that will illustrate the process of overloading functions in MFC using VS .NET.

 User Rating: 1039   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Yes swap chains are the way to go. A little tricky at first, but they will give you exactly what you are looking for, four views. I had it drawing with a splitter, very nice but it took a bit.

 User Rating: 1064   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I would never mix MFC and OGL or D3D. Use MFC to create an application shell only. Then register and create a separate window for OGL/D3D rendering.

Create D3D /OGL context from a separate thread and use this window. Use DirectInput for handlign keyboard and mouse messages.

This way you can acheive a neat separation between MFC and your "actual" app.


 User Rating: 1050   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
I would never mix MFC and OGL or D3D. Use MFC to create an application shell only. Then register and create a separate window for OGL/D3D rendering.


Good point AQ, do you mean you would create a view or frame for that would do the 3D rendering and then each of the views would inherit from this 3D rendering view ?

or do you mean that you would create a rendering object that would then be used by the various windows or views to render ?


 User Rating: 1039   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I also had this problem earlier but your solution [me only thinks] is too long, I didn't actually understand what you did...
Any way you can override ...::OnIdle( lCount ) as thus

....
// Do Stuff here...
return 1; // Not zero, therefore the message loop will always interpret as if you have not finished what you want to do, and continuous updating is thus achieved... Please feedback
....

 User Rating: 1059   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by AQ
I would never mix MFC and OGL or D3D. Use MFC to create an application shell only. Then register and create a separate window for OGL/D3D rendering.

Create D3D /OGL context from a separate thread and use this window. Use DirectInput for handlign keyboard and mouse messages.

This way you can acheive a neat separation between MFC and your "actual" app.


I tend to agree and disagree with this one...

In all my MFC/DX apps (and I have created quite a few) i use 4 swap chains as Big_Bear_Scot said and I create 4 seperate chains... I ignore the 'original' swap chain (the D3D Device itself) to make it a bit easier to repeat.

The swap chains draw to the MFC windows (that way you can take advantage of splitter windows, the MFC message loop and all those lovely MFC classes you can download from codeproject.com etc.).

I then try to pull the render code away from the window, making the current window call the render scene class when OnDraw/OnPaint is called (I cant remember which one at the mo :))etc.

Using this method you do have to have the camera as part of MFC window (well, it makes it much easier for you to control the camera using OnMouseMove etc if it is), though it is more than easy to then derive other MFC windows from this base class, ones to deal with orthogonal projection, perspectve projection etc.

AQ: Surely using DirectInput is overkill when using an MFC app. The nessage loop is more than capable of providing the needed information to control the app?

Just for renference, heres how I update an MFC app continuously.

I create an UpdateApp function, and run this function in a seperate thread. I then call a core Update function (which takes the frame delta for that frame) and then call SendMessage(WM_PAINT ... ) to the source windows. Wrapped around this is a simple timer that makes sure the code is being updated at 60fps (useful when creating model or level editors/viewers). This also avoids calling the WM_PAINT message constantly when the window has not actually finished drawing.

Hope some of that is useful to someone :)
Spree



 User Rating: 1181   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I think there is a slight oversight in your code. The do.... while loop pumps a message even if there is not one there, which makes your loop function be called reliably only if there is a message there. An easy way to counteract this is just change it to a normal while loop. I also got rid of all idle message handling in order to make the program more streamlined.

 User Rating: 1015    Report this Post to a Moderator | Link

The PumpMessage() routine in MFC will block until it recieves a message because of the use of GetMessage...thus this code won't work at all for continous updates...you must override PumpMessage again and change it to be PeekMessage instead! You can pretty much get rid of all the MFC crap in there too and it'll all still work just fine.

 User Rating: 1015    Report this Post to a Moderator | Link

AP, care to share a code snippet of the PumpMessage code?

 User Rating: 1015    Report this Post to a Moderator | Link

Quote:
Original post by Anonymous Poster
The PumpMessage() routine in MFC will block until it recieves a message because of the use of GetMessage...thus this code won't work at all for continous updates...you must override PumpMessage again and change it to be PeekMessage instead! You can pretty much get rid of all the MFC crap in there too and it'll all still work just fine.




 User Rating: 1015    Report this Post to a Moderator | Link

Why not just return true in the OnIdle function?

BOOL CDXMFCApp::OnIdle(LONG lCount)
{
	CWinApp::OnIdle(lCount);
	GameLoop();	
	return true; // Always want more time
}



 User Rating: 1022   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: