Beispiel #1
0
bool compare(Opt& o1, Opt& o2){
    if(o1.is_initialized()){
        return o2.is_initialized() && *o1 == *o2;
    } else {
        return !o2.is_initialized();
    }
}
Beispiel #2
0
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 );
        }
    }
}
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 );

        }
    }
}
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 );
        }
    }
}
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 );
}
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() );
    }
}
Beispiel #7
0
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;
}
Beispiel #8
0
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);
    }
}
Beispiel #9
0
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;
}
Beispiel #10
0
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() );
}
Beispiel #11
0
//}}}
//{{{ 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);
}
void BounceCollisionSubSystem::Update( Actor& actor, double DeltaTime )
{
    Opt<BounceCollisionComponent> bounceCC = actor.Get<BounceCollisionComponent>();
    if (mShotCollisionSubSystem.IsValid()&&bounceCC->IsUseShotCollision())
    {
        mShotCollisionSubSystem->Update(actor, DeltaTime);
    }
}
Beispiel #13
0
//{{{ class SysBashCmd   method
SysBashCmd::SysBashCmd(const char *const name) : Cmd(name) {
    optMgr_.setShortDes("opens a new bash shell environment");
    optMgr_.setDes("opens a new bash shell environment");
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #14
0
//{{{ class SysDisplayCmd   method
SysDisplayCmd::SysDisplayCmd(const char *const name) : Cmd(name) {
  optMgr_.setShortDes("disply picture in X-window");  // short 
  optMgr_.setDes("call the system function display."); // long 
  optMgr_.regArg(new Arg(Arg::OPT, "file name of the picture. can be in jpg, png, gif format ", "FILENAME"));
  Opt *opt = new Opt(Opt::BOOL, "print usage", "");
  opt->addFlag("h");
  opt->addFlag("help");
  optMgr_.regOpt(opt);
}
Beispiel #15
0
//}}}
//{{{ class SysListCmd   method
SysListCmd::SysListCmd(const char *const name) : Cmd(name) {
    optMgr_.setShortDes("list diectory contents");
    optMgr_.setDes("lists contents in DIRECTORY. If not specified, list current directory content.");
    optMgr_.regArg(new Arg(Arg::OPT, "target directories", "DIRECTORY"));
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #16
0
//}}}
//{{{class SysCdCmd     method
SysCdCmd::SysCdCmd(const char *const name) : Cmd(name) {
    optMgr_.setShortDes("change directory");
    optMgr_.setDes("changes working directory to DIRECTORY. If not specified, changes to home directory.");
    optMgr_.regArg(new Arg(Arg::OPT, "target directories", "DIRECTORY"));
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #17
0
//}}}
//{{{ class SysExitCmd   method
SysExitCmd::SysExitCmd(const char *const name, CmdMgr *cmdMgr) : Cmd(name) {
    cmdMgr_ = cmdMgr;
    optMgr_.setShortDes("exit the program");
    optMgr_.setDes("exits the program");
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #18
0
//}}}
//{{{ class SysCatCmd    method
SysCatCmd::SysCatCmd(const char *const name) : Cmd(name) {
    optMgr_.setShortDes("concatenate files and print on the standard output");
    optMgr_.setDes("Concatenate FILE(s), or standard input, to standard output");
    optMgr_.regArg(new Arg(Arg::REQ_INF, "files to be printed", "FILE"));
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #19
0
//}}}
//{{{ class SysSourceCmd method
SysSourceCmd::SysSourceCmd(const char *const name, CmdMgr *cmdMgr) : Cmd(name) {
    cmdMgr_ = cmdMgr;
    optMgr_.setShortDes("run commands from startup file");
    optMgr_.setDes("runs commands from FILE");
    optMgr_.regArg(new Arg(Arg::REQ, "target file with commands", "FILE"));
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #20
0
//}}}
//{{{ class SysHelpCmd   method
SysHelpCmd::SysHelpCmd(const char *const name, CmdMgr *cmdMgr) : Cmd(name) {
    cmdMgr_ = cmdMgr;
    optMgr_.setShortDes("print help messages");
    optMgr_.setDes("prints help for COMMAND. If not specified, prints the usage of the command manager.");
    optMgr_.regArg(new Arg(Arg::OPT, "target command", "COMMAND"));
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
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 );
    }

}
Beispiel #22
0
//}}}
//{{{ class SysSetCmd    method
SysSetCmd::SysSetCmd(const char *const name, CmdMgr *cmdMgr) : Cmd(name) {
    cmdMgr_ = cmdMgr;
    optMgr_.setShortDes("set variables");
    optMgr_.setDes("set VAR to VALUE");
    optMgr_.regArg(new Arg(Arg::OPT, "variable name", "VAR"));
    optMgr_.regArg(new Arg(Arg::OPT, "value of the variable", "VALUE"));
    Opt *opt = new Opt(Opt::BOOL, "print usage", "");
    opt->addFlag("h");
    opt->addFlag("help");
    optMgr_.regOpt(opt);
}
Beispiel #23
0
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;
}
Beispiel #24
0
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;
}
Beispiel #25
0
std::auto_ptr<RotateMessage> RotateMessageSenderSystem::GenerateRotateMessage(Actor &actor)
{
    Opt<IRotateComponent> rotateC = actor.Get<IRotateComponent>();
    if (!rotateC.IsValid())
    {
        return std::auto_ptr<RotateMessage>();
    }
    std::auto_ptr<RotateMessage> rotateMsg(new RotateMessage);
    rotateMsg->mActorGUID=actor.GetGUID();
    rotateMsg->mSpeed=rotateC->GetSpeed();
    rotateMsg->mRotating=rotateC->IsRotating();
    return rotateMsg;
}
std::auto_ptr<PositionMessage> PositionMessageSenderSystem::GeneratePositionMessage( Actor const& actor )
{
    Opt<IPositionComponent> positionC = actor.Get<IPositionComponent>();
    if ( !positionC.IsValid() )
    {
        return std::auto_ptr<PositionMessage>();
    }
    std::auto_ptr<PositionMessage> positionMsg( new PositionMessage );
    positionMsg->mX = std::floor( positionC->GetX() * PRECISION );
    positionMsg->mY = std::floor( positionC->GetY() * PRECISION );
    //positionMsg->mOrientation=positionC->GetOrientation();
    positionMsg->mActorGUID = actor.GetGUID();
    return positionMsg;
}
Beispiel #27
0
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;
}
void HatActionRenderer::Init( const Actor& actor )
{
    Opt<Weapon> weapon = actor.Get<IInventoryComponent>()->GetSelectedWeapon();
    if ( !weapon.IsValid() )
    {
        return;
    }
    SpriteCollection const& Sprites = mRenderableRepo( actor.GetId() );
    Sprite const& Spr = Sprites( mHatId );
    if( Spr.IsValid() )
    {
        mSecsToEnd = Spr.GetSecsToEnd();
    }
}
void HatActionRenderer::FillRenderableSprites( const Actor& actor, IRenderableComponent const& renderableC, RenderableSprites_t& renderableSprites )
{
    SpriteCollection const& Sprites = mRenderableRepo( actor.GetId() );
    Sprite const& Spr = Sprites( mHatId );
    if( Spr.IsValid() )
    {
        SpritePhase const& Phase = Spr( ( int32_t )GetState() );
        Opt<PlayerControllerComponent> playerCC = actor.Get<PlayerControllerComponent>();
        glm::vec4 col = playerCC.IsValid() ? ColorRepo::Get()( playerCC->mControllerId ) : glm::vec4( 1, 1, 1, 1 );
        col.a = GetCloakColor( actor ).a;
        renderableSprites.push_back(
            RenderableSprite( &actor, &renderableC, mHatId, &Spr, &Phase, col ) );
    }
}
Beispiel #30
0
bool BorderMessageHandlerSubSystem::ProcessPending( Message const& message )
{
    BorderMessage const& msg = static_cast<BorderMessage const&>( message );
    Opt<Actor> actor = mScene.GetActor( msg.mActorGUID ); //guaranteed
    L1( "executing %s: actorGUID %d \n", __FUNCTION__, msg.mActorGUID );
    Opt<IBorderComponent> borderC = actor->Get<IBorderComponent>();
    if ( !borderC.IsValid() )
    {
        L1( "borderC not valid" );
        return true;
    }
    borderC->SetBorders( msg.mBorders );
    borderC->SetOuterBorders( msg.mOuterBorders );
    return true;
}