Exemple #1
0
QVariant Subscribe::customCommand(const QString &command, const QList<QVariant> &args)
{
    auto assertWhere = QString("Custom command \"%1\" from module \"%2\"")
            .arg(command).arg(name()).toLocal8Bit();
    auto assertWhatInvalidArgs = "Invalid number of arguments!";
    auto assertWhatInvalidCommand = "Invalid command";

    if (command == "sendNotification")
    {
        Q_ASSERT_X(args.size() == 3, assertWhere.data(), assertWhatInvalidArgs);
        auto gid = args[0].toLongLong();
        auto tag = args[1].toString();
        auto text = args[2].toString();
        sendNotification(gid, tag, text);
    }
    else if (command == "sendForward")
    {
        Q_ASSERT_X(args.size() == 3, assertWhere.data(), assertWhatInvalidArgs);
        auto gid = args[0].toLongLong();
        auto tag = args[1].toString();
        auto msgId = args[2].toLongLong();
        sendForward(gid, tag, msgId);
    }
    else
        Q_ASSERT_X(false, assertWhere.data(), assertWhatInvalidCommand);

    return QVariant();
}
int main(void)
{
    // seed pseudorandom number generator
    srand48(time(NULL));

    // instantiate window
    GWindow window = newGWindow(WIDTH, HEIGHT);

    // instantiate bricks
    initBricks(window);

    // instantiate ball, centered in middle of window
    GOval ball = initBall(window);
    sendForward(ball);  //send ball forword.
    
    // instantiate paddle, centered at bottom of window
    GRect paddle = initPaddle(window);

    // instantiate scoreboard, centered in middle of window, just above ball
    GLabel label = initScoreboard(window);
    sendBackward(label);    //send label backwords

    // number of bricks initially
    int bricks = COLS * ROWS;

    // number of lives initially
    int lives = LIVES;

    // number of points initially
    int points = 0;

    //velocity constants for x and y directions for velocity of ball
    double velocityX = 0.029;
    double velocityY = 0.043;
    //wait for click before starting
    waitForClick();

    // keep playing until game over
    while (lives > 0 && bricks > 0)
    {   
       //moving paddle with mouse movement in x direction only.
        // check for mouse event
        GEvent Mevent = getNextEvent(MOUSE_EVENT);
        // if we heard one
        if (Mevent != NULL)
        {
            // if the Mevent was a mouse movement
            if (getEventType(Mevent) == MOUSE_MOVED)
            {
                // moves paddle only in x direction with movement of mouse.
                double x = getX(Mevent);
                if(x > PADDLEW/2 && x < WIDTH-(PADDLEW/2))
                {
                    setLocation(paddle, x-(PADDLEW/2), PADDLEY );
                }
            }
        }

        //move ball with given velocity constants.
        move(ball, velocityX, velocityY );
            // bounce off right edge of window
            if (getX(ball) + getWidth(ball) >= getWidth(window))
            {
                velocityX = -velocityX;
            }

            // bounce off left edge of window
            else if (getX(ball) <= 0)
            {
                velocityX = -velocityX;
            }
            //bounce off the top edge of window
            else if (getY(ball) <= 0)
            {
                velocityY = -velocityY;
            }
            //if ball touch bottom edge decrese a life and reset the ball at center of window and lunnch again after click.
            else if(getY(ball) + getHeight(ball) >= getHeight(window)) 
            {
                lives = lives-1;
                waitForClick();
                setLocation(ball, WIDTH/2, HEIGHT/2);
                    //close window if live finishes.
                    if(lives == 0){
                    closeGWindow(window);
                    }
            }
        //ball movement, edge bounce , and lives calculation part end here.
        //detect collsion of ball with other objects.
            //paddlecollde is the object with ball collided.
            GObject collide = detectCollision(window ,ball);
                if(collide == paddle){
                    velocityY = -velocityY;
                    //funkey fun with color
                    char* colorpaddle = malloc(20*sizeof(char));
                    colorpaddle = getColorGObject(ball);
                    setColor(paddle,colorpaddle);
                    freeGObject(colorpaddle);
                }
                if(collide == label ){
                    //funkey fun with color
                    char* colorlabel = malloc(20*sizeof(char));
                    colorlabel = getColorGObject(ball);
                    setColor(label,colorlabel);               
                    freeGObject(colorlabel);
                }
             //collidedObj is the object with ball collides.
             GObject collidedObj = detectCollision(window, ball);   
             if(collidedObj){   
             if(collidedObj != paddle && collidedObj != label){
                    //funkey fun with color
                    char* colorball = malloc(20*sizeof(char));
                    colorball = getColorGObject(collidedObj);
                    setColor(ball,colorball);
                    freeGObject(colorball);
                    //if collided object is brick then remove bricks and increse and update score and decrese no of bricks and bounce ball.
                    removeGWindow(window, collidedObj);
                    points++;
                    bricks--;
                    updateScoreboard(window, label, points);
                    velocityY = -velocityY;
                    freeGObject(colorball);
                    freeGObject(collidedObj);
             }
          }
    }
    // wait for click before exiting
    waitForClick();

    // game over
    closeGWindow(window);
    freeGObject(paddle);
    freeGObject(ball);
    freeGObject(label);
    return 0;
}
Exemple #3
0
void KMessageClient::sendForward (const QByteArray &msg, quint32 client)
{
  sendForward (msg, QList <quint32> () << client);
}
Exemple #4
0
void KMessageClient::sendForward (const QByteArray &msg, Q_UINT32 client)
{
  sendForward (msg, QValueList <Q_UINT32> () << client);
}
Exemple #5
0
// comms is an array of communicators of length P.  Only the I and J entries will be valid.  They are the communicators along the given row/column of X.
void trsmr( double *X, double *L, int bs, int bsc, int I, int J, int P, MPI_Comm *comms ) {
  int bs2 = bs*bs;
  int bsrect = bs*bsc;

  double *bufL1 = (double*) malloc( bs2*sizeof(double) );
  double *bufL2 = (double*) malloc( bs2*sizeof(double) );
  double *bufX1 = (double*) malloc( bsrect*sizeof(double) );
  double *bufX2 = (double*) malloc( bsrect*sizeof(double) );

  if( I == J ) {
    
    // perform updates from earlier in the matrix
    for( int j = 0; j < J; j++ ) {
      mybcast( bufL1, bs2, j, comms[J] );
      recvForward( bufX1, bsrect, j, comms[J] );
      localDgemmr( X, bufX1, bufL1, bs, bsc );      
    }
    
    // Send L to everyone in the same column
    mybcast( L, bs2, I, comms[J] );

    // local trsm on this column
    localTrsmr( L, X, bs, bsc );

    // now update the rest of the matrix: X(:,J+1:n) -= X(:,J)*(L(J+1:n,J))^t
    sendForward( X, bsrect, J, P, comms[I] );
  } else {
    double *XL = X;
    double *XU = X+bsrect;
    for( int j = 0; j <= I; j++ ) {
      if( j < J ) {
	// two blocks to update
	// receive L_Jj
	mybcast( bufL1, bs2, j, comms[I] );
	// receive L_Ij
	mybcast( bufL2, bs2, j, comms[J] );
	// receive X_Jj
	recvForward( bufX1, bsrect, j, comms[J] );
	// receive X_Ij
	recvForward( bufX2, bsrect, j, comms[I] );

	localDgemmr( XU, bufX1, bufL1, bs, bsc );
	localDgemmr( XL, bufX2, bufL2, bs, bsc );
      } else if( j == J ) {
	// work on our block in the lower triangle
	// receive the diagonal of L
	mybcast( bufL1, bs2, J, comms[J] );
	localTrsmr( bufL1, XL, bs, bsc );
	mybcast( L, bs2, J, comms[I] );
	sendForward( XL, bsrect, J, P, comms[I] );
	// send the off-diagonal of L

	// one block to update
	recvForward( bufX1, bsrect, j, comms[J] );
	localDgemmr( XU, bufX1, L, bs, bsc );
      } else if( j < I ) {
	// one block to update
	mybcast( bufL1, bs2, j, comms[I] );
	recvForward( bufX1, bsrect, j, comms[J] );
	localDgemmr( XU, bufX1, bufL1, bs, bsc );
      } else  { //j == I
	// work on our block in the upper triangle
	// receive the diagonal of L
	mybcast( bufL1, bs2, I, comms[I] );
	localTrsmr( bufL1, XU, bs, bsc );
	sendForward( XU, bsrect, I, P, comms[J] );
      }
    }
  }
  free(bufL1);
  free(bufL2);
  free(bufX1);
  free(bufX2);  
}