本文整理汇总了C++中Opt::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ Opt::IsValid方法的具体用法?C++ Opt::IsValid怎么用?C++ Opt::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Opt
的用法示例。
在下文中一共展示了Opt::IsValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void PlayerControllerMessageSenderSystem::Update( double DeltaTime )
{
MessageSenderSystem::Update( DeltaTime );
if ( !IsTime() )
{
return;
}
//TODO: might need optimization
Opt<Actor> actor = mScene.GetActor( mProgramState.mControlledActorGUID );
if ( actor.IsValid() )
{
Opt<PlayerControllerComponent> playerControllerC = actor->Get<IControllerComponent>();
if ( playerControllerC.IsValid() )
{
std::auto_ptr<PlayerControllerMessage> playerControllerMsg( new PlayerControllerMessage );
playerControllerMsg->mActorGUID = actor->GetGUID();
playerControllerMsg->mOrientation = std::floor( playerControllerC->mOrientation * PRECISION );
playerControllerMsg->mHeading = std::floor( playerControllerC->mHeading * PRECISION );
playerControllerMsg->mShoot = playerControllerC->mShoot;
playerControllerMsg->mShootAlt = playerControllerC->mShootAlt;
playerControllerMsg->mUseNormalItem = playerControllerC->mUseNormalItem;
playerControllerMsg->mUseReload = playerControllerC->mUseReload;
playerControllerMsg->mMoving = playerControllerC->mMoving;
mMessageHolder.AddOutgoingMessage( playerControllerMsg );
}
}
}
示例2: Update
void NotifyParentOnDeathSystem::Update( double DeltaTime )
{
for ( auto actor : mScene.GetActorsFromMap( GetType_static() ) )
{
Opt<INotifyParentOnDeathComponent> notifyParentOnDeathC = actor->Get<INotifyParentOnDeathComponent>();
if ( !notifyParentOnDeathC.IsValid() )
{
continue;
}
Opt<Actor> parent( mScene.GetActor( notifyParentOnDeathC->GetParentGUID() ) );
Opt<Actor> killer( mScene.GetActor( notifyParentOnDeathC->GetKillerGUID() ) );
if( !parent.IsValid() )
{
continue;
}
Opt<IHealthComponent> healthC = actor->Get<IHealthComponent>();
if( !healthC.IsValid() || healthC->IsAlive() )
{
continue;
}
if( !killer.IsValid() )
{
continue;
}
Opt<IListenChildDeathComponent> listenChildDeathC = parent->Get<IListenChildDeathComponent>();
if ( !listenChildDeathC.IsValid() )
{
continue;
}
listenChildDeathC->SetKillerOfChildGUID( killer->GetGUID() );
}
}
示例3: GetCloakState
CloakSystem::CloakState CloakSystem::GetCloakState( const Actor& actor )
{
Opt<ICloakComponent> cloakC = actor.Get<ICloakComponent>();
if ( !cloakC.IsValid() || !cloakC->IsActive() )
{
return Visible;
}
static core::ProgramState& mProgramState = core::ProgramState::Get();
if ( mProgramState.mControlledActorGUID == actor.GetGUID() )
{
return Cloaked;
}
Opt<ITeamComponent> teamC( actor.Get<ITeamComponent>() );
if ( teamC.IsValid() )
{
static Scene& mScene = Scene::Get();
Opt<Actor> controlledActor = mScene.GetActor( mProgramState.mControlledActorGUID );
if ( controlledActor.IsValid() )
{
Opt<ITeamComponent> controlledTeamC( controlledActor->Get<ITeamComponent>() );
if ( controlledTeamC.IsValid() && controlledTeamC->GetTeam() == teamC->GetTeam() )
{
return Cloaked;
}
else
{
return Invisible;
}
}
}
return Visible;
}
示例4: Update
void StopOnDeathSystem::Update( double DeltaTime )
{
for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
{
Actor& actor = **it;
Opt<IStopOnDeathComponent> stopOnDeathC = actor.Get<IStopOnDeathComponent>();
if ( !stopOnDeathC.IsValid() || stopOnDeathC->IsStopped() )
{
continue;
}
Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>();
if ( !healthC.IsValid() )
{
continue;
}
if ( healthC->IsAlive() )
{
continue;
}
stopOnDeathC->SetStopped( true );
Opt<IMoveComponent> moveC = actor.Get<IMoveComponent>();
if( moveC.IsValid() )
{
moveC->SetMoving( false );
moveC->SetHeadingModifier( 0 );
}
}
}
示例5: Update
void RemoveComponentsOnDeathSystem::Update( double DeltaTime )
{
for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
{
Actor& actor = **it;
Opt<IRemoveComponentsOnDeathComponent> removeComponentsOnDeathC = actor.Get<IRemoveComponentsOnDeathComponent>();
if ( !removeComponentsOnDeathC.IsValid() )
{
continue;
}
Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>();
if( !healthC.IsValid() )
{
continue;
}
if( healthC->IsAlive() )
{
continue;
}
// create copy, component might drop itself
std::vector<int32_t> const comps = removeComponentsOnDeathC->GetComponents();
std::for_each( std::begin( comps ), std::end( comps ),
[&]( int32_t id ) { actor.DropComponent( id ); } );
}
}
示例6: Update
void AccelerationSystem::Update( double DeltaTime )
{
for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
{
Actor& actor = **it;
Opt<IMoveComponent> moveC = actor.Get<IMoveComponent>();
if ( !moveC.IsValid() )
{
continue;
}
Opt<IAccelerationComponent> accelerationC = actor.Get<IAccelerationComponent>();
if ( !accelerationC.IsValid() )
{
continue;
}
double speed = moveC->GetSpeed().mBase.Get();
double acceleration = accelerationC->GetAcceleration();
speed += acceleration * DeltaTime;
speed = ( acceleration > 0.0 ) ?
std::min( speed, accelerationC->GetMaxSpeed() ) :
std::max( speed, accelerationC->GetMinSpeed() );
moveC->GetSpeed().mBase.Set( speed );
}
}
示例7: Update
void ParticleSystem::Update( double DeltaTime )
{
for( auto actor: mScene.GetActorsFromMap( GetType_static() ) )
{
Opt<IEmitterComponent> emitterC = actor->Get<IEmitterComponent>();
if (!emitterC.IsValid())
{
continue;
}
Opt<IPositionComponent> positionC = actor->Get<IPositionComponent>();
if( !positionC.IsValid() )
{
continue;
}
Opt<IMoveComponent> moveC = actor->Get<IMoveComponent>();
glm::vec2 distance(0);
if ( moveC.IsValid() && moveC->IsMoving() && !moveC->IsRooted() )
{
distance = glm::vec2(moveC->GetSpeedX()*DeltaTime, moveC->GetSpeedY()*DeltaTime);
}
emitterC->Update( DeltaTime );
std::vector<int32_t> const& emitted = emitterC->GetEmitTypes();
for( std::vector<int32_t>::const_iterator ie = emitted.begin(), ee = emitted.end(); ie != ee; ++ie )
{
static ParticleEngine& pe( ParticleEngine::Get() );
pe.AddParticle( *ie, glm::vec2( positionC->GetX(), positionC->GetY() ), distance, positionC->GetOrientation() );
}
emitterC->Emitted( emitted );
}
}
示例8: OnShot
void WeaponItemSubSystem::OnShot( core::ShotEvent const& Evt )
{
Opt<Actor> actor( mScene.GetActor( Evt.mActorGUID ) );
if ( !actor.IsValid() )
{
return;
}
Opt<IInventoryComponent> inventoryC = actor->Get<IInventoryComponent>();
if ( !inventoryC.IsValid() )
{
return;
}
Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
if ( !weapon.IsValid() )
{
return;
}
weapon->GetScatter().Shot( Evt.mIsAlt );
if ( Evt.mIsAlt )
{
weapon->SetCooldown( weapon->GetShootAltCooldown() );
weapon->SetBullets( weapon->GetBullets() - weapon->GetShotCostAlt() );
}
else
{
weapon->SetCooldown( weapon->GetShootCooldown() );
weapon->SetBullets( weapon->GetBullets() - weapon->GetShotCost() );
}
}
示例9: clientActor
std::auto_ptr<Actor> SoldierSpawnSystem::Spawn( core::ClientData& clientData, map::SpawnPoint spawnPoint, std::auto_ptr<Actor> player )
{
Opt<Actor> clientActor( mScene.GetActor( clientData.mClientActorGUID ) );
if( clientActor.IsValid() )
{
Opt<IHealthComponent> healthC = clientActor->Get<IHealthComponent>();
if ( healthC.IsValid() && healthC->IsAlive() )
{
L1( "Cannot spawn soldier for clientData (%s) current soldier still alive!\n", clientData.mClientName.c_str() );
return std::auto_ptr<Actor>();
}
}
else
{
L2( "No actor for clientData(%s). (it might be an error on revive)\n", clientData.mClientName.c_str() );
}
L2( "player is valid %d", player.get() );
Opt<IPositionComponent> positionC = player->Get<IPositionComponent>();
L2( "positionC is valid %d", positionC.IsValid() );
positionC->SetX( spawnPoint.mX );
positionC->SetY( spawnPoint.mY );
//TODO: temporary till normal inventory sync
// Opt<IInventoryComponent> inventoryC = player->Get<IInventoryComponent>();
// if ( inventoryC.IsValid() )
// {
// inventoryC->SetSelectedWeapon( AutoId( "pistol" ) );
// }
Opt<PlayerControllerComponent> playerControllerC( player->Get<IControllerComponent>() );
if ( playerControllerC.IsValid() )
{
playerControllerC->mControllerId = clientData.mClientId;
if ( mProgramState.mControlledActorGUID == clientData.mClientActorGUID
&& mProgramState.mMode != core::ProgramState::Server )
{
playerControllerC->SetEnabled( true );
playerControllerC->mActive = true;
mProgramState.mControlledActorGUID = player->GetGUID();
}
}
clientData.mClientActorGUID = player->GetGUID(); //TODO: might seek for a better place
L2( "player created clientId:%d clientName:%s actorId:%d\n", clientData.mClientId, clientData.mClientName.c_str(), clientData.mClientActorGUID );
if ( mProgramState.mMode != core::ProgramState::Server &&
mProgramState.mClientDatas.begin()->mClientActorGUID == player->GetGUID() )
{
Scene::Get().SetPlayerModels( Opt<Actor>( player.get() ) );
}
EventServer<SoldierCreatedEvent>::Get().SendEvent( SoldierCreatedEvent( clientData, Opt<Actor>( player.get() ) ) );
return player;
}
示例10: Recognize
bool HatRecognizer::Recognize( Actor const& actor ) const
{
Opt<PlayerControllerComponent> playerCC = actor.Get<PlayerControllerComponent>();
if ( !playerCC.IsValid() )
{
return false;
}
Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>();
if ( !healthC.IsValid() || !healthC->IsAlive() )
{
return false;
}
return true;
}
示例11: Collide
void BounceCollisionSubSystem::Collide( Actor& actor, Actor& other )
{
Opt<BounceCollisionComponent> bounceCC = actor.Get<BounceCollisionComponent>();
if (mShotCollisionSubSystem.IsValid() && bounceCC->IsUseShotCollision())
{
mShotCollisionSubSystem->Collide(actor, other);
}
//TODO: for now its wallcc should be a bouncableComponent or this should be a collision class
Opt<WallCollisionComponent> wallCC = other.Get<WallCollisionComponent>();
if( !wallCC.IsValid() )
{
return;
}
Opt<IPositionComponent> positionC = actor.Get<IPositionComponent>();
Opt<IMoveComponent> moveC = actor.Get<IMoveComponent>();
Opt<IPositionComponent> otherPositionC = other.Get<IPositionComponent>();
Opt<ICollisionComponent> otherCC = other.Get<ICollisionComponent>();
if ( !otherPositionC.IsValid() || !otherCC.IsValid() || !positionC.IsValid() )
{
return;
}
double const dx = otherPositionC->GetX() - positionC->GetX();
double const dy = otherPositionC->GetY() - positionC->GetY();
const double h = moveC->GetHeading();
double c = cos( h );
double s = sin( h );
double at = atan2( s, c );
double at2 = atan2( c, s );
if( std::abs( dx ) > std::abs( dy ) )
{
c *= -1;
}
else if( std::abs( dx ) < std::abs( dy ) )
{
s *= -1;
}
moveC->SetHeading( atan2( s, c ) );
moveC->GetSpeed().mBase.Set( moveC->GetSpeed().mBase.Get() * ( 1.0 - bounceCC->GetSpeedLossPercent() ) );
if (bounceCC->GetHitCountToKill() > 0)
{
bounceCC->SetHitCountToKill(bounceCC->GetHitCountToKill() - 1);
}
if (bounceCC->IsResetActorsCollidedOnBounce())
{
bounceCC->ResetDamagedActorIds();
}
}
示例12: Ret
glm::vec4 Grid::Box( Actor const& Obj, double Dt )const
{
Opt<IMoveComponent> moveC = Obj.Get<IMoveComponent>();
float const MvX = moveC.IsValid() ? Dt * moveC->GetSpeedX() : 0.0f;
float const MvY = moveC.IsValid() ? Dt * moveC->GetSpeedY() : 0.0f;
double const Radius = Obj.Get<ICollisionComponent>()->GetRadius();
Opt<IPositionComponent> const objPositionC = Obj.Get<IPositionComponent>();
double const Ox = objPositionC->GetX() - mMin.x;
double const Oy = objPositionC->GetY() - mMin.y;
glm::vec4 Ret( Ox - Radius,
Oy - Radius,
Ox + Radius,
Oy + Radius );
if( MvX < 0.0 )
{
Ret.x += MvX;
}
else
{
Ret.z += MvX;
}
if( MvY < 0.0 )
{
Ret.y += MvY;
}
else
{
Ret.w += MvY;
}
return Ret;
}
示例13: AddToActorColors
void EditorSelectSystem::AddToActorColors( int32_t actorGUID, ActorColors_t &actorColors, Opt<ActorColors_t> colorShaders /*= nullptr*/ )
{
static Scene& scene=Scene::Get();
auto actor( scene.GetActor( actorGUID ) );
if (actor.IsValid())
{
auto renderableC( actor->Get<IRenderableComponent>() );
auto color = renderableC.IsValid() ? renderableC->GetColor() : glm::vec4( 1.0 );
if (colorShaders.IsValid())
{
auto found = colorShaders->find( actor->GetGUID() );
if (found != colorShaders->end())
{
// this actor is already selected so the color is the selected color. taking color from the selected and saved colors
color = found->second;
}
}
if (renderableC.IsValid()&&renderableC->GetColor()==EditorVisibilitySystem::InvisibleColor)
{
// do not add to actorColors an invisible actor. That's the point in being invisible
}
else
{
actorColors.emplace( actor->GetGUID(), color );
}
}
}
示例14: Update
void AttachableSystem::Update( double DeltaTime )
{
for (auto actor : mScene.GetActorsFromMap( GetType_static() ))
{
Opt<IAttachableComponent> attachableC = actor->Get<IAttachableComponent>();
if ( !attachableC.IsValid() )
{
continue;
}
Opt<Actor> attachedActor( mScene.GetActor( attachableC->GetAttachedGUID() ) );
if ( attachableC->GetAttachedGUID() == -1 )
{
continue;
}
if ( !attachedActor.IsValid() )
{
attachableC->SetAttachedGUID( -1 );
EventServer< AttachStateChangedEvent>::Get().SendEvent( AttachStateChangedEvent( AttachStateChangedEvent::Detached, -1, actor->GetGUID() ) );
continue;
}
Opt<IHealthComponent> attachedHealthC( attachedActor->Get<IHealthComponent>() );
if ( attachedHealthC.IsValid() )
{
if ( !attachedHealthC->IsAlive() )
{
if (attachableC->IsRemoveOnAttachedDeath())
{
Opt<IHealthComponent> healthC( actor->Get<IHealthComponent>() );
if (healthC.IsValid())
{
healthC->SetHP( 0 );
}
}
attachableC->SetAttachedGUID( -1 );
EventServer<AttachStateChangedEvent>::Get().SendEvent( AttachStateChangedEvent( AttachStateChangedEvent::Detached, attachedActor->GetGUID(), actor->GetGUID() ) );
continue;
}
}
Opt<IPositionComponent> attachedPositionC( attachedActor->Get<IPositionComponent>() );
if ( !attachedPositionC.IsValid() )
{
continue;
}
Opt<IPositionComponent> positionC( actor->Get<IPositionComponent>() );
if ( !positionC.IsValid() )
{
continue;
}
glm::vec2 rvec = glm::rotate(glm::vec2(attachableC->GetPositionX(), attachableC->GetPositionY()), float( attachedPositionC->GetOrientation() ) );
positionC->SetX( attachedPositionC->GetX() + rvec.x );
positionC->SetY( attachedPositionC->GetY() + rvec.y );
if (attachableC->IsInheritOrientation())
{
positionC->SetOrientation( attachedPositionC->GetOrientation() + boost::math::double_constants::pi );
}
}
}
示例15: Update
void CollisionSystem::Update( double DeltaTime )
{
mCollisionGrid.Clear();
for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
{
Actor& actor = **it;
Opt<ICollisionComponent> collisionC = actor.Get<ICollisionComponent>();
if ( collisionC.IsValid() )
{
mCollisionGrid.AddActor( &actor, DeltaTime );
Opt<CollisionSubSystem> collisionSS = GetCollisionSubSystem( collisionC->GetId() );
if ( collisionSS.IsValid() )
{
collisionSS->ClipScene( actor );
}
}
}
PossibleCollisions_t const& PossibleCollisions = mCollisionGrid.GetPossibleCollisions();
for( PossibleCollisions_t::const_iterator i = PossibleCollisions.begin(), e = PossibleCollisions.end(); i != e; ++i )
{
Actor& A = *( i->A1 );
Actor& B = *( i->A2 );
Opt<ICollisionComponent> ACollisionC = A.Get<ICollisionComponent>();
Opt<ICollisionComponent> BCollisionC = B.Get<ICollisionComponent>();
BOOST_ASSERT( ACollisionC.IsValid() && BCollisionC.IsValid() ); //TODO: here this one should be true
CollisionModel const& CollModel = mCollisionStore.GetCollisionModel( ACollisionC->GetCollisionClass(), BCollisionC->GetCollisionClass() );
if( !CollModel.AreActorsColliding( A, B, DeltaTime ) )
{
continue;
}
//TODO: needs optimization, maybe a template parameter for SubSystemHolder to subsystem would do
Opt<CollisionSubSystem> ACollisionSS = GetCollisionSubSystem( ACollisionC->GetId() );
if ( ACollisionSS.IsValid() )
{
ACollisionSS->Collide( A, B );
}
Opt<CollisionSubSystem> BCollisionSS = GetCollisionSubSystem( BCollisionC->GetId() );
if ( BCollisionSS.IsValid() )
{
BCollisionSS->Collide( B, A );
}
}
for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
{
Actor& actor = **it;
Opt<ICollisionComponent> collisionC = actor.Get<ICollisionComponent>();
if ( collisionC.IsValid() )
{
Opt<CollisionSubSystem> collisionSS = GetCollisionSubSystem( collisionC->GetId() );
if ( collisionSS.IsValid() )
{
collisionSS->Update( actor, DeltaTime );
}
}
}
}