/////////////////////////////////////////////////////////////// // // CSpatialDatabaseImpl::FlushUpdateQueue // // Process all entities that have changed since the last call // /////////////////////////////////////////////////////////////// void CSpatialDatabaseImpl::FlushUpdateQueue ( void ) { int iTotalUpdated = 0; for ( std::map < CElement*, int >::iterator it = m_UpdateQueue.begin (); it != m_UpdateQueue.end (); ++it ) { CElement* pEntity = it->first; // Get the new bounding box SEntityInfo newInfo; CSphere sphere = pEntity->GetWorldBoundingSphere (); newInfo.box = CBox ( sphere.vecPosition, fabsf ( sphere.fRadius ) ); // Make everything 2D for now newInfo.box.vecMin.fZ = SPATIAL_2D_Z; newInfo.box.vecMax.fZ = SPATIAL_2D_Z; // Get previous info if ( SEntityInfo* pOldInfo = MapFind ( m_InfoMap, pEntity ) ) { // Don't update if bounding box is the same if ( pOldInfo->box == newInfo.box ) continue; // Remove old bounding box from tree m_Tree.Remove ( &pOldInfo->box.vecMin.fX, &pOldInfo->box.vecMax.fX, pEntity ); } if ( !IsValidSphere ( sphere ) ) continue; // Add new bounding box m_Tree.Insert( &newInfo.box.vecMin.fX, &newInfo.box.vecMax.fX, pEntity ); // Update info map MapSet ( m_InfoMap, pEntity, newInfo ); iTotalUpdated++; #ifdef SPATIAL_DATABASE_DEBUG_OUTPUTA OutputDebugLine ( SString ( "SpatialDatabase::UpdateEntity %08x %2.0f,%2.0f,%2.0f %2.0f,%2.0f,%2.0f" ,pEntity ,info.box.vecMin.fX ,info.box.vecMin.fY ,info.box.vecMin.fZ ,info.box.vecMax.fX ,info.box.vecMax.fY ,info.box.vecMax.fZ ) ); #endif } m_UpdateQueue.clear (); #ifdef SPATIAL_DATABASE_DEBUG_OUTPUTB int iTotalToUpdate = m_UpdateQueue.size (); if ( iTotalToUpdate ) OutputDebugLine ( SString ( "SpatialDatabase::FlushUpdateQueue TotalToUpdate: %d TotalUpdated: %d m_InfoMap: %d tree: %d ", iTotalToUpdate, iTotalUpdated, m_InfoMap.size (), m_Tree.Count () ) ); #endif }
/////////////////////////////////////////////////////////////// // // CClientModelCacheManagerImpl::InsertIntoNeedCacheList // // Update model id closest distance // /////////////////////////////////////////////////////////////// void CClientModelCacheManagerImpl::InsertIntoNeedCacheList(std::map<ushort, float>& outNeedCacheList, ushort usModelId, float fDistSq) { float* pfDistSqCurrent = MapFind(outNeedCacheList, usModelId); if (!pfDistSqCurrent) { MapSet(outNeedCacheList, usModelId, fDistSq); return; } if (fDistSq < *pfDistSqCurrent) *pfDistSqCurrent = fDistSq; }
/////////////////////////////////////////////////////////////// // // CPerfStatLuaMemoryImpl::LuaMemory // // // /////////////////////////////////////////////////////////////// void CPerfStatLuaMemoryImpl::UpdateLuaMemory ( CLuaMain* pLuaMain, int iMemUsed ) { CLuaMainMemory* pLuaMainMemory = MapFind ( AllLuaMemory.LuaMainMemoryMap, pLuaMain ); if ( !pLuaMainMemory ) { MapSet ( AllLuaMemory.LuaMainMemoryMap, pLuaMain, CLuaMainMemory() ); pLuaMainMemory = MapFind ( AllLuaMemory.LuaMainMemoryMap, pLuaMain ); } pLuaMainMemory->Delta += iMemUsed - pLuaMainMemory->Current; pLuaMainMemory->Current = iMemUsed; pLuaMainMemory->Max = Max ( pLuaMainMemory->Max, pLuaMainMemory->Current ); pLuaMainMemory->OpenXMLFiles = pLuaMain->GetXMLFileCount (); pLuaMainMemory->Refs = pLuaMain->m_CallbackTable.size (); pLuaMainMemory->TimerCount = pLuaMain->GetTimerCount (); pLuaMainMemory->ElementCount = pLuaMain->GetElementCount (); pLuaMainMemory->TextDisplayCount = pLuaMain->GetTextDisplayCount (); pLuaMainMemory->TextItemCount = pLuaMain->GetTextItemCount (); }
// First result as string bool CArgMap::Get ( const SString& strCmd, SString& strOut, const char* szDefault ) const { assert ( szDefault ); if ( const SString* pResult = MapFind ( m_Map, Escape ( strCmd ) ) ) { strOut = Unescape ( *pResult ); return true; } strOut = szDefault; return false; }
/////////////////////////////////////////////////////////////// // // CCameraSpatialDatabaseImpl::RemoveItem // // Remove an item from the database // /////////////////////////////////////////////////////////////// void CCameraSpatialDatabaseImpl::RemoveItem ( CPlayerCamera* pCamera ) { // Remove from the tree and info map SItemInfo* pInfo = MapFind ( m_InfoMap, pCamera ); if ( pInfo ) { m_Tree.Remove ( &pInfo->box.vecMin.fX, &pInfo->box.vecMax.fX, pCamera ); MapRemove ( m_InfoMap, pCamera ); } // Remove from the update queue MapRemove ( m_UpdateQueue, pCamera ); }
/////////////////////////////////////////////////////////////// // // CSpatialDatabaseImpl::RemoveEntity // // Remove an entity from the database // /////////////////////////////////////////////////////////////// void CSpatialDatabaseImpl::RemoveEntity ( CElement* pEntity ) { // Remove from the tree and info map SEntityInfo* pInfo = MapFind ( m_InfoMap, pEntity ); if ( pInfo ) { m_Tree.Remove ( &pInfo->box.vecMin.fX, &pInfo->box.vecMax.fX, pEntity ); MapRemove ( m_InfoMap, pEntity ); } // Remove from the update queue MapRemove ( m_UpdateQueue, pEntity ); }
//////////////////////////////////////////////////////////////// // // CRenderWareSA::GetModelTexturesInfo // // Find/create texture info for a modelid // //////////////////////////////////////////////////////////////// CModelTexturesInfo* CRenderWareSA::GetModelTexturesInfo ( ushort usModelId ) { if ( !pGame->GetModelInfo ( usModelId ) ) return NULL; ushort usTxdId = pGame->GetModelInfo ( usModelId )->GetTextureDictionaryID (); CModelTexturesInfo* pInfo = MapFind ( ms_ModelTexturesInfoMap, usTxdId ); if ( !pInfo ) { // Get txd RwTexDictionary* pTxd = CTxdStore_GetTxd ( usTxdId ); if ( !pTxd ) { pGame->GetModelInfo ( usModelId )->Request ( BLOCKING, "CRenderWareSA::GetModelTexturesInfo" ); CTxdStore_AddRef ( usTxdId ); ( (void (__cdecl *)(unsigned short))FUNC_RemoveModel )( usModelId ); pTxd = CTxdStore_GetTxd ( usTxdId ); } else { CTxdStore_AddRef ( usTxdId ); } if ( !pTxd ) return NULL; // Add new info MapSet ( ms_ModelTexturesInfoMap, usTxdId, CModelTexturesInfo () ); pInfo = MapFind ( ms_ModelTexturesInfoMap, usTxdId ); pInfo->usTxdId = usTxdId; pInfo->pTxd = pTxd; // Save original textures GetTxdTextures ( pInfo->originalTextures, pInfo->pTxd ); } return pInfo; }
// Increment use count for an existing lua ref void luaM_inc_use ( lua_State *luaVM, int iFunction, const void* pFuncPtr ) { if ( !luaVM ) return; CLuaMain* pLuaMain = g_pGame->GetLuaManager ()->GetVirtualMachine ( luaVM ); if ( !pLuaMain ) return; CRefInfo* pInfo = MapFind ( pLuaMain->m_CallbackTable, pFuncPtr ); assert ( pInfo ); assert ( pInfo->iFunction == iFunction ); pInfo->ulUseCount++; }
/////////////////////////////////////////////////////////////// // // CAdditionalVertexStreamManager::CreateAdditionalStreamInfo // // // /////////////////////////////////////////////////////////////// SAdditionalStreamInfo* CAdditionalVertexStreamManager::CreateAdditionalStreamInfo ( const SCurrentStateInfo& state ) { SAdditionalStreamInfo* pAdditionalInfo = MapFind ( m_AdditionalStreamInfoMap, state.stream1.pStreamData ); if ( !pAdditionalInfo ) { // Create it SAdditionalStreamInfo info; // Create new decleration D3DVERTEXELEMENT9 elements[MAXD3DDECLLENGTH]; assert ( state.decl.numElements > 3 && state.decl.numElements < 5 ); memcpy ( elements, state.decl.elements, state.decl.numElements * sizeof ( D3DVERTEXELEMENT9 ) ); D3DVERTEXELEMENT9* declNew = &elements[ state.decl.numElements - 1 ]; elements[ state.decl.numElements ] = *declNew; declNew->Stream = 2; declNew->Offset = 0; declNew->Type = D3DDECLTYPE_FLOAT3; declNew->Method = D3DDECLMETHOD_DEFAULT; declNew->Usage = D3DDECLUSAGE_NORMAL; declNew->UsageIndex = 0; if ( FAILED( m_pDevice->CreateVertexDeclaration ( elements, &info.pVertexDeclaration ) ) ) return false; // Create new stream info.Stride = sizeof ( float ) * 3; UINT Size2 = ConvertPTSize ( state.decl.VertexBufferDesc1.Size ); if ( FAILED( m_pDevice->CreateVertexBuffer( Size2, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &info.pStreamData, NULL ) ) ) return false; // Save info MapSet ( m_AdditionalStreamInfoMap, state.stream1.pStreamData, info ); pAdditionalInfo = MapFind ( m_AdditionalStreamInfoMap, state.stream1.pStreamData ); } return pAdditionalInfo; }
// // CHudSA::IsComponentVisible // bool CHudSA::IsComponentVisible ( eHudComponent component ) { SHudComponent* pComponent = MapFind ( m_HudComponentMap, component ); if ( pComponent ) { // Determine if invisible by matching data with disabled values uchar* pSrc = (uchar*)( &pComponent->disabledData ); uchar* pDest = (uchar*)( pComponent->uiDataAddr ); if ( memcmp ( pDest, pSrc, pComponent->uiDataSize ) == 0 ) return false; // Matches disabled bytes return true; } return false; }
//////////////////////////////////////////////////////////////// // // CShaderItem::SetValue // // Set up to 16 floats // //////////////////////////////////////////////////////////////// bool CShaderItem::SetValue ( const SString& strName, const float* pfValues, uint uiCount ) { if ( D3DXHANDLE* phParameter = MapFind ( m_pEffectWrap->m_valueHandleMap, strName.ToUpper () ) ) { // Check if value is changing if ( !m_pShaderInstance->CmpFloatsValue( *phParameter, pfValues, uiCount ) ) { // Check if we need a new shader instance MaybeRenewShaderInstance (); m_pShaderInstance->SetFloatsValue( *phParameter, pfValues, uiCount ); } return true; } return false; }
//////////////////////////////////////////////////////////////// // // CShaderItem::SetValue // // Set one bool // //////////////////////////////////////////////////////////////// bool CShaderItem::SetValue ( const SString& strName, bool bValue ) { if ( D3DXHANDLE* phParameter = MapFind ( m_pEffectWrap->m_valueHandleMap, strName.ToUpper () ) ) { // Check if value is changing if ( !m_pShaderInstance->CmpBoolValue( *phParameter, bValue ) ) { // Check if we need a new shader instance MaybeRenewShaderInstance (); m_pShaderInstance->SetBoolValue( *phParameter, bValue ); } return true; } return false; }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::InsertQueryArguments // // Insert arguments and apply correct escapement for the connection type // /////////////////////////////////////////////////////////////// SString CDatabaseManagerImpl::InsertQueryArguments ( SConnectionHandle hConnection, const char* szQuery, va_list vl ) { // Determine connection type SString* pstrType = MapFind ( m_ConnectionTypeMap, hConnection ); SString strType = pstrType ? *pstrType : ""; if ( strType == "sqlite" ) return InsertQueryArgumentsSqlite ( szQuery, vl ); else if ( strType == "mysql" ) return InsertQueryArgumentsMySql ( szQuery, vl ); // 'Helpful' error message CLogger::ErrorPrintf ( "DatabaseManager internal error #2" ); return ""; }
void CPlayer::RemovePlayerFromDistLists ( CPlayer* pOther ) { dassert ( MapContains ( m_NearPlayerList, pOther ) || MapContains ( m_FarPlayerList, pOther ) ); #ifdef MTA_DEBUG SViewerInfo info; SViewerInfo* pInfo = MapFind ( m_NearPlayerList, pOther ); if ( pInfo ) info = *pInfo; dassert ( MapContains ( m_PureSyncSimSendList, pOther ) == info.bInPureSyncSimSendList ); #endif MapRemove ( m_PureSyncSimSendList, pOther ); m_bPureSyncSimSendListDirty = true; MapRemove ( m_NearPlayerList, pOther ); MapRemove ( m_FarPlayerList, pOther ); }
//////////////////////////////////////////////////////////// // // CClientSound::GetMetaTags // // If the stream is not active, this may not work correctly // //////////////////////////////////////////////////////////// SString CClientSound::GetMetaTags( const SString& strFormat ) { SString strMetaTags = ""; if ( m_pAudio ) { strMetaTags = m_pAudio->GetMetaTags ( strFormat ); m_SavedTags[ strFormat ] = strMetaTags; } else { // Search previously found tags for this stream when it is not active // This may not be such a good idea btw if ( SString* pstrMetaTags = MapFind ( m_SavedTags, strFormat ) ) strMetaTags = *pstrMetaTags; } return strMetaTags; }
//////////////////////////////////////////////////////////////// // // CClientRenderElementManager::Remove // // Called when an element is being deleted. // Remove from lists and release render item // //////////////////////////////////////////////////////////////// void CClientRenderElementManager::Remove ( CClientRenderElement* pElement ) { // Validate assert ( pElement == *MapFind( m_ItemElementMap, pElement->GetRenderItem () ) ); // Remove from this managers list MapRemove ( m_ItemElementMap, pElement->GetRenderItem () ); // Remove from auto texture map if ( pElement->IsTransmit( LUACLASS_CORETEXTURE ) ) { for ( std::map < SString, CClientTexture* >::iterator iter = m_AutoTextureMap.begin () ; iter != m_AutoTextureMap.end () ; ++iter ) { if ( iter->second == pElement ) { m_AutoTextureMap.erase ( iter ); break; } } } // Update stats if ( pElement->IsTransmit( LUACLASS_DXFONT ) ) m_uiStatsDxFontCount--; else if ( pElement->IsTransmit( LUACLASS_GUIFONT ) ) m_uiStatsGuiFontCount--; else if ( pElement->IsTransmit( LUACLASS_SHADER ) ) m_uiStatsShaderCount--; else if ( pElement->IsTransmit( LUACLASS_CORERENDERTARGET ) ) m_uiStatsRenderTargetCount--; else if ( pElement->IsTransmit( LUACLASS_CORESCREENSOURCE ) ) m_uiStatsScreenSourceCount--; else if ( pElement->IsTransmit( LUACLASS_CORETEXTURE ) ) m_uiStatsTextureCount--; // Release render item pElement->GetRenderItem()->Release(); }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::InsertQueryArguments // // Insert arguments and apply correct escapement for the connection type // /////////////////////////////////////////////////////////////// SString CDatabaseManagerImpl::InsertQueryArguments ( SConnectionHandle hConnection, const SString& strQuery, CLuaArguments* pArgs ) { // Check for case of no arguments if ( !pArgs ) return strQuery; // Determine connection type SString* pstrType = MapFind ( m_ConnectionTypeMap, hConnection ); SString strType = pstrType ? *pstrType : ""; if ( strType == "sqlite" ) return InsertQueryArgumentsSqlite ( strQuery, pArgs ); else if ( strType == "mysql" ) return InsertQueryArgumentsMySql ( strQuery, pArgs ); // 'Helpful' error message CLogger::ErrorPrintf ( "DatabaseManager internal error #1\n" ); return ""; }
// Assumes CSimControl::UpdatePuresyncSimPlayer is called soon after this function void CPlayer::MovePlayerToFarList ( CPlayer* pOther ) { OutputDebugLine ( SString ( "[Sync] -- %s: Move %s to farlist", GetNick (), pOther->GetNick () ) ); dassert ( MapContains ( m_NearPlayerList, pOther ) && !MapContains ( m_FarPlayerList, pOther ) ); SViewerInfo* pInfo = MapFind ( m_NearPlayerList, pOther ); #ifdef MTA_DEBUG dassert ( MapContains ( m_PureSyncSimSendList, pOther ) == pInfo->bInPureSyncSimSendList ); #endif if ( pInfo->bInPureSyncSimSendList ) { MapRemove ( m_PureSyncSimSendList, pOther ); m_bPureSyncSimSendListDirty = true; pInfo->bInPureSyncSimSendList = false; } MapSet ( m_FarPlayerList, pOther, *pInfo ); MapRemove ( m_NearPlayerList, pOther ); }
// Decrement use count for an existing lua ref void luaM_dec_use ( lua_State *luaVM, int iFunction, const void* pFuncPtr ) { if ( !luaVM ) return; CLuaMain* pLuaMain = g_pGame->GetLuaManager ()->GetVirtualMachine ( luaVM ); if ( !pLuaMain ) return; CRefInfo* pInfo = MapFind ( pLuaMain->m_CallbackTable, pFuncPtr ); assert ( pInfo ); assert ( pInfo->iFunction == iFunction ); if ( --pInfo->ulUseCount == 0 ) { // Remove on last unuse lua_unref ( luaVM, iFunction ); MapRemove ( pLuaMain->m_CallbackTable, pFuncPtr ); MapRemove ( pLuaMain->m_FunctionTagMap, iFunction ); } }
/////////////////////////////////////////////////////////////// // // CResourceChecker::CheckVersionRequirements // // Update m_strReqClientVersion or m_strReqServerVersion with the version requirement for the // supplied identifier // /////////////////////////////////////////////////////////////// void CResourceChecker::CheckVersionRequirements ( const string& strIdentifierName, bool bClientScript ) { // if ( MTASA_VERSION_TYPE < VERSION_TYPE_RELEASE ) // return; static CHashMap < SString, SString > clientFunctionMap; static CHashMap < SString, SString > serverFunctionMap; // Check if lookup maps need initializing if ( clientFunctionMap.empty () ) { for ( uint i = 0 ; i < NUMELMS( clientFunctionInitList ) ; i++ ) MapSet ( clientFunctionMap, clientFunctionInitList[i].functionName, clientFunctionInitList[i].minMtaVersion ); for ( uint i = 0 ; i < NUMELMS( serverFunctionInitList ) ; i++ ) MapSet ( serverFunctionMap, serverFunctionInitList[i].functionName, serverFunctionInitList[i].minMtaVersion ); } // Select client or server check const CHashMap < SString, SString >& functionMap = bClientScript ? clientFunctionMap : serverFunctionMap; SString& strReqMtaVersion = bClientScript ? m_strReqClientVersion : m_strReqServerVersion; SString& strReqMtaReason = bClientScript ? m_strReqClientReason : m_strReqServerReason; const SString* pResult = MapFind ( functionMap, strIdentifierName ); if ( pResult ) { // This identifier has a version requirement const SString& strResult = *pResult; // Is the new requirement relevant for this MTA generation if ( strResult > CStaticFunctionDefinitions::GetVersionSortable ().Left ( 3 ) ) { // Is the new requirement higher than the current? if ( strResult > strReqMtaVersion ) { strReqMtaVersion = strResult; strReqMtaReason = strIdentifierName; } } } }
int rva_to_offset(int pid, void *address) { char filename[1024]; FILE *fd = NULL; char *sptr = NULL; char buf[1024]; char perm[5]; MemoryMapInfo *mptr = NULL; #ifdef defined(__i386__) uint32_t addr_begin, addr_end, size; #else uint32_t addr_begin, addr_end, size; #endif sprintf(filename, "/proc/%d/maps", pid); if ((fd = fopen(filename, "r")) == NULL) return -1; // lets skip the first line fgets(buf,1024,fd); while (fgets(buf,1024,fd)) { if ((sptr = strchr(buf, '\r')) != NULL) *sptr = 0; if ((sptr = strchr(buf, '\n')) != NULL) *sptr = 0; //printf("\n%s\n", buf); sscanf(buf, "%x-%x %4s %x %*s %*s %*s", &addr_begin, &addr_end, perm, &size, sptr, sptr, sptr); if ((mptr = MapFind(addr_begin)) == NULL) { mptr = (MemoryMapInfo *)calloc(1,sizeof(MemoryMapInfo)); if (mptr != NULL) { mptr->start = addr_begin; mptr->end = addr_end; mptr->size = size; mptr->next = map_list; map_list = mptr; printf("Addr %08X -> %08X perm %s size %X\n", addr_begin, addr_end, perm, size); } } } fclose(fd); }
///////////////////////////////////////////////////////////// // // CDirect3DEvents9::SetVertexDeclaration // // Ensures the correct object gets sent to D3D // ///////////////////////////////////////////////////////////// HRESULT CDirect3DEvents9::SetVertexDeclaration ( IDirect3DDevice9 *pDevice, IDirect3DVertexDeclaration9* pDecl ) { if( pDecl ) { // See if it's a proxy CProxyDirect3DVertexDeclaration* pProxy = NULL; pDecl->QueryInterface ( CProxyDirect3DVertexDeclaration_GUID, (void**)&pProxy ); // If so, use the original vertex declaration if ( pProxy ) { pDecl = pProxy->GetOriginal (); // Update state info CProxyDirect3DDevice9::SD3DVertexDeclState* pInfo = MapFind ( g_pProxyDevice->m_VertexDeclMap, pProxy ); if ( pInfo ) g_pDeviceState->VertexDeclState = *pInfo; } } return pDevice->SetVertexDeclaration ( pDecl ); }
// // CHudSA::SetComponentVisible // void CHudSA::SetComponentVisible ( eHudComponent component, bool bVisible ) { // Handle ALL option if ( component == HUD_ALL ) { for ( std::map < eHudComponent, SHudComponent >::iterator iter = m_HudComponentMap.begin () ; iter != m_HudComponentMap.end () ; ++iter ) { const SHudComponent& component = iter->second; if ( component.bIsPartOfAll ) SetComponentVisible ( component.type, bVisible ); } return; } // Set visiblity of one component SHudComponent* pComponent = MapFind ( m_HudComponentMap, component ); if ( pComponent ) { // Save original bytes if requred if ( pComponent->bSaveOriginalBytes ) { pComponent->origData = *(DWORD*)pComponent->uiDataAddr; pComponent->bSaveOriginalBytes = false; } // Poke bytes uchar* pSrc = (uchar*)( bVisible ? &pComponent->origData : &pComponent->disabledData ); uchar* pDest = (uchar*)( pComponent->uiDataAddr ); for ( uint i = 0 ; i < pComponent->uiDataSize ; i++ ) { if ( pComponent->type != HUD_CLOCK ) MemPut < BYTE > ( pDest + i, pSrc[i] ); else MemPutFast < BYTE > ( pDest + i, pSrc[i] ); } } }
/////////////////////////////////////////////////////////////// // // CClientSpatialDatabaseImpl::FlushUpdateQueue // // Process all entities that have changed since the last call // /////////////////////////////////////////////////////////////// void CClientSpatialDatabaseImpl::FlushUpdateQueue ( void ) { std::map < CClientEntity*, int > updateQueueCopy = m_UpdateQueue; m_UpdateQueue.clear (); for ( std::map < CClientEntity*, int >::iterator it = updateQueueCopy.begin (); it != updateQueueCopy.end (); ++it ) { CClientEntity* pEntity = it->first; // Get the new bounding box SEntityInfo newInfo; CSphere sphere = pEntity->GetWorldBoundingSphere (); newInfo.box = CBox ( sphere.vecPosition, fabsf ( sphere.fRadius ) ); // Make everything 2D for now newInfo.box.vecMin.fZ = SPATIAL_2D_Z; newInfo.box.vecMax.fZ = SPATIAL_2D_Z; // Get previous info if ( SEntityInfo* pOldInfo = MapFind ( m_InfoMap, pEntity ) ) { // Don't update if bounding box is the same if ( pOldInfo->box == newInfo.box ) continue; // Remove old bounding box from tree m_Tree.Remove ( &pOldInfo->box.vecMin.fX, &pOldInfo->box.vecMax.fX, pEntity ); } if ( !IsValidSphere ( sphere ) ) continue; // Add new bounding box m_Tree.Insert( &newInfo.box.vecMin.fX, &newInfo.box.vecMax.fX, pEntity ); // Update info map MapSet ( m_InfoMap, pEntity, newInfo ); } }
/////////////////////////////////////////////////////////////// // // CSpatialDatabaseImpl::IsEntityPresent // // Check if an entity is in the database // /////////////////////////////////////////////////////////////// bool CSpatialDatabaseImpl::IsEntityPresent ( CElement* pEntity ) { return MapFind ( m_InfoMap, pEntity ) != NULL || MapFind ( m_UpdateQueue, pEntity ) != NULL; }
///////////////////////////////////////////////////////////// // // CAdditionalVertexStreamManager::UpdateAdditionalStreamContent // // Generate data in the additional stream // ///////////////////////////////////////////////////////////// bool CAdditionalVertexStreamManager::UpdateAdditionalStreamContent ( SCurrentStateInfo& state, SAdditionalStreamInfo* pAdditionalInfo, uint ReadOffsetStart, uint ReadSize, uint WriteOffsetStart, uint WriteSize ) { //HRESULT hr; IDirect3DVertexBuffer9* pStreamDataPT = state.stream1.pStreamData; IDirect3DVertexBuffer9* pStreamDataN = pAdditionalInfo->pStreamData; uint StridePT = 20; uint StrideN = 12; uint NumVerts = ReadSize / StridePT; assert ( NumVerts == WriteSize / StrideN ); // Get the source vertex bytes std::vector < uchar > sourceArray; sourceArray.resize ( ReadSize ); uchar* pSourceArrayBytes = &sourceArray[0]; { void* pVertexBytesPT = NULL; if ( FAILED( pStreamDataPT->Lock ( ReadOffsetStart, ReadSize, &pVertexBytesPT, D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY ) ) ) return false; memcpy ( pSourceArrayBytes, pVertexBytesPT, ReadSize ); pStreamDataPT->Unlock (); } // Create dest byte buffer std::vector < uchar > destArray; destArray.resize ( WriteSize ); uchar* pDestArrayBytes = &destArray[0]; // Compute dest bytes { // Get index buffer if ( FAILED( m_pDevice->GetIndices( &state.pIndexData ) ) ) return false; // Get index buffer desc D3DINDEXBUFFER_DESC IndexBufferDesc; state.pIndexData->GetDesc ( &IndexBufferDesc ); uint numIndices = state.args.primCount + 2; uint step = 1; if ( state.args.PrimitiveType == D3DPT_TRIANGLELIST ) { numIndices = state.args.primCount * 3; step = 3; } assert ( IndexBufferDesc.Size >= ( numIndices + state.args.startIndex ) * 2 ); // Get index buffer data std::vector < uchar > indexArray; indexArray.resize ( ReadSize ); uchar* pIndexArrayBytes = &indexArray[0]; { void* pIndexBytes = NULL; if ( FAILED( state.pIndexData->Lock ( state.args.startIndex*2, numIndices*2, &pIndexBytes, D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY ) ) ) return false; memcpy ( pIndexArrayBytes, pIndexBytes, numIndices*2 ); state.pIndexData->Unlock (); } // Calc normals std::vector < CVector > NormalList; NormalList.insert ( NormalList.end (), NumVerts, CVector () ); std::map < long long, CVector > doneTrisMap; // For each triangle for ( uint i = 0 ; i < numIndices - 2 ; i += step ) { // Get triangle vertex indici WORD v0 = ((WORD*)pIndexArrayBytes)[ i ]; WORD v1 = ((WORD*)pIndexArrayBytes)[ i + 1 ]; WORD v2 = ((WORD*)pIndexArrayBytes)[ i + 2 ]; if ( v0 >= NumVerts || v1 >= NumVerts || v2 >= NumVerts ) continue; // vert index out of range if ( v0 == v1 || v0 == v2 || v1 == v2 ) continue; // degenerate tri // Get vertex positions from original stream CVector* pPos0 = (CVector*)( pSourceArrayBytes + v0 * 20 ); CVector* pPos1 = (CVector*)( pSourceArrayBytes + v1 * 20 ); CVector* pPos2 = (CVector*)( pSourceArrayBytes + v2 * 20 ); // Calculate the normal CVector Dir1 = *pPos2 - *pPos1; CVector Dir2 = *pPos0 - *pPos1; CVector Normal = Dir1; Normal.CrossProduct ( &Dir2 ); Normal.Normalize (); // Flip normal if triangle was flipped if ( state.args.PrimitiveType == D3DPT_TRIANGLESTRIP && ( i & 1 ) ) Normal = -Normal; // Try to improve results by ignoring duplicated triangles long long key = getTriKey ( v0, v1, v2 ); if ( CVector* pDoneTriPrevNormal = MapFind ( doneTrisMap, key ) ) { // Already done this tri - Keep prev tri if it has a better 'up' rating if ( pDoneTriPrevNormal->fZ > Normal.fZ ) continue; // Remove effect of prev tri NormalList[ v0 ] -= *pDoneTriPrevNormal; NormalList[ v1 ] -= *pDoneTriPrevNormal; NormalList[ v2 ] -= *pDoneTriPrevNormal; } MapSet ( doneTrisMap, key, Normal ); // Add normal weight to used vertices NormalList[ v0 ] += Normal; NormalList[ v1 ] += Normal; NormalList[ v2 ] += Normal; } // Validate normals and set dest data for ( uint i = 0 ; i < NumVerts ; i++ ) { // Validate CVector& Normal = NormalList[i]; if ( Normal.Normalize () < FLOAT_EPSILON ) Normal = CVector ( 0, 0, 1 ); // Set CVector* pNormal = (CVector*)( pDestArrayBytes + i * 12 ); *pNormal = Normal; } } // Set the dest bytes { void* pVertexBytesN = NULL; if ( FAILED( pStreamDataN->Lock ( WriteOffsetStart, WriteSize, &pVertexBytesN, D3DLOCK_NOSYSLOCK ) ) ) return false; memcpy ( pVertexBytesN, pDestArrayBytes, WriteSize ); pStreamDataN->Unlock (); } return true; }
/////////////////////////////////////////////////////////////// // // CAdditionalVertexStreamManager::GetAdditionalStreamInfo // // // /////////////////////////////////////////////////////////////// SAdditionalStreamInfo* CAdditionalVertexStreamManager::GetAdditionalStreamInfo ( IDirect3DVertexBuffer9* pStreamData1 ) { return MapFind ( m_AdditionalStreamInfoMap, pStreamData1 ); }
/////////////////////////////////////////////////////////////// // // CMemStats::CreateTables // // Create formatted tables for drawing with // /////////////////////////////////////////////////////////////// void CMemStats::CreateTables ( void ) { m_TableList.clear (); // // Color setups // #define YELLOW "#FFFF00" #define RED "#FF0000" #define BLUE "#0000FF" #define WHITE "#FFFFFF" #define LT_RED "#FF5050" #define DK_RED "#CF0000" #define GREY "#808080" #define LT_GREY "#C0C0C0" #define INVIS "#000000" #define DK_GREEN "#00CF00" #define LT_GREEN "#30FF30" #define PURPLE "#FF00FF" #define CYAN "#00FFFF" #define LT_CYAN "#00C0F0" // Table header #define HEADER1(text) LT_CYAN text WHITE // Cell colour depending upon the value SString strNumberColorsCreat = GREY "0," CYAN "999999," ; SString strNumberColorsDstry = GREY "0," PURPLE "999999," ; SString strNumberColorsLockStatic = GREY "0," YELLOW "999999," ; SString strNumberColorsLockDynamic = WHITE "0," WHITE "999999," ; SString strNumberColorsMtaVidMem = LT_GREEN "-999999," GREY "0," LT_RED "999999," ; SString strNumberColorsModels = LT_GREEN "-99999," GREY "0," LT_RED "999999," ; SString strNumberColorsWhite = WHITE "0," WHITE "999999," ; SString strNumberColorsGrey = GREY "0," GREY "999999," ; // // Key for weird codes in table.AddRow string: // // | is usually the cell delimiter character // ~X means replace any following zero with character X // ^2 means use number color ^2 for the following value // { /* GTA vidmemory Lock Create Destroy Total TotalKB StaticVertexBuffer 1 1 1 10 1000 DynamicVertexBuffer 1 1 1 10 1000 StaticIndexBuffer 1 1 1 10 1000 DynamicIndexBuffer 1 1 1 10 1000 StaticTexture 1 1 1 10 1000 DynamicTexture 1 1 1 10 1000 Effect 1 1 1 10 1000 */ static const char* const nameList[] = { "Vertices", "Vertices dynamic", "Indices", "Indices dynamic", "Textures", "Textures dynamic", "Effects" }; static const CProxyDirect3DDevice9::SResourceMemory* const nowList[] = { &m_MemStatsNow.d3dMemory.StaticVertexBuffer, &m_MemStatsNow.d3dMemory.DynamicVertexBuffer, &m_MemStatsNow.d3dMemory.StaticIndexBuffer, &m_MemStatsNow.d3dMemory.DynamicIndexBuffer, &m_MemStatsNow.d3dMemory.StaticTexture, &m_MemStatsNow.d3dMemory.DynamicTexture, &m_MemStatsNow.d3dMemory.Effect }; static const CProxyDirect3DDevice9::SResourceMemory* const deltaList[] = { &m_MemStatsDelta.d3dMemory.StaticVertexBuffer, &m_MemStatsDelta.d3dMemory.DynamicVertexBuffer, &m_MemStatsDelta.d3dMemory.StaticIndexBuffer, &m_MemStatsDelta.d3dMemory.DynamicIndexBuffer, &m_MemStatsDelta.d3dMemory.StaticTexture, &m_MemStatsDelta.d3dMemory.DynamicTexture, &m_MemStatsDelta.d3dMemory.Effect }; m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "100,45:R,40:R,40:R,50:R,60:R" ); table.SetNumberColors ( "^1", strNumberColorsLockStatic ); table.SetNumberColors ( "^2", strNumberColorsLockDynamic ); table.SetNumberColors ( "^3", strNumberColorsCreat ); table.SetNumberColors ( "^4", strNumberColorsDstry ); table.AddRow ( HEADER1( "GTA vid memory" ) "|" HEADER1( "Lock" ) "|" HEADER1( "Creat" ) BLUE "|" HEADER1( "Dstry" ) "|" HEADER1( "Count" ) "|" HEADER1( "Using KB" ) ); for ( uint i = 0 ; i < NUMELMS( nameList ) ; i++ ) { if ( i & 1 ) table.AddRow( SString ( "%s|^2~ %d|^3~.%d|^4~.%d|%d|%s" ,nameList[i] ,deltaList[i]->iLockedCount ,deltaList[i]->iCreatedCount ,deltaList[i]->iDestroyedCount ,nowList[i]->iCurrentCount ,*FormatNumberWithCommas ( nowList[i]->iCurrentBytes / 1024 ) ) ); else table.AddRow( SString ( "%s|^1~ %d|^3~.%d|^4~.%d|%d|%s" ,nameList[i] ,deltaList[i]->iLockedCount ,deltaList[i]->iCreatedCount ,deltaList[i]->iDestroyedCount ,nowList[i]->iCurrentCount ,*FormatNumberWithCommas ( nowList[i]->iCurrentBytes / 1024 ) ) ); } } { /* MTA videoMemory ChangeKB TotalKB FreeForMTA -100 1000 UsedByFonts -100 1000 UsedByTextures -100 1000 UsedByRenderTargets -100 1000 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "110,80:R,80:R" ); table.SetNumberColors ( "^1", strNumberColorsMtaVidMem ); table.AddRow ( HEADER1( "MTA vid memory" ) "|" HEADER1( "Change KB" ) "|" HEADER1( "Using KB" ) ); table.AddRow ( SString ( "FreeForMTA|^1~.%s|%s", *FormatNumberWithCommas ( m_MemStatsDelta.dxStatus.videoMemoryKB.iFreeForMTA ), *FormatNumberWithCommas ( m_MemStatsNow.dxStatus.videoMemoryKB.iFreeForMTA ) ) ); table.AddRow ( SString ( "Fonts|^1~.%s|%s", *FormatNumberWithCommas ( m_MemStatsDelta.dxStatus.videoMemoryKB.iUsedByFonts ), *FormatNumberWithCommas ( m_MemStatsNow.dxStatus.videoMemoryKB.iUsedByFonts ) ) ); table.AddRow ( SString ( "Textures|^1~.%s|%s", *FormatNumberWithCommas ( m_MemStatsDelta.dxStatus.videoMemoryKB.iUsedByTextures ), *FormatNumberWithCommas ( m_MemStatsNow.dxStatus.videoMemoryKB.iUsedByTextures ) ) ); table.AddRow ( SString ( "RenderTargets|^1~.%s|%s", *FormatNumberWithCommas ( m_MemStatsDelta.dxStatus.videoMemoryKB.iUsedByRenderTargets ), *FormatNumberWithCommas ( m_MemStatsNow.dxStatus.videoMemoryKB.iUsedByRenderTargets ) ) ); } { /* GTA memory ChangeKB TotalKB iProcessMemSizeKB -100 1000 streamMemSizeKB -100 1000 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "110,30:R,50:R,80:R" ); table.SetNumberColors ( "^1", strNumberColorsMtaVidMem ); table.AddRow ( HEADER1( "GTA memory" ) "| |" HEADER1( "Change KB" ) "|" HEADER1( "Using KB" ) ); table.AddRow ( SString ( "Process memory| | |%s", *FormatNumberWithCommas ( m_MemStatsNow.iProcessMemSizeKB - m_MemStatsNow.iStreamingMemoryUsed / 1024 ) ) ); table.AddRow ( SString ( "Streaming memory| |^1~.%s|%s", *FormatNumberWithCommas ( m_MemStatsDelta.iStreamingMemoryUsed / 1024 ), *FormatNumberWithCommas ( m_MemStatsNow.iStreamingMemoryUsed / 1024 ) ) ); table.AddRow ( SString ( "|Total:|^1~.%s|%s", *FormatNumberWithCommas ( m_MemStatsDelta.iProcessMemSizeKB ), *FormatNumberWithCommas ( m_MemStatsNow.iProcessMemSizeKB ) ) ); } { /* Settings AmountKB videoCardInstalledMemoryKB 2000 streamMemSettingKB 2000 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "140,130:R" ); table.AddRow ( HEADER1( "GTA settings" ) "|" HEADER1( "Setting KB" ) ); table.AddRow ( SString ( "Video card installed memory|%s", *FormatNumberWithCommas ( m_MemStatsNow.dxStatus.videoCard.iInstalledMemoryKB ) ) ); table.AddRow ( SString ( "Streaming memory limit|%s", *FormatNumberWithCommas ( m_MemStatsNow.iStreamingMemoryAvailable / 1024 ) ) ); table.AddRow ( SString ( "Process memory limit|%s", *FormatNumberWithCommas ( m_MemStatsNow.iProcessTotalVirtualKB ) ) ); } { /* RW resources Change Count Textures 0 Rasters 0 Geometries 0 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "140,50:R,60:R" ); table.SetNumberColors ( "^1", strNumberColorsModels ); table.AddRow ( HEADER1( "RW resources" ) "|" HEADER1( "Change" ) "|" HEADER1( "Count" ) ); table.AddRow ( SString ( "Textures|^1~.%d|%d", m_MemStatsDelta.rwResourceStats.uiTextures, m_MemStatsNow.rwResourceStats.uiTextures ) ); table.AddRow ( SString ( "Rasters|^1~.%d|%d", m_MemStatsDelta.rwResourceStats.uiRasters, m_MemStatsNow.rwResourceStats.uiRasters ) ); table.AddRow ( SString ( "Geometries|^1~.%d|%d", m_MemStatsDelta.rwResourceStats.uiGeometries, m_MemStatsNow.rwResourceStats.uiGeometries ) ); } { /* Clothes cache Change Count Cache hit 0 Cache miss 0 Clothes in use 0 Clothes ready for use 0 Old removed 0 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "140,50:R,60:R" ); table.SetNumberColors ( "^0", strNumberColorsWhite ); table.SetNumberColors ( "^1", strNumberColorsModels ); table.SetNumberColors ( "^3", strNumberColorsCreat ); table.SetNumberColors ( "^4", strNumberColorsLockStatic ); table.SetNumberColors ( "^5", strNumberColorsGrey ); table.AddRow ( HEADER1( "Clothes cache" ) "|" HEADER1( "Change" ) "|" HEADER1( "Count" ) ); table.AddRow ( SString ( "Cache hit|^3~ %d|^5~.%d", m_MemStatsDelta.clothesCacheStats.uiCacheHit, m_MemStatsNow.clothesCacheStats.uiCacheHit ) ); table.AddRow ( SString ( "Cache miss|^4~ %d|^5~.%d", m_MemStatsDelta.clothesCacheStats.uiCacheMiss, m_MemStatsNow.clothesCacheStats.uiCacheMiss ) ); table.AddRow ( SString ( "Clothes in use|^1~.%d|^0%d", m_MemStatsDelta.clothesCacheStats.uiNumTotal - m_MemStatsDelta.clothesCacheStats.uiNumUnused, m_MemStatsNow.clothesCacheStats.uiNumTotal - m_MemStatsNow.clothesCacheStats.uiNumUnused ) ); table.AddRow ( SString ( "Clothes ready for use|^1~.%d|%d", m_MemStatsDelta.clothesCacheStats.uiNumUnused, m_MemStatsNow.clothesCacheStats.uiNumUnused ) ); table.AddRow ( SString ( "Old removed|^1~.%d|^5%d", m_MemStatsDelta.clothesCacheStats.uiNumRemoved, m_MemStatsNow.clothesCacheStats.uiNumRemoved ) ); } { m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "110,50:R,60:R,60:R" ); table.SetNumberColors ( "^0", strNumberColorsWhite ); table.SetNumberColors ( "^1", strNumberColorsModels ); table.SetNumberColors ( "^3", strNumberColorsCreat ); table.SetNumberColors ( "^4", strNumberColorsLockStatic ); table.SetNumberColors ( "^5", strNumberColorsGrey ); table.AddRow ( HEADER1( "Model cache" ) "|" HEADER1( "Max" ) "|" HEADER1( "Change" ) "|" HEADER1( "Count" ) ); table.AddRow ( SString ( "Players|^3~ %d|^5~.%d|^1~.%d", m_MemStatsNow.modelCacheStats.uiMaxNumPedModels, m_MemStatsDelta.modelCacheStats.uiNumPedModels, m_MemStatsNow.modelCacheStats.uiNumPedModels ) ); table.AddRow ( SString ( "Vehicles|^3~ %d|^5~.%d|^1~.%d", m_MemStatsNow.modelCacheStats.uiMaxNumVehicleModels, m_MemStatsDelta.modelCacheStats.uiNumVehicleModels, m_MemStatsNow.modelCacheStats.uiNumVehicleModels ) ); } { /* Model usage Change Amount 0-288 Players 1 10 289-399 Other1 1 10 400-611 Vehicles 1 10 612-999 Other2 1 10 1000-1193 Upgrades 1 10 1194-19999 Other3 1 10 20000-24999 Textures 1 10 24999-27000 Other4 1 10 Total 1 10 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "90,50,50:R,60:R" ); table.SetNumberColors ( "^1", strNumberColorsModels ); table.AddRow ( HEADER1( "Models in memory" ) "| |" HEADER1( "Change" ) "|" HEADER1( "Count" ) ); table.AddRow ( SString ( "0-312|(Players)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiPlayerModels_0_312, m_MemStatsNow.modelInfo.uiPlayerModels_0_312 ) ); table.AddRow ( SString ( "313-317| |^1~.%d|%d", m_MemStatsDelta.modelInfo.uiUnknown_313_317, m_MemStatsNow.modelInfo.uiUnknown_313_317 ) ); table.AddRow ( SString ( "318-372|(Weapons)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiWeaponModels_318_372, m_MemStatsNow.modelInfo.uiWeaponModels_318_372 ) ); table.AddRow ( SString ( "373-399| |^1~.%d|%d", m_MemStatsDelta.modelInfo.uiUnknown_373_399, m_MemStatsNow.modelInfo.uiUnknown_373_399 ) ); table.AddRow ( SString ( "400-611|(Vehicles)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiVehicles_400_611, m_MemStatsNow.modelInfo.uiVehicles_400_611 ) ); table.AddRow ( SString ( "612-999| |^1~.%d|%d", m_MemStatsDelta.modelInfo.uiUnknown_612_999, m_MemStatsNow.modelInfo.uiUnknown_612_999 ) ); table.AddRow ( SString ( "1000-1193|(Upgrades)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiUpgrades_1000_1193, m_MemStatsNow.modelInfo.uiUpgrades_1000_1193 ) ); table.AddRow ( SString ( "1194-19999|(World)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiUnknown_1194_19999, m_MemStatsNow.modelInfo.uiUnknown_1194_19999 ) ); table.AddRow ( SString ( "20000-24999|(Textures)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiTextures_20000_24999, m_MemStatsNow.modelInfo.uiTextures_20000_24999 ) ); table.AddRow ( SString ( "25000-25254|(Collisions)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiCollisions_25000_25254, m_MemStatsNow.modelInfo.uiCollisions_25000_25254 ) ); table.AddRow ( SString ( "25255-25510|(Ipls)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiIpls_25255_25510, m_MemStatsNow.modelInfo.uiIpls_25255_25510 ) ); table.AddRow ( SString ( "25511-25574|(Paths)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiPaths_25511_25574, m_MemStatsNow.modelInfo.uiPaths_25511_25574 ) ); table.AddRow ( SString ( "25575-25754|(Anims)|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiAnims_25575_25754, m_MemStatsNow.modelInfo.uiAnims_25575_25754 ) ); table.AddRow ( SString ( "|Total:|^1~.%d|%d", m_MemStatsDelta.modelInfo.uiTotal, m_MemStatsNow.modelInfo.uiTotal ) ); } { /* World shader replacements Change Count World texture draws 0 World shader draws 0 World texture total 0 World shader total 0 Entites explicitly shadered 0 */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "160,50:R,60:R" ); table.AddRow ( HEADER1( "World shader replacements" ) "|" HEADER1( "Change" ) "|" HEADER1( "Count" ) ); table.AddRow ( SString ( "World texture draws|^1~ %d|%d", m_MemStatsDelta.shaderReplacementStats.uiNumReplacementRequests, m_MemStatsNow.shaderReplacementStats.uiNumReplacementRequests ) ); table.AddRow ( SString ( "World shader draws|^1~ %d|%d", m_MemStatsDelta.shaderReplacementStats.uiNumReplacementMatches, m_MemStatsNow.shaderReplacementStats.uiNumReplacementMatches ) ); table.AddRow ( SString ( "World shader full setup|^1~ %d|%d", m_MemStatsDelta.frameStats.iNumShadersFullSetup, m_MemStatsNow.frameStats.iNumShadersFullSetup ) ); table.AddRow ( SString ( "World shader reuse setup|^1~ %d|%d", m_MemStatsDelta.frameStats.iNumShadersReuseSetup, m_MemStatsNow.frameStats.iNumShadersReuseSetup ) ); table.AddRow ( SString ( "World texture total|^1~ %d|%d", m_MemStatsDelta.shaderReplacementStats.uiTotalTextures, m_MemStatsNow.shaderReplacementStats.uiTotalTextures ) ); table.AddRow ( SString ( "World shader total|^1~ %d|%d", m_MemStatsDelta.shaderReplacementStats.uiTotalShaders, m_MemStatsNow.shaderReplacementStats.uiTotalShaders ) ); table.AddRow ( SString ( "Known entities|^1~ %d|%d", m_MemStatsDelta.shaderReplacementStats.uiTotalEntitesRefed, m_MemStatsNow.shaderReplacementStats.uiTotalEntitesRefed ) ); } { /* World shader channels NumTex Shader+Entites *blah . 0 . 0 */ SShaderReplacementStats& now = m_MemStatsNow.shaderReplacementStats; SShaderReplacementStats& delta = m_MemStatsDelta.shaderReplacementStats; m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetNumberColors ( "^1", strNumberColorsModels ); table.SetColumnWidths( "180,40:R,35:R,40:R,35:R" ); table.AddRow ( HEADER1( "World shader channels" ) "|" HEADER1( " " ) "|" HEADER1( "NumTex" ) "|" HEADER1( " " ) "|" HEADER1( "Shad&Ent" ) ); for ( std::map < uint, SMatchChannelStats >::iterator iter = now.channelStatsList.begin () ; iter != now.channelStatsList.end () ; ++iter ) { uint uiId = iter->first; const SMatchChannelStats& channelStatsNow = iter->second; SMatchChannelStats* pChannelStatsDelta = MapFind ( delta.channelStatsList, uiId ); assert ( pChannelStatsDelta ); table.AddRow( SString ( "%s|^1~.%d|%d|^1~.%d|%d" ,*channelStatsNow.strTag ,pChannelStatsDelta->uiNumMatchedTextures ,channelStatsNow.uiNumMatchedTextures ,pChannelStatsDelta->uiNumShaderAndEntities ,channelStatsNow.uiNumShaderAndEntities ) ); } } { /* Pool sizes Capacity Used NAME 100 10 10% */ m_TableList.push_back ( CDxTable ( "|" ) ); CDxTable& table = m_TableList.back (); table.SetColumnWidths( "170,50:R,50:R,40:R" ); table.SetNumberColors ( "^1", strNumberColorsModels ); table.AddRow ( HEADER1( "Pool sizes" ) "|" HEADER1( "Capacity" ) "|" HEADER1( "Used" ) "|" HEADER1( "" ) ); for ( int i = 0; i < MAX_POOLS ; i++ ) { SString strName = EnumToString( (ePools)i ); int iDefCapacity = g_pCore->GetGame()->GetPools()->GetPoolDefaultCapacity ( (ePools)i ); int iCapacity = g_pCore->GetGame()->GetPools()->GetPoolCapacity ( (ePools)i ); int iUsedSpaces = g_pCore->GetGame()->GetPools()->GetNumberOfUsedSpaces ( (ePools)i ); int iUsedPercent = iUsedSpaces * 100 / iCapacity; table.AddRow ( SString ( "%s|%d|%d|%d%%", *strName, iCapacity, iUsedSpaces, iUsedPercent ) ); } } }
/////////////////////////////////////////////////////////////// // // CMemStats::UpdateIntervalStats // // Update stats which are sampled at regular intervals // /////////////////////////////////////////////////////////////// void CMemStats::UpdateIntervalStats ( void ) { MemStatsInfoClear ( m_MemStatsNow ); MemStatsInfoClear ( m_MemStatsDelta ); // // Update 'now' state // SampleState ( m_MemStatsNow ); // // Calculate 'delta' // m_MemStatsDelta.iProcessMemSizeKB = m_MemStatsNow.iProcessMemSizeKB - m_MemStatsPrev.iProcessMemSizeKB; m_MemStatsDelta.iProcessTotalVirtualKB = m_MemStatsNow.iProcessTotalVirtualKB - m_MemStatsPrev.iProcessTotalVirtualKB; m_MemStatsDelta.dxStatus.videoMemoryKB.iFreeForMTA = m_MemStatsNow.dxStatus.videoMemoryKB.iFreeForMTA - m_MemStatsPrev.dxStatus.videoMemoryKB.iFreeForMTA; m_MemStatsDelta.dxStatus.videoMemoryKB.iUsedByFonts = m_MemStatsNow.dxStatus.videoMemoryKB.iUsedByFonts - m_MemStatsPrev.dxStatus.videoMemoryKB.iUsedByFonts; m_MemStatsDelta.dxStatus.videoMemoryKB.iUsedByTextures = m_MemStatsNow.dxStatus.videoMemoryKB.iUsedByTextures - m_MemStatsPrev.dxStatus.videoMemoryKB.iUsedByTextures; m_MemStatsDelta.dxStatus.videoMemoryKB.iUsedByRenderTargets = m_MemStatsNow.dxStatus.videoMemoryKB.iUsedByRenderTargets - m_MemStatsPrev.dxStatus.videoMemoryKB.iUsedByRenderTargets; m_MemStatsDelta.iStreamingMemoryAvailable = m_MemStatsNow.iStreamingMemoryAvailable - m_MemStatsPrev.iStreamingMemoryAvailable; m_MemStatsDelta.iStreamingMemoryUsed = m_MemStatsNow.iStreamingMemoryUsed - m_MemStatsPrev.iStreamingMemoryUsed; for ( uint i = 0 ; i < sizeof ( m_MemStatsDelta.modelInfo ) / sizeof ( uint ) ; i++ ) { m_MemStatsDelta.modelInfo.uiArray[i] = m_MemStatsNow.modelInfo.uiArray[i] - m_MemStatsPrev.modelInfo.uiArray[i]; } static const CProxyDirect3DDevice9::SResourceMemory* const nowList[] = { &m_MemStatsNow.d3dMemory.StaticVertexBuffer, &m_MemStatsNow.d3dMemory.DynamicVertexBuffer, &m_MemStatsNow.d3dMemory.StaticIndexBuffer, &m_MemStatsNow.d3dMemory.DynamicIndexBuffer, &m_MemStatsNow.d3dMemory.StaticTexture, &m_MemStatsNow.d3dMemory.DynamicTexture, &m_MemStatsNow.d3dMemory.Effect }; static const CProxyDirect3DDevice9::SResourceMemory* const prevList[] = { &m_MemStatsPrev.d3dMemory.StaticVertexBuffer, &m_MemStatsPrev.d3dMemory.DynamicVertexBuffer, &m_MemStatsPrev.d3dMemory.StaticIndexBuffer, &m_MemStatsPrev.d3dMemory.DynamicIndexBuffer, &m_MemStatsPrev.d3dMemory.StaticTexture, &m_MemStatsPrev.d3dMemory.DynamicTexture, &m_MemStatsPrev.d3dMemory.Effect }; static CProxyDirect3DDevice9::SResourceMemory* const deltaList[] = { &m_MemStatsDelta.d3dMemory.StaticVertexBuffer, &m_MemStatsDelta.d3dMemory.DynamicVertexBuffer, &m_MemStatsDelta.d3dMemory.StaticIndexBuffer, &m_MemStatsDelta.d3dMemory.DynamicIndexBuffer, &m_MemStatsDelta.d3dMemory.StaticTexture, &m_MemStatsDelta.d3dMemory.DynamicTexture, &m_MemStatsDelta.d3dMemory.Effect }; static const CProxyDirect3DDevice9::SResourceMemory* const maxList[] = { &m_MemStatsMax.d3dMemory.StaticVertexBuffer, &m_MemStatsMax.d3dMemory.DynamicVertexBuffer, &m_MemStatsMax.d3dMemory.StaticIndexBuffer, &m_MemStatsMax.d3dMemory.DynamicIndexBuffer, &m_MemStatsMax.d3dMemory.StaticTexture, &m_MemStatsMax.d3dMemory.DynamicTexture, &m_MemStatsMax.d3dMemory.Effect }; for ( uint i = 0 ; i < NUMELMS( nowList ) ; i++ ) { deltaList[i]->iCreatedCount = nowList[i]->iCreatedCount - prevList[i]->iCreatedCount; deltaList[i]->iCreatedBytes = nowList[i]->iCreatedBytes - prevList[i]->iCreatedBytes; deltaList[i]->iDestroyedCount = nowList[i]->iDestroyedCount - prevList[i]->iDestroyedCount; deltaList[i]->iDestroyedBytes = nowList[i]->iDestroyedBytes - prevList[i]->iDestroyedBytes; deltaList[i]->iLockedCount = maxList[i]->iLockedCount; // Use per-frame max for lock stats } m_MemStatsDelta.rwResourceStats.uiTextures = m_MemStatsNow.rwResourceStats.uiTextures - m_MemStatsPrev.rwResourceStats.uiTextures; m_MemStatsDelta.rwResourceStats.uiRasters = m_MemStatsNow.rwResourceStats.uiRasters - m_MemStatsPrev.rwResourceStats.uiRasters; m_MemStatsDelta.rwResourceStats.uiGeometries = m_MemStatsNow.rwResourceStats.uiGeometries - m_MemStatsPrev.rwResourceStats.uiGeometries; m_MemStatsDelta.clothesCacheStats.uiCacheHit = m_MemStatsNow.clothesCacheStats.uiCacheHit - m_MemStatsPrev.clothesCacheStats.uiCacheHit; m_MemStatsDelta.clothesCacheStats.uiCacheMiss = m_MemStatsNow.clothesCacheStats.uiCacheMiss - m_MemStatsPrev.clothesCacheStats.uiCacheMiss; m_MemStatsDelta.clothesCacheStats.uiNumTotal = m_MemStatsNow.clothesCacheStats.uiNumTotal - m_MemStatsPrev.clothesCacheStats.uiNumTotal; m_MemStatsDelta.clothesCacheStats.uiNumUnused = m_MemStatsNow.clothesCacheStats.uiNumUnused - m_MemStatsPrev.clothesCacheStats.uiNumUnused; m_MemStatsDelta.clothesCacheStats.uiNumRemoved = m_MemStatsNow.clothesCacheStats.uiNumRemoved - m_MemStatsPrev.clothesCacheStats.uiNumRemoved; m_MemStatsDelta.modelCacheStats.uiNumPedModels = m_MemStatsNow.modelCacheStats.uiNumPedModels - m_MemStatsPrev.modelCacheStats.uiNumPedModels; m_MemStatsDelta.modelCacheStats.uiNumVehicleModels = m_MemStatsNow.modelCacheStats.uiNumVehicleModels - m_MemStatsPrev.modelCacheStats.uiNumVehicleModels; m_MemStatsDelta.modelCacheStats.uiMaxNumPedModels = m_MemStatsNow.modelCacheStats.uiMaxNumPedModels - m_MemStatsPrev.modelCacheStats.uiMaxNumPedModels; m_MemStatsDelta.modelCacheStats.uiMaxNumVehicleModels = m_MemStatsNow.modelCacheStats.uiMaxNumVehicleModels - m_MemStatsPrev.modelCacheStats.uiMaxNumVehicleModels; { SShaderReplacementStats& now = m_MemStatsNow.shaderReplacementStats; SShaderReplacementStats& prev = m_MemStatsPrev.shaderReplacementStats; SShaderReplacementStats& delta = m_MemStatsDelta.shaderReplacementStats; delta.uiNumReplacementRequests = now.uiNumReplacementRequests - prev.uiNumReplacementRequests; delta.uiNumReplacementMatches = now.uiNumReplacementMatches - prev.uiNumReplacementMatches; delta.uiTotalTextures = now.uiTotalTextures - prev.uiTotalTextures; delta.uiTotalShaders = now.uiTotalShaders - prev.uiTotalShaders; delta.uiTotalEntitesRefed = now.uiTotalEntitesRefed - prev.uiTotalEntitesRefed; for ( std::map < uint, SMatchChannelStats >::iterator iter = now.channelStatsList.begin () ; iter != now.channelStatsList.end () ; ++iter ) { uint uiId = iter->first; const SMatchChannelStats& channelStatsNow = iter->second; SMatchChannelStats* pChannelStatsPrev = MapFind ( prev.channelStatsList, uiId ); SMatchChannelStats channelStatsDelta = channelStatsNow; if ( pChannelStatsPrev ) { channelStatsDelta.uiNumMatchedTextures -= pChannelStatsPrev->uiNumMatchedTextures; channelStatsDelta.uiNumShaderAndEntities -= pChannelStatsPrev->uiNumShaderAndEntities; } MapSet ( delta.channelStatsList, uiId, channelStatsDelta ); } } // // Set 'prev' for next time // m_MemStatsPrev = m_MemStatsNow; // Clear max records MemStatsInfoClear ( m_MemStatsMax ); }
int main(int argc, char *argv[]) { long long counter = 0; /* machine instruction counter */ int wait_val; /* child's return value */ int pid; /* child's process id */ char buf[1024]; struct user_regs_struct regs; int personality_setting = 0; MemoryMapInfo *mptr = NULL; memset((void *)&emulate_ops, 0, sizeof(struct hack_x86_emulate_ops)); emulate_ops.read = (void *)&emulated_read; emulate_ops.insn_fetch = (void *)&emulated_read_fetch; emulate_ops.write = (void *)&emulated_write; sprintf(buf, "%s.2.trace.%d.log", argv[2], getpid()); ofd = fopen(buf, "wb"); if (ofd == NULL) { fprintf(stderr, "cannot open %s.. exiting\n", buf); exit(-1); } switch (pid = fork()) { case -1: perror("fork"); break; case 0: /* child process starts */ //personality_setting = personality(0xffffffff); //personality(personality_setting|ADDR_NO_RANDOMIZE); ptrace(PTRACE_TRACEME, 0, 0, 0); /* * must be called in order to allow the * control over the child process */ //execl("/bin/ls", "ls", NULL); execl(argv[1],argv[2], NULL); /* * executes the program and causes * the child to stop and send a signal * to the parent, the parent can now * switch to PTRACE_SINGLESTEP */ break; /* child process ends */ default:/* parent process starts */ wait(&wait_val); ptrace(PTRACE_GETREGS, pid, NULL, ®s); printf("%llx\n", regs.rip); // we want to log our instruction address here.. //fwrite((void *)®s.rip, sizeof(uint64_t), 1, ofd); /* * parent waits for child to stop at next * instruction (execl()) */ while (wait_val == 1407 ) { counter++; if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0) perror("ptrace"); /* * switch to singlestep tracing and * release child * if unable call error. */ wait(&wait_val); /* wait for next instruction to complete */ // call another function to grab rwegisters.. // emulate & log the instructions memory addresses ptrace(PTRACE_GETREGS, pid, NULL, ®s); #ifdef defined(__i386__) //printf("0 %X\n", regs.eip); #else //printf("0 %llu\n", regs.rip); #endif emulate_log(pid); // we want to log our instruction address here.. fwrite((void *)®s.rip, sizeof(uint64_t), 1, ofd); mptr = MapFind((void *)regs.rip); if (mptr != NULL) { printf("3 %llu\n", regs.rip); } //if (count++ > 10000) exit(-1); } } // printf("Number of machine instructions : %lld\n", counter); fclose(ofd); return 0; }