当前位置: 首页>>代码示例>>C++>>正文


C++ Common类代码示例

本文整理汇总了C++中Common的典型用法代码示例。如果您正苦于以下问题:C++ Common类的具体用法?C++ Common怎么用?C++ Common使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Common类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AIAction

AIDribbleAction::AIDribbleAction(const Player* p)
	: AIAction(mActionName, p)
{
	float bestscore = -1.0f;
	Vector3 bestvec;
	std::vector<Vector3> tgtvectors;

	if(MatchHelpers::distanceToOwnGoal(*p) < 5.0f)
		return;

	/* TODO: this constant should depend on pitch */
	float dribblelen = 10.0f;
	const unsigned int numDirections = 16;
	for(unsigned int i = 0; i < numDirections; i++) {
		Vector3 vec;
		vec.x = dribblelen * sin(i * 2 * PI / float(numDirections));
		vec.y = dribblelen * cos(i * 2 * PI / float(numDirections));
		tgtvectors.push_back(vec);
	}

	for(auto vec : tgtvectors) {
		auto tgtpos = Vector3(p->getPosition() + vec.normalized() * 16.0f);
		if(!MatchHelpers::onPitch(*p->getMatch(), tgtpos))
			continue;

		/* rather dribble towards opponent goal than away from it */
		float goalDistCoeff = AIHelpers::scaledCoefficient(MatchHelpers::distanceToOppositeGoal(*p, tgtpos), 100.0f);
		/* rather don't dribble near own goal */
		float ownGoalDistCoeff = AIHelpers::scaledCoefficient(MatchHelpers::distanceToOwnGoal(*p, tgtpos), 20.0f);
		float thisscore = (1.0f - ownGoalDistCoeff) * 0.5f + goalDistCoeff * 0.5f;
		for(auto op : MatchHelpers::getOpposingPlayers(*p)) {
			float dist = Common::Math::pointToLineDistance(p->getPosition(),
					tgtpos,
					op->getPosition());
			static const float maxdist = dribblelen;
			if(dist < maxdist) {
				auto po = MatchEntity::vectorFromTo(*p, *op);
				po.normalize();
				auto dot = std::max(0.1, po.dot(vec.normalized()));
				thisscore -= AIHelpers::scaledCoefficient(dist, maxdist) * dot;
				if(thisscore <= 0.0) {
					break;
				}
			}
		}

		thisscore = AIHelpers::checkKickSuccess(*mPlayer, vec, thisscore);

		if(thisscore > bestscore) {
			bestscore = thisscore;
			bestvec = Vector3(vec.normalized() * (0.35f +
					0.15f * (1.0f - mPlayer->getSkills().ShotPower)));
		}
	}
	mScore = bestscore;

	float dribblecoeff = mPlayer->getTeam()->getAITacticParameters().DribbleActionCoefficient;
	mScore *= dribblecoeff;
	mAction = boost::shared_ptr<PlayerAction>(new KickBallPA(bestvec));
}
开发者ID:luchete80,项目名称:FAIEngine,代码行数:60,代码来源:AIActions.cpp

示例2: getRotation

void Vehicle::setRotationToGround()
{
	const auto& orig = getRotation();
	const auto& pos = getPosition();
	Vector3 forward = pos + Common::Math::rotate3D(Vector3(0.0f, 0, 1.0f), orig) * 1.0f;
	Vector3 right = pos + Common::Math::rotate3D(Vector3(-1.0f, 0, 0.0f), orig) * 1.0f;
	float h1 = getHeightAt(pos.x, pos.z);
	float h2 = getHeightAt(forward.x, forward.z);
	float h3 = getHeightAt(right.x, right.z);
	Vector3 p1(pos.x, h1, pos.z);
	Vector3 p2(forward.x, h2, forward.z);
	Vector3 p3(right.x, h3, right.z);
	Vector3 norm = (p2 - p1).normalized().cross((p3 - p1).normalized());

	if(norm.y < 0.0f)
		norm = norm * -1.0f;

	Vector3 dir = Common::Math::rotate3D(Vector3(-1.0f, 0, 0.0f), orig);
	dir.y = 0.0f;
	// rotation along the plane
	Quaternion rot = Quaternion::getRotationTo(Vector3(0, 1, 0), norm);
	// rotation towards heading
	// TODO: this auto-orients the vehicle along the X axis for an unknown reason.
	Quaternion rot2 = Quaternion::getRotationTo(Vector3(-1, 0, 0), dir);
	rot = rot * rot2;
	setRotation(orig.slerp(rot, 0.1f));
}
开发者ID:anttisalonen,项目名称:viper,代码行数:27,代码来源:Vehicle.cpp

