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


C++ SendProp::GetProxyFn方法代码示例

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


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

示例1: Array_Encode

void Array_Encode( const unsigned char *pStruct, DVariant *pVar, const SendProp *pProp, bf_write *pOut, int objectID )
{
	SendProp *pArrayProp = pProp->GetArrayProp();
	AssertMsg( pArrayProp, ("Array_Encode: missing m_pArrayProp for SendProp '%s'.", pProp->m_pVarName) );
	
	int nElements = Array_GetLength( pStruct, pProp, objectID );

	// Write the number of elements.
	pOut->WriteUBitLong( nElements, pProp->GetNumArrayLengthBits() );

	unsigned char *pCurStructOffset = (unsigned char*)pStruct + pArrayProp->GetOffset();
	for ( int iElement=0; iElement < nElements; iElement++ )
	{
		DVariant var;

		// Call the proxy to get the value, then encode.
		pArrayProp->GetProxyFn()( pArrayProp, pStruct, pCurStructOffset, &var, iElement, objectID );
		g_PropTypeFns[pArrayProp->GetType()].Encode( pStruct, &var, pArrayProp, pOut, objectID ); 
		
		pCurStructOffset += pProp->GetElementStride();
	}
}
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:22,代码来源:dt_encode.cpp

示例2: SendPropUtlVector

// Note: your pArrayProp will NOT get iElement set to anything other than 0, because this function installs its
// own proxy in front of yours. pStruct will point at the CUtlVector and pData will point at the element in the CUtlVector.It will pass you the direct pointer to the element inside the CUtlVector.
//
// You can skip the first 3 parameters in pArrayProp because they're ignored. So your array specification
// could look like this:
//   	 SendPropUtlVector(
//	    	SENDINFO_UTLVECTOR( m_FloatArray ),
//			SendPropFloat( NULL, 0, 0, 0 [# bits], SPROP_NOSCALE [flags] ) );
//
// Note: you have to be DILIGENT about calling NetworkStateChanged whenever an element in your CUtlVector changes
// since CUtlVector doesn't do this automatically.
SendProp SendPropUtlVector(
    const char *pVarName,		// Use SENDINFO_UTLVECTOR to generate these 4.
    int offset,			// Used to generate pData in the function specified in varProxy.
    int sizeofVar,		// The size of each element in the utlvector.
    EnsureCapacityFn ensureFn,	// This is the value returned for elements out of the array's current range.
    int nMaxElements,			// Max # of elements in the array. Keep this as low as possible.
    SendProp pArrayProp,		// Describe the data inside of each element in the array.
    SendTableProxyFn varProxy	// This can be overridden to control who the array is sent to.
)
{
    SendProp ret;

    Assert( nMaxElements <= MAX_ARRAY_ELEMENTS );

    ret.m_Type = DPT_DataTable;
    ret.m_pVarName = pVarName;
    ret.SetOffset( 0 );
    ret.SetDataTableProxyFn( varProxy );

    // Handle special proxy types where they always let all clients get the results.
    if ( varProxy == SendProxy_DataTableToDataTable || varProxy == SendProxy_DataTablePtrToDataTable )
    {
        ret.SetFlags( SPROP_PROXY_ALWAYS_YES );
    }


    // Extra data bound to each of the properties.
    CSendPropExtra_UtlVector *pExtraData = new CSendPropExtra_UtlVector;

    pExtraData->m_nMaxElements = nMaxElements;
    pExtraData->m_ElementStride = sizeofVar;
    pExtraData->m_EnsureCapacityFn = ensureFn;
    pExtraData->m_Offset = offset;

    if ( pArrayProp.m_Type == DPT_DataTable )
        pExtraData->m_DataTableProxyFn = pArrayProp.GetDataTableProxyFn();
    else
        pExtraData->m_ProxyFn = pArrayProp.GetProxyFn();


    SendProp *pProps = new SendProp[nMaxElements+1]; // TODO free that again

    // The first property is datatable with an int that tells the length of the array.
    // It has to go in a datatable, otherwise if this array holds datatable properties, it will be received last.
    SendProp *pLengthProp = new SendProp;
    *pLengthProp = SendPropInt( AllocateStringHelper( "lengthprop%d", nMaxElements ), 0, 0, NumBitsForCount( nMaxElements ), SPROP_UNSIGNED, SendProxy_UtlVectorLength );
    pLengthProp->SetExtraData( pExtraData );

    char *pLengthProxyTableName = AllocateUniqueDataTableName( true, "_LPT_%s_%d", pVarName, nMaxElements );
    SendTable *pLengthTable = new SendTable( pLengthProp, 1, pLengthProxyTableName );
    pProps[0] = SendPropDataTable( "lengthproxy", 0, pLengthTable, SendProxy_LengthTable );
    pProps[0].SetExtraData( pExtraData );


    // The first element is a sub-datatable.
    for ( int i = 1; i < nMaxElements+1; i++ )
    {
        pProps[i] = pArrayProp;	// copy array element property setting
        pProps[i].SetOffset( 0 ); // leave offset at 0 so pStructBase is always a pointer to the CUtlVector
        pProps[i].m_pVarName = s_ElementNames[i-1];	// give unique name
        pProps[i].SetExtraData( pExtraData );
        pProps[i].m_ElementStride = i-1;	// Kind of lame overloading element stride to hold the element index,
        // but we can easily move it into its SetExtraData stuff if we need to.

        // We provide our own proxy here.
        if ( pArrayProp.m_Type == DPT_DataTable )
        {
            pProps[i].SetDataTableProxyFn( SendProxy_UtlVectorElement_DataTable );
            pProps[i].SetFlags( SPROP_PROXY_ALWAYS_YES );
        }
        else
        {
            pProps[i].SetProxyFn( SendProxy_UtlVectorElement );
        }
    }

    SendTable *pTable = new SendTable(
        pProps,
        nMaxElements+1,
        AllocateUniqueDataTableName( true, "_ST_%s_%d", pVarName, nMaxElements )
    );

    ret.SetDataTable( pTable );
    return ret;
}
开发者ID:chrizonix,项目名称:RCBot2,代码行数:96,代码来源:dt_utlvector_send.cpp


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