Results 1 to 5 of 5

Thread: Main loop - best practice

  1. #1
    Lesser Knight
    Join Date
    Jan 2011
    Location
    Vienna, Austria
    Posts
    30

    Default Main loop - best practice

    Hello everybody,

    I'm currently in the process of integrating the clanlib GUI into an application. Previously, I just used CL_DisplayWindow to render everything directly.
    I think I figured out most of GUI by now, but I'm not sure abount how to implement the main loop.

    After redesigning, I still want to use my own main loop, and not GUIManager.exec(). Unfortunately, I am quite confused about what the current best practice/recommendation is, because I found several snippets that do this differently.
    Is the way described in the docs still the way to go? => http://clanlib.org/wiki/MainDocs:GUI_Framework
    Or is it better to use the WindowManagerTexture.process() and draw_windows() like in Examples/3D/SpotLight?
    Or some other way?

    As a side note, which window manager should I use best? As I don't need any fancy stuff here, I would have chosen the WindowManagerSystem, but as none of the examples do so I wonder if there are any drawbacks...

    Thanks for clarification,
    spin

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    The usage of clanGUI is very personal.

    Main Loop

    The choices are:

    1) Let CL_GUIManager::exec() control the main loop (System WM and Texture WM)

    Code:
    	CL_GUIManager gui;
    	...
    	gui.exec();
    2) Control the main loop yourself

    (This example is for texture WM only)

    Code:
    	...
    	CL_DisplayWindow window(desc);
    	...
    	CL_GUIWindowManagerTexture wm(window);
    	CL_GUIManager gui(wm, "../../../Resources/GUIThemeAero");
     
    	while (!quit)
    	{
    		Draw_The_Scene();
     
    		wm.process();
    		wm.draw_windows(gc);
     
    		window.flip(1);
    		CL_KeepAlive::process();
    	}
    Remember, you do not have to use wm.draw_windows(), you can use wm.get_windows() and draw the textures manually in their own OpenGL shader.

    3) Create your own window manager

    Only required if you application needs to do advanced features when drawing components to the screen that is not possible in the texture WM.

    System WM vs Texture WM

    If only GUI components are drawn to the screen, the System WM is the most efficient. Else use Texture WM.

    System WM acts like a standard Microsoft Windows GUI application. The window is only drawn to when required. (A side note: System WM and clanSWRender work very well together)

    Texture WM draws to CL_Texture's when required, which are then all drawn to the screen. (A side note: The root component has the CL_Texture. Multiple root components may share CL_Textures in a CL_TextureGroup for efficiency)

  3. #3
    Lesser Knight
    Join Date
    Jan 2011
    Location
    Vienna, Austria
    Posts
    30

    Default

    Thank you very much for your explanations.

    I have two new questions on the window manager though:

    If only GUI components are drawn to the screen, the System WM is the most efficient. Else use Texture WM.
    I have created a new, custom GUI component to render my game main view. I draw a lot of textures etc in there - does this still count as "only GUI component"?

    When using the System WM, there is no process() function like in the Texture WM. The documentation for GUIManager states that GUIManager::exec(false) should not be used anymore. Is there any alternative to looping through the events myself?

    Thanks again,
    spin
    Last edited by spin; 01-08-2011 at 09:29 AM. Reason: process() -> exec()

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Quote Originally Posted by spin View Post
    I have created a new, custom GUI component to render my game main view. I draw a lot of textures etc in there - does this still count as "only GUI component"?

    When using the System WM, there is no process() function like in the Texture WM. The documentation for GUIManager states that GUIManager:: p rocess(false should not be used anymore. Is there any alternative to looping through the events myself?
    1) Yes I think so. But if the game uses animation (i.e. the component is constantly redrawn), I would not use the System WM because it does not use page flipping (partial drawn components maybe displayed). Another developer that is familiar with the System WM needs to confirm this

    2) Assuming you meant to say "..GUIManager::exec(false) should not be used anymore". Then no, the System WM does not have a "process()" function. Since the System WM is event driven, it does not make sense for it to have have a custom main loop
    Last edited by rombust; 01-07-2011 at 06:58 PM. Reason: lol @ forum treating ::process(false) as a smillie

  5. #5
    Lesser Knight
    Join Date
    Jan 2011
    Location
    Vienna, Austria
    Posts
    30

    Default

    Yes, I meant exec(), not process.
    I just implemented it using the TextureWindowManager, and it works like a charm. So I guess I'll just stick to it

    Thanks again for your fast and very helpful answers!

Similar Threads

  1. X error when creating main window
    By texhel in forum Official ClanLib SDK Forums
    Replies: 16
    Last Post: 10-18-2010, 04:19 PM
  2. CL_CommandLine with Cross-platform application main
    By russ_allegro in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 05-05-2010, 10:59 PM
  3. Main Developer ?
    By zyklo in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 08-21-2008, 03:00 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •