Exemplo n.º 1
0
void CMarker::SetTarget ( const CVector* pTargetVector )
{
    // Got a target vector?
    if ( pTargetVector )
    {
        // Different from our current target
        if ( !m_bHasTarget || m_vecTarget != *pTargetVector )
        {
            // Is this a marker type that has a destination?
            if ( m_ucType == CMarker::TYPE_CHECKPOINT || m_ucType == CMarker::TYPE_RING )
            {
                // Set the target position
                m_bHasTarget = true;
                m_vecTarget = *pTargetVector;

                // Tell everyone that knows about this marker
                CBitStream BitStream;
                BitStream.pBitStream->Write ( static_cast < unsigned char > ( 1 ) );
                BitStream.pBitStream->Write ( m_vecTarget.fX );
                BitStream.pBitStream->Write ( m_vecTarget.fY );
                BitStream.pBitStream->Write ( m_vecTarget.fZ );
                BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_MARKER_TARGET, *BitStream.pBitStream ) );
            }
            else
            {
                // Reset the target position
                m_bHasTarget = false;
            }
        }
    }
    else
    {
        // Not already without target?
        if ( m_bHasTarget )
        {
            // Reset the target position
            m_bHasTarget = false;

            // Is this a marker type that has a destination?
            if ( m_ucType == CMarker::TYPE_CHECKPOINT || m_ucType == CMarker::TYPE_RING )
            {
                // Tell everyone that knows about this marker
                CBitStream BitStream;
                BitStream.pBitStream->Write ( static_cast < unsigned char > ( 0 ) );
                BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_MARKER_TARGET, *BitStream.pBitStream ) );
            }
        }
    }
}
Exemplo n.º 2
0
void CMarker::SetPosition ( const CVector& vecPosition )
{
    // Different from our current position?
    if ( m_vecPosition != vecPosition )
    {
        // Set the new position
        m_vecPosition = vecPosition;
        if ( m_pCollision )
            m_pCollision->SetPosition ( vecPosition );
        UpdateSpatialData ();

        // If attached, client should handle the position correctly
        if (  m_pAttachedTo )
            return;

        // We need to make sure the time context is replaced 
        // before that so old packets don't arrive after this.
        GenerateSyncTimeContext ();

        // Tell all the players that know about us
        CBitStream BitStream;
        BitStream.pBitStream->Write ( vecPosition.fX );
        BitStream.pBitStream->Write ( vecPosition.fY );
        BitStream.pBitStream->Write ( vecPosition.fZ );
        BitStream.pBitStream->Write ( GetSyncTimeContext () );
        BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_ELEMENT_POSITION, *BitStream.pBitStream ) );
    }
}
Exemplo n.º 3
0
void CMarker::SetIcon ( unsigned char ucIcon )
{
    if ( m_ucIcon != ucIcon )
    {
        m_ucIcon = ucIcon;

        // Tell everyone that knows about this marker
        CBitStream BitStream;
        BitStream.pBitStream->Write ( m_ucIcon );
        BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_MARKER_ICON, *BitStream.pBitStream ) );
    }
}
Exemplo n.º 4
0
void CMarker::SetSize ( float fSize )
{
    // Different from our current size?
    if ( fSize != m_fSize )
    {
        // Set the new size and update the col object
        m_fSize = fSize;
        UpdateCollisionObject ( m_ucType );

        // Tell all players
        CBitStream BitStream;
        BitStream.pBitStream->Write ( fSize );
        BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_MARKER_SIZE, *BitStream.pBitStream ) );
    }
}
Exemplo n.º 5
0
void CMarker::SetColor ( const SColor color )
{
    // Different from our current color?
    if ( color != m_Color )
    {
        // Set the new color
        m_Color = color;

        // Tell all the players
        CBitStream BitStream;
        BitStream.pBitStream->Write ( color.B  );
        BitStream.pBitStream->Write ( color.G );
        BitStream.pBitStream->Write ( color.R );
        BitStream.pBitStream->Write ( color.A );
        BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_MARKER_COLOR, *BitStream.pBitStream ) );
    }
}
Exemplo n.º 6
0
// Used to send the root element data when a player joins
void CElement::SendAllCustomData ( CPlayer* pPlayer )
{
    for ( map < std::string, SCustomData >::const_iterator iter = m_pCustomData->SyncedIterBegin() ; iter != m_pCustomData->SyncedIterEnd(); ++iter )
    {
        const std::string& strName = iter->first;
        const SCustomData& customData = iter->second;
        if ( customData.bSynchronized )
        {
            // Tell our clients to update their data
            unsigned short usNameLength = static_cast < unsigned short > ( strName.length () );
            CBitStream BitStream;
            BitStream.pBitStream->WriteCompressed ( usNameLength );
            BitStream.pBitStream->Write ( strName.c_str (), usNameLength );
            customData.Variable.WriteToBitStream ( *BitStream.pBitStream );
            pPlayer->Send ( CElementRPCPacket ( this, SET_ELEMENT_DATA, *BitStream.pBitStream ) );
        }
    }
}
Exemplo n.º 7
0
void CMarker::SetMarkerType ( unsigned char ucType )
{
    // Different from our current type?
    if ( ucType != m_ucType )
    {
        // Set the new type
        unsigned char ucOldType = m_ucType;
        m_ucType = ucType;
        UpdateCollisionObject ( ucOldType );

        // Tell all players
        CBitStream BitStream;
        BitStream.pBitStream->Write ( ucType );
        BroadcastOnlyVisible ( CElementRPCPacket ( this, SET_MARKER_TYPE, *BitStream.pBitStream ) );

        // Is the new type not a checkpoint or a ring? Remove the target
        if ( ucType != CMarker::TYPE_CHECKPOINT && ucType != CMarker::TYPE_RING )
        {
            m_bHasTarget = false;
        }
    }
}