Beispiel #1
0
void addBall(){

    if(!ball.created){ //singleton pattern
        ball.centre.point_x = (resolution_w-resolution_x)/2;
        ball.centre.point_y = (resolution_h-resolution_y)/2;
        defaultBalllocationX = (resolution_w-resolution_x)/2;
        defaultBalllocationY =  (resolution_h-resolution_y)/2;

	currentBallOfX = ball.centre.point_x;
        currentBallOfY = ball.centre.point_y;

        // pPanel notify for created pPanel
        balldirectionX = DEFAULT_BALLSPEEDX;
        balldirectionY = DEFAULT_BALLSPEEDY;
        
	rt_mutex_acquire(&txMutex[E_GAME], TM_INFINITE);
	memset(gameData, 0, sizeof(gameData));
	sprintf(gameData, "score;%d;%d;",player_score,opponent_score);
	padString(gameData);
	rt_mutex_release(&txMutex[E_GAME]);
      	
	 memset(ballData, 0, sizeof(ballData));
         sprintf(ballData, "ball;%d;%d;%d;",defaultBalllocationX, defaultBalllocationY, ball.radius);
         padString(ballData);
	 ball.created = true;
    }
}
Beispiel #2
0
void addPong(){
    if (nPongs < MAX_PONGS){
        pongs[nPongs].leftCorner.point_x = ((resolution_w-resolution_x)/2 - (pongLength/2));
        pongs[nPongs].leftCorner.point_y = resolution_y;
        oppoentPointLocationX = ((resolution_w-resolution_x)/2 - (pongLength/2));

        rt_mutex_acquire(&txMutex[E_ADD], TM_INFINITE);
	memset(pongData[0], 0, sizeof(pongData[0]));
        sprintf(pongData[0], "pong;%d;",pongs[nPongs].leftCorner.point_x);
        sprintf(pongData[0] + strlen(pongData[0]), 
		"%d;%d;%d;", pongs[nPongs].leftCorner.point_y,pongLength,pongs[nPongs].height);
	padString(pongData[0]);
        rt_mutex_release(&txMutex[E_ADD]);
        
        pongs[nPongs].length = pongLength;
        nPongs++;
        pongs[nPongs].leftCorner.point_x =((resolution_w-resolution_x)/2 - (pongLength/2));
        pongs[nPongs].leftCorner.point_y = DEFAULT_HEIGHT;
        locationPointOfX = ((resolution_w-resolution_x)/2 - (pongLength/2)); 

	rt_mutex_acquire(&txMutex[E_ADD], TM_INFINITE);
	memset(pongData[1], 0, sizeof(pongData[1]));
        sprintf(pongData[1], "pong;%d;",pongs[nPongs].leftCorner.point_x);
        sprintf(pongData[1] + strlen(pongData[1]), 
		"%d;%d;%d;", pongs[nPongs].leftCorner.point_y,pongLength,pongs[nPongs].height);
	padString(pongData[1]);
	rt_mutex_release(&txMutex[E_ADD]);
        nPongs++;
    }
}
void PrintHelper::printItems(const Item& item, stringstream& ss) {
    stringstream sst;
    
    string headings[Item::NUM_ITEMS];
    for (int i=0; i<Item::NUM_ITEMS; i++) {
        if (i<5) {
            headings[i] = "! "+Item::ITEM_NAMES[i]+"("+Item::ITEM_CODES[i]+"):";
        } else if (i == 5) {
            headings[i] = "!\n! Scrolls      ! "+Item::ITEM_CODES[i]+":";
        } else {
            headings[i] = "! "+Item::ITEM_CODES[i]+":";
        }
    }

    int paddings[] = { 15, 16, 16, 16, 16, 25, 8, 8, 8, 8, 8, 8, 8 };
    
    printHR(ss);
    for (int i=0; i<13; i++) {
        sst.str("");
        sst << headings[i] << item.getItemCount(i);
        padString( sst, paddings[i] );
        ss << sst.str();
    }
    ss << "!\n";
    
}
Beispiel #4
0
void opponentMovement(char strOpponent){
    int err;

    if(strOpponent == 'R'){
          if (!(err=illegal_move_check(oppoentPointLocationX, standardPongSpeed))){
              oppoentPointLocationX = oppoentPointLocationX + standardPongSpeed;
              pongs[opponent].leftCorner.point_x = oppoentPointLocationX;
              pongs[opponent].leftCorner.point_y = resolution_y;
          }
	   else {
	        oppoentPointLocationX = oppoentPointLocationX - (err * standardPongSpeed);
	        pongs[opponent].leftCorner.point_x = oppoentPointLocationX;
          }
    }

    else if (strOpponent == 'L'){
        if (!(err=illegal_move_check(oppoentPointLocationX, standardPongSpeed))){
              oppoentPointLocationX = oppoentPointLocationX - standardPongSpeed;
              pongs[opponent].leftCorner.point_x = oppoentPointLocationX;
              pongs[opponent].leftCorner.point_y = resolution_y;
          }
	else {

	      oppoentPointLocationX = oppoentPointLocationX + (-err * standardPongSpeed);
	      pongs[opponent].leftCorner.point_x = oppoentPointLocationX;
	  }
    }

     rt_mutex_acquire(&txMutex[E_MOVE], TM_INFINITE);
     memset(moveData[1], 0, sizeof(moveData[1]));
     sprintf(moveData[1], "player2;%d;%d;%d;%d;",
         pongs[opponent].leftCorner.point_x, pongs[opponent].leftCorner.point_y,pongLength, pongs[opponent].height);
     padString(moveData[1]);
     rt_mutex_release(&txMutex[E_MOVE]);
}
Beispiel #5
0
void move(char str){
     
    int err;
    if(str == 'R'){
          if ((err=illegal_move_check(locationPointOfX, standardPongSpeed)) == 0){
              locationPointOfX = locationPointOfX + standardPongSpeed;
              pongs[player].leftCorner.point_x = locationPointOfX;
              pongs[player].leftCorner.point_y = DEFAULT_HEIGHT;
	  }
          else {
	        locationPointOfX = locationPointOfX - (err * standardPongSpeed);
	        pongs[player].leftCorner.point_x = locationPointOfX;
          }
    }

    else if (str == 'L'){
        if ((err=illegal_move_check(locationPointOfX, standardPongSpeed)) == 0){
              locationPointOfX = locationPointOfX - standardPongSpeed;
              pongs[player].leftCorner.point_x = locationPointOfX;
              pongs[player].leftCorner.point_y = DEFAULT_HEIGHT;
          }
	else {
	      locationPointOfX = locationPointOfX + (-err * standardPongSpeed);
	      pongs[player].leftCorner.point_x = locationPointOfX;
	  }
    }

       rt_mutex_acquire(&txMutex[E_MOVE], TM_INFINITE);
       memset(moveData[0], 0, sizeof(moveData[0]));
       sprintf(moveData[0], "player1;%d;%d;%d;%d;",
               pongs[player].leftCorner.point_x, pongs[player].leftCorner.point_y,pongLength, 
               pongs[player].height);
       padString(moveData[0]);
       rt_mutex_release(&txMutex[E_MOVE]);
}
Beispiel #6
0
void bouncingCheck (int x,int y, int radius, int directionX,int directionY){
        if(x + directionX < resolution_x){
            changeBallDirectionHorizontal();
        }
        else if(x +directionX + radius > resolution_w){
            changeBallDirectionHorizontal();
        }
        /* check if we hit the topmost pong */
        if (y+ directionY + (radius/4) <pongs[opponent].leftCorner.point_y + pongs[opponent].height ){
             if(x+directionX + radius > pongs[opponent].leftCorner.point_x &&
                x+directionX + radius < pongs[opponent].leftCorner.point_x+pongLength+radius){
                    bounceOpponent = true;
                    changeBallDirectionVertical();
                }
             else{ // in the vicinity to score a point 
                 player_score++;
		 rt_mutex_acquire(&txMutex[E_GAME],TM_INFINITE);
		 memset(gameData, 0, sizeof(gameData));
		 sprintf(gameData, "score;%d;%d;",player_score,opponent_score);
		 padString(gameData);
		 rt_mutex_release(&txMutex[E_GAME]);                 
                 reset = true;
             }
            
         }
	
        /* check if we hit the bottom-most pong */  
        if (y+ directionY + (radius/4) +pongs[player].height >pongs[player].leftCorner.point_y){
	     if(x+directionX + radius > pongs[player].leftCorner.point_x &&
                x+directionX + radius < pongs[player].leftCorner.point_x+pongLength+radius){
                    bounceplayer = true; 
                    changeBallDirectionVertical();
                }
	     else{                  opponent_score++;
                 rt_mutex_acquire(&txMutex[E_GAME],TM_INFINITE);
 		 memset(gameData, 0, sizeof(gameData));
		 sprintf(gameData, "score;%d;%d;",player_score,opponent_score);
		 padString(gameData);
		 rt_mutex_release(&txMutex[E_GAME]); 
                 reset = true;
             }
             
       }
		
}
void ofxVideoGrabber::toggleRecord() {
    if(f == NULL) {
        setpriority(PRIO_PROCESS, 0, -20);
        
        char *buf = new char[PATH_MAX];
        time_t t = time(0);
        tm now=*localtime(&t);
        strftime(buf, PATH_MAX-1, "/Users/chris/capture_video_%Y%m%d%H%M%S.ser", &now);
        ofLog(OF_LOG_NOTICE, buf);
        f = fopen(buf, "w");
        
        writeString("LUCAM-RECORDER");
        writeUInt32(0); // LuID (0 = unknown)
        writeUInt32(0); // ColorID (0 = MONO)
        writeUInt32(0); // LittleEndian (0 = Big endian)
        writeUInt32(width); // ImageWidth
        writeUInt32(height); // ImageHeight
        writeUInt32(bpp * 8); // PixelDepth
        writeUInt32(0); // FrameCount
                
        struct passwd *pwent = getpwuid(getuid());
        sprintf(buf, "%s", pwent->pw_gecos);
        padString(buf, 40);
        writeString(buf);
        
        sprintf(buf, "%s", videoGrabber->getCameraModel());
        padString(buf, 40);
        writeString(buf);
        
        sprintf(buf, "Lunt LS60THa");
        padString(buf, 40);
        writeString(buf);
        
        writeUInt64(0); // DateTime
        writeUInt64(0); // DateTime_UTC
        writtenFrames = 0;
    } else {
        fseek(f, 38, SEEK_SET);
        writeUInt32(writtenFrames);
        fclose(f);
        f = NULL;
        setpriority(PRIO_PROCESS, 0, 0);
    }
}
Beispiel #8
0
void resetScore(){
        if(nPongs >= MAX_PONGS){
            player_score = 0;
            opponent_score = 0;
            rt_mutex_acquire(&txMutex[E_GAME], TM_INFINITE);
	    memset(gameData, 0, sizeof(gameData));
  	    sprintf(gameData, "reset;");
	    padString(gameData);
	    rt_mutex_release(&txMutex[E_GAME]);
        }
} 
Beispiel #9
0
void ballmove()
{	
   currentBallOfX = ball.centre.point_x;
   currentBallOfY = ball.centre.point_y;

   bouncingCheck(currentBallOfX, currentBallOfY, ball.radius, balldirectionX, balldirectionY);
   currentBallOfX += balldirectionX;
   currentBallOfY += balldirectionY;
   ball.centre.point_x = currentBallOfX;
   ball.centre.point_y = currentBallOfY;

   memset(ballData, 0, sizeof(ballData));
   sprintf(ballData, "ball;%d;%d;%d;", currentBallOfX, currentBallOfY, ball.radius);
   padString(ballData);
}
void PrintHelper::printItems(const Item& item, stringstream& ss) {
    /*
     ss  << ": POTION " << formatItemCount(item.getItemCount(1))
     << " : SHIELD " << formatItemCount(item.getItemCount(2))
     << " : DMG-BOOST " << formatItemCount(item.getItemCount(3))
     << " : REVIVE " << formatItemCount(item.getItemCount(4))
     << " : LASSO " << formatItemCount(item.getItemCount(5)) << " :\n"
     << ": S-A " << formatItemCount(item.getItemCount(6))
     << " : S-B " << formatItemCount(item.getItemCount(7))
     << " : S-C " << formatItemCount(item.getItemCount(8))
     << " : S-D " << formatItemCount(item.getItemCount(9))
     << " : S-E " << formatItemCount(item.getItemCount(10))
     << " : S-F " << formatItemCount(item.getItemCount(11))
     << " : S-G " << formatItemCount(item.getItemCount(12))
     << " : S-H " << formatItemCount(item.getItemCount(13)) << " :\n";
     */
    stringstream sst;
    
    //    string headings[] = { "! Potion:", "! Shield:", "! Dmg-Boost:", "! Revive:",
    //        "! Lasso:", "!\n! Scrolls      ! S-A:", "! S-B:", "! S-C:", "! S-D:",
    //        "! S-E:", "! S-F:", "! S-G:", "! S-H:" };
    string headings[Item::NUM_ITEMS];
    for (int i=0; i<Item::NUM_ITEMS; i++) {
        if (i<5) {
            headings[i] = "! "+Item::ITEM_NAMES[i]+"("+Item::ITEM_CODES[i]+"):";
        } else if (i == 5) {
            headings[i] = "!\n! Scrolls      ! "+Item::ITEM_CODES[i]+":";
        } else {
            headings[i] = "! "+Item::ITEM_CODES[i]+":";
        }
    }
    //    = { "! Potion(po):", "! Shield(sh):", "! Enrage(en):", "! Revive(re):",
    //        "! Lasso(la):", "!\n! Scrolls      ! sa:", "! sb:", "! sc:", "! sd:",
    //        "! se:", "! sf:", "! sg:", "! sh:" };
    int paddings[] = { 15, 16, 16, 16, 16, 25, 8, 8, 8, 8, 8, 8, 8 };
    
    printHR(ss);
    for (int i=0; i<13; i++) {
        sst.str("");
        sst << headings[i] << item.getItemCount(i);
        padString( sst, paddings[i] );
        ss << sst.str();
    }
    ss << "!\n";
    
}
Beispiel #11
0
/* alarm_handler 
** is triggered once 10s is passed to inform player 
** wait time has expired - issue start
*/
void alarm_handler(void *arg) 
{
     int sock = *(int *)&arg;
     int echolen;
    
     /* start the countdown */
     rt_task_set_periodic(NULL, TM_NOW, 1000000000ULL);
     int i;
    for(i = 15; i >= 0; i--){
       rt_task_wait_period(NULL); 

        rt_mutex_acquire(&txMutex[E_WAIT], TM_INFINITE);
            memset(countData, 0, sizeof(countData));
            sprintf(countData, "count;%d;", i);
            padString(countData);
        rt_mutex_release(&txMutex[E_WAIT]);

        echolen = strlen(countData);
        if(send(sock, countData,echolen, 0) != echolen)
     	rt_err("send()");

     /*2 View mode case*/
          if(viewMode > 1){
		if(send(viewSocket2, countData, echolen, 0) != echolen)
     		rt_err("send()");
	  }
    }
     if(!issuedStart)
       rt_task_delete(NULL); //not need two players connected

     rt_mutex_acquire(&autoStart, TM_INFINITE);
     issuedStart = true;
     rt_mutex_release(&autoStart);
     AIMode = true;
      
     printf("FORCED START client playing with AI!\n");
     /* below we emulate the add, start */
     addPong();     
     echolen = strlen(pongData[0]);
     if(send(sock, pongData[0],echolen, 0) != echolen)
     	rt_err("send()");

     /*2 View mode case*/
          if(viewMode > 1){
		if(send(viewSocket2, pongData[0], echolen, 0) != echolen)
     		rt_err("send()");
	  }

     echolen = strlen(pongData[1]);
     if(send(sock, pongData[1],echolen, 0) != echolen) 
     	rt_err("send()");

      /*2 View mode case*/
     if(viewMode > 1){
		if(send(viewSocket2, pongData[1], echolen, 0) != echolen)
     		rt_err("send()");
     }

     start(); 
     echolen = strlen(gameData);
     if(send(sock, gameData, echolen, 0) != echolen)
     	 rt_err("send()");
     
      /*2 View mode case*/
      if(viewMode > 1){
		if(send(viewSocket2, gameData, echolen, 0) != echolen)
     		rt_err("send()");
      } 


     echolen = strlen(ballData);
     if(send(sock, ballData, echolen, 0) != echolen)
	 rt_err("send()");

	
     /*2 View mode case*/
          if(viewMode > 1){
		if(send(viewSocket2, ballData, echolen, 0) != echolen)
     		rt_err("send()");
	  }


     if(rt_task_resume(&recvThread[0]))
	rt_err("rt_task_resume()");
     if(rt_task_resume(&ballThread))	
	 rt_err("rt_task_resume()");

}
std::string CTestMonitor::displayQueueTimes(double timeIntervalSeconds, CFrameGrinder* pFrameGrinder) const
{
    double dTemp;
    char buf[256];
    static std::string initTitles[] = {"Camera", "BlobDetect", "Text", "Browser", "Total", " "};
    std::string sLine, sRet;

    sLine = "";
    unsigned int i = 0;
    unsigned int nColSize = 20;
    while (0 != initTitles[i].compare(" "))
    {
        padString(sLine, i * nColSize);
        sLine += initTitles[i];
        i++;
    }
    sRet += sLine;
    sRet += "\n";

    sLine = "";
    nColSize = 10;
    for (i = 0; i < NUMBER_OF_TIME_IN_TASK; i++)
    {
        padString(sLine, i * nColSize);
        dTemp = m_savedElapsedSeconds[i];
        dTemp *= 1000.0;
        sprintf(buf, "%0.2fms", dTemp);
        sLine += buf;
    }
    sRet += sLine;
    sRet += "\n";

    sLine = "Done: ";
    nColSize = 20;
    for (i = 0; i < NUMBER_OF_TASK_DONE_TYPES; i++)
    {
        padString(sLine, 10 + (i * nColSize));
        sprintf(buf, "%d", m_nTasksDone[i]);
        sLine += buf;
    }
    sRet += sLine;
    sRet += "\n";

    sLine = "Drop: ";
    nColSize = 20;
    for (i = 1; i < CVideoFrame::NUMBER_OF_FRAME_QUEUES - 1; i++)
    {
        padString(sLine, 10 + ((i - 1) * nColSize));
        sprintf(buf, "%d", pFrameGrinder->m_frameQueueList[i].m_droppedFrames);
        sLine += buf;
    }
    sRet += sLine;
    sRet += "\n";

    unsigned int framesPerSecTextComplete = 0;
    if (timeIntervalSeconds > 0)
    {
        framesPerSecTextComplete = m_nTasksDone[TASK_DONE_TEXT] / timeIntervalSeconds;
    }
    sprintf(buf, "viking_cv Version %d.%d.%d    Interval:  %02f sec", VERSION_YEAR, VERSION_INTERFACE, VERSION_BUILD, timeIntervalSeconds);
    sRet += buf;
    sRet += "\n";

    sprintf(buf, "avgTimeBetweenCameraFrames: %0.2fms    avgLatencyForProcessingFrame: %0.2fms", m_avgTimeBetweenCameraFramesMilliseconds, m_avgLatencyForProcessingFrameMilliseconds);
    sRet += buf;
    sRet += "\n\n";

    return sRet;
}