Example #1
0
void
runtime·starttheworld(bool extra)
{
	M *m;

	schedlock();
	runtime·gcwaiting = 0;
	setmcpumax(runtime·gomaxprocs);
	matchmg();
	if(extra && canaddmcpu()) {
		// Start a new m that will (we hope) be idle
		// and so available to help when the next
		// garbage collection happens.
		// canaddmcpu above did mcpu++
		// (necessary, because m will be doing various
		// initialization work so is definitely running),
		// but m is not running a specific goroutine,
		// so set the helpgc flag as a signal to m's
		// first schedule(nil) to mcpu-- and grunning--.
		m = runtime·newm();
		m->helpgc = 1;
		runtime·sched.grunning++;
	}
	schedunlock();
}
Example #2
0
Matrix State::getAcceleration()
{
    Matrix newm(3, 1, 0.0);
    newm[0][0] = m[6][0];
    newm[1][0] = m[7][0];
    newm[2][0] = m[8][0];
	return newm;
}
Example #3
0
Matrix State::geSpeed()
{
    Matrix newm(3, 1, 0.0);
    newm[0][0] = m[3][0];
    newm[1][0] = m[4][0];
    newm[2][0] = m[5][0];
	return newm;
}
Example #4
0
Matrix State::getPostion()
{
    Matrix newm(3, 1, 0.0);
    newm[0][0] = m[0][0];
    newm[1][0] = m[1][0];
    newm[2][0] = m[2][0];
	return newm;
}
Example #5
0
Matrix argpermute(const Matrix& m, const int* indices)
{
  Matrix newm(m.Nrows(),m.Ncols());
  newm=0.;
  for (int i=0;i<m.Nrows();++i)
    for (int j=0;j<m.Ncols();++j)
      newm.element(i,j)=m.element(indices[i],indices[j]);
  return newm;
}
Example #6
0
// Kick off new m's as needed (up to mcpumax).
// Sched is locked.
static void
matchmg(void)
{
	G *gp;
	M *mp;

	if(m->mallocing || m->gcing)
		return;

	while(haveg() && canaddmcpu()) {
		gp = gget();
		if(gp == nil)
			runtime·throw("gget inconsistency");

		// Find the m that will run gp.
		if((mp = mget(gp)) == nil)
			mp = runtime·newm();
		mnextg(mp, gp);
	}
}
Example #7
0
void
runtime·starttheworld(void)
{
    M *mp;
    int32 max;

    // Figure out how many CPUs GC could possibly use.
    max = runtime·gomaxprocs;
    if(max > runtime·ncpu)
        max = runtime·ncpu;
    if(max > MaxGcproc)
        max = MaxGcproc;

    schedlock();
    runtime·gcwaiting = 0;
    setmcpumax(runtime·gomaxprocs);
    matchmg();
    if(runtime·gcprocs() < max && canaddmcpu()) {
        // If GC could have used another helper proc, start one now,
        // in the hope that it will be available next time.
        // It would have been even better to start it before the collection,
        // but doing so requires allocating memory, so it's tricky to
        // coordinate.  This lazy approach works out in practice:
        // we don't mind if the first couple gc rounds don't have quite
        // the maximum number of procs.
        // canaddmcpu above did mcpu++
        // (necessary, because m will be doing various
        // initialization work so is definitely running),
        // but m is not running a specific goroutine,
        // so set the helpgc flag as a signal to m's
        // first schedule(nil) to mcpu-- and grunning--.
        mp = runtime·newm();
        mp->helpgc = 1;
        runtime·sched.grunning++;
    }
    schedunlock();
}
Example #8
0
//
// ProjectileObjType::MissilePhysics
//
// Simulate a missile, which includes acceleration, turning etc
//
void ProjectileObjType::MissilePhysics(ProjectileObj &obj, Matrix &m, Vector &s)
{
  // Has the odometer clocked ?
  if ((obj.distTravelled * obj.distTravelled) > obj.weaponType->GetMaxRange2())
  {
    GameObjCtrl::MarkForDeletion(&obj);
  }

  F32 speed = obj.GetSpeed();
  F32 fMag = 20.0f;

  // Homing in on target
  if (missile.homingRate > 1e-3F)
  {
    const Target &t = obj.GetTarget();

    if (t.Alive() /* && (t.GetType() == Target::OBJECT)*/)
    {
      Vector f = t.GetLocation() - m.posit;
      fMag = f.Magnitude();

      if (fMag > 0.1F)
      {
        // Close enough to do some rotation
        f *= (1.0F / fMag);
        F32 fdot = f.Dot(m.front);

        if (fdot > missile.cosHomingRate)
        {
          // Within the max turning rate, turn directly there
          m.SetFromFront(f);
        }
        else
        {
          // Axis to rotate around
          Vector u = (f * -1.0F).Cross(m.front);
          u.Normalize();
          Vector r = u.Cross(f);

          // Turn left or right?
          F32 rdot = r.Dot(m.front);

          // Rotate at maximum allowable rate
          F32 angle = Utils::FSign(rdot) * missile.homingRate * GameTime::INTERVAL;
          
          if (fdot < 0.0F)
          {
            if (obj.wasBehind)
            {
              // Keep turning in the last direction
              angle = Utils::FSign(obj.lastAngle) * missile.homingRate * GameTime::INTERVAL;
            }
            else
            {
              // Setup the prev angle, and keep it that way
              obj.lastAngle = angle;
              obj.wasBehind = TRUE;
            }
          }
          else
          {
            // Target not behind us any more
            obj.wasBehind = FALSE;
          }

          // Do the rotation
          Matrix newm(Quaternion(angle, u));
          newm.Rotate(m.front, m.front);
          m.SetFromFront(m.front);
        }
      }
    }
  }

  // Waver the trajectory
  if (missile.waverTurn != 0.0F)
  {
    F32 waverTurn = missile.waverTurn;

    F32 fMag2 = fMag * fMag;

    // If we're in the last 20m then reduce the waver turn
    if (fMag < 20.0f)
    {
      waverTurn *= fMag2 * 0.0025f;
    }

    // apply the waver pitch
    F32 pitchAng = waverTurn * GameTime::INTERVAL * 
      (F32)sin(obj.waverPitch * missile.waverRate * GameTime::INTERVAL);
    Matrix pitchMat(Quaternion(pitchAng, m.right));
    pitchMat.Rotate(m.front, m.front);
    obj.waverPitch += Random::sync.Float() + Random::sync.Float();

    // apply the waver yaw
    F32 yawAng = waverTurn * GameTime::INTERVAL * 
      (F32)sin(obj.waverYaw * missile.waverRate * GameTime::INTERVAL);
    Matrix yawMat(Quaternion(yawAng, m.up));
    yawMat.Rotate(m.front, m.front);
    obj.waverYaw += Random::sync.Float() + Random::sync.Float();

    // update the transform matrix
    m.SetFromFront(m.front);
  }

  // Acceleration
  speed = Min<F32>(missile.topSpeed, speed + missile.acceleration * GameTime::INTERVAL);

  // Velocity
  Vector veloc = m.front * speed;
  
  // Displacement
  s = veloc * GameTime::INTERVAL;

  // Update speed and velocity
  obj.SetSpeed(speed);
  obj.SetVelocity(veloc);
}