void tr_bandwidthAllocate (tr_bandwidth * b, tr_direction dir, unsigned int period_msec) { int i, peerCount; tr_ptrArray tmp = TR_PTR_ARRAY_INIT; tr_ptrArray low = TR_PTR_ARRAY_INIT; tr_ptrArray high = TR_PTR_ARRAY_INIT; tr_ptrArray normal = TR_PTR_ARRAY_INIT; struct tr_peerIo ** peers; /* allocateBandwidth () is a helper function with two purposes: * 1. allocate bandwidth to b and its subtree * 2. accumulate an array of all the peerIos from b and its subtree. */ allocateBandwidth (b, TR_PRI_LOW, dir, period_msec, &tmp); peers = (struct tr_peerIo**) tr_ptrArrayBase (&tmp); peerCount = tr_ptrArraySize (&tmp); for (i=0; i<peerCount; ++i) { tr_peerIo * io = peers[i]; tr_peerIoRef (io); tr_peerIoFlushOutgoingProtocolMsgs (io); switch (io->priority) { case TR_PRI_HIGH: tr_ptrArrayAppend (&high, io); /* fall through */ case TR_PRI_NORMAL: tr_ptrArrayAppend (&normal, io); /* fall through */ default: tr_ptrArrayAppend (&low, io); } } /* First phase of IO. Tries to distribute bandwidth fairly to keep faster * peers from starving the others. Loop through the peers, giving each a * small chunk of bandwidth. Keep looping until we run out of bandwidth * and/or peers that can use it */ phaseOne (&high, dir); phaseOne (&normal, dir); phaseOne (&low, dir); /* Second phase of IO. To help us scale in high bandwidth situations, * enable on-demand IO for peers with bandwidth left to burn. * This on-demand IO is enabled until (1) the peer runs out of bandwidth, * or (2) the next tr_bandwidthAllocate () call, when we start over again. */ for (i=0; i<peerCount; ++i) tr_peerIoSetEnabled (peers[i], dir, tr_peerIoHasBandwidthLeft (peers[i], dir)); for (i=0; i<peerCount; ++i) tr_peerIoUnref (peers[i]); /* cleanup */ tr_ptrArrayDestruct (&normal, NULL); tr_ptrArrayDestruct (&high, NULL); tr_ptrArrayDestruct (&low, NULL); tr_ptrArrayDestruct (&tmp, NULL); }
/* * decide phase execution */ void BallTaking::update(BallTakingOutput& output) { output.isLeavingPossible = false; ballData(output); output.isTakable = takable.isFilled() && takable.getAverage() == 1; if(theMotionSelection.ratios[MotionRequest::takeBall] > 0) { //finished if(phaseLeavingPossible && phase == 5) { output.isLeavingPossible = true; //todo odometry offset side = 0; phase = 0; phaseStart = 0; phaseLeavingPossible = false; return; } else if(phaseLeavingPossible) { phase++; phaseStart = theFrameInfo.time; phaseLeavingPossible = false; } if(phase == 0) phaseZero(output); else if(phase == 1) phaseOne(output); else if(phase == 2) phaseTwo(output); else if(phase == 3) phaseThree(output); else if(phase == 4) phaseFour(output); else if(phase == 5) phaseFive(output); int hardness = 90; output.jointHardness.hardness[JointData::LHipRoll] = hardness; output.jointHardness.hardness[JointData::LHipPitch] = hardness; output.jointHardness.hardness[JointData::LKneePitch] = hardness; output.jointHardness.hardness[JointData::LAnklePitch] = hardness; output.jointHardness.hardness[JointData::LAnkleRoll] = hardness; output.jointHardness.hardness[JointData::RHipRoll] = hardness; output.jointHardness.hardness[JointData::RHipPitch] = hardness; output.jointHardness.hardness[JointData::RKneePitch] = hardness; output.jointHardness.hardness[JointData::RAnklePitch] = hardness; output.jointHardness.hardness[JointData::RAnkleRoll] = hardness; output.angles[JointData::LShoulderPitch] = JointData::ignore; output.angles[JointData::LShoulderRoll] = JointData::ignore; output.angles[JointData::RShoulderPitch] = JointData::ignore; output.angles[JointData::RShoulderRoll] = JointData::ignore; output.angles[JointData::LElbowRoll] = JointData::ignore; output.angles[JointData::LElbowYaw] = JointData::ignore; output.angles[JointData::RElbowRoll] = JointData::ignore; output.angles[JointData::RElbowYaw] = JointData::ignore; output.angles[JointData::HeadPitch] = JointData::ignore; output.angles[JointData::HeadYaw] = JointData::ignore; } }
void BigMoney::update(float deltaTime, Player* player) { m_collisionBox = { Vector2f(m_position.x - 175 + 100, m_position.y - 175), 250, 250 }; switch (m_phaseNumber) { case 1: { phaseOne(); } break; case 2: { phaseTwo(deltaTime, player); } break; case 3: { phaseThree(deltaTime); } break; } for (int i = 0; i < MAX_PROJECTILE_AMOUNT; i++) { if (m_Projectiles[i].isActive()) m_Projectiles[i].update(deltaTime); } //Check for collision with the projectiles for bosses and the player for (int i = 0; i < MAX_PROJECTILE_AMOUNT; i++) if (m_Projectiles[i].isActive()) if (Collision(m_Projectiles[i].getCollisionBox(), player->getCollisionBox()) && m_collisionTimer.getTicks() > 2000) { m_collisionTimer.start(); if (player->getPlayerHealth() > 0) player->hit(); } //Special collision case for implosion attack for (int i = 500; i < 700; i++) { if (m_Projectiles[i].isActive() && m_phaseNumber != 2) { if (Collision(m_Projectiles[i].getCollisionBox(), m_collisionBox)) { GLfloat scale = m_Projectiles[i].getXScale() - 3 * deltaTime; m_Projectiles[i].setScale(scale, scale); if (scale <= 0.05f) { m_Projectiles[i].setScale(1.f, 1.f); m_Projectiles[i].setActive(false); } } } } //Player hits boss for (int i = 0; i < player->getWeapon()->getBulletAmount(); i++) { if (player->getWeapon()->getProjectiles()[i].isActive()) { if (Collision(m_collisionBox, player->getWeapon()->getProjectiles()[i].getCollisionBox())) { if (m_bossCollisionTimer.getTicks() > 1500) { m_bossCollisionTimer.start(); switch (m_phaseNumber) { case 1: { m_health -= 3.75; } break; case 2: { m_health -= 3; } break; case 3: { m_health -= 5; } break; } } player->getWeapon()->getProjectiles()[i].reload(Vector2f(0, 0), Vector2f(0, 0), 0, 0); } } } m_healthBarParticleEmitter->setLifeDuration(3.f / (100 / m_health)); m_healthBarParticleEmitter->setLifeVariance(1.f / (100 / m_health)); m_healthBarParticleEmitter->update(deltaTime, Vector2f(randFloat(2.f, 4.f), randFloat(0.05f / (m_health / 100), -0.05f / (m_health / 100)))); if (m_phaseNumber == 3 && m_health == 0) { Warp::getInstance().setPosition(m_position); Warp::getInstance().update(deltaTime); } }