Skip to main content
GameDev.net gamedev.net
🔒 Locked

Setting up a message loop for CAD system

Started by AverageMidget Aug 11, 2013 at 7:34 AM 2 replies 1.6k views
Original Post
AverageMidget
AverageMidget

This may be a stupid question but I've search my little butt off and can't find anything about it. I know in a game loop you want continuous rendering because there's usually action happening but in a cad (computer aided design) system, there's no need for that, right? You really only need to redraw the window when the user moves the camera or modifies the content.

Maybe I'm over-thinking it and I should just do it the game way. I figured I could save some CPU cycles if it wasn't trying to constantly render.

Has anyone programmed a CAD application and, if so, how did you set up your message loop?

haegarr
haegarr

A CAD application is a typical desktop application. As such it is driven by events for which a loop is waiting, inclusively sleeping if no events are pending.




Maybe I'm over-thinking it and I should just do it the game way.

Nope! Do it the correct way and use the system's typical event loop. One don't wants a CAD application to take over the machine, so that other tasks are slowed down up to be unusable. One don't wants the graphics card to be heating for nothing. One don't wants to hear the fans annoying noise for no reason.

Comparing an application's event loop with a game loop, then the game loop is "over-thinking" w.r.t. the needs for CAD. The event loop is implemented and used a trillion times and works well.




... how did you set up your message loop?

Although more or less the same on each platform, the details depend just on the platform specifics. In general: Sleep until events are pending, fetch the events, handle them. That's all.

SyncViews
SyncViews

I would just use existing UI stuff like wxWidgets, QT etc. Then you can put an OpenGL/DirectX context in a window to do whatever you need there, and have event loops, window layout, and a list of basic and advanced UI controls readily available.

Don't know about QT, but for wxWidgets there is a built in wxGLCanvas and wxGLContext. See http://www.wxwidgets.org/docs/tutorials/opengl.htm and http://docs.wxwidgets.org/trunk/classwx_g_l_canvas.html .

You can also easily tell it to repaint a specific window (usually for custom controls as a result of input, you could also do it when running an animation) which will then you your custom rendering code.

Burnt_Fyr
Burnt_Fyr

Basicly, rather than rendering in the message loop, put your rendering in the WM_PAINT handler of the window. The it will be redrawn when windows needs it too, and you can also invalidate the client rectangle when your user edits the cad model, causing the window to be rendered

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.