Example #1
0
/*
===========
main
===========
*/
int main (int argc, char **argv)
{
    CommandLine()->CreateCmdLine( argc, argv );

    MathLib_Init( 2.2f, 2.2f, 0.0f, 1.0f, false, false, false, false );
    InstallAllocationFunctions();
    InstallSpewFunction();

    VVIS_SetupMPI( argc, argv );

    // Install an exception handler.
    if ( g_bUseMPI && !g_bMPIMaster )
        SetupToolsMinidumpHandler( VMPI_ExceptionFilter );
    else
        SetupDefaultToolsMinidumpHandler();

    return RunVVis( argc, argv );
}
int ShaderCompile_Subprocess_Main( char const *szSubProcessData )
{
	// Set our crash handler
	SetupToolsMinidumpHandler( ShaderCompile_Subprocess_ExceptionHandler );

	// Get our kernel objects
	SubProcessKernelObjects_Open objs( szSubProcessData );

	if ( !objs.IsValid() )
		return -1;

	// Enter the command pumping loop
	SubProcessKernelObjects_Memory shrmem( &objs );
	for (
		void *pvMemory = NULL;
		NULL != ( pvMemory = shrmem.Lock() );
		shrmem.Unlock()
		)
	{
		// The memory is actually a command
		char const *szCommand = ( char const * ) pvMemory;
		
		if ( !stricmp( "keepalive", szCommand ) )
		{
			ZeroMemory( pvMemory, 4 * sizeof( DWORD ) );
			continue;
		}

		if ( !stricmp( "quit", szCommand ) )
		{
			ZeroMemory( pvMemory, 4 * sizeof( DWORD ) );
			return 0;
		}

		CmdSink::IResponse *pResponse = NULL;
		if ( InterceptFxc::TryExecuteCommand( szCommand, &pResponse ) )
		{
			byte *pBytes = ( byte * ) pvMemory;
			
			// Result
			DWORD dwSucceededResult = pResponse->Succeeded() ? 1 : 0;
			* ( DWORD * ) pBytes = dwSucceededResult;
			pBytes += sizeof( DWORD );

			// Result buffer len
			DWORD dwBufferLength = pResponse->GetResultBufferLen();
			* ( DWORD * ) pBytes = dwBufferLength;
			pBytes += sizeof( DWORD );

			// Result buffer
			const void *pvResultBuffer = pResponse->GetResultBuffer();
			memcpy( pBytes, pvResultBuffer, dwBufferLength );
			pBytes += dwBufferLength;

			// Listing - copy string
			const char *szListing = pResponse->GetListing();
			if ( szListing )
			{
				while ( 0 != ( * ( pBytes ++ ) = * ( szListing ++ ) ) )
				{
					NULL;
				}
			}
			else
			{
				* ( pBytes ++ ) = 0;
			}
		}
		else
		{
			ZeroMemory( pvMemory, 4 * sizeof( DWORD ) );
		}
	}

	return -2;
}