当前位置: 首页>>代码示例>>C++>>正文


C++ CElement::GetID方法代码示例

本文整理汇总了C++中CElement::GetID方法的典型用法代码示例。如果您正苦于以下问题:C++ CElement::GetID方法的具体用法?C++ CElement::GetID怎么用?C++ CElement::GetID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CElement的用法示例。


在下文中一共展示了CElement::GetID方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _GetEntitiesFromRoot

void CElement::_GetEntitiesFromRoot ( unsigned int uiTypeHash, std::map < CElement*, int >& mapResults )
{
    t_mapEntitiesFromRoot::iterator find = ms_mapEntitiesFromRoot.find ( uiTypeHash );
    if ( find != ms_mapEntitiesFromRoot.end () )
    {
        CChildListType& listEntities = find->second;
        CElement* pEntity;
        unsigned int uiIndex = 0;

        for ( CChildListType::const_reverse_iterator i = listEntities.rbegin ();
              i != listEntities.rend ();
              ++i )
        {
            pEntity = *i;

            assert ( pEntity );
            ElementID ID = pEntity->GetID ();
            assert ( ID != INVALID_ELEMENT_ID );
            assert ( pEntity == CElementIDs::GetElement ( ID ) );
            if ( pEntity->IsBeingDeleted () )
                OutputDebugString ( SString ( "Server: 0x%08x  %s is flagged as IsBeingDeleted() but is still in GetEntitiesFromRoot\n", pEntity, pEntity->GetTypeName ().c_str () ) );

            assert ( mapResults.find ( pEntity ) == mapResults.end () );
            mapResults [ pEntity ] = 1;
        }
    }    
}
开发者ID:Bargas,项目名称:mtasa-blue,代码行数:27,代码来源:CElement.cpp

示例2: switch

vector < char * > * CLuaArguments::WriteToCharVector ( vector < char * > * values )
{
    vector < CLuaArgument* > ::const_iterator iter = m_Arguments.begin ();
    for ( ; iter != m_Arguments.end () ; iter++ )
    {
        switch ( (*iter)->GetType() )
        {
        case LUA_TNUMBER:
            {
                char * szValue = new char [ 20 ];
                itoa ( ( int ) (*iter)->GetNumber(), szValue, 10 );
                values->push_back ( szValue );
                break;
            }
        case LUA_TSTRING:
            {
                const char * szString = (*iter)->GetString().c_str ();
                char * szValue = new char [ strlen ( szString ) + 1 ];
                strcpy ( szValue, szString );
                values->push_back ( szValue );
                break;
            }
        case LUA_TBOOLEAN:
            {
                char * szValue = new char [ 6 ];
                if ( (*iter)->GetBoolean() )
                    values->push_back ( strcpy ( szValue, "true" ) );
                else
                    values->push_back ( strcpy ( szValue, "false" ) );
                break;
            }
        case LUA_TLIGHTUSERDATA:
            {
                char * szValue = new char [10];
                memset(szValue,0,10);
                CElement* pElement = (*iter)->GetElement ();
			    if ( VERIFY_ELEMENT(pElement) )
			    {
                    _snprintf ( szValue, 9, "E#%d", (int)pElement->GetID() );
			    }
			    else
			    {
				    g_pGame->GetScriptDebugging()->LogError ( NULL, "Couldn't serialize argument list, invalid element specified. Passing empty string instead." );
			    }
                values->push_back ( szValue );
            }        
        default:
            {
                char * szEmpty = new char [ 1 ];
                szEmpty[0] = '\0';
                values->push_back ( szEmpty );
            }
        }
    }
    return values;
}
开发者ID:MrHankey,项目名称:multitheftauto,代码行数:56,代码来源:CLuaArguments.cpp

示例3: WriteToString

