Qt4 game loop




















This may use more memory than the static play function, but it may also play more immediately depending on the underlying platform audio facilities. Destroys this sound object. If the sound is not finished playing, the stop function is called before the sound object is destructed.

See also stop and isFinished. If no sound is available, all QSound operations work silently and quickly. An application may choose either to notify the user if sound is crucial to the application or to operate silently without bothering the user. Note: On Windows this always returns true because some sound card drivers do not implement a way to find out whether it is available or not. See also loopsRemaining and setLoops. Returns the remaining number of times the sound will loop this value decreases each time the sound is played.

See also loops and isFinished. See also stop , loopsRemaining , and isFinished. The function returns immediately. Depending on the platform audio facilities, other sounds may stop or be mixed with the new sound. The sound can be played again at any time, possibly mixing or replacing previous plays of the sound. Documentation contributions included herein are the copyrights of their respective owners.

Now all the demos in the Qt-examples and on the web seem to be either fully event-based e. So I am a bit lost here. One idea I could find was to create a QTimer with a timer of e. Like this:. Is that a good solution? Or is my view of the problem somehow wrong and I don't need a game loop to accomplish my goal? The solution shouldn't use any desktop-only stuff from Qt, i. Source: Game loop in Qt. Usual game loop of simple game can look like this not sure if I understand you correctly though.

Each class that represents game object have 2 public methods: update ; and render ; On each call of QTimer object you iterate over all game objects and call their update method. After it you repeat the same for render method ;.

In render methods each object just draws itself on display. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 7 years, 10 months ago. Active 3 years, 8 months ago. Viewed 7k times. Thus, a developer who wishes to invoke slots in the new thread must use the worker-object approach; new slots should not be implemented directly into a subclassed QThread.

When subclassing QThread , keep in mind that the constructor executes in the old thread while run executes in the new thread. If a member variable is accessed from both functions, then the variable is accessed from two different threads. Check that it is safe to do so. Note: Care must be taken when interacting with objects across different threads. See Synchronizing Threads for details. QThread will notifiy you via a signal when the thread is started , finished , and terminated , or you can use isFinished and isRunning to query the state of the thread.

You can stop the thread by calling exit or quit. In extreme cases, you may want to forcibly terminate an executing thread. However, doing so is dangerous and discouraged. Please read the documentation for terminate and setTerminationEnabled for detailed information.

From Qt 4. Use wait to block the calling thread, until the other thread has finished execution or until a specified time has passed. The static functions currentThreadId and currentThread return identifiers for the currently executing thread. The former returns a platform specific ID for the thread; the latter returns a QThread pointer.

To choose the name that your thread will be given as identified by the command ps -L on Linux, for example , you can call setObjectName before starting the thread. If you don't call setObjectName , the name given to your thread will be the class name of the runtime type of your thread object for example, "RenderThread" in the case of the Mandelbrot Example , as that is the name of the QThread subclass.

Note that this is currently not available with release builds on Windows. QThread also provides static, platform independent sleep functions: sleep , msleep , and usleep allow full second, millisecond, and microsecond resolution respectively. Note: wait and the sleep functions should be unnecessary in general, since Qt is an event-driven framework. Instead of wait , consider listening for the finished signal.

Instead of the sleep functions, consider using QTimer. Constructs a new QThread to manage a new thread. The parent takes ownership of the QThread. The thread does not begin executing until start is called. Note that deleting a QThread object will not stop the execution of the thread it manages.

Deleting a running QThread i. Wait for the finished signal before deleting the QThread. Returns a pointer to a QThread which manages the currently executing thread. Warning: The handle returned by this function is used for internal purposes and should not be used in any application code. Warning: On Windows, the returned value is a pseudo-handle for the current thread. It can't be used for numerical comparison.

Enters the event loop and waits until exit is called, returning the value that was passed to exit. The value returned is 0 if exit is called via quit. This function is meant to be called from within run.

It is necessary to call this function to start event handling. See also quit and exit. After calling this function, the thread leaves the event loop and returns from the call to QEventLoop::exec.

The QEventLoop::exec function returns returnCode. Note that unlike the C library function of the same name, this function does return to the caller -- it is event processing that stops. If the eventloop in QThread::exec is not running then the next call to QThread::exec will also return immediately. See also quit and QEventLoop.



0コメント

  • 1000 / 1000