Avoiding the game cycle in XNA 4.0

I am developing a simple 3D model viewer on XNA 4.0. Is there a way to avoid an endless game loop with the Draw and Update functions? I need to render 3D graphics, but without endless scene rendering. I mean, I need to redraw the scene only when it really has changed.

+4
source share
4 answers

I suggest taking a look at how they do this in their samples:

App Hub - WinForms Series 1
App Hub - WinForms 2 Series

+4
source

Why exactly do you want this?

If you use the winforms application, you have more control over the refresh and paint cycle, but you can also transfer the scene to a texture first and then stop rendering at all.

+2
source

You will need to roll your own multi-threaded loop; if you stop either Update or Draw , then the other will also stall. Another consideration is that if your window is somehow obscured (in an environment without DWM, such as window overlapping), stopping Draw will leave areas of your window unpainted.

If you want to continue this; what you do is run a Thread first time you call Update and then use ManualResetEvent to synchronize the two.

A more reliable option is to turn the entire scene into RenderTarget2D when updating the scene; if the scene has not been changed since the last call to Update or Draw simply displays RenderTarget2D instead of the entire scene. This is still an endless loop, but it tends to your requirement (even if it doesn't match it).

+1
source

This scenario is best solved using WinForms or WPF as the host for your rendering system. I have worked with such systems before, and I found using SlimDX with WPF Interop was my preferred solution. Using this approach allows you to add the good user interface features provided by WPF and overlap with the 3D model displayed on the surface.

+1
source

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


All Articles