void StarSystem::Update( float priority ) { Unit *unit; bool firstframe = true; //No time compression here float normal_simulation_atom = SIMULATION_ATOM; time += GetElapsedTime(); _Universe->pushActiveStarSystem( this ); if ( time/SIMULATION_ATOM >= (1./PHY_NUM) ) { while ( time/SIMULATION_ATOM >= (1.) ) { //Chew up all SIMULATION_ATOMs that have elapsed since last update ExecuteDirector(); TerrainCollide(); Unit::ProcessDeleteQueue(); current_stage = MISSION_SIMULATION; collidetable->Update(); for (un_iter iter = drawList.createIterator(); (unit = *iter); ++iter) unit->SetNebula( NULL ); UpdateMissiles(); //do explosions UpdateUnitPhysics( firstframe ); firstframe = false; } time -= SIMULATION_ATOM; } SIMULATION_ATOM = normal_simulation_atom; _Universe->popActiveStarSystem(); }
void Bullet::update() { this->PhysicsObject::updatePhysics(); if (timer.getRunTime() > startTime + Lifespan) { mIsDead = true; } static Vector2f Normal; static Vector2f CollisionPoint; static Vector2f MTD; if (mFriendly && game.mEnemyManager.checkBulletCollision(this)) { game.mEffectManager.addEffect( new StaticAnimationEffect(position, .4, BulletCollisionAnimation32, velocity.angle(), 1)); kill(); return; } if (!mFriendly && player.checkBulletCollision(this, Normal, CollisionPoint, MTD)) { //player collision game.mEffectManager.addEffect( new StaticAnimationEffect(position, .4, BulletCollisionAnimation32, velocity.angle(), 1)); player.health -= 25; kill(); return; } if (TerrainCollide(position, mRadius)) { Vector2f normal; world.getNormal(position.x, normal); game.mEffectManager.addEffect( new StaticAnimationEffect( Vector2f(position.x, world.getHeight(position.x)) + normal, .8, GroundCollisionAnimation32, normal.angle() + PI / 2, 1)); kill(); return; } }
//client void StarSystem::Update( float priority, bool executeDirector ) { bool firstframe = true; double pythontime = 0; ///this makes it so systems without players may be simulated less accurately for (unsigned int k = 0; k < _Universe->numPlayers(); ++k) if (_Universe->AccessCockpit( k )->activeStarSystem == this) priority = 1; float normal_simulation_atom = SIMULATION_ATOM; SIMULATION_ATOM /= ( priority/getTimeCompression() ); ///just be sure to restore this at the end time += GetElapsedTime(); _Universe->pushActiveStarSystem( this ); //WARNING PERFORMANCE HACK!!!!! if (time > 2*SIMULATION_ATOM) time = 2*SIMULATION_ATOM; double bolttime = 0; if ( time/SIMULATION_ATOM >= (1./PHY_NUM) ) { //Chew up all SIMULATION_ATOMs that have elapsed since last update while ( time/SIMULATION_ATOM >= (1./PHY_NUM) ) { if (current_stage == MISSION_SIMULATION) { TerrainCollide(); UpdateAnimatedTexture(); Unit::ProcessDeleteQueue(); double pythonidea = queryTime(); if ( (run_only_player_starsystem && _Universe->getActiveStarSystem( 0 ) == this) || !run_only_player_starsystem ) if (executeDirector) ExecuteDirector(); pythontime = queryTime()-pythonidea; static int dothis = 0; if ( this == _Universe->getActiveStarSystem( 0 ) ) if ( (++dothis)%2 == 0 ) AUDRefreshSounds(); for (unsigned int i = 0; i < active_missions.size(); ++i) //waste of farkin time active_missions[i]->BriefingUpdate(); current_stage = PROCESS_UNIT; } else if (current_stage == PROCESS_UNIT) { UpdateUnitPhysics( firstframe ); UpdateMissiles(); //do explosions collidetable->Update(); if ( this == _Universe->getActiveStarSystem( 0 ) ) UpdateCameraSnds(); bolttime = queryTime(); bolttime = queryTime()-bolttime; current_stage = MISSION_SIMULATION; firstframe = false; } time -= (1./PHY_NUM)*SIMULATION_ATOM; } unsigned int i = _Universe->CurrentCockpit(); for (unsigned int j = 0; j < _Universe->numPlayers(); ++j) if (_Universe->AccessCockpit( j )->activeStarSystem == this) { _Universe->SetActiveCockpit( j ); _Universe->AccessCockpit( j )->updateAttackers(); if ( _Universe->AccessCockpit( j )->Update() ) { SIMULATION_ATOM = normal_simulation_atom; _Universe->SetActiveCockpit( i ); _Universe->popActiveStarSystem(); return; } } _Universe->SetActiveCockpit( i ); } if ( sigIter.isDone() ) sigIter = drawList.createIterator(); else ++sigIter; while ( !sigIter.isDone() && !UnitUtil::isSignificant( *sigIter) ) ++sigIter; //If it is done, leave it NULL for this frame then. //WARNING cockpit does not get here... SIMULATION_ATOM = normal_simulation_atom; //WARNING cockpit does not get here... _Universe->popActiveStarSystem(); }