示例#1
0
AudioOutputSample *AudioOutput::playSample(const QString &filename, bool loop) {
	SoundFile *handle = AudioOutputSample::loadSndfile(filename);
	if (handle == NULL)
		return NULL;

	while ((iMixerFreq == 0) && isAlive()) {
		QThread::yieldCurrentThread();
	}

	if (! iMixerFreq)
		return NULL;

	QWriteLocker locker(&qrwlOutputs);
	AudioOutputSample *aos = new AudioOutputSample(filename, handle, loop, iMixerFreq);
	qmOutputs.insert(NULL, aos);

	return aos;

}
示例#2
0
void Totem::Update(uint32 update_diff, uint32 time )
{
    Unit *owner = GetOwner();
    if (!owner || !owner->isAlive() || !isAlive())
    {
        UnSummon();                                         // remove self
        return;
    }

    if (m_duration <= update_diff)
    {
        UnSummon();                                         // remove self
        return;
    }
    else
        m_duration -= update_diff;

    Creature::Update( update_diff, time );
}
示例#3
0
void GameObj::update(SoundManager &sm, b2Vec2 nearest) {
//	this->elapsedTime = elapsedTime;

	if(!body->IsActive()) {
		return;
	}

	bool doRanged = true;

	if(isAlive()) {
		move(sm);

		// Melee Attacks
		for(std::list<GameObj*>::iterator it = enemies.begin(); it != enemies.end(); ++it) {
			if((*it)->isAlive()) {
				attack((*it), sm);
				doRanged = false;
			}
		}

		// Ranged attacks
		if(doRanged) {
			if(goSettings._LAUNCH_MAX_VEL) {
				rangedAttack(nearest);
			}
		}

		// Proccess ground contact
		if(groundContact) {
			// BULLETS - disappear after striking the ground.
			if(goSettings.getType() == Settings::OBJ_T_BULLET) {
				goSettings.setHP(0);
//				body->SetActive(false);
			}
		}
	} else {
//		body->SetTransform(b2Vec2(-5000, -5000), 0.0);
	}

	// Special Behavior (defined in derived classes)
	updateSpecial(sm);

}
示例#4
0
	virtual void run() {
		GCPin pin;

		// wait for led object from mailbox
		pin = mail.wait();		// use operator '= (xHandle)' to receive the GC object.

		// turn off the LED by CPin operator
		*pin = LED_OFF;

		// thread while-loop
		while(isAlive()) {

			// blink LED
			if ( pin ) {
				pin->invert();
			}
			sleep(200);
		}
		DBG("gcLED destroyed\n");
	}
