5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ofThreadを指定したfpsで動かす

Last updated at Posted at 2018-05-20

ofThreadで作成したスレッドの実行速度は不定

ofThreadで作成したスレッドの実行速度は不定で、ofSetFrameRate()でも制御できない。

ofTimerを使う

forum.openframeworks.ccでofTimerを利用した方法があった。
60fps(16ms)。で動かしたい場合は、以下のようにする。

class ThreadedUpdate : public ofThread {
public:
    
    void setup() {
        timer_.setPeriodicEvent(16666666); //引数の単位は、ns
        startThread();
    }

    void draw() const {

    }

private:
    void threadedFunction() {
        while(isThreadRunning()) {
            timer_.waitNext();
            if(lock()) {
                //...do something
                unlock();
            } else {
                ofLogWarning("threadedFunction()") << "Unable to lock mutex.";
            }
        }
    }

    ofTimer timer_;
};
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?