示例#1
0
文件: rx.cpp 项目: tony2909/green
// Will analyse every buffer from 
void detection(uint nDetect, int nStorage){
  bool isDetected=false;
  int nCurrent=0;
  short *storage_short;
  storage_short=new short [nStorage];
  short *p=0;
  float power;
  int i2=0,count_trans=0;
  while(1){
    std::this_thread::yield();
    if (isDetected){
      // Store the elements in storage_short
      if (nCurrent<nStorage){
	// Fill storage_short
	i2=0;
	int conj_rx;
	while ((nCurrent<nStorage) && (i2<2*((int) nDetect))){	  
	  conj_rx=pow(-1,nCurrent);
	  //DispVal(conj_rx);
	  storage_short[nCurrent]=(p[i2])*conj_rx;
	  nCurrent++; i2++;
	};
	// Relase the just stored element
	std::this_thread::yield();
	delete[] (usrpQ.front());
	mtxUsrp.lock();
	usrpQ.pop();
	mtxUsrp.unlock();
	std::this_thread::yield();

	//Wait for a new element
	sem_wait(&usrpReady);
	p=usrpQ.front();
      }
      else{
	// End of transmission
	count_trans=0;
	isDetected=false;
	nCurrent=0;
	mtxDetection.lock();
	detectionQ.push(storage_short);
	mtxDetection.unlock();
	sem_post(&detectionReady);
	storage_short=new short[nStorage];
      }
    }
    else{
      // Wait for new element
      sem_wait(&usrpReady);
      p=usrpQ.front();
      // Test of detection
      power=powerTotArray(p, (int)2*nDetect);
      //DispVal(power);

      count_trans++;//Avoid transient power amplification

      //Power threshold=200 150USRP2 count trns 10000 

      if (power>150&& count_trans>10000){
	// If detection, keep the element
	std::cout<<"Detected Transmission\n";
	//exit(1);
	isDetected=true;
      }
      else{
	// Release the element
	std::this_thread::yield();
	delete[] (usrpQ.front());
	mtxUsrp.lock();
	usrpQ.pop();
	mtxUsrp.unlock();
	std::this_thread::yield();
      }
    }
  }
}
示例#2
0
void CPremove(cvec dataC, int tIni, int nCarriers, int nOFDM_symbols, int Pre, int Post, std::queue<cvec> &OFDM_data){


  int pt=tIni;
  cvec aux(nCarriers), Pre1(Pre), Pre2(Pre);
  cvec Pre1conj(Pre), mult(Pre);
  cvec data(nCarriers);
  //cycle to Remove CP:
  
  for(int i1=0;i1<nOFDM_symbols;i1++){

    //cycle to get Prefix, OFDM sysmbol and Post fix:
    for(int i2=0; i2<Pre; i2++){
      Pre1.set(i2,dataC[pt+i2]);
    }
    //std::cout<<"Pre1="<<Pre1<<"\n";

    pt=pt+Pre;

    for(int i2=0;i2<nCarriers;i2++){
      aux.set(i2,dataC[i2+pt]);
    }
    //std::cout<<"aux="<<aux<<"\n";

    pt=pt+nCarriers-Pre;
    
    
    for(int i2=0; i2<Pre ;i2++){
      Pre2.set(i2,dataC[i2+pt]);
    }
    
    //std::cout<<"Pre2="<<Pre2<<"\n";

    pt=pt+Post+Pre;

    //Process data and store it in the queue:
   
    Pre1conj =itpp::conj(Pre1);
       
    mult= itpp::elem_mult(Pre1conj,Pre2); 	
  
    complex<double> sum=itpp::sum(mult);
    double nuOff=arg(sum)/(2*M_PI*nCarriers);
    //DispVal(nuOff);
    
    complex<double> arg1;
   
    for(int i3=0; i3<nCarriers; i3++){
      arg1=complex<double>(0,-1*2*M_PI*nuOff*i3);
      aux[i3]=aux[i3]*exp(arg1);
    }
    //DispVal(aux);
    data=itpp::fft(aux);
    //DispVal(data);
      //Inserte data in Processing queue:
   
    OFDM_data.push(data);

    //DispVal(i1);
    //DispVal(pt);
   
  }

 
  return;
}
示例#3
0
/** Return a queue with the Pilot Phase filtered based on a scalar Kalman filter
 *
 * @pre:
 *    - Pilot: queue of vec's with the received pilots
 *    - nPilot: number of pilots per OFDM symbol
 *    - F, G and H: state model definiton
 *    - R1 and R2: User parameters of the Kalman -> covariance of the noise
 *    - x0: vector of matrix with the initialization of the kalman
 *    - Q0: initialization of the error covariance matrix 
 *
 * @post:
 *    - Pilots are now filter!
 */
