Results 1 to 4 of 4

Thread: use of CL_Timer

  1. #1

    Default use of CL_Timer

    I'm going to do some time based calculation and I found CL_Timer.
    so this is what I did
    CL_Timer logic_timer;
    logic_timer.func_expired().set<World>(this,&World: :logic_calc);
    logic_timer.start(40);//25calcs per second
    while (!quit)
    {
    if (CL_DisplayMessageQueue::has_messages())
    CL_DisplayMessageQueue:rocess();
    //some process
    //draw
    }
    and I just found it will never go into World::logic_calc.
    I think it's probably because I have not do some "keepalive", but how to?
    and would World::logic_calc run in another thread so that I should use mutex?
    Thanks

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

    Default

    I have created a new test, in Tests/Core/Timer in SVN. (On the 2.0.3 release version, it's in Tests/Display/Window/timer.cpp)

    Code:
    {
    	CL_Timer timer_1;
    	timer_1.func_expired().set(this, &TestApp::funx_timer_1);
    	timer_1.start(1000, true);
    	while(true)
    	{
    		CL_KeepAlive::process();
    		
    		// Note - Use the following function if the display windows exist
    		//CL_DisplayMessageQueue::process();
    	}
    }
    void TestApp::funx_timer_1()
    {
    	// Called every second
    }
    CL_DisplayMessageQueue::process() handles CL_KeepAlive objects, so do not call CL_KeepAlive::process() if you call CL_DisplayMessageQueue::process()

    Hope that helps

  3. #3

    Default

    after all I found my critical problem is I called
    if (CL_DisplayMessageQueue::has_messages())
    {
    CL_DisplayMessageQueue:rocess();
    }
    instead of CL_DisplayMessageQueue:rocess().

    so..I don't need to add some code but delete some instead.. that's ...some strange though..

    Thankyou.

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Its an error in has_messages() that it only returns true if there is a Windowing system message, but not if a keep alive object (such as CL_Timer) has flagged that it wants to be processed.

    It starts working when removing the has_messages() check because process() then notices there is a flagged keep alive objects and processes it.

    The "if (has_messages()) process()" thing is no longer needed. Its a relic from a time when process() would always block and now with a 0 timeout it will never block.

Similar Threads

  1. CL_Timer
    By Judas in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 05-26-2009, 06:52 PM
  2. CL_Timer in ClanLib 0.9
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 01-08-2009, 10:35 AM
  3. CL_Timer in ClanLib 0.9
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 07-06-2007, 10:09 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
  •