Ejemplo n.º 1
0
static Tile
substituteTile(Tile* dst, const Tile* src)
{
    Tile tmp;

    restoreTile(&tmp, dst);
    restoreTile(dst, src);

    return tmp;
}
Ejemplo n.º 2
0
/*
 * NOTE: Before invoking this function 'tileA' must be initialized accordingly
 *       so as it stores a square tile of the matrix A.
 */
static void
genMulOnDiagonalTile(
    struct KgenContext *ctx,
    BlasGenSettings *gset,
    TileSet *tileSet,
    const TileMulOpts *mulOpts)
{
    char tmp[1024];
    FetchOpts fetchOpts;
    const SubproblemDim *dim = &gset->subdims[1];
    TilePostFetchPrivate pfPriv[2];
    TileMulOpts optsNew;
    const CLBLASKernExtra *extra = gset->kextra;
    CLBLASKernExtra extraNew;
    KernelExtraFlags kflags = extra->flags;
    Tile t;
    bool isTail;

    memset(&fetchOpts, 0, sizeof(fetchOpts));
    fetchOpts.regName = "b";
    fetchOpts.mrole = MATRIX_A;
    fetchOpts.lineOffset = 0;
    fetchOpts.linesNum = (unsigned int)dim->y;

    // setup options to multiply on the inverted tile
    memcpy(&optsNew, mulOpts, sizeof(TileMulOpts));
    optsNew.flags &= ~TILEMUL_TRB;

    kgenAddStmt(ctx, "// Fetch and invert the square tile located on the "
                     "diagonal\n");

    // The matrix B play the role of A
    t = substituteTile(&gset->tileA, &tileSet->bAsSqA);

    isTail = ((kflags & KEXTRA_TAILS_M) != 0);
    genFetchInputTile(ctx, mulOpts->fctx, gset, &fetchOpts);
    setFetchHandler(&optsNew, gset, genTrxmPostFetchZero, pfPriv);

    /*
     * There is no needs in zeroing tail along K in case of the lower
     * triangular matrix because it is in the "other" triangle which is
     * never accessed
     */
    if (isTail && !isMatrixUpper(kflags)) {
        memcpy(&extraNew, extra, sizeof(extraNew));
        extraNew.flags &= ~KEXTRA_TAILS_K_LOWER;
        gset->kextra = &extraNew;
    }
    genTrxmPostFetchZero(ctx, MATRIX_A, pfPriv);

    /*
     * One must zero the tail part of a fetched square tile
     * in order to avoid influence of the trailing trash on the resulting
     * inverted tile (evaluating proceeds from the bottom towards the top
     *                of the tile)
     */
    if (isTail) {
        genZeroTileTrash(ctx, gset, MATRIX_A, &gset->tileA);
    }

    restoreTile(&gset->tileA, &t);

    if(gset->flags & BGF_EXPLICIT_INLINE) {
        genTileInverting(ctx, gset, tileSet);
    }
    else {
        sprintf(tmp, "invertTile(%s, %s);\n\n",
                tileSet->squareA.baseName, tileSet->bAsSqA.baseName);
        kgenAddStmt(ctx, tmp);
    }

    gset->tileBX = tileSet->bAsC;
    genTileCopy(ctx, &gset->tileBX, &gset->tileCY, TILECOPY_ASSIGN);

    /*
     * For the lower diagonal not integrally decomposed matrix A
     * it's enough to zero the tail part of the result in order to
     * clear trash accumulated over the update loop
     */
    if (isTail && !isMatrixUpper(kflags)) {
        genZeroTileTrash(ctx, gset, MATRIX_B, &gset->tileBX);
    }

    genZeroTile(ctx, &gset->tileCY);

    genMulTiles(ctx, gset, &optsNew);
    kgenAddBlankLine(ctx);

    // restore original extra
    gset->kextra = extra;
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------------
void Simulator::handleDiskCollisions(Disk* disk, GameObject* o)
{
	if (o->typeName == "Wall")
	{	
		wallHitAfterThrow = true;

		if (previousWallHit == "NULL")
		{
			// gameDisk->needsOrientationUpdate = true;
			previousWallHit = o->getGameObjectName();
			// adjustDiskOrientation(disk, disk->getBody()->getLinearVelocity(), previousWallHit);
			gameMusic->playCollisionSound("Disk", "Wall");
		}
		else if (previousWallHit != o->getGameObjectName())
		{
			// disk->needsOrientationUpdate = true;
			previousWallHit = o->getGameObjectName();
			// adjustDiskOrientation(disk, disk->getBody()->getLinearVelocity(), previousWallHit);
			gameMusic->playCollisionSound("Disk", "Wall");
		}
	}
	// Player
	else if (o->typeName == "Player")
	{
		if (((Player*)o)->checkHolding() == false)
		{
			if (((Player*)o)->checkPlayerCanCatch())
			{
				((Player*)o)->attachDisk((Disk*)disk);
				disk->setHolder(((Player*)o)->getPlayerID());
				gameMusic->playCollisionSound("Disk", "Player");
				safeToSpawnPowerUps = true;
			}
			gameStart = true;
			gameState = STARTED;
			gameMusic->playCollisionSound("Disk", "Player");
		}
	}
	// Target
	else if (o->typeName == "Target")
	{
		if (((Target*)o)->checkHitFlag() == false)
		{
		    ((Target*)o)->toggleHitFlag();
			removeObject(o->getGameObjectName());
			if (((Target*)o)->getPowerUpType() != TARGET)
			{
				powerUpType puType = ((Target*)o)->getPowerUpType();		

			    if (disk->activatePowerUp(puType, disk->getPlayerLastThrew()))
			        restoreTile(disk->getPlayerLastThrew()->getPlayerID() - 1);
                
                gameMusic->playCollisionSound("Disk", "Target");

             	if (puType == EXPLOSIVE || puType == SPEED)
             		((Target*)o)->setReceiverID(disk->getDiskID());
             	else
                	((Target*)o)->setReceiverID(disk->getPlayerLastThrew()->getPlayerID());
                
                removedPowerUps.push_back((Target*)o);
			}
			else
			{
				Ogre::Real width, height, gap;
			    Ogre::Real posx, posy, posz;

				width = gameRoom->getWidth();
				height = gameRoom->getHeight();
				gap = gameRoom->getGapSize();

				posx = Ogre::Math::RangeRandom(-width/2.0f, width/2.0f);
				posy = Ogre::Math::RangeRandom(gameRoom->getFloorPositionY()/2.0f, -gameRoom->getFloorPositionY()/2.0f);
				posz = Ogre::Math::RangeRandom(-gap/2.0f, -height/2.0f);
			    o->getSceneNode()->setPosition(posx, posy, posz);
			    gameMusic->playCollisionSound("Disk", "Target");
				o->addToSimulator();
		    }
		}
	}
	else if (o->typeName == "Tile" && !((Tile *)o)->checkHitFlag() && wallHitAfterThrow && !playerList[((Disk*)disk)->getPlayerLastThrew()->getPlayerID() - 1]->checkHolding() && playerList[1] != NULL)  // HARD CODE PLAYER FLAG
	{	
		((Tile *)o)->toggleHitFlag(); // Mark that the tile has been hit

		destroyTiles((Tile*)o);

		disk->resetPowerUp();
		((Player*)getGameObject(disk->getPlayerLastThrew()->getGameObjectName()))->attachDisk((Disk*)disk);

		newRemovedTile = true;
	}
	if(sceneMgr->hasManualObject("Circle"))
	{
		sceneMgr->destroyManualObject("Circle");
		sceneMgr->destroySceneNode("CircleNode");
		predictedHit();
	}

}