void CEditorRoot::OnThink(void)
{
	BaseClass::OnThink();

	if ( IsBuildModeActive() )
	{
		Panel *pBuild = FindChildByName( "BuildModeDialog" );
		if ( pBuild && !pBuild->IsCursorOver() && input()->IsKeyDown( KEY_LCONTROL ) )
			pBuild->MoveToFront();
	}

	input()->GetCursorPosition( Mx, My );
	ScreenToLocal(Mx,My);

	Vector2D mCoords = GetSafeFlowgraph()->GetMousePosInNodeSpace();
	m_pLabel_Coords->SetText( VarArgs( "position: %10.1f / %10.1f", mCoords.x, mCoords.y ) );

	static CFastTimer _timer;
	_timer.End();
	double _frametime = _timer.GetDuration().GetSeconds();
	_timer.Start();
	m_pLabel_FrameTime->SetText( VarArgs( "fps: %4.1f, ms: %8.7f", 1.0f/max( 0.00001f, _frametime ), _frametime ) );

	if ( m_bPainting )
		input()->SetCursorOveride( dc_hand );

	// FML
	SortButtons();
	//if ( m_bNeedsButtonPush )
	//	SortButtons();

#ifdef SHADER_EDITOR_DLL_SWARM
	VPANEL modal = input()->GetAppModalSurface();
	static bool bFailed = false;

	if ( !bFailed && modal > 0 && modal != GetVPanel() )
	{
		if ( !m_bHalfView && IsVisible() && !ipanel()->HasParent( modal, GetVPanel() ) )
		{
			const char *pszModalName = ipanel()->GetName( modal );
			const char *names[] = {
				"SteamCloudConfirmation",
				"AddonAssociation",
			};

			const int numnames = ARRAYSIZE( names );
			for ( int i = 0; i < numnames; i++ )
			{
				if ( !Q_stricmp( names[i], pszModalName ) )
				{
					ToggleVisible();
					return;
				}
			}

			bFailed = true;
		}
	}
#endif
}
Exemplo n.º 2
0
static void AppendTimer( int idx, char *buf, size_t bufsize, CFastTimer& timer )
{
	char s[ 32 ];
	Q_snprintf( s, sizeof( s ), "%d %6.3f ms", idx, timer.GetDuration().GetMillisecondsF() );

	Q_strncat( buf, s, bufsize );
}
Exemplo n.º 3
0
int main( int argc, char* argv[] )
{
	if ( argc < 2 )
	{
		return PrintUsage();
	}

	const char *pClientOrServer = argv[1];
	const char *pIP = NULL;

	bool bClient = false;
	if ( stricmp( pClientOrServer, "-client" ) == 0 )
	{
		if ( argc < 3 )
		{
			return PrintUsage();
		}

		bClient = true;
		pIP = argv[2];
	}

	CUtlVector<unsigned char> recvBuf;
	if ( bClient )
	{
		DoClientConnect( pIP );

		// Ok, now start blasting packets of different sizes and measure how long it takes to get an ack back.
		int nIterations = 30;
		
		for ( int size=350; size <= 350000; size += 512 )
		{
			CUtlVector<unsigned char> buf;
			buf.SetCount( size );

			double flTotalRoundTripTime = 0;

			CFastTimer throughputTimer;
			throughputTimer.Start();

			for ( int i=0; i < nIterations; i++ )
			{
				for ( int z=0; z < size; z++ )
					buf[z] = (char)rand();
				
				SendData( buf.Base(), buf.Count() );
				
				CFastTimer timer;
				timer.Start();
					RecvData( recvBuf );
				timer.End();

				
				// Make sure we got the same data back.
				assert( recvBuf.Count() == buf.Count() );
				for ( z=0; z < size; z++ )
				{
					assert( recvBuf[z] == buf[z] );
				}
					

				//if ( i % 100 == 0 )
				//	printf( "%05d\n", i );
printf( "%d\n", i );
				flTotalRoundTripTime += timer.GetDuration().GetMillisecondsF();
			}
			throughputTimer.End();
			double flTotalSeconds = throughputTimer.GetDuration().GetSeconds();

			double flAvgRoundTripTime = flTotalRoundTripTime / nIterations;
			printf( "%d: %.2f ms per roundtrip (%d bytes/sec) sec: %.2f megs: %.2f\n", 
				size, 
				flAvgRoundTripTime, 
				(int)((size*nIterations)/flTotalSeconds),
				flTotalSeconds,
				(double)(size*nIterations) / (1024*1024)  );
		}

		// Send an 'end' message to the server.
		int val = -1;
		SendData( &val, sizeof( val ) );
	}
	else
	{
		// Wait for a connection.
		DoServerConnect();

		// Wait for packets and ack them.
		while ( 1 )
		{
			RecvData( recvBuf );
			if ( !g_pSocket )
				break;

			if ( recvBuf.Count() < 4 )
			{
				assert( false );
			}

			SendData( recvBuf.Base(), recvBuf.Count() );
		}
	}

	return 0;
}
//-----------------------------------------------------------------------------
// Purpose: takes a screenshot for the replay system
//-----------------------------------------------------------------------------
void CReplayScreenshotTaker::TakeScreenshot( WriteReplayScreenshotParams_t &params )
{
	if ( !m_pViewRender )
		return;

	CFastTimer timer;
	ConVarRef replay_debug( "replay_debug" );
	bool bDbg = replay_debug.IsValid() && replay_debug.GetBool();

	int width = params.m_nWidth;
	int height = params.m_nHeight;

	CMatRenderContextPtr pRenderContext( materials );
	pRenderContext->MatrixMode( MATERIAL_PROJECTION );
	pRenderContext->PushMatrix();
	
	pRenderContext->MatrixMode( MATERIAL_VIEW );
	pRenderContext->PushMatrix();

	extern bool g_bRenderingScreenshot;
	g_bRenderingScreenshot = true;

	// Push back buffer on the stack with small viewport
	pRenderContext->PushRenderTargetAndViewport( m_pScreenshotTarget, 0, 0, width, height );

	// setup the view to render
	CViewSetup viewSetup = m_View;
	viewSetup.x = 0;
	viewSetup.y = 0;
	viewSetup.width = width;
	viewSetup.height = height;
	viewSetup.fov = ScaleFOVByWidthRatio( m_View.fov, ( (float)width / (float)height ) / ( 4.0f / 3.0f ) );
	viewSetup.m_bRenderToSubrectOfLargerScreen = true;

	// Setup view origin/angles
	if ( params.m_pOrigin )
	{
		viewSetup.origin = *params.m_pOrigin;
	}
	if ( params.m_pAngles )
	{
		viewSetup.angles = *params.m_pAngles;
	}

	timer.Start();
	
		// draw out the scene - don't draw the HUD or the viewmodel
		m_pViewRender->RenderView( viewSetup, VIEW_CLEAR_DEPTH | VIEW_CLEAR_COLOR, 0 );

	timer.End();
	if ( bDbg ) Warning( "Screenshot RenderView(): %.4f s\n", timer.GetDuration().GetSeconds() );

	timer.Start();

		// Get Bits from the material system
		pRenderContext->ReadPixels( 0, 0, width, height, m_pUnpaddedPixels, IMAGE_FORMAT_RGB888 );

	timer.End();
	if ( bDbg ) Warning( "Screenshot ReadPixels(): %.4f s\n", timer.GetDuration().GetSeconds() );

	// Some stuff to be setup dependent on padded vs. not padded
	int nSrcWidth, nSrcHeight;
	unsigned char *pSrcImage;

	// Setup dimensions as needed
	int nPaddedWidth = m_aPaddedDims[0];
	int nPaddedHeight = m_aPaddedDims[1];

	// Allocate
	unsigned char *pUnpaddedImage = m_pUnpaddedPixels;
	unsigned char *pPaddedImage = m_pPaddedPixels;
	
	timer.Start();
		// Copy over each row individually
		for ( int nRow = 0; nRow < height; ++nRow )
		{
			unsigned char *pDst = pPaddedImage + 3 * ( nRow * nPaddedWidth );
			const unsigned char *pSrc = pUnpaddedImage + 3 * ( nRow * width );
			V_memcpy( pDst, pSrc, 3 * width );
		}
	timer.End();
	if ( bDbg ) Warning( "Screenshot copy image: %.4f s\n", timer.GetDuration().GetSeconds() );

	// Setup source data
	nSrcWidth = nPaddedWidth;
	nSrcHeight = nPaddedHeight;
	pSrcImage = pPaddedImage;

	if ( !m_pVTFTexture )
		return;

	// Copy the image data over to the VTF
	unsigned char *pDestBits = m_pVTFTexture->ImageData();
	int nDstSize = nSrcWidth * nSrcHeight * 3;
	V_memcpy( pDestBits, pSrcImage, nDstSize );

	bool bWriteResult = true;

	// Reset put
	m_pBuffer->SeekPut( CUtlBuffer::SEEK_HEAD, 0 );

	timer.Start();
		// Serialize to the buffer
		bWriteResult = m_pVTFTexture->Serialize( *m_pBuffer );
	timer.End();
	if ( bDbg ) Warning( "Screenshot VTF->Serialize(): %.4f s\n", timer.GetDuration().GetSeconds() );
	
	if ( !bWriteResult )
	{
		Warning( "Couldn't write Replay screenshot.\n" );
		bWriteResult = false;

		return;
	}

	// async write to disk (this will take ownership of the memory)
	char szPathedFileName[_MAX_PATH];
	Q_snprintf( szPathedFileName, sizeof(szPathedFileName), "//MOD/%s", params.m_pFilename );

	timer.Start();
		filesystem->AsyncWrite( szPathedFileName, m_pBuffer->Base(), m_pBuffer->TellPut(), false );
	timer.End();
	if ( bDbg ) Warning( "Screenshot AsyncWrite(): %.4f s\n", timer.GetDuration().GetSeconds() );

	// restore our previous state
	pRenderContext->PopRenderTargetAndViewport();
	
	pRenderContext->MatrixMode( MATERIAL_PROJECTION );
	pRenderContext->PopMatrix();
	
	pRenderContext->MatrixMode( MATERIAL_VIEW );
	pRenderContext->PopMatrix();

	g_bRenderingScreenshot = false;
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *hintCriteria - 
// Output : CAI_Hint
//-----------------------------------------------------------------------------
CAI_Hint *CAI_HintManager::FindHint( CAI_BaseNPC *pNPC, const Vector &position, const CHintCriteria &hintCriteria )
{
#if defined( HINT_PROFILING )
	CFastTimer timer;
	timer.Start();
#endif
	bool singleType = hintCriteria.MatchesSingleHintType();
	bool lookingForNearest = hintCriteria.HasFlag( bits_HINT_NODE_NEAREST );
	bool bIgnoreHintType = true;

	CUtlVector< CAIHintVector * > lists;
	if ( singleType )
	{
		int slot = CAI_HintManager::gm_TypedHints.Find( hintCriteria.GetFirstHintType() );
		if ( slot != CAI_HintManager::gm_TypedHints.InvalidIndex() )
		{
			lists.AddToTail( &CAI_HintManager::gm_TypedHints[ slot ] );
		}
	}
	else
	{
		int typeCount = hintCriteria.NumHintTypes();
		if ( typeCount > 0 )
		{
			for ( int listType = 0; listType < typeCount; ++listType )
			{
				int slot = CAI_HintManager::gm_TypedHints.Find( hintCriteria.GetHintType( listType ) );
				if ( slot != CAI_HintManager::gm_TypedHints.InvalidIndex() )
				{
					lists.AddToTail( &CAI_HintManager::gm_TypedHints[ slot ] );
				}
			}
		}
		else
		{
			// Still need to check hint type in this case
			lists.AddToTail( &CAI_HintManager::gm_AllHints );
			bIgnoreHintType = false;
		}
	}

	CAI_Hint *pBestHint	= NULL;

	int visited = 0;

	int listCount = lists.Count();

	if ( listCount == 0 )
		return NULL;
	
	// Try the fast match path
	int i, count;
	// Start with hint after the last one used
	CAI_Hint *pTestHint = NULL;

	float flBestDistance = MAX_TRACE_LENGTH;

	if ( !lookingForNearest )
	{
		// Fast check of previous results
		count = CAI_HintManager::GetFoundHintCount();
		for ( i = 0; i < count; ++i )
		{
			pTestHint = CAI_HintManager::GetFoundHint( i );
			if ( pTestHint )
			{
				Assert( dynamic_cast<CAI_Hint *>(pTestHint) != NULL );
				++visited;
				if ( pTestHint->HintMatchesCriteria( pNPC, hintCriteria, position, &flBestDistance ) )
				{
#if defined( HINT_PROFILING )
					Msg( "fast result visited %d\n", visited );
#endif
					return pTestHint;
				}
			}
		}
	}

	// Longer search, reset best distance
	flBestDistance = MAX_TRACE_LENGTH;

	for ( int listNum = 0; listNum < listCount; ++listNum )
	{
		CAIHintVector *list = lists[ listNum ];
		count = list->Count();
		// -------------------------------------------
		//  If we have no hints, bail
		// -------------------------------------------
		if ( !count )
			continue;

		//  Now loop till we find a valid hint or return to the start
		for ( i = 0 ; i < count; ++i )
		{
			pTestHint = list->Element( i );
			Assert( pTestHint );

			++visited;

			Assert( dynamic_cast<CAI_Hint *>(pTestHint) != NULL );
			if ( pTestHint->HintMatchesCriteria( pNPC, hintCriteria, position, &flBestDistance, false, bIgnoreHintType ) )
			{
				// If we were searching for the nearest, just note that this is now the nearest node
				if ( lookingForNearest )
				{
					pBestHint = pTestHint;
				}
				else 
				{
					// If we're not looking for the nearest, we're done
					CAI_HintManager::AddFoundHint( pTestHint );
#if defined( HINT_PROFILING )
					Msg( "visited %d\n", visited );
#endif
					return pTestHint;
				}
			}
		} 
	}
	// Return the nearest node that we found
	if ( pBestHint )
	{
		CAI_HintManager::AddFoundHint( pBestHint );
	}
	
#if defined( HINT_PROFILING )
	timer.End();

	Msg( "visited %d\n", visited );
	if ( !pBestHint )
	{
		Msg( "%i search failed for [%d] at pos %.3f %.3f %.3f [%.4f msec ~ %.4f msec per node]\n",
			gpGlobals->tickcount,
			pNPC ? pNPC->entindex() : -1,
			position.x, position.y, position.z,
			timer.GetDuration().GetMillisecondsF(),
			timer.GetDuration().GetMillisecondsF()/max( (float)visited, 1.0f ) );
	}
#endif
	return pBestHint;
}