Ejemplo n.º 1
0
Creature* TimeQueue::getMinCreature() {
  CHECK(creatures.size() > 0);
  removeDead();
  QElem elem = queue.top();
  if (elem.time == elem.creature->getTime())
    return elem.creature;
  else {
    queue.pop();
    removeDead();
    queue.push({elem.creature, elem.creature->getTime()});
    CHECK(queue.top().creature->getTime() == queue.top().time);
    return queue.top().creature;
  }
}
Ejemplo n.º 2
0
void Room::update(float time, glm::vec3 player_pos) {
    /*CREACION DE BALAS*/
    for (Enemy *enemy : enemies){
        if (enemy->type() == 3 and ((Arbok*)enemy)->isShooting()){ // Arbok, puede tener una bala
            glm::vec3 dirBullet = glm::normalize(player_pos - enemy->position());
            glm::vec3 posBullet = enemy->position() + dirBullet * enemy->radius() * 2.0f;
            enemies.push_back(new Bullet(posBullet,dirBullet,0,enemy->getPower()*2,enemy->radius()));
        } // otro enemigo dispara 8 balas
    }

    /*REBOTE EN LAS PAREDES */
    for (Enemy *enemy : enemies) {
        glm::vec3 nextpos = enemy->stepTest(time, player_pos);
        RoomWhere npos = where(nextpos.x, nextpos.z, enemy->radius());
        if (npos == CAN_BE  and !enemiesCollision(enemy,nextpos))
            enemy->step();
        else if(npos == COLLISION and enemy->type() == 4)
            enemy->step();
        else if (npos == E_COLLISION or npos == W_COLLISION)
            enemy->reflectDirection(-1,1);
        else if (npos == N_COLLISION or npos == S_COLLISION)
            enemy->reflectDirection(1,-1);
        else if (npos > CAN_BE and enemy->type() == 4) //bala muere en las puertas
            enemy->receiveImpact(1);
    }

    /*calcular colisiones de las balas*/
    for (Enemy *enemy : enemies) {
        int damage = bulletCollision(enemy);
        if (damage>0)
            enemy->receiveImpact(damage);
    }

    for (ParticleEngine *pe : particles)
        pe->step(time);
    removeDead();
}
/*runs the physics simulation until it is stopped*/
void MyLevel::run(){
	{
		Lock l(runningMutex);
		running=true;
	}
	float32 timeStep = 1.0f / stepsPerSecond;//seconds
	int32 velocityIterations = 6;
	int32 positionIterations = 2;
	LOG(INFO)<<"physics simulation of level started";
	bool bossEncounterStarted=false;
	try{
		while(isRunning()){
			if(!bossEncounterStarted && bossEncounter){
				bossEncounterStarted=true;
				startBossEncounter();
			}
			moveScreen();
			removeDead();
			createNewObjects();
			world.Step(timeStep, velocityIterations, positionIterations);
			tickAll(timeStep);
			redrawForClient();
			respawnAll();
			//if no megamans left exit
			if(allMegamansDead()){
				LOG(INFO)<<"all megamans dead";
				game->notify(new LevelFinished(LOST,id));
				this->stop();
			}
			usleep(timeStep* 1000000 );
		}
	}catch(std::exception& e){
		LOG(ERROR)<<e.what();
	}
	LOG(INFO)<<"physics simulation of level stopped";
}
Ejemplo n.º 4
0
void optimize(SYMBOL *funcsp)
{
    //printf("optimization start\n");
    if (chosenAssembler->gen->pre_gcse)
        chosenAssembler->gen->pre_gcse(intermed_head);
    #ifdef DUMP_GCSE_INFO
        if (icdFile && funcsp)
            fprintf(icdFile, 
                "\n*************************FUNCTION %s********************************\n", funcsp->name);
    #endif 

    /*
     * icode optimizations goes here.  Note that LCSE is done through
     * DAG construction during the actual construction of the blocks
     * so it is already done at this point.
     *
     * Order IS important!!!!!!!!! be careful!!!!!
     *
     * note that some of these optimizations make changes to the code,
     * with the exception of the actual global optimization pass we are
     * never really deleting dead code at the time we make changes
     * becase we aren't 100% certain what will really be dead
     * we do separate dead-code passes occasionally to clean it up
     */
    /* Global opts */
    
    flows_and_doms();
    gatherLocalInfo(funcsp);
    if (cparams.prm_optimize && !functionHasAssembly)
    {
        Precolor();
        RearrangePrecolors();
    //printf("ssa\n");
        TranslateToSSA();
    //printf("const\n");
        if (optflags & OPT_CONSTANT)
        {
            ConstantFlow(); /* propagate constants */
            RemoveInfiniteThunks();
//			RemoveCriticalThunks();
            doms_only(FALSE);
        }
//		if (optflags & OPT_RESHAPE)
//			Reshape();		/* loop expression reshaping */
    //printf("stren\n");
        if (optflags & OPT_LSTRENGTH)
            ReduceLoopStrength(); /* loop index variable strength reduction */
    //printf("invar\n");
        if (optflags & OPT_INVARIANT)
            MoveLoopInvariants();	/* move loop invariants out of loops */

        if (optflags & OPT_GLOBAL)
        {
        //printf("alias\n");
            AliasPass1();
        }
    //printf("ssa out\n");
        TranslateFromSSA(FALSE);
        removeDead(blockArray[0]);
//		RemoveCriticalThunks();
        if (optflags & OPT_GLOBAL)
        {
    //printf("alias 2\n");
            AliasPass2();
            //printf("global\n");
            GlobalOptimization(); /* partial redundancy, code motion */
            AliasRundown();
        }
                 //printf("end opt\n");
           RemoveCriticalThunks();
        removeDead(blockArray[0]);
        RemoveInfiniteThunks();
    }
    else
    {
        RemoveCriticalThunks();
        RemoveInfiniteThunks();
    }
    /* backend modifies ICODE to improve code generation */
    if (chosenAssembler->gen->post_gcse)
    {
        chosenAssembler->gen->post_gcse(intermed_head);
    }
    /* register allocation - this first where we go into SSA form and backi s because 
     * at this point for global allocation we had to reuse original
     * register names, but the register allocation phase works better
     * when registers are disentangled and have smaller lifetimes
     * 
     * while we are back in SSA form we do some improvements to the code that will
     * help in register allocation and code generation.
     */
    definesInfo();
    liveVariables();
    doms_only(TRUE);
        //printf("to ssa\n");
    TranslateToSSA();
    CalculateInduction();

    /* lower for backend, e.g. do transformations that will improve the eventual
     * code gen, such as picking scaled indexed modes, moving constants, etc...
     */
        //printf("prealloc\n");
    Prealloc(1);
        //printf("from ssa\n");
    TranslateFromSSA(TRUE);
    //printf("peep\n");
      peep_icode(FALSE);			/* peephole optimizations at the ICODE level */
    RemoveCriticalThunks();
    removeDead(blockArray[0]);			/* remove dead blocks */

            //printf("allocate\n");
    /* now do the actual allocation */
    AllocateRegisters(intermed_head); 
    /* backend peephole optimization can sometimes benefit by knowing what is live */
            //printf("live\n");

    CalculateBackendLives();
    sFree();
    peep_icode(TRUE);	/* we do branche opts last to not interfere with other opts */
            //printf("optimzation done\n");

}
Ejemplo n.º 5
0
void removeDead(BLOCK *b)
{
    static BRIGGS_SET *live;
    BITINT *p;
    int j,k;
    QUAD *tail;
    BLOCKLIST *bl;
    BOOL done = FALSE;
    if (b == blockArray[0])
    {
        int i;
        liveVariables();
        live = briggsAlloc(tempCount);
        for (i=0; i < blockCount; i++)
            if (blockArray[i])
            {
                QUAD *tail = blockArray[i]->head;
                while (tail != blockArray[i]->tail->fwd)
                {
                    tail->live = tail->alwayslive;
                    tail = tail->fwd;
                }
                blockArray[i]->visiteddfst = FALSE;
            }
    }
    b->visiteddfst = TRUE;
    briggsClear(live);
    p = b->liveOut;
    for (j=0; j < (tempCount + BITINTBITS-1)/BITINTBITS; j++,p++)
        if (*p)
            for (k=0; k < BITINTBITS; k++)
                if (*p & (1 << k))
                {
                    briggsSet(live, j*BITINTBITS + k);
                }
    tail = b->tail;
    while (tail != b->head->back)
    {
        markLiveInstruction(live, tail);
        tail = tail->back;
    }
    bl = b->succ;
    while (bl)
    {
        if (!bl->block->visiteddfst)
            removeDead(bl->block);
        bl = bl->next;
    }
    if (b == blockArray[0])
    {
        QUAD *head = intermed_head;
        BOOL changed = FALSE;
        int i;
        for (i=0; i < blockCount; i++)
        {
            BLOCK *b1 = blockArray[i];
            if (b1)
            {
                QUAD *head = b1->head;
                while (head != b1->tail->fwd)
                {
                    if (!head->live)
                    {
                        if (head->dc.opcode != i_block && !head->ignoreMe && head->dc.opcode != i_label)
                        {
                            changed = TRUE;
                            RemoveInstruction(head);
                            if (head->dc.opcode == i_coswitch || head->dc.opcode >= i_jne && head->dc.opcode <= i_jge)//FIXME && ||
                            {
                                BLOCKLIST *bl = head->block->succ->next;
                                head->block->succ->next = NULL;
                                while (bl)
                                {
                                    if (bl->block->critical)
                                        UnlinkCritical(bl->block);
                                    bl = bl->next;
                                }
                            }
                        }
                    }
                    head = head->fwd;
                }
            }
        }
        if (changed)
        {
            removeDead(b);
        }
    }
}