本文整理汇总了C++中Opt类的典型用法代码示例。如果您正苦于以下问题:C++ Opt类的具体用法?C++ Opt怎么用?C++ Opt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Opt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare
bool compare(Opt& o1, Opt& o2){
if(o1.is_initialized()){
return o2.is_initialized() && *o1 == *o2;
} else {
return !o2.is_initialized();
}
}
示例2: attachedActor
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 );
}
}
}
示例3: 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 );
}
}
}
示例4: 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 );
}
}
}
示例5: actor
void MouseAdapterSystem::Update( double DeltaTime )
{
Opt<Actor> actor( mScene.GetActor( mProgramState.mControlledActorGUID ) );
if ( !actor.IsValid() )
{
return;
}
int32_t playerId = 1;
static input::PlayerControlDevice& pcd( input::PlayerControlDevice::Get() );
if( pcd.GetControlDevice( playerId ) != input::PlayerControlDevice::KeyboardAndMouse )
{
return;
}
InputState inputState = mInputSystem->GetInputState( playerId );
Opt<IPositionComponent> actorPositionC = actor->Get<IPositionComponent>();
inputState.mOrientation = atan2( mY - actorPositionC->GetY(), mX - actorPositionC->GetX() );
inputState.mCursorX = mX;
inputState.mCursorY = mY;
if ( mMouse->IsButtonPressed( MouseSystem::Button_Left ) )
{
inputState.mShoot = true;
}
else if ( mMouse->IsButtonPressed( MouseSystem::Button_Right ) )
{
inputState.mShootAlt = true;
}
mInputSystem->SetInputState( playerId, inputState );
}
示例6: parent
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() );
}
}
示例7: teamC
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;
}
示例8: test_one_arg
void test_one_arg() {
using Opt = std::optional<T>;
{
Opt opt;
auto & v = opt.emplace();
static_assert( std::is_same_v<T&, decltype(v)>, "" );
assert(static_cast<bool>(opt) == true);
assert(*opt == T(0));
assert(&v == &*opt);
}
{
Opt opt;
auto & v = opt.emplace(1);
static_assert( std::is_same_v<T&, decltype(v)>, "" );
assert(static_cast<bool>(opt) == true);
assert(*opt == T(1));
assert(&v == &*opt);
}
{
Opt opt(2);
auto & v = opt.emplace();
static_assert( std::is_same_v<T&, decltype(v)>, "" );
assert(static_cast<bool>(opt) == true);
assert(*opt == T(0));
assert(&v == &*opt);
}
{
Opt opt(2);
auto & v = opt.emplace(1);
static_assert( std::is_same_v<T&, decltype(v)>, "" );
assert(static_cast<bool>(opt) == true);
assert(*opt == T(1));
assert(&v == &*opt);
}
}
示例9: main
int main(int argc, char *argv[])
{
Opt *options = new Opt();
int count,i,status,opt_status;
pid_t process;
signal(SIGINT, main_signal_reaction); // Registrace funkce pro odchyt signalu
opt_status = options->load(argc,argv);
if(opt_status == HELP) return EXIT_SUCCESS; // Vypis napovedy a konec
else if(opt_status == OPTION_FAIL) return EXIT_FAILURE; // Chyba v parametrech, konec
if((options->check()) == OPTION_FAIL) return EXIT_FAILURE;
vector<Service*> services;
count = options->addresses.size();
if(count == 1)
{// jedna sluzba
Service *a = new Service();
a->start(options, 0);
delete a;
delete options;
}
else
{// vice sluzeb
for(i=0; i<count; i++)
{
process = fork();
if(process == 0)
{// Nova sluzba
Service *a = new Service();
a->start(options, i);
delete a;
delete options;
exit(0); // sluzba konci
}
else
{// Rodic ulozi pid potomka do vektoru
main_children.push_back(process);
}
}
for(i=0; i<count; i++)
{// Cekani na ukonceni sluzeb (v normalnim pripade)
waitpid(-1, &status, 0); // Cekani na jakehokoli potomka, az se ukonci
}
}
return EXIT_SUCCESS;
}
示例10: AutoId
void IRoom::PlaceLevelEndPoint( RoomDesc &roomDesc, glm::vec2 pos )
{
auto endPoint = ActorFactory::Get()( AutoId( "platform" ) );
Opt<IPositionComponent> positionC = endPoint->Get<IPositionComponent>();
positionC->SetX( pos.x );
positionC->SetY( pos.y );
mScene.AddActor( endPoint.release() );
}
示例11: Cmd
//}}}
//{{{ class SysPwdCmd method
SysPwdCmd::SysPwdCmd(const char *const name) : Cmd(name) {
optMgr_.setShortDes("print name of current directory");
optMgr_.setDes("prints the full filename of the current working directory");
Opt *opt = new Opt(Opt::BOOL, "print usage", "");
opt->addFlag("h");
opt->addFlag("help");
optMgr_.regOpt(opt);
}
示例12: Update
void BounceCollisionSubSystem::Update( Actor& actor, double DeltaTime )
{
Opt<BounceCollisionComponent> bounceCC = actor.Get<BounceCollisionComponent>();
if (mShotCollisionSubSystem.IsValid()&&bounceCC->IsUseShotCollision())
{
mShotCollisionSubSystem->Update(actor, DeltaTime);
}
}
示例13: 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 );
}
}
示例14: orientationMessage
std::auto_ptr<OrientationMessage> OrientationMessageSenderSystem::GenerateOrientationMessage( Actor& actor )
{
Opt<IPositionComponent> positionC = actor.Get<IPositionComponent>();
if ( !positionC.IsValid() )
{
return std::auto_ptr<OrientationMessage>();
}
std::auto_ptr<OrientationMessage> orientationMessage( new OrientationMessage );
orientationMessage->mOrientation = std::floor( positionC->GetOrientation() * PRECISION );
orientationMessage->mActorGUID = actor.GetGUID();
return orientationMessage;
}
示例15: borderMsg
std::auto_ptr<BorderMessage> BorderMessageSenderSystem::GenerateBorderMessage( Actor& actor )
{
Opt<IBorderComponent> borderC = actor.Get<IBorderComponent>();
if ( !borderC.IsValid() )
{
return std::auto_ptr<BorderMessage>();
}
std::auto_ptr<BorderMessage> borderMsg( new BorderMessage );
borderMsg->mActorGUID = actor.GetGUID();
borderMsg->mBorders = borderC->GetBorders();
borderMsg->mOuterBorders = borderC->GetOuterBorders();
return borderMsg;
}