示例3:

SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer) {
    Common common;
    if (common.unflatten(buffer, inputCount)) {
        fCropRect = common.cropRect();
        fInputCount = common.inputCount();
        fInputs = SkNEW_ARRAY(SkImageFilter*, fInputCount);
        common.detachInputs(fInputs);
    } else {
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:8,代码来源:SkImageFilter.cpp

示例4: fUsesSrcInput

SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer)
    : fUsesSrcInput(false)
    , fCropRect(SkRect(), 0x0)
    , fUniqueID(next_image_filter_unique_id()) {
    Common common;
    if (common.unflatten(buffer, inputCount)) {
        this->init(common.inputs(), common.inputCount(), &common.cropRect());
    }
}
开发者ID:03050903,项目名称:skia,代码行数:9,代码来源:SkImageFilter.cpp

示例5: dispatcher

 static void dispatcher( Common< Package > &common, std::vector< Self > &workers ) {
     while ( common.processed() < common.worldSize() ) {
         Daemon::instance().probe( [&]( Channel channel ) {
             Self::processDispatch( common, workers, channel );
         },
         ChannelType::Master,
         100
                                 );
     }
 }
开发者ID:spito,项目名称:dp,代码行数:10,代码来源:workerPing.hpp

示例6: CreateProc

SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
    Common common;
    if (!common.unflatten(buffer, -1)) {
        return NULL;
    }

    const int count = common.inputCount();
    bool hasModes = buffer.readBool();
    if (hasModes) {
        SkAutoSTArray<4, SkXfermode::Mode> modes(count);
        SkAutoSTArray<4, uint8_t> modes8(count);
        if (!buffer.readByteArray(modes8.get(), count)) {
            return NULL;
        }
        for (int i = 0; i < count; ++i) {
            modes[i] = (SkXfermode::Mode)modes8[i];
            buffer.validate(SkIsValidMode(modes[i]));
        }
        if (!buffer.isValid()) {
            return NULL;
        }
        return Create(common.inputs(), count, modes.get(), &common.cropRect(), common.uniqueID());
    }
    return Create(common.inputs(), count, NULL, &common.cropRect(), common.uniqueID());
}
开发者ID:3rdexp,项目名称:soui,代码行数:25,代码来源:SkMergeImageFilter.cpp

示例7: fUsesSrcInput

SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer)
  : fUsesSrcInput(false)
  , fUniqueID(next_image_filter_unique_id()) {
    Common common;
    if (common.unflatten(buffer, inputCount)) {
        fCropRect = common.cropRect();
        fInputCount = common.inputCount();
        fInputs = SkNEW_ARRAY(SkImageFilter*, fInputCount);
        common.detachInputs(fInputs);
        for (int i = 0; i < fInputCount; ++i) {
            if (NULL == fInputs[i] || fInputs[i]->usesSrcInput()) {
                fUsesSrcInput = true;
            }
        }
    } else {
开发者ID:Dnnono,项目名称:skia,代码行数:15,代码来源:SkImageFilter.cpp

示例8: notifyAll

    static void notifyAll( Common< Package > &common ) {
        common.progress();
        OutputMessage msg;
        msg.tag( Tag::Done );

        Daemon::instance().sendAll( msg );
    }
开发者ID:spito,项目名称:dp,代码行数:7,代码来源:workerPing.hpp

示例9: Vector3

Common::Vector3 MatchHelpers::playerJumpVelocity(const Player& p, const Common::Vector3& dir)
{
	if(!p.standing() || p.isAirborne() || dir.z < 0.01f) {
		return Vector3();
	}
	if(dir.length() < 0.1f) {
		return Vector3();
	}
	Vector3 v(dir.normalized());
	if(p.isGoalkeeper())
		v *= 1.0f + 2.0f * p.getSkills().GoalKeeping;
	else
		v *= 1.5f + 1.0f * p.getSkills().Heading;
	v *= 3.0f;
	v.z = Common::clamp(1.5f, v.length(), 4.5f);
	return v;
}
开发者ID:NashBean,项目名称:freekick3,代码行数:17,代码来源:MatchHelpers.cpp

示例10: InitAnimation

	void AnimationSystem::InitAnimation(Common &common, Vec2 scale, Vec2 screen) {
		animation.mTexture = common.getTextureResource("explosion");

		animation.mPos.x = screen.x / 2 * scale.x;
		animation.mPos.y = screen.y / 2 * scale.y;
		animation.mCurrentFrame = 0;
		animation.mFrameTime = 0.0f;
		animation.mScale = scale;
	}
开发者ID:syvjohan,项目名称:Games,代码行数:9,代码来源:AnimationSystem.cpp

示例11: Init

void Common::Init(int argc, char* argv[]) {
    unsigned i = 0;

    _logfile = fopen("logfile.txt", "w");
    if(!_logfile) {
        MessageBox(NULL, TEXT("unable to create logfile"), TEXT("Error"), MB_OK);
    }

    char delim = 0;
#ifdef _WIN32
    delim = '\\';
#endif
    assert(0 != delim);

    _baseDir = CurrentDirectory();

    bool ignoreLedaDir = false;
    i = 0;
    while(i < argc && !ignoreLedaDir) {
        if(!strcmp("--ignoreledadir", argv[i]))
            ignoreLedaDir = true;
        i++;
    }

    const char* s;
    if(s = getenv("LEDA_DIR")) {
        if(!ignoreLedaDir) _baseDir = s;
        common.printf("INFO - environment variable 'LEDA_DIR' set to '%s'\n", s);
    }
    else common.printf("INFO - environment variable 'LEDA_DIR' not set.\n");

    i = 0;
    while(i < argc - 1) {
        if(!strcmp("--basedir", argv[i]))
            _baseDir = DirOf(argv[i + 1]);
        i++;
    }

    if(delim != _baseDir.back()) _baseDir += delim;
    _baseDir += std::string("res") + delim;
    printf("INFO - base directory is '%s'.\n", _baseDir.c_str());
}
开发者ID:plainoldcj,项目名称:nubuck,代码行数:42,代码来源:common.cpp

示例12: grab

void SecondaryReplicator::DrainQueueAsyncOperation::FinishWaitForQueueToDrain(Common::AsyncOperationSPtr const & asyncOperation)
{
    auto error = dispatchQueue_->EndWaitForQueueToDrain(asyncOperation);
    ReplicatorEventSource::Events->SecondaryDrainDispatchQueueDone(
            parent_.partitionId_, 
            parent_.endpointUniqueId_,
            queueType_,
            static_cast<int>(error.ReadValue()),
            drainScenario_);
    AsyncOperationSPtr const & thisSPtr = asyncOperation->Parent;
    if (error.IsSuccess() && requireServiceAck_)
    {
        bool cancelRequested = false;
        {
            AcquireWriteLock grab(lock_);
            hasQueueDrainCompletedSuccessfully_ = true;
            cancelRequested = isCancelRequested_;
        }

        if (cancelRequested)
        {
            {
                AcquireWriteLock grab(lock_);
                startedComplete_ = true;
            }

            this->TryComplete(thisSPtr, ErrorCode(Common::ErrorCodeValue::OperationCanceled));
        }
        else if (isCopyQueue_)
        {
            CheckIfAllCopyOperationsAcked(thisSPtr);
        }
        else
        {
            CheckIfAllReplicationOperationsAcked(thisSPtr);
        }
    }
    else
    { 
        {
            AcquireWriteLock grab(lock_);
            startedComplete_ = true;
        }

        thisSPtr->TryComplete(thisSPtr, error);
    }
}
开发者ID:vturecek,项目名称:Service-Fabric,代码行数:47,代码来源:SecondaryReplicator.DrainQueueAsyncOperation.cpp

示例13: lock

ErrorCode Replicator::ChangeRoleAsyncOperation::CreateInitialSecondary()
{
    AcquireWriteLock lock(parent_.lock_);
    ASSERT_IF(
        parent_.primary_ || parent_.secondary_, 
        "{0}: The primary and secondary shouldn't exist when changing role to IDLE", 
        parent_.ToString());

    ErrorCode error;
    if (newRole_ == ::FABRIC_REPLICA_ROLE_ACTIVE_SECONDARY)
    {
        error = parent_.state_.TransitionToSecondaryActive();
    }
    else
    {
        error = parent_.state_.TransitionToSecondaryIdle();
    }

    if (!error.IsSuccess())
    {
        return error;
    }

    parent_.secondary_ = move(SecondaryReplicator::CreateSecondary(
        parent_.config_,
        parent_.perfCounters_,
        parent_.replicaId_,
        parent_.hasPersistedState_,
        parent_.endpointUniqueId_,
        parent_.stateProvider_,
        parent_.partition_,
        parent_.version_,
        parent_.transport_,
        parent_.partitionId_,
        parent_.healthClient_,
        parent_.apiMonitor_));

    return ErrorCode(Common::ErrorCodeValue::Success);
}
开发者ID:vturecek,项目名称:Service-Fabric,代码行数:39,代码来源:Replicator.ChangeRoleAsyncOperation.cpp

示例14: main

int main(int argC, const char* argV[])
{
   Common common;
   common.report();


   TestServer::provideRadarEndpoint(new SocketSensorEndpoint(5003));
   TestServer::provideTcasEndpoint(new SocketSensorEndpoint(5002));
   TestServer::provideAdsbEndpoint(new SocketSensorEndpoint(5001));
   TestServer::provideOwnshipEndpoint(new SocketSensorEndpoint(5000));

   //__DIR__ is injected in compile time
   std::string test;
   if(argC < 2)
   {
      std::cout << "test-server: <test-file-name.xml>" << std::endl;
      return -1;
   }

   else
   {
      test = std::string(argV[1]);
   }
   std::string s(test);
   TestFileParser parser;
   // true if building test case is successful
   try {


      if (parser.load(s)) {
         std::cout << s << std::endl;

         TestCase testCase = parser.GetTestCase();
         PositionVerificationTest positionTest(std::make_shared<TestCase>(TestCase(testCase)));
         NumPlanesVerificationTest numPlanesTest(std::make_shared<TestCase>(TestCase(testCase)));
         //Validator::addTester(std::make_shared<PositionVerificationTest>(std::move(positionTest)));
         Validator::addTester(std::make_shared<NumPlanesVerificationTest>(std::move(numPlanesTest)));
         TestEnvironment environment;
         environment.acceptConnections();
         environment.start(testCase);

         std::cout << "Environment has finished accepting connections" << std::endl;
      }
      TestServer::shutdown();
   }
   catch(std::exception e)
   {
      std::cerr << "Error in loading test case: " << e.what() << std::endl;
   }

/*
   std::cout<<"\n----Test File 2----"<<std::endl;
   //__DIR__ is injected in compile time
   std::string s2(__DIR__"/resources/TestCaseExample2.xml");
   // true if building test case is successful
   if(parser.load(s2)) {
      TestCase tc = parser.GetTestCase();

   }

   std::cout<<"\n-----Test File 3----"<<std::endl;
   //__DIR__ is injected in compile time
   std::string s3(__DIR__"/resources/TestCaseExample3.xml");
   // true if building test case is successful
   if(parser.load(s3)) {
      TestCase tc = parser.GetTestCase();

      }
   }
*/

/*
   TestCase testCase;
   TestServerPlane ownshipPlane;
   ownshipPlane.setMotion(LinearMotion(Vector3d(0,0,8000), Vector3d(875,0,0)));
   ownshipPlane.setTailNumber("N00000");
   ownshipPlane.setAdsbEnabled(true);

   TestServerPlane otherPlane;
   otherPlane.setMotion(LinearMotion(Vector3d(5,15,-2000), Vector3d(0,875,0)));
   otherPlane.setTailNumber("N12345");
   otherPlane.setAdsbEnabled(true);

   testCase.setOwnship(ownshipPlane);
   testCase.addPlane(otherPlane);

   testCase.setTotalTime(10.0f);
   //Test cases start at lat 0 long 0
   testCase.complete();


   TestEnvironment environment;
   environment.acceptConnections();
   environment.start(testCase);

   std::cout << "Environment has finished accepting connections" << std::endl;
   TestServer::shutdown();
*/
   return 0;
}
开发者ID:fedorareis,项目名称:SAA-App,代码行数:100,代码来源:main.cpp

示例15: ownGoalPosition

Vector3 MatchHelpers::ownGoalPosition(const Team& t)
{
	const Match* m = t.getMatch();
	assert(m);
	if(attacksUp(t)) {
		return m->convertRelativeToAbsoluteVector(RelVector3(Vector3(0, -1, 0)));
	}
	else {
		return m->convertRelativeToAbsoluteVector(RelVector3(Vector3(0, 1, 0)));
	}
}
开发者ID:NashBean,项目名称:freekick3,代码行数:11,代码来源:MatchHelpers.cpp


注:本文中的Common类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。