How to make a QGLWidget a real time game loop?
-
From Qt's documentation:
A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed. -
I saw that but when I do this
@m_animationTimer.setSingleShot(false);
connect(&m_animationTimer, SIGNAL(timeout()), this, SLOT(OnIdle()));
m_animationTimer.start(0);@
[quote author="kkrzewniak" date="1297960472"]From Qt's documentation: A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.[/quote]
I saw that but this is what I was explaining above, the timer send events asynchronously even when other event are being proccesed, not when the queue is empty.
This is importnat because this application is running a sevral threads on teh background.
if for example I go to the menu and a Load a different scene, the render should stops,
but is does not so the mommnet I click I get all kind of rasing conditions.
I suppose I can fix that but tha was not nessesary before.when I set it to this
@ m_animationTimer.setSingleShot(false);
connect(&m_animationTimer, SIGNAL(timeout()), this, SLOT(OnIdle()));
m_animationTimer.start(0);
@It update as fast as it can, but still have the problem that if you click on en menu for example the timer still update send even and it should stops, because there are other events with higher priority.
Basically I need the updates if and only if when the system has nothing else to do.To Bradley I see it is a signal, I read the explanation of that signal and it is no clear to me by I will experiment with that,
I see that there are other signals as well. -
[quote author="Bradley" date="1297960977"]@ connect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(onAboutToBlock())); @[/quote]
That does part of what I want but still not exacty, because it does update as fas as it can
however it still send the same sinal when I click on the menu.
I need tha teh signal to be the lowest possible priority of all signals.Maybe I did it wrong, I implemenetd like this
@connect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(OnIdle()));
...
void newtonDemos::OnIdle()
{
m_canvas->update();
}@is that how is supposet to be?
-
so I though somethomg liek this shopuld do it, but it does not
@void newtonDemos::OnIdle()
{
static bool updateCanvas;
if (updateCanvas) {
updateCanvas = true;
m_canvas->update();
updateCanvas = false;
}
}@what does "a funtion that coul block" means?
bq. This signal is emitted after the event loop returns from a function that could block. -
For what I can see the only way I can do this is by having a bool that is toggled on each action/slot,
and that does not sound like an elegant or atractive solution.I can not beleive this is not a trivial operation in Qt.
This is the default behavior in window -
I can upload the two application to my server and post a link to it maybe some one can
take a look and tell me how to do what I want.
the window and the QT. -
Well I could not find a clean way to do it, but it does no matter, I can acomplishe the same in diffrnet way
I end up doing this@void newtonDemos::OnIdle()
{
if (m_doVisualUpdates) {
m_canvas->update();
}
}@and I set m_doVisualUpdates on and off on eh relvane Menu actions.
It is still better than using a timer, and I also learned a lot about trapping events wih Qt.
Thank every one for the help. -
Hello I am here again with the same problem but this time in different OS.
If you remember you told me that adding this action will make my display to refresh perpetually as fast as the system can
In my init window I added this
@// create the render window
m_canvas = new DemoEntityManager (this, glFormat);
setCentralWidget(m_canvas);connect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(OnIdle())); @
The idle function is this
@void newtonDemos::OnIdle()
{
if (m_doVisualUpdates) {
m_canvas->update();
}
}@m_doVisualUpdates is set to true.
This works beatifully on all windows systems and all Linux 32 and 64 system a tested,
But on the Mac it fails to call OnIdle.
OnIdle is only called once and after that only whne some event happens, like moving the mouce or touching a key.Is there something different on the Mac that does not refresh like is does on other OS?
If so how do I make a Game loop on a Mac running OS X?