char* CLuaArgument::WriteToString(char* szBuffer, int length)
{
    switch (GetType())
    {
        case LUA_TNIL:
        {
            snprintf(szBuffer, length, "0");
            return szBuffer;
        }
        case LUA_TBOOLEAN:
        {
            if (GetBoolean())
                snprintf(szBuffer, length, "true");
            else
                snprintf(szBuffer, length, "false");
            return szBuffer;
        }
        case LUA_TTABLE:
        {
            g_pGame->GetScriptDebugging()->LogError(
                NULL, "Cannot convert table to string (do not use tables as keys in tables if you want to send them over http/JSON).");
            return NULL;
        }
        case LUA_TNUMBER:
        {
            int iNumber;
            if (ShouldUseInt(GetNumber(), &iNumber))
            {
                snprintf(szBuffer, length, "%d", iNumber);
                return szBuffer;
            }
            else
            {
                snprintf(szBuffer, length, "%f", GetNumber());
                return szBuffer;
            }
            break;
        }
        case LUA_TSTRING:
        {
            const char*    szTemp = GetString().c_str();
            unsigned short usLength = static_cast<unsigned short>(strlen(szTemp));
            if (strlen(szTemp) == usLength)
            {
                snprintf(szBuffer, length, "%s", szTemp);
                return szBuffer;
            }
            else
            {
                g_pGame->GetScriptDebugging()->LogError(NULL, "String is too long. Limit is 65535 characters.");
            }
            break;
        }

        case LUA_TLIGHTUSERDATA:
        case LUA_TUSERDATA:
        {
            CElement*  pElement = GetElement();
            CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromScriptID(reinterpret_cast<unsigned long>(GetUserData()));
            if (pElement)
            {
                snprintf(szBuffer, length, "#E#%d", (int)pElement->GetID().Value());
                return szBuffer;
            }
            else if (pResource)
            {
                snprintf(szBuffer, length, "#R#%s", pResource->GetName().c_str());
                return szBuffer;
            }
            else
            {
                g_pGame->GetScriptDebugging()->LogError(NULL, "Couldn't convert element to string, only valid elements can be sent.");
                return NULL;
            }
            break;
        }
        default:
        {
            g_pGame->GetScriptDebugging()->LogError(NULL,
                                                    "Couldn't convert argument to string, unsupported data type. Use String, Number, Boolean or Element.");
            return NULL;
        }
    }
    return NULL;
}
开发者ID:Audifire,项目名称:mtasa-blue,代码行数:85,代码来源:CLuaArgument.cpp

示例4: WriteToJSONObject

json_object* CLuaArgument::WriteToJSONObject(bool bSerialize, CFastHashMap<CLuaArguments*, unsigned long>* pKnownTables)
{
    switch (GetType())
    {
        case LUA_TNIL:
        {
            return json_object_new_int(0);
        }
        case LUA_TBOOLEAN:
        {
            return json_object_new_boolean(GetBoolean());
        }
        case LUA_TTABLE:
        {
            ulong* pTableId;
            if (pKnownTables && (pTableId = MapFind(*pKnownTables, m_pTableData)))
            {
                // Self-referencing table
                char szTableID[10];
                snprintf(szTableID, sizeof(szTableID), "^T^%lu", *pTableId);
                return json_object_new_string(szTableID);
            }
            else
            {
                return m_pTableData->WriteTableToJSONObject(bSerialize, pKnownTables);
            }
        }
        case LUA_TNUMBER:
        {
            int iNumber;
            if (ShouldUseInt(GetNumber(), &iNumber))
            {
                return json_object_new_int(iNumber);
            }
            else
            {
                return json_object_new_double(GetNumber());
            }
            break;
        }
        case LUA_TSTRING:
        {
            SString strTemp = GetString();
            if (strTemp.length() > 3 && strTemp[0] == '^' && strTemp[2] == '^' && strTemp[1] != '^')
            {
                // Prevent clash with how MTA stores elements, resources and table refs as strings
                strTemp[2] = '~';
            }
            if (strTemp.length() <= USHRT_MAX)
            {
                return json_object_new_string_len((char*)strTemp.c_str(), strTemp.length());
            }
            else
            {
                g_pGame->GetScriptDebugging()->LogError(NULL, "Couldn't convert argument list to JSON. Invalid string specified, limit is 65535 characters.");
            }
            break;
        }
        case LUA_TLIGHTUSERDATA:
        case LUA_TUSERDATA:
        {
            CElement*  pElement = GetElement();
            CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromScriptID(reinterpret_cast<unsigned long>(GetUserData()));

            // Elements are dynamic, so storing them is potentially unsafe
            if (pElement && bSerialize)
            {
                char szElementID[10] = {0};
                snprintf(szElementID, 9, "^E^%d", (int)pElement->GetID().Value());
                return json_object_new_string(szElementID);
            }
            else if (pResource)
            {
                char szElementID[MAX_RESOURCE_NAME_LENGTH + 4] = {0};
                snprintf(szElementID, MAX_RESOURCE_NAME_LENGTH + 3, "^R^%s", pResource->GetName().c_str());
                return json_object_new_string(szElementID);
            }
            else
            {
                if (pElement)            // eg toJSON() with valid element
                    g_pGame->GetScriptDebugging()->LogError(NULL, "Couldn't convert userdata argument to JSON, elements not allowed for this function.");
                else if (!bSerialize)            // eg toJSON() with invalid element
                    g_pGame->GetScriptDebugging()->LogError(
                        NULL, "Couldn't convert userdata argument to JSON, only valid resources can be included for this function.");
                else
                    g_pGame->GetScriptDebugging()->LogError(NULL,
                                                            "Couldn't convert userdata argument to JSON, only valid elements or resources can be included.");
                return NULL;
            }
            break;
        }
        default:
        {
            g_pGame->GetScriptDebugging()->LogError(
                NULL, "Couldn't convert argument list to JSON, unsupported data type. Use Table, Nil, String, Number, Boolean, Resource or Element.");
            return NULL;
        }
    }
    return NULL;
}
开发者ID:Audifire,项目名称:mtasa-blue,代码行数:100,代码来源:CLuaArgument.cpp

