//-----------------------------------------------------------------------------
// Places Detail Objects in the lump
//-----------------------------------------------------------------------------
static void SetLumpData( )
{
	// Sort detail props by leaf
	qsort( s_DetailObjectLump.Base(), s_DetailObjectLump.Count(), sizeof(DetailObjectLump_t), SortFunc );

	GameLumpHandle_t handle = GetGameLumpHandle(GAMELUMP_DETAIL_PROPS);
	if (handle != InvalidGameLump())
		DestroyGameLump(handle);
	int nDictSize = s_DetailObjectDictLump.Count() * sizeof(DetailObjectDictLump_t);
	int nSpriteDictSize = s_DetailSpriteDictLump.Count() * sizeof(DetailSpriteDictLump_t);
	int nObjSize = s_DetailObjectLump.Count() * sizeof(DetailObjectLump_t);
	int nSize = nDictSize + nSpriteDictSize + nObjSize + 3 * sizeof(int);

	handle = CreateGameLump( GAMELUMP_DETAIL_PROPS, nSize, 0, GAMELUMP_DETAIL_PROPS_VERSION );

	// Serialize the data
	CUtlBuffer buf( GetGameLump(handle), nSize );
	buf.PutInt( s_DetailObjectDictLump.Count() );
	if (nDictSize)
		buf.Put( s_DetailObjectDictLump.Base(), nDictSize );
	buf.PutInt( s_DetailSpriteDictLump.Count() );
	if (nSpriteDictSize)
		buf.Put( s_DetailSpriteDictLump.Base(), nSpriteDictSize );
	buf.PutInt( s_DetailObjectLump.Count() );
	if (nObjSize)
		buf.Put( s_DetailObjectLump.Base(), nObjSize );
}
Exemplo n.º 2
0
void CmdLib_FPrintf( FileHandle_t hFile, const char *pFormat, ... )
{
	static CUtlVector<char> buf;
	if ( buf.Count() == 0 )
		buf.SetCount( 1024 );

	va_list marker;
	va_start( marker, pFormat );
	
	while ( 1 )
	{
		int ret = Q_vsnprintf( buf.Base(), buf.Count(), pFormat, marker );
		if ( ret >= 0 )
		{
			// Write the string.
			g_pFileSystem->Write( buf.Base(), ret, hFile );
			
			break;
		}
		else
		{
			// Make the buffer larger.
			int newSize = buf.Count() * 2;
			buf.SetCount( newSize );
			if ( buf.Count() != newSize )
			{
				Error( "CmdLib_FPrintf: can't allocate space for text." );
			}
		}
	}

	va_end( marker );
}
void RunInDLL( const char *pFilename, CUtlVector<char*> &newArgv )
{
	if ( g_pConnMgr )						   
		g_pConnMgr->SetAppState( VMPI_SERVICE_STATE_BUSY );

	bool bSuccess = false;
	CSysModule *pModule = Sys_LoadModule( pFilename );
	if ( pModule )
	{
		CreateInterfaceFn fn = Sys_GetFactory( pModule );
		if ( fn )
		{
			ILaunchableDLL *pDLL = (ILaunchableDLL*)fn( LAUNCHABLE_DLL_INTERFACE_VERSION, NULL );
			if( pDLL )
			{
				// Do this here because the executables we would have launched usually would do it.
				CommandLine()->CreateCmdLine( newArgv.Count(), newArgv.Base() );
				pDLL->main( newArgv.Count(), newArgv.Base() );
				bSuccess = true;
				SpewOutputFunc( MySpewOutputFunc );
			}
		}

		Sys_UnloadModule( pModule );
	}
	
	if ( !bSuccess )
	{
		Msg( "Error running VRAD (or VVIS) out of DLL '%s'\n", pFilename );
	}

	if ( g_pConnMgr )
		g_pConnMgr->SetAppState( VMPI_SERVICE_STATE_IDLE );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeSingleIndexedComponent::Intersection( const CDmeSingleIndexedComponent &rhs )
{
	const int nLhs = Count();
	const int nRhs = rhs.Count();

	int l = 0;
	int r = 0;

	if ( IsComplete() )
	{
		// TODO
		Assert( 0 );
	}
	else
	{
		CUtlVector< int > newComponents;
		newComponents.EnsureCapacity( nLhs );
		CUtlVector< float > newWeights;
		newWeights.EnsureCapacity( nLhs );

		while ( l < nLhs || r < nRhs )
		{
			// In LHS but not RHS
			while ( l < nLhs && ( r >= nRhs || m_Components[ l ] < rhs.m_Components[ r ] ) )
			{
				++l;
			}

			// In RHS but not LHS
			while ( r < nRhs && ( l >= nLhs || m_Components[ l ] > rhs.m_Components[ r ] ) )
			{
				++r;
			}

			// In Both LHS & RHS
			while ( l < nLhs && r < nRhs && m_Components[ l ] == rhs.m_Components[ r ] )
			{
				newComponents.AddToTail( m_Components[ l ] );
				newWeights.AddToTail( m_Weights[ l ] );
				++l;
				++r;
			}
		}

		m_Components.CopyArray( newComponents.Base(), newComponents.Count() );
		m_Weights.CopyArray( newWeights.Base(), newWeights.Count() );
	}

	m_CompleteCount.Set( 0 );
	m_bComplete.Set( false );
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// Computes a convex hull from the studio model
//-----------------------------------------------------------------------------
CPhysCollide* ComputeConvexHull( studiohdr_t* pStudioHdr )
{
	CUtlVector<CPhysConvex*>	convexHulls;

	for (int body = 0; body < pStudioHdr->numbodyparts; ++body )
	{
		mstudiobodyparts_t *pBodyPart = pStudioHdr->pBodypart( body );
		for( int model = 0; model < pBodyPart->nummodels; ++model )
		{
			mstudiomodel_t *pStudioModel = pBodyPart->pModel( model );
			for( int mesh = 0; mesh < pStudioModel->nummeshes; ++mesh )
			{
				// Make a convex hull for each mesh
				// NOTE: This won't work unless the model has been compiled
				// with $staticprop
				mstudiomesh_t *pStudioMesh = pStudioModel->pMesh( mesh );
				convexHulls.AddToTail( ComputeConvexHull( pStudioMesh ) );
			}
		}
	}

	// Convert an array of convex elements to a compiled collision model
	// (this deletes the convex elements)
	return s_pPhysCollision->ConvertConvexToCollide( convexHulls.Base(), convexHulls.Size() );
}
Exemplo n.º 6
0
void PerfThread_SendSpewText()
{
	// Send the spew text to the database.
	CCriticalSectionLock csLock( &g_SpewTextCS );
	csLock.Lock();
		
		if ( g_SpewText.Count() > 0 )
		{
			g_SpewText.AddToTail( 0 );
			
			if ( g_bMPI_StatsTextOutput )
			{
				g_pDB->AddCommandToQueue( new CSQLDBCommand_TextMessage( g_SpewText.Base() ), NULL );
			}
			else
			{
				// Just show one message in the vmpi_job_watch window to let them know that they need
				// to use a command line option to get the output.
				static bool bFirst = true;
				if ( bFirst )
				{
					char msg[512];
					V_snprintf( msg, sizeof( msg ), "%s not enabled", VMPI_GetParamString( mpi_Stats_TextOutput ) );
					bFirst = false;
					g_pDB->AddCommandToQueue( new CSQLDBCommand_TextMessage( msg ), NULL );
				}
			}
			
			g_SpewText.RemoveAll();
		}

	csLock.Unlock();
}
Exemplo n.º 7
0
void mx::createAccleratorTable( int numentries, Accel_t *entries )
{
	CUtlVector< ACCEL > accelentries;

	for ( int i = 0; i < numentries; ++i )
	{
		const Accel_t& entry = entries[ i ];

		ACCEL add;
		add.key = entry.key;
		add.cmd = entry.command;
		add.fVirt = 0;
		if ( entry.flags & ACCEL_ALT )
		{
			add.fVirt |= FALT;
		}
		if ( entry.flags & ACCEL_CONTROL )
		{
			add.fVirt |= FCONTROL;
		}
		if ( entry.flags & ACCEL_SHIFT )
		{
			add.fVirt |= FSHIFT;
		}
		if ( entry.flags & ACCEL_VIRTKEY )
		{
			add.fVirt |= FVIRTKEY;
		}

		accelentries.AddToTail( add );
	}

	g_hAcceleratorTable = ::CreateAcceleratorTable( accelentries.Base(), accelentries.Count() );
}
Exemplo n.º 8
0
void CEntityTouchManager::FrameUpdatePostEntityThink()
{
	VPROF( "CEntityTouchManager::FrameUpdatePostEntityThink" );
	// Loop through all entities again, checking their untouch if flagged to do so
	
	int count = m_updateList.Count();
	if ( count )
	{
		// copy off the list
		CBaseEntity **ents = (CBaseEntity **)stackalloc( sizeof(CBaseEntity *) * count );
		memcpy( ents, m_updateList.Base(), sizeof(CBaseEntity *) * count );
		// clear it
		m_updateList.RemoveAll();
		
		// now update those ents
		for ( int i = 0; i < count; i++ )
		{
			//Assert( ents[i]->GetCheckUntouch() );
			if ( ents[i]->GetCheckUntouch() )
			{
				ents[i]->PhysicsCheckForEntityUntouch();
			}
		}
		stackfree( ents );
	}
}
Exemplo n.º 9
0
static void WriteRecordingFile()
{
	// Store the command size
	*(int*)&g_pRecordingBuffer[g_CommandStartIdx] = 
		g_pRecordingBuffer.Size() - g_CommandStartIdx;

#ifndef CRASH_RECORDING
	// When not crash recording, flush when buffer gets too big, 
	// or when Present() is called
	if ((g_pRecordingBuffer.Size() < COMMAND_BUFFER_SIZE) &&
		(g_pRecordingBuffer[g_CommandStartIdx+4] != DX8_PRESENT))
		return;
#endif

	FILE* fp = OpenRecordingFile();
	if (fp)
	{
		// store the command size
		fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp );
		fflush( fp );
#ifndef CRASH_RECORDING
		fclose( fp );
#endif
	}

	g_pRecordingBuffer.RemoveAll();
}
Exemplo n.º 10
0
void SendProxy_UtlVectorElement(
    const SendProp *pProp,
    const void *pStruct,
    const void *pData,
    DVariant *pOut,
    int iElement,
    int objectID )
{
    CSendPropExtra_UtlVector *pExtra = (CSendPropExtra_UtlVector*)pProp->GetExtraData();
    Assert( pExtra );

    // 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.
    iElement = pProp->GetElementStride();

    // NOTE: this is cheesy, but it does the trick.
    CUtlVector<int> *pUtlVec = (CUtlVector<int>*)((char*)pStruct + pExtra->m_Offset);
    if ( iElement >= pUtlVec->Count() )
    {
        // Pass in zero value.
        memset( pOut, 0, sizeof( *pOut ) );
    }
    else
    {
        // Call through to the proxy they passed in, making pStruct=the CUtlVector and forcing iElement to 0.
        pExtra->m_ProxyFn( pProp, pData, (char*)pUtlVec->Base() + iElement*pExtra->m_ElementStride, pOut, 0, objectID );
    }
}
Exemplo n.º 11
0
void CVRadDLL::GetBSPInfo( CBSPInfo *pInfo )
{
	pInfo->dlightdata = pdlightdata->Base();
	pInfo->lightdatasize = pdlightdata->Count();

	pInfo->dfaces = dfaces;
	pInfo->m_pFacesTouched = g_FacesTouched.Base();
	pInfo->numfaces = numfaces;
	
	pInfo->dvertexes = dvertexes;
	pInfo->numvertexes = numvertexes;

	pInfo->dedges = dedges;
	pInfo->numedges = numedges;

	pInfo->dsurfedges = dsurfedges;
	pInfo->numsurfedges = numsurfedges;

	pInfo->texinfo = texinfo.Base();
	pInfo->numtexinfo = texinfo.Count();

	pInfo->g_dispinfo = g_dispinfo.Base();
	pInfo->g_numdispinfo = g_dispinfo.Count();

	pInfo->dtexdata = dtexdata;
	pInfo->numtexdata = numtexdata;

	pInfo->texDataStringData = g_TexDataStringData.Base();
	pInfo->nTexDataStringData = g_TexDataStringData.Count();

	pInfo->texDataStringTable = g_TexDataStringTable.Base();
	pInfo->nTexDataStringTable = g_TexDataStringTable.Count();
}
Exemplo n.º 12
0
void CTilegenAction_AddRoomCandidates::Execute( CLayoutSystem *pLayoutSystem )
{
	if ( m_pLevelTheme == NULL )
	{
		const char *pThemeName = m_pThemeNameExpression->Evaluate( pLayoutSystem->GetFreeVariables() );
		m_pLevelTheme = CLevelTheme::FindTheme( pThemeName );
		if ( m_pLevelTheme == NULL )
		{
			Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", pThemeName );
			pLayoutSystem->OnError();
			return;
		}
	}

	CUtlVector< const CRoomTemplate * > validRoomTemplates;
	BuildRoomTemplateList( pLayoutSystem, m_pLevelTheme, m_pRoomTemplateFilter, m_bExcludeGlobalFilters, &validRoomTemplates );

	const CRoomTemplate **ppRoomTemplates = const_cast< const CRoomTemplate ** >( validRoomTemplates.Base() );
	BuildRoomCandidateList( 
		pLayoutSystem, 
		ppRoomTemplates, 
		validRoomTemplates.Count(), 
		m_pExitFilter, 
		m_pRoomCandidateFilter, 
		m_pRoomCandidateFilterAction,
		m_pRoomCandidateFilterCondition,
		m_bExcludeGlobalFilters );
}
Exemplo n.º 13
0
void CMySQLQuery::Format( const char *pFormat, ... )
{
	#define QUERYTEXT_GROWSIZE	1024

	// This keeps growing the buffer and calling _vsnprintf until the buffer is 
	// large enough to hold all the data.
	m_QueryText.SetSize( QUERYTEXT_GROWSIZE );
	while ( 1 )
	{
		va_list marker;
		va_start( marker, pFormat );
		int ret = _vsnprintf( m_QueryText.Base(), m_QueryText.Count(), pFormat, marker );
		va_end( marker );

		if ( ret < 0 )
		{
			m_QueryText.SetSize( m_QueryText.Count() + QUERYTEXT_GROWSIZE );
		}
		else
		{
			m_QueryText[ m_QueryText.Count() - 1 ] = 0;
			break;
		}
	}
}
Exemplo n.º 14
0
void ResizeAnimationLayerCallback( void *pStruct, int offsetToUtlVector, int len )
{
	C_BaseAnimatingOverlay *pEnt = (C_BaseAnimatingOverlay*)pStruct;
	CUtlVector < CAnimationLayer > *pVec = &pEnt->m_AnimOverlay;
	CUtlVector< CInterpolatedVar< CAnimationLayer > > *pVecIV = &pEnt->m_iv_AnimOverlay;
	
	Assert( (char*)pVec - (char*)pEnt == offsetToUtlVector );
	Assert( pVec->Count() == pVecIV->Count() );
	Assert( pVec->Count() <= C_BaseAnimatingOverlay::MAX_OVERLAYS );
	
	int diff = len - pVec->Count();
	if ( diff != 0 )
	{
		// remove all entries
		for ( int i=0; i < pVec->Count(); i++ )
		{
			pEnt->RemoveVar( &pVec->Element( i ) );
		}

		pEnt->InvalidatePhysicsRecursive( BOUNDS_CHANGED );

		// adjust vector sizes
		if ( diff > 0 )
		{
			for ( int i = 0; i < diff; ++i )
			{
				int j = pVec->AddToTail( );
				(*pVec)[j].SetOwner( pEnt );
			}
			pVecIV->AddMultipleToTail( diff );
		}
		else
		{
			pVec->RemoveMultiple( len, -diff );
			pVecIV->RemoveMultiple( len, -diff );
		}

		// Rebind all the variables in the ent's list.
		for ( int i=0; i < len; i++ )
		{
			IInterpolatedVar *pWatcher = &pVecIV->Element( i );
			pWatcher->SetDebugName( s_m_iv_AnimOverlayNames[i] );
			pEnt->AddVar( &pVec->Element( i ), pWatcher, LATCH_ANIMATION_VAR, true );
		}
	}

	// FIXME: need to set historical values of nOrder in pVecIV to MAX_OVERLAY

	// Ensure capacity
	pVec->EnsureCapacity( len );

	int nNumAllocated = pVec->NumAllocated();

	// This is important to do because EnsureCapacity doesn't actually call the constructors
	// on the elements, but we need them to be initialized, otherwise it'll have out-of-range
	// values which will piss off the datatable encoder.
	UtlVector_InitializeAllocatedElements( pVec->Base() + pVec->Count(), nNumAllocated - pVec->Count() );
}
Exemplo n.º 15
0
void CVMPIServiceConnMgr::AddConsoleOutput( const char *pMsg )
{
	// Tell clients of the new text string.
	CUtlVector<char> data;
	data.AddToTail( VMPI_SERVICE_UI_PROTOCOL_VERSION );
	data.AddToTail( VMPI_SERVICE_TO_UI_CONSOLE_TEXT );
	data.AddMultipleToTail( strlen( pMsg ) + 1, pMsg );
	SendPacket( -1, data.Base(), data.Count() );
}
	virtual void OnPacketReceived( CTCPPacket *pPacket )
	{
		if ( g_ClientPacket.Count() < pPacket->GetLen() )
			g_ClientPacket.SetSize( pPacket->GetLen() );
		
		memcpy( g_ClientPacket.Base(), pPacket->GetData(), pPacket->GetLen() );
		g_ClientPacketEvent.SetEvent();
		pPacket->Release();
	}
Exemplo n.º 17
0
void CColorCorrectionMgr::UpdateColorCorrection()
{
	ResetColorCorrectionWeights();
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
	IClientMode *pClientMode = GetClientMode();

	Assert( pClientMode );
	if ( !pPlayer || !pClientMode )
	{
		return;
	}

	pClientMode->OnColorCorrectionWeightsReset();
	float ccScale = pClientMode->GetColorCorrectionScale();

	UpdateColorCorrectionEntities( pPlayer, ccScale, g_ColorCorrectionList.Base(), g_ColorCorrectionList.Count() );
	UpdateColorCorrectionVolumes( pPlayer, ccScale, g_ColorCorrectionVolumeList.Base(), g_ColorCorrectionVolumeList.Count() );
	CommitColorCorrectionWeights();
}
Exemplo n.º 18
0
void CStaticPropMgr::UnserializeLeafList( CUtlBuffer& buf )
{
	int nCount = buf.GetInt();
	m_StaticPropLeaves.Purge();
	if ( nCount > 0 )
	{
		m_StaticPropLeaves.AddMultipleToTail( nCount );
		buf.Get( m_StaticPropLeaves.Base(), nCount * sizeof(StaticPropLeafLump_t) );
	}
}
Exemplo n.º 19
0
//-----------------------------------------------------------------------------
// Copy the vertex dictionary to the finalized processed data
// Leaves the source data intact, necessary for later processes.
// Routines can then choose which data they operate on
//-----------------------------------------------------------------------------
static void SetProcessedWithDictionary( CUtlVector<s_source_t*> &lods, CVertexDictionary &vertexDict,
	CUtlVector<s_face_t> &faces, CUtlVector<s_mesh_t> &meshes, int *pMeshVertIndexMaps[MAX_NUM_LODS] )
{
	int	i;
	int nNumLODs = lods.Count();
	s_source_t *pRootLodSrc = lods[0];

	s_loddata_t *pLodData = new s_loddata_t;
	memset(pLodData, 0, sizeof(s_loddata_t));
	
	// all lods have link to processed data
	for (i=0; i<nNumLODs; i++)
	{
		lods[i]->pLodData = pLodData;
	}

	int nVertexCount = vertexDict.VertexCount();

	pLodData->vertex = (s_vertexinfo_t *)kalloc( nVertexCount, sizeof( s_vertexinfo_t ) );
	pLodData->numvertices = nVertexCount;
	pLodData->face = (s_face_t *)kalloc( faces.Count(), sizeof( s_face_t ));
	pLodData->numfaces = faces.Count();
	
	for ( i = 0; i < nVertexCount; ++i )
	{
		pLodData->vertex[i].globalBoneweight = vertexDict.Vertex( i ).m_BoneWeight;
		Assert( pLodData->vertex[i].globalBoneweight.numbones <= 4 );
		pLodData->vertex[i].position	= vertexDict.Vertex( i ).m_Position;
		pLodData->vertex[i].normal		= vertexDict.Vertex( i ).m_Normal;
		pLodData->vertex[i].texcoord	= vertexDict.Vertex( i ).m_TexCoord;
		pLodData->vertex[i].tangentS	= vertexDict.Vertex( i ).m_TangentS;
		pLodData->vertex[i].bLoD		= vertexDict.Vertex( i ).m_bLoD;
	}

	memcpy( pLodData->face, faces.Base(), faces.Count() * sizeof( s_face_t ) );
	memcpy( pLodData->mesh, meshes.Base(), meshes.Count() * sizeof( s_mesh_t ) );

	for (i=0; i<MAX_NUM_LODS; i++)
	{
		pLodData->pMeshVertIndexMaps[i] = pMeshVertIndexMaps[i];
	}
}
int CALLBACK SetPasswordDlgProc(
  HWND hwndDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
)
{
	switch( uMsg )
	{
		case WM_INITDIALOG:
		{
			if ( g_pPassword )
			{
				HWND hWnd = GetDlgItem( hwndDlg, IDC_PASSWORD );
				SetWindowText( hWnd, g_pPassword );
			}
		}
		break;

		case WM_COMMAND:
		{
			switch( wParam )
			{
				case IDOK:
				{
					// Set our new password.
					HWND hWnd = GetDlgItem( hwndDlg, IDC_PASSWORD );
					if ( hWnd )
					{
						char tempBuf[512];
						GetWindowText( hWnd, tempBuf, sizeof( tempBuf ) );

						// Send it to the service.
						CUtlVector<char> data;
						data.AddToTail( VMPI_SERVICE_UPDATE_PASSWORD );
						data.AddMultipleToTail( strlen( tempBuf ) + 1, tempBuf );
						g_ConnMgr.SendPacket( -1, data.Base(), data.Count() );
					}
					EndDialog( hwndDlg, 0 );
				}
				break;
			
				case IDCANCEL:
				{
					EndDialog( hwndDlg, 0 );
				}
				break;
			}
		}
		break;
	}

	return FALSE;
}
Exemplo n.º 21
0
//-----------------------------------------------------------------------------
// Purpose: Performs the actual partial rebuilds of the mesh, merging multiple
//			updates in one.
//-----------------------------------------------------------------------------
void CRecastMgr::UpdateRebuildPartial()
{
	if( !m_pendingPartialMeshUpdates.Count() )
		return;

	PartialMeshUpdate_t &curUpdate = m_pendingPartialMeshUpdates.Head();

	bool bDidMerge;
	int nTests = 0, nMerges = 0;
	do {
		bDidMerge = false;
		for( int i = m_pendingPartialMeshUpdates.Count() - 1; i >= 1; i-- )
		{
			if( IsBoxIntersectingBox( curUpdate.vMins, curUpdate.vMaxs,
				m_pendingPartialMeshUpdates[i].vMins, m_pendingPartialMeshUpdates[i].vMaxs ) )
			{
				curUpdate.vMins = VectorMin( curUpdate.vMins, m_pendingPartialMeshUpdates[i].vMins );
				curUpdate.vMaxs = VectorMax( curUpdate.vMaxs, m_pendingPartialMeshUpdates[i].vMaxs );
				m_pendingPartialMeshUpdates.Remove( i );
				bDidMerge = true;
				nMerges++;
			}
		}
		nTests++;
	} while( bDidMerge && nTests < 100 );

	if( recast_build_partial_debug.GetBool() && nMerges > 0 )
	{
		DevMsg( "CRecastMgr::UpdateRebuildPartial: Merged multiple updates (%d) into one\n", nMerges+1 );
	}

	// Load map mesh
	if( !LoadMapMesh( recast_build_partial_debug.GetBool(), true, curUpdate.vMins, curUpdate.vMaxs ) )
	{
		Warning( "CRecastMgr::UpdateRebuildPartial: failed to load map data!\n" );
		return;
	}

	// Perform the update
	CUtlVector<CRecastMesh *> meshesToBuild;
	for ( int i = m_Meshes.First(); i != m_Meshes.InvalidIndex(); i = m_Meshes.Next(i ) )
	{
		if( IsMeshBuildDisabled( m_Meshes[i]->GetName() ) )
			continue;
		meshesToBuild.AddToTail( m_Meshes[i] );
	}

	CParallelProcessor<CRecastMesh *, CFuncJobItemProcessor<CRecastMesh *>, 2 > processor;
	processor.m_ItemProcessor.Init( &ThreadedRebuildPartialMesh, &PreThreadedBuildMesh, &PostThreadedBuildMesh );
	processor.Run( meshesToBuild.Base(), meshesToBuild.Count(), 1, recast_build_numthreads.GetInt(), g_pThreadPool );

	m_pendingPartialMeshUpdates.Remove( 0 );
}
Exemplo n.º 22
0
void CJobWatchDlg::OnIdle()
{
	CUtlVector<char> text;

	// Any new text? This would indicate that the process is running currently.
	if ( GetCurrentWorkerText( text, m_CurMessageIndex ) && text.Count() > 0 )
	{
		FormatAndSendToEditControl( m_TextOutput.GetSafeHwnd(), text.Base() );
	}

	FillGraph();
}
Exemplo n.º 23
0
void RecvProxy_UtlVectorElement_DataTable( const RecvProp *pProp, void **pOut, void *pData, int objectID )
{
	CRecvPropExtra_UtlVector *pExtra = (CRecvPropExtra_UtlVector*)pProp->GetExtraData();

	int iElement = pProp->GetElementStride();
	Assert( iElement < pExtra->m_nMaxElements );

	// NOTE: this is cheesy, but it does the trick.
	CUtlVector<int> *pUtlVec = (CUtlVector<int>*)((char*)pData + pExtra->m_Offset);

	// Call through to the proxy they passed in, making pStruct=the CUtlVector and forcing iElement to 0.
	pExtra->m_DataTableProxyFn( pProp, pOut, (char*)pUtlVec->Base() + iElement*pExtra->m_ElementStride, objectID );
}
Exemplo n.º 24
0
//-----------------------------------------------------------------------------
// Purpose: Builds all navigation meshes
//-----------------------------------------------------------------------------
bool CRecastMgr::Build( bool loadDefaultMeshes )
{
	double fStartTime = Plat_FloatTime();

	// Load map mesh
	if( !LoadMapMesh() )
	{
		Warning("CRecastMesh::Build: failed to load map data!\n");
		return false;
	}

	// Insert all meshes first
	if( loadDefaultMeshes )
	{
		InitDefaultMeshes();
	}
	CUtlVector<CRecastMesh *> meshesToBuild;
	for ( int i = m_Meshes.First(); i != m_Meshes.InvalidIndex(); i = m_Meshes.Next(i ) )
	{
		if( IsMeshBuildDisabled( m_Meshes[i]->GetName() ) )
			continue;
		meshesToBuild.AddToTail( m_Meshes[i] );
	}

	// Create meshes
	if( recast_build_threaded.GetBool() )
	{
		// Build threaded
		CParallelProcessor<CRecastMesh *, CFuncJobItemProcessor<CRecastMesh *>, 2 > processor;
		processor.m_ItemProcessor.Init( &ThreadedBuildMesh, &PreThreadedBuildMesh, &PostThreadedBuildMesh );
		processor.Run( meshesToBuild.Base(), meshesToBuild.Count(), 1, recast_build_numthreads.GetInt(), g_pThreadPool );
	}
	else
	{
		if( V_strlen( recast_build_single.GetString() ) > 0 )
		{
			BuildMesh( m_pMapMesh, recast_build_single.GetString() );
		}
		else
		{
			for( int i = 0; i < meshesToBuild.Count(); i++ )
			{
				BuildMesh( m_pMapMesh, meshesToBuild[i]->GetName() );
			}
		}
	}

	m_bLoaded = true;
	DevMsg( "CRecastMgr: Finished generating %d meshes in %f seconds\n", m_Meshes.Count(), Plat_FloatTime() - fStartTime );
	return true;
}
Exemplo n.º 25
0
CMacroTextureData* LoadMacroTextureFile( const char *pFilename )
{
	FileHandle_t hFile = g_pFileSystem->Open( pFilename, "rb" );
	if ( hFile == FILESYSTEM_INVALID_HANDLE )
		return NULL;

	// Read the file in.
	CUtlVector<char> tempData;
	tempData.SetSize( g_pFileSystem->Size( hFile ) );
	g_pFileSystem->Read( tempData.Base(), tempData.Count(), hFile );
	g_pFileSystem->Close( hFile );
	
	
	// Now feed the data into a CUtlBuffer (great...)
	CUtlBuffer buf;
	buf.Put( tempData.Base(), tempData.Count() );

	
	// Now make a texture out of it.
	IVTFTexture *pTex = CreateVTFTexture();
	if ( !pTex->Unserialize( buf ) )
		Error( "IVTFTexture::Unserialize( %s ) failed.", pFilename );

	pTex->ConvertImageFormat( IMAGE_FORMAT_RGBA8888, false );	// Get it in a format we like.

	
	// Now convert to a CMacroTextureData.
	CMacroTextureData *pData = new CMacroTextureData;
	pData->m_Width = pTex->Width();
	pData->m_Height = pTex->Height();
	pData->m_ImageData.EnsureCapacity( pData->m_Width * pData->m_Height * 4 );
	memcpy( pData->m_ImageData.Base(), pTex->ImageData(), pData->m_Width * pData->m_Height * 4 );

	DestroyVTFTexture( pTex );

	Msg( "-- LoadMacroTextureFile: %s\n", pFilename );
	return pData;
}
Exemplo n.º 26
0
void CDispMeshEvent::GetVirtualMesh( void *userData, virtualmeshlist_t *pList )
{
	Assert(userData==((void *)this));
	pList->pVerts = m_verts.Base();
	pList->indexCount = m_indexCount;
	pList->triangleCount = m_indexCount/3;
	pList->vertexCount = m_verts.Count();
	pList->surfacePropsIndex = 0;	// doesn't matter here, reset at runtime
	pList->pHull = NULL;
	int indexMax = ARRAYSIZE(pList->indices);
	int indexCount = min(m_indexCount, indexMax);
	Assert(m_indexCount < indexMax);
	Q_memcpy( pList->indices, m_pIndices, sizeof(*m_pIndices) * indexCount );
}
KeyValues* ReadKeyValuesFile( const char *pFilename )
{
	// Read in the gameinfo.txt file and null-terminate it.
	FILE *fp = fopen( pFilename, "rb" );
	if ( !fp )
		return NULL;
	CUtlVector<char> buf;
	fseek( fp, 0, SEEK_END );
	buf.SetSize( ftell( fp ) + 1 );
	fseek( fp, 0, SEEK_SET );
	fread( buf.Base(), 1, buf.Count()-1, fp );
	fclose( fp );
	buf[buf.Count()-1] = 0;

	KeyValues *kv = new KeyValues( "" );
	if ( !kv->LoadFromBuffer( pFilename, buf.Base() ) )
	{
		kv->deleteThis();
		return NULL;
	}
	
	return kv;
}
Exemplo n.º 28
0
// Write the buffered crap out on shutdown.
void FinishRecording()
{
#ifndef CRASH_RECORDING
	FILE* fp = OpenRecordingFile();
	if (fp)
	{
		// store the command size
		fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp );
		fflush( fp );
	}

	g_pRecordingBuffer.RemoveAll();
#endif
}
Exemplo n.º 29
0
void CPlaneList::AddBrushes( void )
{
	CUtlVector<listplane_t> temp;
	for ( int brushnumber = 0; brushnumber < numbrushes; brushnumber++ )
	{
		if ( IsBrushReferenced(brushnumber) )
		{
			CUtlVector<winding_t *> windings;

			for ( int i = 0; i < dbrushes[brushnumber].numsides; i++ )
			{
				dbrushside_t *pside = dbrushsides + i + dbrushes[brushnumber].firstside;
				if (pside->bevel)
					continue;
				dplane_t *pplane = dplanes + pside->planenum;
				winding_t *w = BaseWindingForPlane( pplane->normal, pplane->dist - m_shrink );
				for ( int j = 0; j < dbrushes[brushnumber].numsides && w; j++ )
				{
					if (i == j)
						continue;
					dbrushside_t *pClipSide = dbrushsides + j + dbrushes[brushnumber].firstside;
					if (pClipSide->bevel)
						continue;
					dplane_t *pClipPlane = dplanes + pClipSide->planenum;
					ChopWindingInPlace (&w, -pClipPlane->normal, -pClipPlane->dist+m_shrink, 0); //CLIP_EPSILON);
				}
				if ( w )
				{
					windings.AddToTail( w );
				}
			}

			CUtlVector<Vector *> vertList;
			for ( int p = 0; p < windings.Count(); p++ )
			{
				for ( int v = 0; v < windings[p]->numpoints; v++ )
				{
					vertList.AddToTail( windings[p]->p + v );
				}
			}
			CPhysConvex *pConvex = physcollision->ConvexFromVerts( vertList.Base(), vertList.Count() );
			if ( pConvex )
			{
				physcollision->SetConvexGameData( pConvex, brushnumber );
				AddConvex( pConvex );
			}
			temp.RemoveAll();
		}
	}
}
void VMPI_ProcessLeafAmbient( int iThread, uint64 iLeaf, MessageBuffer *pBuf )
{
	CUtlVector<ambientsample_t> list;
	ComputeAmbientForLeaf(iThread, (int)iLeaf, list);

	VMPI_SetCurrentStage( "EncodeLeafAmbientResults" );

	// Encode the results.
	int nSamples = list.Count();
	pBuf->write( &nSamples, sizeof( nSamples ) );
	if ( nSamples )
	{
		pBuf->write( list.Base(), list.Count() * sizeof( ambientsample_t ) );
	}
}