• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ofMutex类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ofMutex的典型用法代码示例。如果您正苦于以下问题:C++ ofMutex类的具体用法?C++ ofMutex怎么用?C++ ofMutex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ofMutex类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: update

			//----------
			void MovingHead::update() {
				if (this->powerStateSignal != this->power) {
					if (this->power) {
						//global store of power circuit control
						static map<string, float> lastPowerUpPerCircuit;
						static ofMutex lastPowerUpPerCircuitMutex;

						//lock to make sure nobody else is doing the same thing right now
						lastPowerUpPerCircuitMutex.lock();
						{
							//try and find this power circuit
							auto findCircuit = lastPowerUpPerCircuit.find(this->powerCircuit.get());
							if (findCircuit == lastPowerUpPerCircuit.end()) {
								//register this circuit, say the last spark on it was really long ago
								lastPowerUpPerCircuit.insert(pair<string, float>(this->powerCircuit.get(), std::numeric_limits<float>::min()));
							}
							
							//check if we've had a power on event too recently
							auto now = ofGetElapsedTimef();
							auto & lastPowerUpOnThisCircuit = lastPowerUpPerCircuit[this->powerCircuit.get()];
							if (now - this->pauseBetweenPowerUps.get() > lastPowerUpOnThisCircuit) {
								//ok it's time, let's boot
								this->powerStateSignal = true;
								lastPowerUpOnThisCircuit = now;
								cout << "Powering up " << this->getName() << " at " << now << "s" << endl;
							}
							else {
								//no let's wait and have another see next frame
								float x = 0.0f; //in case we want to put a break point here
							}
						}
						lastPowerUpPerCircuitMutex.unlock();
					}
					else {
						this->powerStateSignal = false;
					}

				}
			}
开发者ID:arturoc,项目名称:ofxRulr,代码行数:40,代码来源:MovingHead.cpp


示例2:

void
Java_cc_openframeworks_OFAndroid_onTouchUp(JNIEnv*  env, jclass  thiz, jint id,jfloat x,jfloat y,jfloat pressure){
	ofTouchEventArgs touch;
	touch.id = id;
	touch.x = x;
	touch.y = y;
	touch.pressure = pressure;
	touch.type = ofTouchEventArgs::up;
	if(threadedTouchEvents){
		ofNotifyMouseReleased(x,y,0);
		ofNotifyEvent(ofEvents().touchUp,touch);
	}else{
		mutex.lock();
		touchEventArgsQueue.push(touch);
		mutex.unlock();
	}
}
开发者ID:Geistyp,项目名称:openFrameworks,代码行数:17,代码来源:ofAppAndroidWindow.cpp


示例3: ofNotifyEvent

 void
 Java_cc_openframeworks_OFAndroid_onTouchDown(JNIEnv*  env, jclass  thiz, jint id,jfloat x,jfloat y,jfloat pressure,jfloat majoraxis,jfloat minoraxis,jfloat angle) {
     ofTouchEventArgs touch;
     touch.id = id;
     touch.x = x;
     touch.y = y;
     touch.pressure = pressure;
     touch.majoraxis = majoraxis;
     touch.minoraxis = minoraxis;
     touch.angle = angle;
     touch.type = ofTouchEventArgs::down;
     if(threadedTouchEvents) {
         window->events().notifyMousePressed(x,y,0);
         ofNotifyEvent(window->events().touchDown,touch);
     } else {
         mutex.lock();
         touchEventArgsQueue.push(touch);
         mutex.unlock();
     }
 }
开发者ID:Ahbee,项目名称:openFrameworks,代码行数:20,代码来源:ofAppAndroidWindow.cpp


示例4:

void
Java_cc_openframeworks_OFAndroid_onTouchMoved(JNIEnv*  env, jclass  thiz, jint id,jfloat x,jfloat y,jfloat pressure){
	ofTouchEventArgs touch;
	touch.id = id;
	touch.x = x;
	touch.y = y;
	touch.pressure = pressure;
	touch.type = ofTouchEventArgs::move;
	if(threadedTouchEvents){
		ofNotifyMouseMoved(x,y);
		ofNotifyMouseDragged(x,y,0);
		ofNotifyEvent(ofEvents().touchMoved,touch);
	}else{
		mutex.lock();
		if(accumulateTouchEvents && !touchEventArgsQueue.empty() && touchEventArgsQueue.back().type==ofTouchEventArgs::move){
			touchEventArgsQueue.back() = touch;
		}else{
			touchEventArgsQueue.push(touch);
		}
		mutex.unlock();
	}
}
开发者ID:Kenn2013,项目名称:openFrameworks,代码行数:22,代码来源:ofAppAndroidWindow.cpp


示例5: threadedFunction