示例5: WriteToBitStream


//.........这里部分代码省略.........
            else if (dataType == DATA_TYPE_FLOAT)
            {
                bitStream.WriteBit(true);
                bitStream.WriteBit(false);
                bitStream.Write(fNumber);
            }
            else
            {
                bitStream.WriteBit(true);
                bitStream.WriteBit(true);
                bitStream.Write(dNumber);
            }
            break;
        }

        // String argument
        case LUA_TSTRING:
        {
            // Grab the string and its length. Is it short enough to be sendable?
            const char*    szTemp = m_strString.c_str();
            size_t         sizeTemp = m_strString.length();
            unsigned short usLength = static_cast<unsigned short>(sizeTemp);
            if (sizeTemp == usLength)
            {
                // This is a string argument
                type.data.ucType = LUA_TSTRING;
                bitStream.Write(&type);

                // Write its length
                bitStream.WriteCompressed(usLength);

                // Write the content too if it's not empty
                if (usLength > 0)
                {
                    bitStream.Write(szTemp, usLength);
                }
            }
            else
            {
                // This is a long string argument
                type.data.ucType = LUA_TSTRING_LONG;
                bitStream.Write(&type);

                // Write its length
                uint uiLength = sizeTemp;
                bitStream.WriteCompressed(uiLength);

                // Write the content too if it's not empty
                if (uiLength > 0)
                {
                    bitStream.AlignWriteToByteBoundary();
                    bitStream.Write(szTemp, uiLength);
                }
            }
            break;
        }

        // Element argument
        case LUA_TLIGHTUSERDATA:
        case LUA_TUSERDATA:
        {
            // Grab the element from this userdata pointer. Valid and has a synced element ID?
            CElement* pElement = GetElement();
            if (pElement && pElement->GetID() != INVALID_ELEMENT_ID)
            {
                // Write its ID
                type.data.ucType = LUA_TUSERDATA;
                bitStream.Write(&type);
                bitStream.Write(pElement->GetID());
            }
            else
            {
                // Jax: this just spams the script debugger, it's not really neccesary
                // LogUnableToPacketize ( "Couldn't packetize argument list, invalid element specified." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write(&type);
                return false;
            }

            break;
        }

        // Unpacketizable type.
        default:
        {
            // Unpacketizable
            LogUnableToPacketize("Couldn't packetize argument list, unknown type specified.");

            // Write a nil though so other side won't get out of sync
            type.data.ucType = LUA_TNIL;
            bitStream.Write(&type);
            return false;
        }
    }

    // Success
    return true;
}
开发者ID:Audifire,项目名称:mtasa-blue,代码行数:101,代码来源:CLuaArgument.cpp

示例6: json_object_new_int

