Ejemplo n.º 1
0
	// Removes chromosome from the group
	bool GaChromosomeGroup::Remove(GaChromosomeStorage* chromosome,
		bool dontRecycle/* = false*/)
	{
		// check membership flag to see if this chromosome is a member of the group
		if( _membershipFlag && !chromosome->GetFlags().IsFlagSetAll( _membershipFlag ) )
			return false;

		_hasShuffleBackup = false;

		int j = 0;
		// find and remove chromosomes
		for( int i = 0; i < _count - 1; i++ )
		{
			if( _chromosomes[ i ] != chromosome )
				// current chromosome is not the one that should be removed
				_chromosomes[ j++ ] = _chromosomes[ i ];
			else
				RemoveHelper( chromosome, dontRecycle );
		}

		if( _count == j )
			// chromosome is not found
			return false;

		_count = j;
		return true;
	}
Ejemplo n.º 2
0
	// Removes chromosomes at the bottom of the population
	void GaChromosomeGroup::Trim(int newCount,
		bool dontRecycle/* = false*/)
	{
		GA_ARG_ASSERT( Common::Exceptions::GaArgumentOutOfRangeException, newCount >= 0, "newCount", "Count cannot be negative value.", "Population" );

		_hasShuffleBackup = false;

		while( _count > newCount )
			RemoveHelper( _chromosomes[ --_count ], dontRecycle );
	}
Ejemplo n.º 3
0
	// Removes chromosome from the group
	void GaChromosomeGroup::Remove(int index,
		bool dontRecycle/* = false*/)
	{
		_hasShuffleBackup = false;

		_count--;

		RemoveHelper( _chromosomes[ index ], dontRecycle );

		// move other chromosomes to fill the gap
		for( int i = index; i < _count; i++ )
			_chromosomes[ i ] = _chromosomes[ i + 1 ];
	}
Ejemplo n.º 4
0
	void GACALL GaChromosomeGroup::Remove(bool dontRecycle/* = false*/)
	{
		int newCount = 0;
		for( int i = 0; i < _count; i++ )
		{
			// keep chromosome?
			if( !_chromosomes[ i ]->GetFlags().IsFlagSetAny( GaChromosomeStorage::GACF_REMOVE_CHROMOSOME ) )
				_chromosomes[ newCount++ ] = _chromosomes[ i ];
			else
				RemoveHelper( _chromosomes[ i ], dontRecycle );
		}

		_count = newCount;
	}
Ejemplo n.º 5
0
void CScriptCameraHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {
  switch (msg) {
  case EScriptObjectMessage::Deleted:
  case EScriptObjectMessage::Deactivate:
    mgr.GetCameraManager()->DeleteCameraHint(GetUniqueId(), mgr);
    break;
  case EScriptObjectMessage::InitializedInArea:
    InitializeInArea(mgr);
    break;
  default:
    break;
  }

  if (GetActive()) {
    switch (msg) {
    case EScriptObjectMessage::Increment:
      AddHelper(sender);
      mgr.GetCameraManager()->AddActiveCameraHint(GetUniqueId(), mgr);
      x166_inactive = false;
      break;
    case EScriptObjectMessage::Decrement:
      RemoveHelper(sender);
      mgr.GetCameraManager()->AddInactiveCameraHint(GetUniqueId(), mgr);
      break;
    default:
      break;
    }
  }

  if (msg == EScriptObjectMessage::Follow) {
    if (!GetActive()) {
      if (TCastToConstPtr<CActor> act = mgr.GetObjectById(sender)) {
        zeus::CVector3f followerToThisFlat = x168_origXf.origin - act->GetTranslation();
        followerToThisFlat.z() = 0.f;
        if (followerToThisFlat.canBeNormalized())
          followerToThisFlat.normalize();
        else
          followerToThisFlat = act->GetTransform().basis[1];
        zeus::CVector3f target = act->GetTranslation() + followerToThisFlat;
        target.z() = x168_origXf.origin.z() + followerToThisFlat.z();
        SetTransform(zeus::lookAt(act->GetTranslation(), target));
      }
    }
    AddHelper(sender);
    mgr.GetCameraManager()->AddActiveCameraHint(GetUniqueId(), mgr);
  }

  CActor::AcceptScriptMsg(msg, sender, mgr);
}