示例#5
0
void AngryKleptobot::doSomething()      //if angry bot can fire, then it fires else it does what a normal kleptobot will do
{
    if(!isAlive())
        return;
    
    if(getTicks() != getTempTicks())
    {
        increaseTick();
        return;
    }
    
    if(fire(getX(), getY(), getDirection()))
    {
        setTicksToZero();
        return;
    }
    else
        Kleptobot::doSomething();

}
示例#6
0
void Warship::refresh(float detalTime)
{
    limit+=detalTime;
    sumChangeStatusTime+=detalTime;
    fire();
    if(isAlive())
    {
        if(_isBeHited)
        {
            status = 2;
            _isBeHited = false;
        }
        else if(sumChangeStatusTime > detalChangeStatusTime)
        {
            changeStatus();
            sumChangeStatusTime = 0.f;
        }
    }
    move(Direction*speed*detalTime);
}
示例#7
0
character* golem::attack(character* enemy,const short& plusDP) throw(Error)
try
{//metodo ereditato
    short hp;
    if(enemy->getHP() && isAlive())
    {
        if(enemy!=this)//se è un attacco offensivo non è possibile autoinfliggerselo
            hp=enemy->getHP()-(getDP()+plusDP+getStrength());
        else//enemy==this;non esistono attacchi curativi per i tipi demon
        {	
            throw Error();
            return NULL;
        }
        enemy->setHP(hp);
    }
    return enemy;
}
catch(Error e){
    cout<<"Invalid target "<<endl;
}
void toweringinferno::heatvision::HeatvisionSystem::preUpdate()
{
    for(auto civilianIt = m_civilians.begin(); civilianIt != m_civilians.end(); ++civilianIt)
    {
        civilianIt->pos = civilianIt->nextPos;
    }

    auto deadCivilianIt = m_civilians.begin();
    while(deadCivilianIt != m_civilians.end())
    {
        if (deadCivilianIt->isAlive())
        {
            ++deadCivilianIt;
        }
        else
        {
            deadCivilianIt = m_civilians.erase(deadCivilianIt);
        }
    }
}
示例#9
0
void LeftRight::execute() {
    //if is alive and can fall
    if (isAlive() && shape->isCanFall()) {
        bool canMove = true;
        //set the value of the move depending of the direction
        int x = 1;
        if (getDirection() == Direction::LEFT) {
            x = -1;
        }
        //get the position of the squares if we move the shape
        vector<Square*> squares = shape->nextMove(x, 0);

        //for every square...
        for (int i = 0; i < shape->getNUMBER_OF_SQUARES() && canMove; i++) {
            //check the range
            if (squares[i]->getX() < 0
                    || squares[i]->getX() > board->getNumberColumns() - 1
                    || squares[i]->getY() < 0
                    || squares[i]->getY() > board->getNumberRows() - 1) {

                canMove = false;
            } else {
                //check if is filled by another square
                if (board->isFilled(shape, *(squares[i]))!= TypeSquare::NoSquare) {
                    canMove = false;
                }
            }
        }

        //if we can move, move it definitively
        if (canMove) {
            shape->move(x, 0);
            //update the board
            board->updateBoard();
        }
        
        std::for_each(squares.begin(), squares.end(), std::default_delete<Square>());

    }
    alive = false;
}
示例#10
0
文件: Particle.cpp 项目: KAlO2/Pea
void Particle::step(float dt)
{
	if(!isAlive())
		return;

	if(lifespan < dt)
		dt = lifespan;

	lifespan -= dt;

	if(inv_mass > 0)
	{
		// apply force like gravity
		vec3f acceleration(0.0f);
		vec3f dv = acceleration * dt;

		// update position and velocity
		position += (velocity + dv/2) * dt;  // (vt0 + vt1)/2 * dt;
		velocity += dv;
	}
}
示例#11
0
void Enemy03::update(){
	move();
	hitCircleUpdate();

	collision = active = isActive();

	if(active){
		shot();
	}

	needDelete = ! isAlive();

	if(life <= 0.0f){
		ScoreMng.addScore(1000);
		PlaySound(SoundMng.get(SE_EXPLOSION02));
		dropItem();
		ObjectMng.set(ENEMY_EXPLOSION, new EnemyExplosion(ImageMng.get(EE_01), position));
	}

	privActive = active;
}
示例#12
0
void
Group::onSessionInitiateFailure(const ProcessPtr &process, Session *session) {
	vector<Callback> actions;

	TRACE_POINT();
	// Standard resource management boilerplate stuff...
	PoolPtr pool = getPool();
	boost::unique_lock<boost::mutex> lock(pool->syncher);
	assert(process->isAlive());
	assert(isAlive() || getLifeStatus() == SHUTTING_DOWN);

	UPDATE_TRACE_POINT();
	P_DEBUG("Could not initiate a session with process " <<
		process->inspect() << ", detaching from pool if possible");
	if (!pool->detachProcessUnlocked(process, actions)) {
		P_DEBUG("Process was already detached");
	}
	pool->fullVerifyInvariants();
	lock.unlock();
	runAllActions(actions);
}
示例#13
0
void AI::think()
{
	while(isAlive())
	{
		if(g_game->isPaused())
		{
			boost::this_thread::sleep(boost::posix_time::milliseconds(100));
			continue;
		}

		if(!m_creature->isWalking())
		{
			while(!move(Direction(1 + rand() % 4)));
			//g_game.placeBomb(m_creature);
		}

		boost::this_thread::sleep(boost::posix_time::milliseconds(100));
	}

	delete this;
}
示例#14
0
// The 'self' parameter is for keeping the current Group object alive
void
Group::lockAndMaybeInitiateOobw(const ProcessPtr &process, DisableResult result, GroupPtr self) {
	TRACE_POINT();
	
	// Standard resource management boilerplate stuff...
	PoolPtr pool = getPool();
	boost::unique_lock<boost::mutex> lock(pool->syncher);
	if (OXT_UNLIKELY(!process->isAlive() || !isAlive())) {
		return;
	}

	assert(process->oobwStatus == Process::OOBW_IN_PROGRESS);

	if (result == DR_SUCCESS) {
		if (process->enabled == Process::DISABLED) {
			P_DEBUG("Process " << process->inspect() << " disabled; proceeding " <<
				"with out-of-band work");
			process->oobwStatus = Process::OOBW_REQUESTED;
			if (shouldInitiateOobw(process)) {
				initiateOobw(process);
			} else {
				// We do not re-enable the process because it's likely that the
				// administrator has explicitly changed the state.
				P_DEBUG("Out-of-band work for process " << process->inspect() << " aborted "
					"because the process no longer requests out-of-band work");
				process->oobwStatus = Process::OOBW_NOT_ACTIVE;
			}
		} else {
			// We do not re-enable the process because it's likely that the
			// administrator has explicitly changed the state.
			P_DEBUG("Out-of-band work for process " << process->inspect() << " aborted "
				"because the process was reenabled after disabling");
			process->oobwStatus = Process::OOBW_NOT_ACTIVE;
		}
	} else {
		P_DEBUG("Out-of-band work for process " << process->inspect() << " aborted "
			"because the process could not be disabled");
		process->oobwStatus = Process::OOBW_NOT_ACTIVE;
	}
}
示例#15
0
void BugSpray::doSomething()
{
	if (!(isAlive()))
		return;

	setTicks(getTicks() - 1);

	if (getTicks() == 0)
		setDead();
	else
	{
		//Destroy Destroyable Brick
		if (getWorld()->getLev()->getContentsOf(getX(), getY()) == Level::destroyable_brick)
		{
			getWorld()->deadActor(getX(), getY(), IID_DESTROYABLE_BRICK);
		}

		//Destroy Player
		if (getWorld()->getPlayer()->getX() == getX() &&
			getWorld()->getPlayer()->getY() == getY())
		{
			getWorld()->getPlayer()->setDead();
		}

		//Destroy Zumi's
		Actor* actor = getWorld()->WhatActorHere(getX(), getY());
		SimpleZumi* sz = dynamic_cast<SimpleZumi*>(actor);
		ComplexZumi* cz = dynamic_cast<ComplexZumi*>(actor);
		if (sz)
			getWorld()->deadActor(getX(), getY(), IID_SIMPLE_ZUMI);
		else if (cz)
			getWorld()->deadActor(getX(), getY(), IID_COMPLEX_ZUMI);

		//Destory other Sprayers
		if (getWorld()->getSprayerCount() >= 1)
		{
			getWorld()->checkSprayer(getX(), getY());
		}
	}
}
示例#16
0
void gameW::updateGeneration()
{
    for(int i = 0; i < mapSize; i++)
    {
        for(int j = 0; j < mapSize; j++)
        {
            nextGeneration[i * mapSize + j] = isAlive(i, j);
        }
    }
    qDebug() << "NOWE NOWE";


    for(int i = 0; i < mapSize; i++)
    {
        for(int j = 0; j < mapSize; j++)
        {
            currentGeneration[i * mapSize + j] = nextGeneration[i * mapSize + j];
        }
    }

    update();
}
示例#17
0
void c_win32Thread::start(const char *caller){
	if (NULL == threadHandle){
		if (NULL == (threadHandle = CreateThread(
			              0,              // default security attributes
						  stackSize_l,    // use default stack size
						  threadFunction, // thread function name
						  this,           // argument to thread function
						  0,              // use default creation flags
			              &threadId)))    // returns the thread identifier
		{
			FZRTE_ERROR("thread : start() Error could not create the thread!");
		}
		else {
			FZRTE_INFO("%s : Win32Thread : Created New Thread [0x%x]", caller, threadId);
		}
	}

	//wait till the thread is up and running
	do {
		Sleep(1);
	} while (!isAlive());
}
示例#18
0
/////////////////////////////////////////////////
/// Opposition: Unit treats another unit as an enemy it can attack (immediate response)
///
/// @note Relations API Tier 1
///
/// Backported from TBC+ client-side counterpart: <tt>CGUnit_C::CanAttackNow(const CGUnit_C *this, const CGUnit_C *unit)</tt>
/// Intended usage is to verify direct requests to attack something.
/// First appeared in TBC+ clients, backported for API unification between expansions.
/////////////////////////////////////////////////
bool Unit::CanAttackNow(const Unit* unit) const
{
    // Simple sanity check
    if (!unit)
        return false;

    // Original logic

    // We can't initiate attack while dead or ghost
    if (!isAlive())
        return false;

    // We can't initiate attack while mounted
    if (IsMounted())
        return false;

    // We can't initiate attack on dead units
    if (!unit->isAlive())
        return false;

    return CanAttack(unit);
}
void PlayerVitalityParticle::update(double dt) {
    if (isAlive()) {
        slowCounter += dt;
        if (slowCounter > slowInterval) {
            slowCounter -= slowInterval;
            vel = vel.mult(0.75);
        }

        vel = vel.translate(acc.mult(dt));
        pos = pos.translate(vel.mult(dt));
        if (rotation >= 0.0) {
            rotation += (360.0 / 1000.0) * dt;
        } else {
            rotation -= (360.0 / 1000.0) * dt;
        }

        lifetime += dt;
        if (lifetime > duration) {
            lifetime = duration;
        }
    }
}
示例#20
0
void Monster::onThink(Duration elapsedTime) {
	Creature::onThink(elapsedTime);

	if (!isAlive()) {
		return;
	}

	if (despawn()) {
		exitWorld();
		return;
	}

	updateRelationship();
	updateTarget();
	updateRetargeting(elapsedTime);
	updateFollowing();
	updateBabbling(elapsedTime);

	// TODO refactor >>
	onThinkDefense(std::chrono::duration_cast<Milliseconds>(elapsedTime).count());
	// <<
}
示例#21
0
void LSSNetworkHandler::inMessage(std::string pMessage, int pSocket){
	std::string command = Tokenizer::getCommandSpace(pMessage, 1);
	std::string param = Tokenizer::getParameters(pMessage);

	if (command == "connect"){
		connect(pSocket, param);

	} else if (command == "startClient"){
		outMessage( std::to_string(LssOperations::newSession()) , pSocket);

	} else if (command == "format"){
		format(pSocket, param);

	} else if (command == "isAlive"){
		isAlive(pSocket, param);

	}else if (command == "readBlock"){
		readBlock(pSocket, param);

	} else if (command == "writeBlock"){
		writeBlock(pSocket, param);

	} else if (command == "getSize"){
		getSize(pSocket, param);
	
	} else if (command == "disconnect"){
		disconnectClient();

	}else if (command == "writeBytes"){
		writeBytes(pSocket, param);

	} else if (command == "readBytes"){
		readBytes(pSocket, param);

	} else {
		defaultCase(pSocket, command);

	}
}
示例#22
0
文件: System.cpp 项目: Jose-Luis/mpe
//------------------------------------------------------------------------------
//       Class:  System
//      Method:  update
// Description:
//------------------------------------------------------------------------------
void System::updateParticles(Real theElapsedTime)
{
   for (auto affector =  mAffectors.begin();
         affector != mAffectors.end();
         affector++)
   {
      if ( (*affector)->isAlive() )
      {
         (*affector)->update(theElapsedTime);

         for (auto particle =  mParticles.begin();
               particle != mParticles.end();
               particle++)
         {
            (*affector)->affect(*particle, theElapsedTime);
         }
      }
      else
      {
         affector = mAffectors.erase(affector);
         affector++;
      }
   }

   for (auto particle =  mParticles.begin();
         particle < mParticles.end();
         particle++)
   {
      if(particle->isAlive())
      {
         particle->update(theElapsedTime);
      }
      else
      {
          mParticles.removeParticle(particle);
      }
   }

}
示例#23
0
void cleanAst() {
  cleanModuleList();
  //
  // clear back pointers to dead ast instances
  //
  forv_Vec(TypeSymbol, ts, gTypeSymbols) {
    for(int i = 0; i < ts->type->methods.n; i++) {
      FnSymbol* method = ts->type->methods.v[i];
      if (method && !isAliveQuick(method))
        ts->type->methods.v[i] = NULL;
      if (AggregateType* ct = toAggregateType(ts->type)) {
        if (ct->defaultInitializer && !isAliveQuick(ct->defaultInitializer))
          ct->defaultInitializer = NULL;
        if (ct->destructor && !isAliveQuick(ct->destructor))
          ct->destructor = NULL;
      }
    }
    for(int i = 0; i < ts->type->dispatchChildren.n; i++) {
      Type* type = ts->type->dispatchChildren.v[i];
      if (type && !isAlive(type))
        ts->type->dispatchChildren.v[i] = NULL;
    }
  }

  // check iterator-resume-label/goto data before nodes are free'd
  verifyNcleanRemovedIterResumeGotos();
  verifyNcleanCopiedIterResumeGotos();

  // clean the other module vectors, without deleting the ast instances (they
  // will be deleted with the clean_gvec call for ModuleSymbols.) 
  clean_modvec(allModules);
  clean_modvec(userModules);
  clean_modvec(mainModules);
 
  //
  // clean global vectors and delete dead ast instances
  //
  foreach_ast(clean_gvec);
}
示例#24
0
ErrorCode ProcessBase::afterResume() {
  if (!isAlive()) {
    return kSuccess;
  }

  // Disable breakpoints and try to hit the breakpoint.
  for (auto bpm : std::list<BreakpointManager *>{softwareBreakpointManager(),
                                                 hardwareBreakpointManager()}) {
    if (bpm == nullptr) {
      continue;
    }

    bpm->disable();
    for (auto it : _threads) {
      if (bpm->hit(it.second)) {
        DS2LOG(Debug, "hit breakpoint for tid %" PRI_PID, it.second->tid());
      }
    }
  }

  return kSuccess;
}
示例#25
0
void GameWidget::newGeneration()
{
    if(generations < 0)
        generations++;
    int notChanged=0;
    for(int k=1; k <= universeSize; k++) {
        for(int j=1; j <= universeSize; j++) {
            next[k*universeSize + j] = isAlive(k, j);
            if(next[k*universeSize + j] == universe[k*universeSize + j])
                notChanged++;
        }
    }
    if(notChanged == universeSize*universeSize) {
        QMessageBox::information(this,
                                 tr("Game lost sense"),
                                 tr("The End. Now game finished because all the next generations will be the same."),
                                 QMessageBox::Ok);
        stopGame();
        gameEnds(true);
        return;
    }
    for(int k=1; k <= universeSize; k++) {
        for(int j=1; j <= universeSize; j++) {
            universe[k*universeSize + j] = next[k*universeSize + j];
        }
    }
    update();
    generations--;
    if(generations == 0) {
        stopGame();
        gameEnds(true);
        QMessageBox::information(this,
                                 tr("Game finished."),
                                 tr("Iterations finished."),
                                 QMessageBox::Ok,
                                 QMessageBox::Cancel);
    }
}
示例#26
0
void
Group::restart(const Options &options, RestartMethod method) {
	vector<Callback> actions;

	assert(isAlive());
	P_DEBUG("Restarting group " << name);

	// If there is currently a restarter thread or a spawner thread active,
	// the following tells them to abort their current work as soon as possible.
	restartsInitiated++;

	processesBeingSpawned = 0;
	m_spawning   = false;
	m_restarting = true;
	detachAll(actions);
	getPool()->interruptableThreads.create_thread(
		boost::bind(&Group::finalizeRestart, this, shared_from_this(),
			options.copyAndPersist().clearPerRequestFields(),
			method, getPool()->spawnerFactory, restartsInitiated, actions),
		"Group restarter: " + name,
		POOL_HELPER_THREAD_STACK_SIZE
	);
}
示例#27
0
void Totem::UnSummon()
{
    SendObjectDeSpawnAnim(GetGUID());

    CombatStop();
    RemoveAurasDueToSpell(GetSpell());

    if (Unit *owner = GetOwner())
    {
        owner->_RemoveTotem(this);
        owner->RemoveAurasDueToSpell(GetSpell());

        //remove aura all party members too
        if (owner->GetTypeId() == TYPEID_PLAYER)
        {
            // Not only the player can summon the totem (scripted AI)
            if (Group *pGroup = ((Player*)owner)->GetGroup())
            {
                for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
                {
                    Player* Target = itr->getSource();
                    if(Target && pGroup->SameSubGroup((Player*)owner, Target))
                        Target->RemoveAurasDueToSpell(GetSpell());
                }
            }
        }

        if (owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->AI())
            ((Creature*)owner)->AI()->SummonedCreatureDespawn((Creature*)this);
    }

    // any totem unsummon look like as totem kill, req. for proper animation
    if (isAlive())
        SetDeathState(DEAD);

    AddObjectToRemoveList();
}
示例#28
0
void TempSummon::UnSummon(uint32 msTime)
{
    if (msTime)
    {
        ForcedUnsummonDelayEvent* pEvent = new ForcedUnsummonDelayEvent(*this);

        m_Events.AddEvent(pEvent, m_Events.CalculateTime(msTime));
        return;
    }

    // Custom operations
    switch(GetEntry())
    {
        // Force of Nature
        case 36070:
            // If not it's directly handled in JustDied
            if(IsAIEnabled && isAlive())
            {
                 AI()->JustDied(this);
            }
            break;
    }

    //ASSERT(!isPet());
    if (isPet())
    {
        ((Pet*)this)->Remove(PET_SAVE_NOT_IN_SLOT);
        ASSERT(!IsInWorld());
        return;
    }

    Unit* owner = GetSummoner();
    if (owner && owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsAIEnabled)
        owner->ToCreature()->AI()->SummonedCreatureDespawn(this);

    AddObjectToRemoveList();
}
示例#29
0
void ShockParticle::update(double dt) {
    if (isAlive()) {
        turnCounter += dt;
        if (turnCounter > turnInterval) {
            turnCounter -= turnInterval;

            Engine::RandomNumberGenerator *rng =
                Engine::Core::getInstance()->getRandomNumberGenerator();

            int direction = rng->randomInt(0, 1);
            if (direction == 0) {
                vel =
                    Vector(std::cos(M_PI / 4.0) * vel.x -
                           std::sin(M_PI / 4.0) * vel.y,
                           std::sin(M_PI / 4.0) * vel.x +
                           std::cos(M_PI / 4.0) * vel.y,
                           vel.z);
            } else if (direction == 1) {
                vel =
                    Vector(std::cos(-M_PI / 4.0) * vel.x -
                           std::sin(-M_PI / 4.0) * vel.y,
                           std::sin(-M_PI / 4.0) * vel.x +
                           std::cos(-M_PI / 4.0) * vel.y,
                           vel.z);
            }
            vel = vel.mult(0.5);
        }

        vel = vel.translate(acc.mult(dt));
        pos = pos.translate(vel.mult(dt));
    
        lifetime += dt;
        if (lifetime > duration) {
            lifetime = duration;
        }
    }
}
void CC3UniformlyEvolvingPointParticle::updateBeforeTransform( CC3NodeUpdatingVisitor* visitor )
{
	super::updateBeforeTransform( visitor );

	if( !isAlive() ) 
		return;
	
	GLfloat dt = visitor->getDeltaTime();
	
	if ( hasSize() )
		setSize( getSize() + (m_sizeVelocity * dt) );
	
	if ( hasColor() )
	{
		// We have to do the math on each component instead of using the color math functions
		// because the functions clamp prematurely, and we need negative values for the velocity.
		ccColor4F currColor = getColor4F();
		setColor4F( ccc4f(CLAMP(currColor.r + (m_colorVelocity.r * dt), 0.0f, 1.0f),
					CLAMP(currColor.g + (m_colorVelocity.g * dt), 0.0f, 1.0f),
					CLAMP(currColor.b + (m_colorVelocity.b * dt), 0.0f, 1.0f),
					CLAMP(currColor.a + (m_colorVelocity.a * dt), 0.0f, 1.0f)) 
		);
	}
}