json_object * CLuaArgument::WriteToJSONObject ( bool bSerialize, std::map < CLuaArguments*, unsigned long > * pKnownTables )
{
    switch ( GetType () )
    {
        case LUA_TNIL:
        {
            return json_object_new_int(0);
        }
        case LUA_TBOOLEAN:
        {
            return json_object_new_boolean(GetBoolean ());
        }
        case LUA_TTABLE:
        {
            if ( pKnownTables && pKnownTables->find ( m_pTableData ) != pKnownTables->end () )
            {
                char szTableID[10];
                _snprintf ( szTableID, sizeof(szTableID), "^T^%lu", pKnownTables->find ( m_pTableData )->second );
                return json_object_new_string ( szTableID );
            }
            else
            {
                return m_pTableData->WriteTableToJSONObject ( bSerialize, pKnownTables );
            }
        }
        case LUA_TNUMBER:
        {
			float fNum = static_cast < float > ( GetNumber () );
			int iNum = static_cast < int > ( GetNumber () );
			if ( iNum == fNum )
			{
                return json_object_new_int(iNum);
			}
			else
			{
				return json_object_new_double(fNum);
			}
            break;
        }
        case LUA_TSTRING:
        {
            const char* szTemp = GetString ().c_str ();
            unsigned short usLength = static_cast < unsigned short > ( strlen ( szTemp ) );
			if ( strlen ( szTemp ) == usLength )
			{
				return json_object_new_string_len ( (char *)szTemp, usLength );
			}
			else
			{
				g_pGame->GetScriptDebugging()->LogError ( NULL, "Couldn't convert argument list to JSON. Invalid string specified, limit is 65535 characters." );
			}
            break;
        }
        case LUA_TLIGHTUSERDATA:
        {
			CElement* pElement = GetElement ();
            CResource* pResource = reinterpret_cast < CResource* > ( GetLightUserData() );
			
			// Elements are dynamic, so storing them is potentially unsafe
			if ( pElement && bSerialize )
			{
				char szElementID[10] = {0};
                _snprintf ( szElementID, 9, "^E^%d", (int)pElement->GetID() );
				return json_object_new_string ( szElementID );
			}
            else if ( VERIFY_RESOURCE(pResource) )
            {
				char szElementID[MAX_RESOURCE_NAME_LENGTH+4] = {0};
                _snprintf ( szElementID, MAX_RESOURCE_NAME_LENGTH+3, "^R^%s", pResource->GetName().c_str () );
				return json_object_new_string ( szElementID );
            }
			else
			{
				g_pGame->GetScriptDebugging()->LogError ( NULL, "Couldn't convert argument list to JSON, only valid elements can be sent." );
				return NULL;
			}
            break;
        }
		default:
		{
			g_pGame->GetScriptDebugging()->LogError ( NULL, "Couldn't convert argument list to JSON, unsupported data type. Use Table, Nil, String, Number, Boolean, Resource or Element." );
			return NULL;
		}
    }
    return NULL;
}
开发者ID:50p,项目名称:multitheftauto,代码行数:86,代码来源:CLuaArgument.cpp

示例7: WriteToBitStream


//.........这里部分代码省略.........
        case LUA_TNUMBER:
        {
            type.data.ucType = LUA_TNUMBER;
            bitStream.Write ( &type );
            float fNumber = static_cast < float > ( GetNumber () );
            long lNumber = static_cast < long > ( fNumber );
            float fNumberInteger = static_cast < float > ( lNumber );

            // Check if the number is an integer and can fit a long datatype
            if ( fabs ( fNumber ) > fabs ( fNumberInteger + 1 ) ||
                 fabs ( fNumber - fNumberInteger ) >= FLOAT_EPSILON )
            {
                bitStream.WriteBit ( true );
                bitStream.Write ( fNumber );
            }
            else
            {
                bitStream.WriteBit ( false );
                bitStream.WriteCompressed ( lNumber );
            }
            break;
        }

        // String argument
        case LUA_TSTRING:
        {           
            // Grab the string and its length. Is it short enough to be sendable?
            const char* szTemp = m_strString.c_str ();
            size_t sizeTemp = strlen ( szTemp );
            unsigned short usLength = static_cast < unsigned short > ( sizeTemp );
			if ( sizeTemp == usLength )
			{
                // This is a string argument
                type.data.ucType = LUA_TSTRING;
			    bitStream.Write ( &type );

                // Write its length
				bitStream.WriteCompressed ( usLength );

                // Write the content too if it's not empty
                if ( usLength > 0 )
                {
				    bitStream.Write ( const_cast < char* > ( szTemp ), usLength );
                }
			}
			else
			{
                // Too long string
                LogUnableToPacketize ( "Couldn't packetize argument list. Invalid string specified, limit is 65535 characters." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
                return false;
			}
            break;
        }

        // Element argument
        case LUA_TLIGHTUSERDATA:
        {
            // Grab the element from this userdata pointer. Valid and has a synced element ID?
			CElement* pElement = GetElement ();
			if ( pElement && pElement->GetID () != INVALID_ELEMENT_ID )
			{
                // Write its ID
                type.data.ucType = LUA_TLIGHTUSERDATA;
				bitStream.Write ( &type );
				bitStream.WriteCompressed ( static_cast < ElementID > ( pElement->GetID () ) );
			}
			else
			{
                // Jax: this just spams the script debugger, it's not really neccesary
                // LogUnableToPacketize ( "Couldn't packetize argument list, invalid element specified." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
				return false;
			}

            break;
        }

        // Unpacketizable type.
		default:
		{
            // Unpacketizable
			LogUnableToPacketize ( "Couldn't packetize argument list, unknown type specified." );

            // Write a nil though so other side won't get out of sync
            type.data.ucType = LUA_TNIL;
            bitStream.Write ( &type );
			return false;
		}
    }

    // Success
    return true;
}
开发者ID:50p,项目名称:multitheftauto,代码行数:101,代码来源:CLuaArgument.cpp

示例8: Write