//--------------------------------------------------------------
void ofxThreadedVideo::threadedFunction(){

    while (isThreadRunning()){

        if(lock()){

            // if there's a movie to load...
            if(loadPath != ""){

                loadVideoID = getNextLoadID();

                paths[loadVideoID] = loadPath;
                loadPath = "";
#ifdef TARGET_OSX
                vector<string> pathParts = ofSplitString(paths[loadVideoID], "/");
#else
                vector<string> pathParts = ofSplitString(paths[loadVideoID], "\\");
#endif
                names[loadVideoID] = pathParts[pathParts.size() - 1];

                // using a static mutex blocks all threads (including the main app) until we've loaded
                ofxThreadedVideoMutex.lock();

                // load that movie!
                if(videos[loadVideoID].loadMovie(paths[loadVideoID])){

                    ofLogVerbose() << "Loaded" << names[loadVideoID] << " " << loadVideoID;

                    // start rolling if AutoPlay is true
                    if (bUseAutoPlay) videos[loadVideoID].play();

                    // set pixel refs
                    pixels[loadVideoID] = &videos[loadVideoID].getPixelsRef();

                }else{

                    ofLogVerbose() << "Could not load video";
                    loadVideoID = VIDEO_NONE;

                    // send event notification
                    ofxThreadedVideoEvent videoEvent = ofxThreadedVideoEvent(paths[loadVideoID], VIDEO_EVENT_LOAD_FAIL, this);
                    ofNotifyEvent(threadedVideoEvent, videoEvent, this);
                }


                ofxThreadedVideoMutex.unlock();

            }

            // do threaded update of videos
            updateVideo(currentVideoID);
            updateVideo(loadVideoID);

            unlock();

            // sleep a bit so we don't thrash the cores!!
            ofSleepMillis(1000/30); // TODO: implement target frame rate? US might need 30 here?

        }
    }
}
开发者ID:oaragones,项目名称:ofxThreadedVideo,代码行数:62,代码来源:ofxThreadedVideo.cpp


示例6: glViewport

/* Call to render the next GL frame */
void
Java_cc_openframeworks_OFAndroid_render( JNIEnv*  env, jclass  thiz )
{

	if(paused || surfaceDestroyed) return;

	if(!threadedTouchEvents){
		mutex.lock();
		queue<ofTouchEventArgs> events = touchEventArgsQueue;
		while(!touchEventArgsQueue.empty()) touchEventArgsQueue.pop();
		mutex.unlock();

		while(!events.empty()){
			switch(events.front().type){
			case ofTouchEventArgs::down:
				ofNotifyMousePressed(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchDown,events.front());
				break;
			case ofTouchEventArgs::up:
				ofNotifyMouseReleased(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchUp,events.front());
				break;
			case ofTouchEventArgs::move:
				ofNotifyMouseMoved(events.front().x,events.front().y);
				ofNotifyMouseDragged(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchMoved,events.front());
				break;
			case ofTouchEventArgs::doubleTap:
				ofNotifyEvent(ofEvents().touchDoubleTap,events.front());
				break;
			case ofTouchEventArgs::cancel:
				ofNotifyEvent(ofEvents().touchCancelled,events.front());
				break;
			}
			events.pop();
		}
	}

	ofNotifyUpdate();


	if(ofGetGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->startRender();
	}
	int width, height;

	width  = sWindowWidth;
	height = sWindowHeight;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	//glViewport( 0, 0, width, height );
	ofViewport(0, 0, width, height, false);		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	if ( bClearAuto == true || ofGetFrameNum() < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}

	if(bSetupScreen) ofSetupScreen();
	ofNotifyDraw();

	if(ofGetGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->finishRender();
	}

}
开发者ID:Kenn2013,项目名称:openFrameworks,代码行数:69,代码来源:ofAppAndroidWindow.cpp


示例7: ofGetElapsedTimeMicros

/* Call to render the next GL frame */
void
Java_cc_openframeworks_OFAndroid_render( JNIEnv*  env, jclass  thiz )
{
	unsigned long beginFrameMicros = ofGetElapsedTimeMicros();

	if(paused) return;

	lastFrameTime = double(beginFrameMicros - previousFrameMicros)/1000000.;

	previousFrameMicros = beginFrameMicros;

	if(!threadedTouchEvents){
		mutex.lock();
		while(!touchEventArgsQueue.empty()){
			switch(touchEventArgsQueue.front().type){
			case ofTouchEventArgs::down:
				ofNotifyEvent(ofEvents().touchDown,touchEventArgsQueue.front());
				break;
			case ofTouchEventArgs::up:
				ofNotifyEvent(ofEvents().touchUp,touchEventArgsQueue.front());
				break;
			case ofTouchEventArgs::move:
				ofNotifyEvent(ofEvents().touchMoved,touchEventArgsQueue.front());
				break;
			case ofTouchEventArgs::doubleTap:
				ofNotifyEvent(ofEvents().touchDoubleTap,touchEventArgsQueue.front());
				break;
			}
			touchEventArgsQueue.pop();
		}
		mutex.unlock();
	}

	ofNotifyUpdate();


	int width, height;

	width  = sWindowWidth;
	height = sWindowHeight;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	//glViewport( 0, 0, width, height );
	ofViewport(0, 0, width, height, false);		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	if ( bClearAuto == true || nFrameCount < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}

	if(bSetupScreen) ofSetupScreen();
	ofNotifyDraw();

	unsigned long currTime = ofGetElapsedTimeMicros();
	unsigned long frameMicros = currTime - beginFrameMicros;

	nFrameCount++;		// increase the overall frame count*/
	frames++;

	if(currTime - onesec>=1000000){
		frameRate = frames;
		frames = 0;
		onesec = currTime;
	}

	if(bFrameRateSet && frameMicros<oneFrameTime) usleep(oneFrameTime-frameMicros);

}
开发者ID:damiannz,项目名称:openFrameworks,代码行数:71,代码来源:ofAppAndroidWindow.cpp



注:本文中的ofMutex类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ofNode类代码示例发布时间:2022-05-31
下一篇:
C++ ofMesh类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap