Exemple #1
0
ResultStatus CubeWorker::defineCubeAreas(PCube cube)
{
	vector<string> areaIds;
	vector<PArea> areas;

	message.clear();

	vector<string> result;

	// send area request to cube worker
	ResultStatus status = execute("CUBE;" + StringUtils::convertToString(dbid) + ";" + StringUtils::convertToString(cubeid), result);

	if (status == RESULT_FAILED) {
		return status;
	}

	// check result
	if (!result.empty()) {
		if (result.at(0).substr(0, 6) == "ERROR;") {
			message = result[0].substr(6);
			return RESULT_FAILED;
		} else {
			status = readAreaLines(result, areaIds, areas);

			if (status == RESULT_FAILED) {
				notifyShutdown();
				return status;
			}
		}
	}

	if (areaIds.empty()) {
		Logger::debug << "cube '" << cube->getName() << "' has no worker areas, shutting down worker" << endl;
		notifyShutdown();
		cube->removeWorker();
		return RESULT_OK;
	}

	// check areas
	bool ok = checkAreas(areaIds, areas);

	if (ok) {
		Logger::info << "got area for cube '" << cube->getName() << "'" << endl;

		if (Logger::isTrace()) {
			for (vector<string>::const_iterator i = result.begin(); i != result.end(); ++i) {
				Logger::trace << *i << endl;
			}
		}

		cube->setWorkerAreas(areaIds, areas);
	} else {
		notifyShutdown();
		cube->removeWorker();
		return RESULT_FAILED;
	}

	return notifyAreaBuildOk();
}
Exemple #2
0
/*********************************************
		SDL event loop
**********************************************/
void App::utilEventLoop(){

	SDL_Event event;

    while ( !done ){
	   
	    while ( SDL_PollEvent( &event ) ){
	    
	    	//Hand the event off to the GUI first. If the GUI handles it, it's
	    	//done. 
#ifdef ENABLE_GUI
	    	if(processGUIEvent(event)){
	    		continue;
	    	}
#endif
	    
		    switch( event.type ){
						      
			case SDL_VIDEORESIZE:
			    //handle resize event
			    surface = SDL_SetVideoMode( event.resize.w, event.resize.h, 
			    							16, videoFlags );
			    if ( !surface ){
				    ERR( "Could not get a surface after resize: %s\n", 
				    	SDL_GetError( ) );
				    notifyShutdown();
				}
			    resizeWindow( event.resize.w, event.resize.h );
#ifdef ENABLE_GUI
			    resizeGUI( event.resize.w, event.resize.h );
#endif
			    break;
			
			case SDL_QUIT:
			    //handle quit requests
			    notifyShutdown();
			    break;
			
			case SDL_MOUSEBUTTONDOWN:
								
				if(mFlowMgr->onClick(event.button.button, 
									fMouseX, fMouseY, fMouseZ)){
					break;
				}			
				
				onMouseEvent(event.button.button, SDL_MOUSEBUTTONDOWN); 
				beginDrag();
												
				break;	
				
			case SDL_MOUSEBUTTONUP:
				onMouseEvent(event.button.button, SDL_MOUSEBUTTONUP); 
				endDrag();
				break;	
				
			case SDL_KEYDOWN:
				handleKeyEvent(&event.key.keysym, event.type);
				break;
			
			case SDL_KEYUP:
				handleKeyEvent(&event.key.keysym, event.type);
				break;
			
			default:
			    break;
			}
		}
		
	    if (!done){
	    
	    	//Do one frames worth of work and figure out the length of time
	    	uint32_t startTime = SDL_GetTicks();
			renderMain();
			updateMain();
			uint32_t endTime = SDL_GetTicks();
			
			//Figure out the scaling factor for FPS-independent movement
			uint32_t diff = endTime - startTime;
			
			if (iMaxFrameRate > 0 && diff < 1000 / iMaxFrameRate) {
				SDL_Delay((1000 / iMaxFrameRate) - diff);
				diff = 1000 / iMaxFrameRate;
			}
			
			fTimeScale = (float)diff * fTimeScaleScale;
			
			//Every hour, do a cleanup
			if(fCleanupTimer < 0.0f){
				ps()->doPeriodicCleanup();				
				fCleanupTimer = CLEANUP_TIMER;
			}
			
			//Update our various timers
			fCleanupTimer -= fTimeScale;
			fUptime += fTimeScale;
			fParticleFPS = fTimeScale;
		}
	}
	
}