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 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 #3
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;
}
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 );
        }
    }
}
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 ); } );
    }
}
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 #7
0
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 );
    }
}
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() );
    }
}
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;
}
Beispiel #10
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 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();
    }
}
Beispiel #12
0
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;
}
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 );

        }
    }
}
Beispiel #14
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 );
        }
    }
}
Beispiel #15
0
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 );
            }
        }
    }
}
Beispiel #16
0
void FlashMessageHandlerSubSystem::Execute( Message const& message )
{
    FlashMessage const& msg = static_cast<FlashMessage const&>( message );
    Opt<Actor> actor = mScene.GetActor( msg.mActorGUID );
    if ( !actor.IsValid() )
    {
        L1( "cannot find actor with GUID: (%s) %d \n", __FUNCTION__, msg.mActorGUID );
        return;
    }
    Opt<IPositionComponent> positionC = actor->Get<IPositionComponent>();
    if ( !positionC.IsValid() )
    {
        return;
    }
    positionC->SetX( msg.mX / PRECISION );
    positionC->SetY( msg.mY / PRECISION );
}
void WeaponItemSubSystem::SetProjectilePosition(Actor& projectile, Actor& actor)
{
    Opt<IPositionComponent> projPositionC = projectile.Get<IPositionComponent>();
    Opt<IPositionComponent> actorPositionC = actor.Get<IPositionComponent>();
    glm::vec2 rvec(0.0, 0.0);
    Opt<IInventoryComponent> inventoryC = actor.Get<IInventoryComponent>();
    if (inventoryC.IsValid())
    {
        Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
        if (weapon.IsValid())
        {
            rvec.x += weapon->GetPositionX();
            rvec.y -= weapon->GetPositionY();
        }
    }
    rvec=glm::rotate(rvec, float(actorPositionC->GetOrientation()));
    projPositionC->SetX( projPositionC->GetX() + actorPositionC->GetX() + rvec.x );
    projPositionC->SetY( projPositionC->GetY() + actorPositionC->GetY() + rvec.y );
}
void ExplodeOnHitSystem::Update( double DeltaTime )
{
    for( auto actor : mScene.GetActorsFromMap( GetType_static() ) )
    {
        Opt<IExplodeOnHitComponent> explodeOnHitC = actor->Get<IExplodeOnHitComponent>();
        if ( !explodeOnHitC.IsValid() || !explodeOnHitC->IsExploded() )
        {
            continue;
        }
        WeaponItemSubSystem::Projectiles_t projectiles;
        ExplodeOnDeathSystem::FillExplosionProjectiles( *explodeOnHitC.Get(), *actor, projectiles );
        Scatter scatter;
        WeaponItemSubSystem::Get()->AddProjectiles( *actor, projectiles, scatter );
        Opt<IHealthComponent> healthC = actor->Get<IHealthComponent>();
        if( healthC.IsValid() )
        {
            healthC->SetHP( 0 );
        }
    }
}
Beispiel #19
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;
}
void ExplodeOnHitSystem::Update( double DeltaTime )
{
    for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it )
    {
        Actor& actor = **it;
        Opt<IExplodeOnHitComponent> explodeOnHitC = actor.Get<IExplodeOnHitComponent>();
        if ( !explodeOnHitC.IsValid() || !explodeOnHitC->IsExploded() )
        {
            continue;
        }
        WeaponItemSubSystem::Projectiles_t projectiles;
        ExplodeOnDeathSystem::FillExplosionProjectiles( *explodeOnHitC.Get(), actor, projectiles );
        Scatter scatter;
        WeaponItemSubSystem::Get()->AddProjectiles( actor, projectiles, scatter );
        Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>();
        if( healthC.IsValid() )
        {
            healthC->SetHP( 0 );
        }
    }
}
Beispiel #21
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;
}
void PlayerControllerMessageHandlerSubSystem::Execute( Message const& message )
{
    PlayerControllerMessage const& msg = static_cast<PlayerControllerMessage const&>( message );
    //        L1("executing PlayerController: %d \n",msg.mSenderId );
    Opt<Actor> actor = mScene.GetActor( msg.mActorGUID );
    if ( !actor.IsValid() )
    {
        L1( "cannot find actor with GUID: (that is not possible) %d \n", msg.mActorGUID );
        return;
    }

    Opt<PlayerControllerComponent> playerControllerC = actor->Get<IControllerComponent>();
    if ( !playerControllerC.IsValid() )
    {
        L1( "playercontroller is called on an actor that has no player_controller_component \n" );
        return;
    }
    playerControllerC->mOrientation = msg.mOrientation / PRECISION;
    playerControllerC->mHeading = msg.mHeading / PRECISION;
    playerControllerC->mShoot = msg.mShoot;
    playerControllerC->mShootAlt = msg.mShootAlt;
    if (msg.mUseNormalItem.IsActive())
    {
        playerControllerC->mUseNormalItem.Activate();
    }
    else
    {
        playerControllerC->mUseNormalItem.Deactivate();
    }
    if (msg.mUseReload.IsActive())
    {
        playerControllerC->mUseReload.Activate();
    }
    else
    {
        playerControllerC->mUseReload.Deactivate();
    }
    playerControllerC->mMoving = msg.mMoving;
}
Beispiel #23
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;
}
bool SetOwnershipMessageHandlerSubSystem::ProcessPending( Message const& message )
{
    SetOwnershipMessage const& msg = static_cast<SetOwnershipMessage const&>( message );
    Opt<Actor> actor = mScene.GetActor( msg.mActorGUID ); //guaranteed
    L1( "executing %s: actorGUID %d \n", __FUNCTION__, msg.mActorGUID );
    Opt<PlayerControllerComponent> playerControllerC( actor->Get<IControllerComponent>() );
    if ( !playerControllerC.IsValid() )
    {
        L1( "setownership is called on an actor that is not playerControllable \n" );
        return true;
    }

    playerControllerC->mControllerId = msg.mClientId;

    if ( msg.mClientId == mProgramState.mClientId )
    {
        L1( "thats my id! actorguid: %d,%d \n", msg.mActorGUID, PlayerControllerComponent::GetType_static() );
        Opt<Actor> oldActor = mScene.GetActor( mProgramState.mControlledActorGUID );
        if ( oldActor.IsValid() )
        {
            Opt<PlayerControllerComponent> pcc = oldActor->Get<IControllerComponent>();
            if( pcc.IsValid() )
            {
                pcc->SetEnabled( false );
                pcc->mActive = false;
            }
        }
        mProgramState.mControlledActorGUID = msg.mActorGUID;
        playerControllerC->SetEnabled( true );
        playerControllerC->mActive = true;
        mScene.SetPlayerModels( actor );
    }
    Opt<core::ClientData> clientData( mProgramState.FindClientDataByClientId( msg.mClientId ) );
    if ( clientData.IsValid() )
    {
        clientData->mClientActorGUID = msg.mActorGUID;
    }
    return true;
}
void CollisionSystem::Update( double DeltaTime )
{
    static const auto enableCollision = Settings::Get().GetInt( "collisions.enable", 1 ) != 0;
    if( !enableCollision )
    {
        return;
    }
    mUpdateTimer.Log( "start collision" );
    mPerfTimer.Log( "pre build grid" );
    std::vector<std::pair<Opt<CollisionSubSystem>, Actor*>> collisionAndActors;
    for (auto actor : mScene.GetActorsFromMap( GetType_static() ))
    {
        Opt<ICollisionComponent> collisionC = actor->Get<ICollisionComponent>();
        if ( collisionC.IsValid() )
        {
            Opt<CollisionSubSystem> collisionSS = GetCollisionSubSystem( collisionC->GetId() );
            if ( collisionSS.IsValid() )
            {
                collisionAndActors.push_back( std::make_pair( collisionSS, actor ) );
                collisionSS->ClipScene( *actor );
            }
            mCollisionGrid.AddActor( actor, DeltaTime, collisionC );
        }
    }
    mPerfTimer.Log( "post build grid" );
    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 );
        }
    }
    mPerfTimer.Log( "post collide" );
    for (auto& collAndActor : collisionAndActors)
    {
        collAndActor.first->Update( *collAndActor.second, DeltaTime );
    }
    mPerfTimer.Log( "post collSS" );
    mUpdateTimer.Log( "end collision" );
}
void WeaponItemSubSystem::AddProjectiles( Actor& actor, Projectiles_t& projectiles, Scatter& scatter, bool alt/*=false*/ )
{
    double actorOrientation = actor.Get<IPositionComponent>()->GetOrientation();
    int scat = int( scatter.GetCalculated() * 1000 );
    if( scat )
    {
        double realScatter = ( RandomGenerator::global()() % ( scat + 1 ) - scat / 2. );
        L2( "realScatter:%f\n", realScatter );
        actorOrientation += ( RandomGenerator::global()() % ( scat + 1 ) - scat / 2. ) * 0.001 * boost::math::double_constants::pi;
    }

    L2( "calculated and updated scatter:%f\n", scatter.GetCalculated() );
    Opt<IPositionComponent> actorPositionC = actor.Get<IPositionComponent>();
    for( Projectiles_t::iterator i = projectiles.begin(), e = projectiles.end(); i != e; ++i )
    {
        Actor& Proj = **i;
        SetProjectilePosition( Proj, actor );
        Opt<ShotCollisionComponent> shotCC = Proj.Get<ICollisionComponent>();
        if ( shotCC.IsValid() )
        {
            shotCC->SetParentGUID( actor.GetGUID() );
        }
        Opt<IOwnerComponent> ownerC = Proj.Get<IOwnerComponent>();
        if ( ownerC.IsValid() && ownerC->GetOwnerGUID() == -1 ) //if proj owner is set, then not the given actor is the owner
        {
            ownerC->SetOwnerGUID( actor.GetGUID() );
        }

        Opt<IPositionComponent> projPositionC = Proj.Get<IPositionComponent>();
        projPositionC->SetOrientation( projPositionC->GetOrientation() + actorOrientation );
        Opt<IMoveComponent> moveC( Proj.Get<IMoveComponent>() );
        if ( moveC.IsValid() )
        {
            moveC->SetHeading( projPositionC->GetOrientation() );
        }
        mScene.AddActor( &Proj );
    }
}
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;
}
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 EditorSelectSystem::SetActorColors( ActorColors_t const& actorGUIDs, Opt<glm::vec4> col )
{
    static Scene& scene = Scene::Get();
    for (auto& actorGUID : actorGUIDs)
    {
        auto actor = scene.GetActor( actorGUID.first );
        auto renderableC( actor->Get<IRenderableComponent>() );
        if (renderableC.IsValid())
        {
            renderableC->SetColor( col.IsValid()?*col:actorGUID.second );
        }
    }

}
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 ) );
    }
}