bool CPlayerPuresyncPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    if ( m_pSourceElement )
    {
        CPlayer * pSourcePlayer = static_cast < CPlayer * > ( m_pSourceElement );

        ElementID PlayerID = pSourcePlayer->GetID ();
        unsigned short usLatency = pSourcePlayer->GetPing ();
        const CControllerState& ControllerState = pSourcePlayer->GetPad ()->GetCurrentControllerState ();
        CElement* pContactElement = pSourcePlayer->GetContactElement ();

        // Get current weapon slot
        unsigned char ucWeaponSlot = pSourcePlayer->GetWeaponSlot ();

        // Flags
        SPlayerPuresyncFlags flags;
        flags.data.bIsInWater       = ( pSourcePlayer->IsInWater () == true );
        flags.data.bIsOnGround      = ( pSourcePlayer->IsOnGround () == true );
        flags.data.bHasJetPack      = ( pSourcePlayer->HasJetPack () == true );
        flags.data.bIsDucked        = ( pSourcePlayer->IsDucked () == true );
        flags.data.bWearsGoogles    = ( pSourcePlayer->IsWearingGoggles () == true );
        flags.data.bHasContact      = ( pContactElement != NULL );
        flags.data.bIsChoking       = ( pSourcePlayer->IsChoking () == true );
        flags.data.bAkimboTargetUp  = ( pSourcePlayer->IsAkimboArmUp () == true );
        flags.data.bIsOnFire        = ( pSourcePlayer->IsOnFire () == true );
        flags.data.bHasAWeapon      = ( ucWeaponSlot != 0 );
        flags.data.bSyncingVelocity = ( !flags.data.bIsOnGround || pSourcePlayer->IsSyncingVelocity () );
        flags.data.bStealthAiming   = ( pSourcePlayer->IsStealthAiming () == true );

        CVector vecPosition = pSourcePlayer->GetPosition ();
        if ( pContactElement )
            pSourcePlayer->GetContactPosition ( vecPosition );
        float fCameraRotation = pSourcePlayer->GetCameraRotation ();

        BitStream.WriteCompressed ( PlayerID );

        // Write the time context
        BitStream.Write ( pSourcePlayer->GetSyncTimeContext () );

        BitStream.WriteCompressed ( usLatency );
        WriteFullKeysync ( ControllerState, BitStream );
/*
        // Figure out what to send
        SPlayerPuresyncSentHeader sent;
        sent.bFlags             = CompareAndSet ( usFlags,          pSourcePlayer->lastSent.usFlags );
        sent.bPosition          = CompareAndSet ( vecPosition,      pSourcePlayer->lastSent.vecPosition );
        sent.bRotation          = CompareAndSet ( fRotation,        pSourcePlayer->lastSent.fRotation );
        sent.bVelocity          = CompareAndSet ( vecVelocity,      pSourcePlayer->lastSent.vecVelocity );
        sent.bHealth            = CompareAndSet ( ucHealth,         pSourcePlayer->lastSent.ucHealth );
        sent.bArmor             = CompareAndSet ( ucArmor,          pSourcePlayer->lastSent.ucArmor );
        sent.bCameraRotation    = CompareAndSet ( fCameraRotation,  pSourcePlayer->lastSent.fCameraRotation );
        sent.bWeaponType        = CompareAndSet ( ucWeaponType,     pSourcePlayer->lastSent.ucWeaponType );
        sent.Write ( BitStream );

        if ( sent.bPosition )
        {
            BitStream.Write ( vecPosition.fX );
            BitStream.Write ( vecPosition.fY );
            BitStream.Write ( vecPosition.fZ );
        }

        if ( sent.bRotation )
            BitStream.Write ( fRotation );

        etc... Could also do a 'sent' header in WriteFullKeysync
*/
        BitStream.Write ( &flags );

        if ( pContactElement )
            BitStream.WriteCompressed ( pContactElement->GetID () );

        SPositionSync position ( false );
        position.data.vecPosition = vecPosition;
        BitStream.Write ( &position );

        SPedRotationSync rotation;
        rotation.data.fRotation = pSourcePlayer->GetRotation ();
        BitStream.Write ( &rotation );

        if ( flags.data.bSyncingVelocity )
        {
            SVelocitySync velocity;
            pSourcePlayer->GetVelocity ( velocity.data.vecVelocity );
            BitStream.Write ( &velocity );
        }

        // Player health and armor
        SPlayerHealthSync health;
        health.data.fValue = pSourcePlayer->GetHealth ();
        BitStream.Write ( &health );

        SPlayerArmorSync armor;
        armor.data.fValue = pSourcePlayer->GetArmor ();
        BitStream.Write ( &armor );

        BitStream.Write ( fCameraRotation );

        if ( flags.data.bHasAWeapon )
        {
            unsigned int uiSlot = ucWeaponSlot;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例9: Write

bool CEntityAddPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    SPositionSync position ( false );

    // Check that we have any entities
    if ( m_Entities.size () > 0 )
    {
        // Write the number of entities
        unsigned int NumElements = m_Entities.size ();
        BitStream.WriteCompressed ( NumElements );

        // For each entity ...
        CVector vecTemp;
        vector < CElement* > ::const_iterator iter = m_Entities.begin ();
        for ( ; iter != m_Entities.end (); iter++ )
        {
            // Entity id
            CElement* pElement = *iter;
            BitStream.Write ( pElement->GetID () );

            // Entity type id
            unsigned char ucEntityTypeID = static_cast < unsigned char > ( pElement->GetType () );
            BitStream.Write ( ucEntityTypeID );

            // Entity parent
            CElement* pParent = pElement->GetParentEntity ();
            ElementID ParentID = INVALID_ELEMENT_ID;
            if ( pParent )
                ParentID = pParent->GetID ();
            BitStream.Write ( ParentID );

            // Entity interior
            BitStream.Write ( pElement->GetInterior () );

            // Entity dimension
            BitStream.WriteCompressed ( pElement->GetDimension () );

            // Entity attached to
            CElement* pElementAttachedTo = pElement->GetAttachedToElement ();
            if ( pElementAttachedTo )
            {
                BitStream.WriteBit ( true );
                BitStream.Write ( pElementAttachedTo->GetID () );

                // Attached position and rotation
                SPositionSync attachedPosition ( false );
                SRotationDegreesSync attachedRotation ( false );
                pElement->GetAttachedOffsets ( attachedPosition.data.vecPosition,
                                               attachedRotation.data.vecRotation );
                BitStream.Write ( &attachedPosition );
                BitStream.Write ( &attachedRotation );
            }
            else
                BitStream.WriteBit ( false );

            // Entity collisions enabled
            bool bCollisionsEnabled = true;

            switch ( pElement->GetType() )
            {
                case CElement::VEHICLE:
                {
                    CVehicle* pVehicle = static_cast < CVehicle* > ( pElement );
                    bCollisionsEnabled = pVehicle->GetCollisionEnabled ( );
                    break;
                }
                case CElement::OBJECT:
                {
                    CObject* pObject = static_cast < CObject* > ( pElement );
                    bCollisionsEnabled = pObject->GetCollisionEnabled ( );
                    break;
                }
                case CElement::PED:
                case CElement::PLAYER:
                {
                    CPed* pPed = static_cast < CPed* > ( pElement );
                    bCollisionsEnabled = pPed->GetCollisionEnabled ( );
                    break;
                }
            }

            BitStream.WriteBit ( bCollisionsEnabled );
            
            // Write custom data
            CCustomData* pCustomData = pElement->GetCustomDataPointer ();
            assert ( pCustomData );
            BitStream.WriteCompressed ( pCustomData->CountOnlySynchronized () );
            map < string, SCustomData > :: const_iterator iter = pCustomData->IterBegin ();
            for ( ; iter != pCustomData->IterEnd (); iter++ )
            {
                const char* szName = iter->first.c_str ();
                const CLuaArgument* pArgument = &iter->second.Variable;
                bool bSynchronized = iter->second.bSynchronized;

                if ( bSynchronized )
                {
                    unsigned char ucNameLength = static_cast < unsigned char > ( strlen ( szName ) );
                    BitStream.Write ( ucNameLength );
                    BitStream.Write ( szName, ucNameLength );
                    pArgument->WriteToBitStream ( BitStream );
//.........这里部分代码省略.........
开发者ID:qaisjp,项目名称:green-candy,代码行数:101,代码来源:CEntityAddPacket.cpp

示例10: WriteToBitStream


//.........这里部分代码省略.........
            }
            break;
        }

        // String argument
        case LUA_TSTRING:
        {           
            // Grab the string and its length. Is it short enough to be sendable?
            const char* szTemp = m_strString.c_str ();
            size_t sizeTemp = m_strString.length ();
            unsigned short usLength = static_cast < unsigned short > ( sizeTemp );
            if ( sizeTemp == usLength )
            {
                // This is a string argument
                type.data.ucType = LUA_TSTRING;
                bitStream.Write ( &type );

                // Write its length
                bitStream.WriteCompressed ( usLength );

                // Write the content too if it's not empty
                if ( usLength > 0 )
                {
                    bitStream.Write ( szTemp, usLength );
                }
            }
            else
            if ( sizeTemp > 65535 && bitStream.Version () >= 0x027 && g_pGame->CalculateMinClientRequirement () >= LONG_STRING_MIN_VERSION )
            {
                // This is a long string argument
                type.data.ucType = LUA_TSTRING_LONG;
                bitStream.Write ( &type );

                // Write its length
                uint uiLength = sizeTemp;
                bitStream.WriteCompressed ( uiLength );

                // Write the content too if it's not empty
                if ( uiLength > 0 )
                {
                    bitStream.AlignWriteToByteBoundary ();
                    bitStream.Write ( szTemp, uiLength );
                }
            }
            else
            {
                // Too long string
                LogUnableToPacketize ( "Couldn't packetize argument list. Invalid string specified, limit is 65535 characters."
                                       " To use longer strings, set script <min_mta_version> to " LONG_STRING_MIN_VERSION " or higher." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
                return false;
            }
            break;
        }

        // Element argument
        case LUA_TLIGHTUSERDATA:
        {
            // Grab the element from this userdata pointer. Valid and has a synced element ID?
            CElement* pElement = GetElement ();
            if ( pElement && pElement->GetID () != INVALID_ELEMENT_ID )
            {
                // Write its ID
                type.data.ucType = LUA_TLIGHTUSERDATA;
                bitStream.Write ( &type );
                bitStream.Write ( pElement->GetID () );
            }
            else
            {
                // Jax: this just spams the script debugger, it's not really neccesary
                // LogUnableToPacketize ( "Couldn't packetize argument list, invalid element specified." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
                return false;
            }

            break;
        }

        // Unpacketizable type.
        default:
        {
            // Unpacketizable
            LogUnableToPacketize ( "Couldn't packetize argument list, unknown type specified." );

            // Write a nil though so other side won't get out of sync
            type.data.ucType = LUA_TNIL;
            bitStream.Write ( &type );
            return false;
        }
    }

    // Success
    return true;
}
开发者ID:pombredanne,项目名称:openvice,代码行数:101,代码来源:CLuaArgument.cpp


注:本文中的CElement::GetID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。