std::queue<itpp::vec> kalmanPhase (std::queue<itpp::vec> Pilot, int nPilot, itpp::mat F, itpp::mat G, itpp::mat H, itpp::mat R1, itpp::mat R2, std::vector<itpp::mat> x0 , itpp::mat Q0){
  
 
  itpp::mat x_pred(2,1);
  itpp::mat y_pred(1,1);
  itpp::mat P_1(2,2);
  itpp::mat x_hat_1(2,1);
  itpp::mat Q_1(2,2); 

  std::queue<itpp::vec> filtPilot; 
  
  int PilotSizeIni=Pilot.size();
  std::vector<itpp::mat> xhat_filt_p(nPilot), Q(nPilot);
  //kalman first iterartion:
  
  itpp::vec y=Pilot.front(); //Take measurements from data
  Pilot.pop();
   for(int i=0; i<nPilot;i++){
      //one iteration of the kalman
      kalmanPhaseIteration ( y(i), R1, R2,  x0[i], Q0, F, G, H, &x_pred, &y_pred, &P_1, &x_hat_1, &Q_1 );
      //update xhatfilt and Q
      xhat_filt_p[i]=x_hat_1;
      Q[i]=Q_1;
    }
    //store new filtered pilot vector into queue:
   itpp::vec aux(nPilot);
   for(int i=0;i<nPilot;i++){
     aux.set(i,xhat_filt_p[i].get(0,0));
   }
   filtPilot.push(aux);
  
  //Kalman loop:
  for(int i1=1; i1<PilotSizeIni;i1++){
    itpp::vec y=Pilot.front(); //Take measurements from data
    Pilot.pop();
    for(int i2=0; i2<nPilot;i2++){
      //one iteration of the kalman
      kalmanPhaseIteration (y(i2),R1,R2, xhat_filt_p[i2], Q[i2], F, G, H, &x_pred, &y_pred, &P_1, &x_hat_1, &Q_1 );
      //update xhatfilt and Q
      xhat_filt_p[i2]=x_hat_1;
      Q[i2]=Q_1;
    }
    //store new filtered pilot vector into queue:
   itpp::vec aux(nPilot);
   for(int i=0;i<nPilot;i++){
     aux.set(i,xhat_filt_p[i].get(0,0));
   }
   filtPilot.push(aux);

  }

  //DispVal(Pilot.size());
  //DispVal(filtPilot.size());
  if(PilotSizeIni!=(int)filtPilot.size()){
    std::cout<<"Error in filtering!\n";
    exit(1);
  }

  return filtPilot;

}
示例#4
0
void LogerManager::run()
{
    _runing = true;
    LOGA("-----------------  log4z thread started!   ----------------------------");
    for (int i = 0; i <= _lastId; i++)
    {
        if (_loggers[i]._enable)
        {
            LOGA("logger id=" << i
                << " key=" << _loggers[i]._key
                << " name=" << _loggers[i]._name
                << " path=" << _loggers[i]._path
                << " level=" << _loggers[i]._level
                << " display=" << _loggers[i]._display);
        }
    }

    _semaphore.post();


    LogData * pLog = NULL;
    int needFlush[LOG4Z_LOGGER_MAX] = {0};
    time_t lastCheckUpdate = time(NULL);
    while (true)
    {
        while(popLog(pLog))
        {
            if (pLog->_id <0 || pLog->_id > _lastId)
            {
                freeLogData(pLog);
                continue;
            }
            LoggerInfo & curLogger = _loggers[pLog->_id];

            if (pLog->_type != LDT_GENERAL)
            {
                onHotChange(pLog->_id, (LogDataType)pLog->_type, pLog->_typeval, std::string(pLog->_content, pLog->_contentLen));
                curLogger._handle.close();
                freeLogData(pLog);
                continue;
            }
            
            //
            _ullStatusTotalPopLog ++;
            //discard
            
            if (!curLogger._enable || pLog->_level <curLogger._level  )
            {
                freeLogData(pLog);
                continue;
            }


            if (curLogger._display && !LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
            {
                showColorText(pLog->_content, pLog->_level);
            }
            if (LOG4Z_ALL_DEBUGOUTPUT_DISPLAY && !LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
            {
#ifdef WIN32
                OutputDebugStringA(pLog->_content);
#endif
            }


            if (curLogger._outfile && !LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
            {
                if (!openLogger(pLog))
                {
                    freeLogData(pLog);
                    continue;
                }

                curLogger._handle.write(pLog->_content, pLog->_contentLen);
                curLogger._curWriteLen += (unsigned int)pLog->_contentLen;
                needFlush[pLog->_id] ++;
                _ullStatusTotalWriteFileCount++;
                _ullStatusTotalWriteFileBytes += pLog->_contentLen;
            }
            else if (!LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
            {
                _ullStatusTotalWriteFileCount++;
                _ullStatusTotalWriteFileBytes += pLog->_contentLen;
            }

            freeLogData(pLog);
        }

        for (int i=0; i<=_lastId; i++)
        {
            if (_loggers[i]._enable && needFlush[i] > 0)
            {
                _loggers[i]._handle.flush();
                needFlush[i] = 0;
            }
            if(!_loggers[i]._enable && _loggers[i]._handle.isOpen())
            {
                _loggers[i]._handle.close();
            }
        }

        //! delay. 
        sleepMillisecond(100);

        //! quit
        if (!_runing && _logs.empty())
        {
            break;
        }
        
        if (_hotUpdateInterval != 0 && time(NULL) - lastCheckUpdate > _hotUpdateInterval)
        {
            updateConfig();
            lastCheckUpdate = time(NULL);
        }
        


    }

    for (int i=0; i <= _lastId; i++)
    {
        if (_loggers[i]._enable)
        {
            _loggers[i]._enable = false;
            closeLogger(i);
        }
    }

}
示例#5
0
文件: AIO.c 项目: Nadasua/HBNews
		void queue_add(TaskItem& item)
		{
			pthread_mutex_lock(&m_mutex);
			w_items.push(item);
			pthread_mutex_unlock(&m_mutex);
		}
示例#6
0
	void AudioManager::updateAudioEffects() {
		static std::queue<int> nextNumbers; // indexes used!
		if (m_bIsPlayingNumber == true) {           // number update
			if (isAnyNumberPlayed() == false) {     // one sound finished
				if (m_iChannelNumber == -1) {
					if (m_iNumberToPlay == 0) {
						nextNumbers.push(0);
						m_iNumberToPlay = -1;
					}
				}
				if (m_iChannelNumber == -1 || Mix_Playing(m_iChannelNumber) != 1) {
					if (m_iNumberToPlay == -1 && nextNumbers.empty() == true) { // number finished
						m_bIsPlayingNumber = false;
						return;
					}
					if (nextNumbers.empty() == false) {
						m_aSndNum[nextNumbers.front()].play();
						m_iChannelNumber = m_aSndNum[nextNumbers.front()].getChannel();
						nextNumbers.pop();
					} else { // calculate numbers to play
						std::string sNum   = Util::toString(m_iNumberToPlay);
						int         length = sNum.length();
						int         subStrLength = ( (length-1) % 3) + 1;
						ESoundNumber sn = SND_NUM_NONE;
						switch ( (length-1) / 3) {
							case 1:  sn = SND_NUM_THOUSAND; break;
							case 2:  sn = SND_NUM_MILLION; break;
							case 3:  sn = SND_NUM_BILLION; break;
							default: sn = SND_NUM_NONE; break;
						}
						
						std::string sNumSub;
						for(int i = 0; i < subStrLength; i++) {
							sNumSub += sNum[i];
						}
						
						if (subStrLength >= 3) {
							nextNumbers.push(Util::parseInt(Util::toString(sNumSub[0])));
							nextNumbers.push(static_cast<int>(SND_NUM_HUNDRED));
						}
						if (subStrLength >= 2) {
							if (sNumSub.length() == 3) {
								sNumSub.erase(0,1);
							}
							if (Util::parseInt(sNumSub) >= 20) { //tys
								switch (Util::parseInt(std::string(1,sNumSub[0]))) {
									case 2: nextNumbers.push(static_cast<int>(SND_NUM_20)); break;
									case 3: nextNumbers.push(static_cast<int>(SND_NUM_30)); break;
									case 4: nextNumbers.push(static_cast<int>(SND_NUM_40)); break;
									case 5: nextNumbers.push(static_cast<int>(SND_NUM_50)); break;
									case 6: nextNumbers.push(static_cast<int>(SND_NUM_60)); break;
									case 7: nextNumbers.push(static_cast<int>(SND_NUM_70)); break;
									case 8: nextNumbers.push(static_cast<int>(SND_NUM_80)); break;
									case 9: nextNumbers.push(static_cast<int>(SND_NUM_90)); break;
									default: break;
								}
							}
							else if (sNumSub.length() == 2 && Util::parseInt(Util::toString(sNumSub[0])) != 0){ // teens
								nextNumbers.push(Util::parseInt(sNumSub));
							}
						}
						if (subStrLength == 1 || (subStrLength > 1 && Util::parseInt(sNumSub) > 20)) { // normal numbers (1 - 9)
							if (                 Util::parseInt(Util::toString(sNumSub[sNumSub.length() - 1])) != 0) {
								nextNumbers.push(Util::parseInt(Util::toString(sNumSub[sNumSub.length() - 1])));
							}
						}
						
						
						if (sn != SND_NUM_NONE)
							nextNumbers.push(static_cast<int>(sn));
						
						//adjust number
						for (int i = 0; i < subStrLength; i++) {
							sNum.erase(0,1);
						}
						
						//adjust numberToPlay
						if (sNum.length() > 0) {
							m_iNumberToPlay = Util::parseInt(sNum);
						} else {
							m_iNumberToPlay = -1; // ended
						}
					}
				}
			}
		}
	}
示例#7
0
bool LogerManager::pushLog(LogData * pLog, const char * file, int line)
{
    // discard log
    if (pLog->_id < 0 || pLog->_id > _lastId || !_runing || !_loggers[pLog->_id]._enable)
    {
        freeLogData(pLog);
        return false;
    }

    //filter log
    if (pLog->_level < _loggers[pLog->_id]._level)
    {
        freeLogData(pLog);
        return false;
    }
    if (_loggers[pLog->_id]._fileLine && file)
    {
        const char * pNameBegin = file + strlen(file);
        do
        {
            if (*pNameBegin == '\\' || *pNameBegin == '/') { pNameBegin++; break; }
            if (pNameBegin == file) { break; }
            pNameBegin--;
        } while (true);
        zsummer::log4z::Log4zStream ss(pLog->_content + pLog->_contentLen, LOG4Z_LOG_BUF_SIZE - pLog->_contentLen); 
        ss << " " << pNameBegin << ":" << line;
        pLog->_contentLen += ss.getCurrentLen();
    }
    if (pLog->_contentLen < 3) pLog->_contentLen = 3;
    if (pLog->_contentLen +3 <= LOG4Z_LOG_BUF_SIZE ) pLog->_contentLen += 3;

    pLog->_content[pLog->_contentLen - 1] = '\0';
    pLog->_content[pLog->_contentLen - 2] = '\n';
    pLog->_content[pLog->_contentLen - 3] = '\r';
    pLog->_contentLen--; //clean '\0'


    if (_loggers[pLog->_id]._display && LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
    {
        showColorText(pLog->_content, pLog->_level);
    }

    if (LOG4Z_ALL_DEBUGOUTPUT_DISPLAY && LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
    {
#ifdef WIN32
        OutputDebugStringA(pLog->_content);
#endif
    }

    if (_loggers[pLog->_id]._outfile && LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
    {
        AutoLock l(_logLock);
        if (openLogger(pLog))
        {
            _loggers[pLog->_id]._handle.write(pLog->_content, pLog->_contentLen);
            closeLogger(pLog->_id);
            _ullStatusTotalWriteFileCount++;
            _ullStatusTotalWriteFileBytes += pLog->_contentLen;
        }
    }

    if (LOG4Z_ALL_SYNCHRONOUS_OUTPUT)
    {
        freeLogData(pLog);
        return true;
    }
    
    AutoLock l(_logLock);
    _logs.push(pLog);
    _ullStatusTotalPushLog ++;
    return true;
}
示例#8
0
 static void pop (std::queue<T>& que) {
     que.pop();
 }
示例#9
0
	void notify_event(const Ctrl& ctrl, uint32_t devnum=0) {
	  scoped_lock lock(guard_);
	  shared_ptr<event_ctrl<Ctrl> > p(new event_ctrl<Ctrl>(ctrl, devnum));
	  eventQueue_.push(p);
	  wakeup_.notify_one();
	}
示例#10
0
 static void push(std::queue<T>& que, U&& data) {
     que.push(data);
 }
示例#11
0
void ProcessPacket( Packet *pack, int nsp_index)
{
	//double diff = pack->time - prev_time;
	//prev_time = pack->time;
	//printf("timediff = %.3f ms\n", 1000*diff);

	//printf("Processing Packet: type %i, nbytes %i, time %.3f\n", pack.type, pack.nbytes, pack.time);

	int display_chan = 0;

	switch( pack->type){

		case Packet::TYPE_SPIKE:
		{
		
			// add copy of spike packet to queue buffer
			SpikePacket *sp = (SpikePacket*)pack;
			SpikePacket sp_copy = *sp;
			spikeQueue.push(sp_copy);
			LARGE_INTEGER t_spikePack;
			QueryPerformanceCounter(&t_spikePack);
			stQueue.push(t_spikePack);

			break;	
		
		} //end case
		case Packet::TYPE_WAVEDATA:
		{
			printf("~");
			break;
		}
		case Packet::TYPE_GROUP:
		{
			GroupPacket *wave_pack = (GroupPacket*) pack;
			bool done = LFPData.AddSample(wave_pack->data);
			if (done) //we have enough samples to send onwards
			{
				if (overflow_possible)
					printf("LFP Overflow - Packet Lost\n");
				overflow_possible = true;
			}
			else
			{
				overflow_possible =  false;
			}
			break;
		}

		case Packet::TYPE_HEARTBEAT:
		{
			theCounter.GetAndResetCount( theCount, MAX_TOTAL_SPIKE_CHANS_PER_SOURCE);
			threshCounter.GetAndResetCount( threshCount, MAX_SPIKE_CHANS_PER_SOURCE);

			SendDigEvents(); // send first so that combiner will include in current sample
			SendCounts( pack->time, theCount, MAX_TOTAL_SPIKE_CHANS_PER_SOURCE, nsp_index);
			
			if(collect_LFP){
				SendLFPs(nsp_index, pack->time);
			}
			else{
				int buffer_length=0;
				LFPData.GetAndReset(lfpdata, &buffer_length);
			}

			SendStimSyncEvents();

			if(collect_snippets){
				SendSnippets();
				SendRejectedSnippets();
			}
			else{
				Overall_Spike_Count = 0;
				Snippet_Message_Number= 0;
				Overall_Rejected_Count = 0;
				Rejected_Snippet_Message_Number = 0;

			}	
			
			//printf(".");
			break;
		}
		case Packet::TYPE_STATUS:
		{
			StatusPacket *status_pack = (StatusPacket*) pack;
			double mega_bytes_received = ((double)status_pack->bytesReceived) / (1024.0 * 1024.0);

            if (status_pack->packetsDropped > 0)
                printf("x");
            else
                printf("S");

			TotalCounter.GetAndResetCount( TotalCount, MAX_CEREBUS_TOTAL_UNITS);

			break;
		}
		case Packet::TYPE_DIGITAL:
		{
			DigitalPacket *digital_pack = (DigitalPacket*) pack;
			
			// subtract bits that were already high
			unsigned int data = digital_pack->data[0] & ~prevDigDataRaw;
			prevDigDataRaw = digital_pack->data[0];
			bool stimRelatedEvent = false;
			// handle stim sync events
			if (data & stimSyncMask) { // check if digital event is due to a stim sync pulse
				artifactTimer = pack->time; // set artifact timer
				AddStimSyncEvent(digital_pack,nsp_index,pack->time);
				clearQueue(nsp_index); // buffer can be cleared without further delay

				data = data & ~stimSyncMask; // reset stimSyncBit for remaining comparisons
				stimRelatedEvent = true;
			}
			
			// misc. digital events
			if ((data != prevDigData) && ((digCount > 1) || (!stimRelatedEvent && prevDigDataRaw != prevDigData))){ // this will ignore falling edges of stim related events, but accept all other bit changes
				AddDigitalEvent(digital_pack,nsp_index,pack->time);
			}

			prevDigData = data;
			digCount++;
			
			break;	
		}
	default:
		// Any other types of packets are ignored
		break;
	}
}
 int push(int n){
     std::unique_lock<std::mutex> lck(mtx);
     Task.push(n);
     isEmpty.notify_all();
     return 0;
 }
示例#13
0
文件: emerge.cpp 项目: sfan5/minetest
bool EmergeThread::pushBlock(v3s16 pos)
{
    m_block_queue.push(pos);
    return true;
}
 bool empty() const
 {
     std::lock_guard<std::mutex> lock(_mtx);
     return _data.empty();
 }
示例#15
0
void ShowKeyboard() {
	lock_guard guard(frameCommandLock);
	frameCommands.push(FrameCommand("showKeyboard", ""));
}
示例#16
0
void add_right( int index ) {
  if( index + 1 < M * N && room_state[index + 1] == 0 ){
    q.push( index + 1 );
    room_state[index+1] = count;
  }
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		transfer* TransferFBO = reserveTransfer();
		transfer* TransferFB = reserveTransfer();

		{
			glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
			glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(
				GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4),
				GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

			//glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f);
			glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
		
			*Pointer = Projection * this->view() * Model;

			// Make sure the uniform buffer is uploaded
			glUnmapBuffer(GL_UNIFORM_BUFFER);
		}

		{
			glEnable(GL_DEPTH_TEST);
			glDepthFunc(GL_LESS);

			glViewport(0, 0, static_cast<GLsizei>(WindowSize.x) * this->FramebufferScale, static_cast<GLsizei>(WindowSize.y) * this->FramebufferScale);

			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
			//glEnable(GL_FRAMEBUFFER_SRGB);
			float Depth(1.0f);
			glClearBufferfv(GL_DEPTH , 0, &Depth);
			glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

			glUseProgram(ProgramName[program::TEXTURE]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
			glBindVertexArray(VertexArrayName[program::TEXTURE]);
			glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

			glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

			glBindBuffer(GL_PIXEL_PACK_BUFFER, TransferFBO->Buffer);
			glReadBuffer(GL_COLOR_ATTACHMENT0);
			glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, 0);
			TransferFBO->Fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
		}

		{
			glDisable(GL_DEPTH_TEST);

			glViewport(0, 0, static_cast<GLsizei>(WindowSize.x), static_cast<GLsizei>(WindowSize.y));

			glBindFramebuffer(GL_FRAMEBUFFER, 0);

			glUseProgram(ProgramName[program::SPLASH]);

			glActiveTexture(GL_TEXTURE0);
			glBindVertexArray(VertexArrayName[program::SPLASH]);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);

			glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);

			glBindBuffer(GL_PIXEL_PACK_BUFFER, TransferFB->Buffer);
			glReadBuffer(GL_BACK);
			glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, 0);
			TransferFB->Fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
		}

		this->queryTranfer();

		printf("Live %d, Free %d\r", static_cast<int>(ReadPixelBufferLive.size()), static_cast<int>(ReadPixelBufferFree.size()));

		return true;
	}
示例#18
0
void System_SendMessage(const char *command, const char *parameter) {
	lock_guard guard(frameCommandLock);
	frameCommands.push(FrameCommand(command, parameter));
}
示例#19
0
int main()
{
  std::ifstream fin("castle.in", std::ios::in);
  
  fin>>M>>N;

  for( int i = 0; i < M * N; ++i ) fin >> room[i];

  for( int i = 0; i < M * N; ++i ) room_state[i] = 0;
  
#if 0
  for( int i = 0; i < M * N; ++i ) {
    std::cout << room[i];
    if( i % M == M-1 ) std::cout << std::endl;
    else std::cout << " ";
  }
    std::cout << M << " " << N << " "
	    <<  M * N << std::endl;
#endif

  for( int i = 0; i < M * N; ++i ){
    if( room_state[i] == 0 ){
      int temp_max_count = 0;
      q.push( i );
      while( !q.empty() ){
	int index = q.front();
	temp_max_count++;
	room_state[index] = count;
	q.pop();
#if 0
	std::cout << count << ":" << index/M + 1 << " " << index % M + 1 << std::endl;
#endif
	switch( room[index] ){
	case 0:
	  add_left( index );
	  add_up( index );
	  add_right( index );
	  add_down( index );
	  break;
	case 1:
	  {
	    add_left_edge( index );
	    add_up( index );
	    add_right( index );
	    add_down( index );
	  }
	  break;
	case 2:
	  {
	    add_left( index );
	    add_up_edge( index );
	    add_right( index );
	    add_down( index );
	  }
	  break;
	case 3:
	  {
	    add_left_edge( index );
	    add_up_edge( index );
	    add_right( index );
	    add_down( index );
	  }
	  break;
	case 4:
	  {
	    add_left( index );
	    add_up( index );
	    add_right_edge( index );
	    add_down( index );
	  }
	  break;
	case 5:
	  {
	    add_left_edge( index );
	    add_up( index );
	    add_right_edge( index );
	    add_down( index );
	  }
	  break;
	case 6:
	  {
	    add_left( index );
	    add_up_edge( index );
	    add_right_edge( index );
	    add_down( index );
	  } 
	  break;
	case 7:
  	  {
	    add_left_edge( index );
	    add_up_edge( index );
	    add_right_edge( index );
	    add_down( index );
	  } 
	  break;
	case 8:
  	  {
	    add_left( index );
	    add_up( index );
	    add_right( index );
	    add_down_edge( index );
	  } 
	  break;
	case 9:
	  {
	    add_left_edge( index );
	    add_up( index );
	    add_right( index );
	    add_down_edge( index );
	  } 
	  break;
	case 10:
	  {
	    add_left( index );
	    add_up_edge( index );
	    add_right( index );
	    add_down_edge( index );
	  } 
	  break;
	case 11:
	  {
	    add_left_edge( index );
	    add_up_edge( index );
	    add_right( index );
	    add_down_edge( index );
	  } 
	  break;
	case 12:
	  {
	    add_left( index );
	    add_up( index );
	    add_right_edge( index );
	    add_down_edge( index );
	  } 
	  break;
	case 13:
	  {
	    add_left_edge( index );
	    add_up( index );
	    add_right_edge( index );
	    add_down_edge( index );
	  } 
	  break;
	case 14:
	  {
	    add_left( index );
	    add_up_edge( index );
	    add_right_edge( index );
	    add_down_edge( index );
	  } 
	  break;
	case 15:
	  {
	    add_left_edge( index );
	    add_up_edge( index );
	    add_right_edge( index );
	    add_down_edge( index );
	  }
	  break;
	default:
	  break;
	}
      }
      room_num[count] = temp_max_count;
      max_count = std::max( max_count, temp_max_count );
      count++;
    }
  }
  std::ofstream fout("castle.out", std::ios::out );
#if 0
  std::cout << count - 1 << std::endl;
  std::cout << max_count << std::endl;
#endif
  fout << count - 1 << std::endl;
  fout << max_count << std::endl;
  int a, b, c;
  a = N;
  b = M;
  c = 4;
  
  for( int i = 0; i < edge_count; ++i ){
#if 0
    std::cout << edge1[i] / M  + 1 << ":" << edge1[i] % M + 1 << " "
	      << edge2[i] / M  + 1 << ":" << edge2[i] %M + 1 << std::endl;
#endif
    if( room_state[edge1[i]] != room_state[edge2[i]] ){
      if( new_max_count < room_num[room_state[edge1[i]]] + room_num[room_state[edge2[i]]] ){
	new_max_count = room_num[room_state[edge1[i]]] + room_num[room_state[edge2[i]]];
	if( abs( edge2[i] - edge1[i] ) == 1 ) {
	  int temp = std::min( edge1[i], edge2[i] );
	  a = temp / M + 1;
	  b = temp % M + 1;
	  c = 4;
	}else{
	  int temp = std::max( edge1[i], edge2[i] );
	  a = temp / M + 1;
	  b = temp % M + 1;
	  c = 2;
	}
      }else if( new_max_count == room_num[room_state[edge1[i]]] + room_num[room_state[edge2[i]]] ) {
	if( abs( edge1[i] - edge2[i] ) == 1 ){
	  int temp = std::min( edge1[i], edge2[i] );
	  if( temp % M + 1< b || (temp % M + 1 == b && temp / M + 1 > a)){
	    a = temp / M + 1;
	    b = temp % M + 1;
	    c = 4;
	  }
	}else {
	  int temp = std::max( edge1[i], edge2[i] );
	  if( temp % M + 1 < b || ( temp % M + 1 == b && temp / M + 1 > a ) ){
	    a = temp / M + 1;
	    b = temp % M + 1;
	    c = 2;
	  }
	}
	    
      }
      //      new_max_count = std::max( new_max_count,
      //			room_num[room_state[edge1[i]]] + room_num[room_state[edge2[i]]] );
#if 0
      std::cout << room_num[room_state[edge1[i]]] << ":" << room_num[room_state[edge2[i]]] << " " << new_max_count << std::endl;
      std::cout << a << " " << b << " " << c << std::endl;
#endif
    }
    
  }

  fout << new_max_count << std::endl;
  fout << a  << " "<< b << " "<< (c == 2? 'N' : 'E') << std::endl;
  return 0;
}
示例#20
0
 ~DictOut( ) {
     if (!outputs.empty())
         std::cerr << "Warning: did not output DictOut" << std::endl;
 }
示例#21
0
void add_left( int index ){
  if( index - 1 >= 0 && room_state[index -1 ] == 0 ){
    q.push( index - 1 );
    room_state[index - 1] = count;
  }
}
示例#22
0
 void add( std::string name, std::string value ) {
     outputs.push( new Entry( name, value ) );
 }
 bool wait_pop(T& value)
 {
     std::unique_lock<std::mutex> lock(_mtx);
     _data_cond.wait(lock, [this]() { return _terminate || !_data.empty(); });
     return _pop(value);
 }
 void push(T&& new_value)
 {
     std::lock_guard<std::mutex> lock(_mtx);
     _data.push(std::move(new_value));
     _data_cond.notify_one();
 }
 void push(const T& new_value)
 {
     std::lock_guard<std::mutex> lock(_mtx);
     _data.push(new_value);
     _data_cond.notify_one();
 }
 std::shared_ptr<T> wait_pop()
 {
     std::unique_lock<std::mutex> lock(_mtx);
     _data_cond.wait(lock, [this]() { return _terminate || !_data.empty(); });
     return _pop();
 }
示例#27
-5
// Android implementation of callbacks to the Java part of the app
void SystemToast(const char *text) {
	lock_guard guard(frameCommandLock);
	frameCommands.push(FrameCommand("toast", text));
}
示例#28
-5
 void add( std::string name, uint64_t value ) {
     std::stringstream ssv;
     ssv << value;
     outputs.push( new Entry( name, ssv.str() ));
 }
示例#29
-10
void PushCommand(std::string cmd, std::string param) {
	lock_guard guard(frameCommandLock);
	frameCommands.push(FrameCommand(cmd, param));
}
示例#30
-19
 typename std::queue<T>::size_type
 unsafe_size() {
     return q_.size();
 }