size_t CStdMemAlloc::DefaultFailHandler( size_t nBytes ) { if ( IsX360() && !IsRetail() ) { #ifdef _X360 ExecuteOnce( { char buffer[256]; _snprintf( buffer, sizeof( buffer ), "***** Memory pool overflow, attempted allocation size: %u ****\n", nBytes ); XBX_OutputDebugString( buffer ); } );
char* CXZip::GetEntryFileName( unsigned CRC, char* pDefault ) { Assert( IsValid() ); if( IsRetail() ) { return pDefault; } else { // Make sure I have a filename section: if( m_Header.FilenameStringsOffset == 0 || m_Header.FilenameEntries == 0 || CRC == 0 ) { return pDefault; } // If the filename chunk isn't here, load it up: if( !m_pFilenames ) { MEM_ALLOC_CREDIT_("xZip"); m_pFilenames = (xZipFilenameEntry_t*)malloc( m_Header.FilenameStringsLength ); m_pRead( m_pFilenames, m_Header.FilenameStringsOffset, -1, m_Header.FilenameStringsLength, m_hUser ); // TODO: Swap! for( unsigned int i=0; i< m_Header.FilenameEntries; i++ ) { m_Swap.SwapFieldsToTargetEndian<xZipFilenameEntry_t>(&m_pFilenames[i]); } } // Find this entry in the preload directory xZipFilenameEntry_t entry; entry.FilenameCRC = CRC; xZipFilenameEntry_t* found = (xZipFilenameEntry_t*)bsearch( &entry, m_pFilenames, m_Header.FilenameEntries, sizeof(xZipFilenameEntry_t), xZipFilenameEntry_t::xZipFilenameEntryCompare ); if( !found ) return pDefault; return (((char*)m_pFilenames) + found->FilenameOffset) - m_Header.FilenameStringsOffset; } }
//----------------------------------------------------------------------------- // Draws all the debugging info //----------------------------------------------------------------------------- void CDebugViewRender::Draw2DDebuggingInfo( const CViewSetup &view ) { if ( IsX360() && IsRetail() ) return; // HDRFIXME: Assert NULL rendertarget if ( mat_yuv.GetInt() && (engine->GetDXSupportLevel() >= 80) ) { IMaterial *pMaterial; pMaterial = materials->FindMaterial( "debug/yuv", TEXTURE_GROUP_OTHER, true ); if( !IsErrorMaterial( pMaterial ) ) { DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height ); } } if ( mat_hsv.GetInt() && (engine->GetDXSupportLevel() >= 90) ) { IMaterial *pMaterial; pMaterial = materials->FindMaterial( "debug/hsv", TEXTURE_GROUP_OTHER, true ); if( !IsErrorMaterial( pMaterial ) ) { DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height ); } } // Draw debugging lightmaps if ( mat_showlightmappage.GetInt() != -1 ) { CLightmapDebugView clientView( assert_cast<CViewRender *>( ::view ) ); clientView.Setup( view ); clientView.Draw(); } if ( cl_drawshadowtexture.GetInt() ) { int nSize = cl_shadowtextureoverlaysize.GetInt(); g_pClientShadowMgr->RenderShadowTexture( nSize, nSize ); } const char *pDrawMaterial = cl_drawmaterial.GetString(); if ( pDrawMaterial && pDrawMaterial[0] ) { RenderMaterial( pDrawMaterial ); } if ( mat_showwatertextures.GetBool() ) { OverlayWaterTextures(); } if ( mat_showcamerarendertarget.GetBool() ) { float w = mat_wateroverlaysize.GetFloat(); float h = mat_wateroverlaysize.GetFloat(); #ifdef PORTAL g_pPortalRender->OverlayPortalRenderTargets( w, h ); #else OverlayCameraRenderTarget( "debug/debugcamerarendertarget", 0, 0, w, h ); #endif } if ( mat_showframebuffertexture.GetBool() ) { // HDRFIXME: Get rid of these rendertarget sets assuming that the assert at the top of this function is true. CMatRenderContextPtr pRenderContext( materials ); pRenderContext->PushRenderTargetAndViewport( NULL ); OverlayFrameBufferTexture( 0 ); OverlayFrameBufferTexture( 1 ); pRenderContext->PopRenderTargetAndViewport( ); } const char *pDrawTexture = mat_drawTexture.GetString(); if ( pDrawTexture && pDrawTexture[0] ) { OverlayShowTexture( pDrawTexture, mat_drawTextureScale.GetFloat() ); } #ifdef _X360 if ( mat_drawColorRamp.GetBool() ) { OverlayColorRamp( mat_drawColorRamp.GetInt() == 2 ); } #endif if ( r_flashlightdrawdepth.GetBool() ) { shadowmgr->DrawFlashlightDepthTexture( ); } if ( mat_drawTitleSafe.GetBool() ) { OverlayTitleSafe(); } }
//----------------------------------------------------------------------------- // Rendering //----------------------------------------------------------------------------- int CNewParticleEffect::DrawModel( int flags ) { VPROF_BUDGET( "CNewParticleEffect::DrawModel", VPROF_BUDGETGROUP_PARTICLE_RENDERING ); if ( r_DrawParticles.GetBool() == false ) return 0; #ifdef C17 // City17: DX7? Don't draw. if (engine->GetDXSupportLevel() < 80) return 0; #endif if ( !g_pClientMode->ShouldDrawParticles() || !ParticleMgr()->ShouldRenderParticleSystems() ) return 0; if ( ( flags & ( STUDIO_SHADOWDEPTHTEXTURE | STUDIO_SSAODEPTHTEXTURE ) ) != 0 ) { return 0; } // do distance cull check here. We do it here instead of in particles so we can easily only do // it for root objects, not bothering to cull children individually CMatRenderContextPtr pRenderContext( materials ); Vector vecCamera; pRenderContext->GetWorldSpaceCameraPosition( &vecCamera ); if ( CalcSqrDistanceToAABB( m_MinBounds, m_MaxBounds, vecCamera ) > ( m_pDef->m_flMaxDrawDistance * m_pDef->m_flMaxDrawDistance ) ) { if ( !IsRetail() && ( g_cl_particle_show_bbox || ( g_cl_particle_show_bbox_cost != 0 ) ) ) { DebugDrawBbox ( true ); } // Still need to make sure we set this or they won't follow their attachemnt points. m_flNextSleepTime = Max ( m_flNextSleepTime, ( g_pParticleSystemMgr->GetLastSimulationTime() + m_pDef->m_flNoDrawTimeToGoToSleep )); return 0; } if ( flags & STUDIO_TRANSPARENCY ) { int viewentity = render->GetViewEntity(); C_BaseEntity *pCameraObject = cl_entitylist->GetEnt( viewentity ); // apply logic that lets you skip rendering a system if the camera is attached to its entity if ( pCameraObject && ( m_pDef->m_nSkipRenderControlPoint != -1 ) && ( m_pDef->m_nSkipRenderControlPoint <= m_nHighestCP ) ) { C_BaseEntity *pEntity = (EHANDLE)GetControlPointEntity( m_pDef->m_nSkipRenderControlPoint ); if ( pEntity ) { // If we're in thirdperson, we still see it if ( !input->CAM_IsThirdPerson() ) { if ( pEntity == pCameraObject ) return 0; C_BaseEntity *pRootMove = pEntity->GetRootMoveParent(); if ( pRootMove == pCameraObject ) return 0; // If we're spectating in-eyes of the camera object, we don't see it C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer == pCameraObject ) { C_BaseEntity *pObTarget = pPlayer->GetObserverTarget(); if ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE && (pObTarget == pEntity || pRootMove == pObTarget ) ) return 0; } } } } pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->PushMatrix(); pRenderContext->LoadIdentity(); Render( pRenderContext, IsTwoPass(), pCameraObject ); pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->PopMatrix(); } else { g_pParticleSystemMgr->AddToRenderCache( this ); } if ( !IsRetail() ) { CParticleMgr *pMgr = ParticleMgr(); if ( pMgr->m_bStatsRunning ) { pMgr->StatsNewParticleEffectDrawn ( this ); } if ( g_cl_particle_show_bbox || ( g_cl_particle_show_bbox_cost != 0 ) ) { DebugDrawBbox ( false ); } } return 1; }
bool CAI_LocalNavigator::MoveCalcDirect( AILocalMoveGoal_t *pMoveGoal, bool bOnlyCurThink, float *pDistClear, AIMoveResult_t *pResult ) { AI_PROFILE_SCOPE(CAI_LocalNavigator_MoveCalcDirect); bool bRetVal = false; if ( pMoveGoal->speed ) { CAI_Motor *pMotor = GetOuter()->GetMotor(); float minCheckDist = pMotor->MinCheckDist(); float probeDist = m_pPlaneSolver->CalcProbeDist( pMoveGoal->speed ); // having this match steering allows one fewer traces float checkDist = MAX( minCheckDist, probeDist ); float checkStepDist = MAX( 16.0, probeDist * 0.5 ); if ( pMoveGoal->flags & ( AILMG_TARGET_IS_TRANSITION | AILMG_TARGET_IS_GOAL ) ) { // clamp checkDist to be no farther than MAX distance to goal checkDist = MIN( checkDist, pMoveGoal->maxDist ); } if ( checkDist <= 0.0 ) { *pResult = AIMR_OK; return true; } float moveThisInterval = pMotor->CalcIntervalMove(); bool bExpectingArrival = (moveThisInterval >= checkDist); if ( !m_FullDirectTimer.Expired() ) { if ( !m_fLastWasClear || ( !VectorsAreEqual(pMoveGoal->target, m_LastMoveGoal.target, 0.1) || !VectorsAreEqual(pMoveGoal->dir, m_LastMoveGoal.dir, 0.1) ) || bExpectingArrival ) { m_FullDirectTimer.Force(); } } if ( bOnlyCurThink ) // Outer code claims to have done a validation (probably a simplify operation) { m_FullDirectTimer.Set( TIME_DELAY_FULL_DIRECT_PROBE[AIStrongOpt()] ); } // First, check the probable move for this cycle bool bTraceClear = true; Vector testPos; if ( !bExpectingArrival ) { testPos = GetLocalOrigin() + pMoveGoal->dir * moveThisInterval; bTraceClear = GetMoveProbe()->MoveLimit( pMoveGoal->navType, GetLocalOrigin(), testPos, GetOuter()->GetAITraceMask(), pMoveGoal->pMoveTarget, 100.0, ( pMoveGoal->navType == NAV_GROUND ) ? AIMLF_2D : AIMLF_DEFAULT, &pMoveGoal->directTrace ); if ( !bTraceClear ) { // Adjust probe top match expected probe dist (relied on later in process) pMoveGoal->directTrace.flDistObstructed = (checkDist - moveThisInterval) + pMoveGoal->directTrace.flDistObstructed; } if ( !IsRetail() && ai_debug_directnavprobe.GetBool() ) { if ( !bTraceClear ) { DevMsg( GetOuter(), "Close obstruction %f\n", checkDist - pMoveGoal->directTrace.flDistObstructed ); NDebugOverlay::Line( WorldSpaceCenter(), Vector( testPos.x, testPos.y, WorldSpaceCenter().z ), 255, 0, 0, false, 0.1 ); if ( pMoveGoal->directTrace.pObstruction ) NDebugOverlay::Line( WorldSpaceCenter(), pMoveGoal->directTrace.pObstruction->WorldSpaceCenter(), 255, 0, 255, false, 0.1 ); } else { NDebugOverlay::Line( WorldSpaceCenter(), Vector( testPos.x, testPos.y, WorldSpaceCenter().z ), 0, 255, 0, false, 0.1 ); } } pMoveGoal->thinkTrace = pMoveGoal->directTrace; } // Now project out for future obstructions if ( bTraceClear ) { if ( m_FullDirectTimer.Expired() ) { testPos = GetLocalOrigin() + pMoveGoal->dir * checkDist; float checkStepPct = (checkStepDist / checkDist) * 100.0; if ( checkStepPct > 100.0 ) checkStepPct = 100.0; bTraceClear = GetMoveProbe()->MoveLimit( pMoveGoal->navType, GetLocalOrigin(), testPos, GetOuter()->GetAITraceMask(), pMoveGoal->pMoveTarget, checkStepPct, ( pMoveGoal->navType == NAV_GROUND ) ? AIMLF_2D : AIMLF_DEFAULT, &pMoveGoal->directTrace ); if ( bExpectingArrival ) pMoveGoal->thinkTrace = pMoveGoal->directTrace; if (ai_debug_directnavprobe.GetBool() ) { if ( !bTraceClear ) { NDebugOverlay::Line( GetOuter()->EyePosition(), Vector( testPos.x, testPos.y, GetOuter()->EyePosition().z ), 255, 0, 0, false, 0.1 ); DevMsg( GetOuter(), "Obstruction %f\n", checkDist - pMoveGoal->directTrace.flDistObstructed ); } else { NDebugOverlay::Line( GetOuter()->EyePosition(), Vector( testPos.x, testPos.y, GetOuter()->EyePosition().z ), 0, 255, 0, false, 0.1 ); DevMsg( GetOuter(), "No obstruction\n" ); } } } else { if ( ai_debug_directnavprobe.GetBool() ) DevMsg( GetOuter(), "No obstruction (Near probe only)\n" ); } } pMoveGoal->bHasTraced = true; float distClear = checkDist - pMoveGoal->directTrace.flDistObstructed; if (distClear < 0.001) distClear = 0; if ( bTraceClear ) { *pResult = AIMR_OK; bRetVal = true; m_fLastWasClear = true; } else if ( ( pMoveGoal->flags & ( AILMG_TARGET_IS_TRANSITION | AILMG_TARGET_IS_GOAL ) ) && pMoveGoal->maxDist < distClear ) { *pResult = AIMR_OK; bRetVal = true; m_fLastWasClear = true; } else { *pDistClear = distClear; m_fLastWasClear = false; } } else { // Should never end up in this function with speed of zero. Probably an activity problem. *pResult = AIMR_ILLEGAL; bRetVal = true; } m_LastMoveGoal = *pMoveGoal; if ( bRetVal && m_FullDirectTimer.Expired() ) m_FullDirectTimer.Set( TIME_DELAY_FULL_DIRECT_PROBE[AIStrongOpt()] ); return bRetVal; }
//----------------------------------------------------------------------------- // Rendering //----------------------------------------------------------------------------- int CNewParticleEffect::DrawModel( int flags ) { VPROF_BUDGET( "CNewParticleEffect::DrawModel", VPROF_BUDGETGROUP_PARTICLE_RENDERING ); if ( r_DrawParticles.GetBool() == false ) return 0; // City17: DX7? Don't draw. if( engine->GetDXSupportLevel() < 80 ) return 0; if ( !g_pClientMode->ShouldDrawParticles() || !ParticleMgr()->ShouldRenderParticleSystems() ) return 0; if( flags & STUDIO_SHADOWDEPTHTEXTURE ) return 0; // do distance cull check here. We do it here instead of in particles so we can easily only do // it for root objects, not bothering to cull children individually CMatRenderContextPtr pRenderContext( materials ); Vector vecCamera; pRenderContext->GetWorldSpaceCameraPosition( &vecCamera ); if ( CalcSqrDistanceToAABB( m_MinBounds, m_MaxBounds, vecCamera ) > ( m_pDef->m_flMaxDrawDistance * m_pDef->m_flMaxDrawDistance ) ) return 0; if ( flags & STUDIO_TRANSPARENCY ) { int viewentity = render->GetViewEntity(); C_BaseEntity *pCameraObject = cl_entitylist->GetEnt( viewentity ); // apply logic that lets you skip rendering a system if the camera is attached to its entity if ( pCameraObject && ( m_pDef->m_nSkipRenderControlPoint != -1 ) && ( m_pDef->m_nSkipRenderControlPoint <= m_nHighestCP ) && ( GetControlPointEntity( m_pDef->m_nSkipRenderControlPoint ) == pCameraObject ) ) return 0; pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->PushMatrix(); pRenderContext->LoadIdentity(); Render( pRenderContext, IsTwoPass(), pCameraObject ); pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->PopMatrix(); } else { g_pParticleSystemMgr->AddToRenderCache( this ); } if ( !IsRetail() && cl_particles_show_bbox.GetBool() ) { Vector center = GetRenderOrigin(); Vector mins = m_MinBounds - center; Vector maxs = m_MaxBounds - center; int r, g; if ( GetAutoUpdateBBox() ) { // red is bad, the bbox update is costly r = 255; g = 0; } else { // green, this effect presents less cpu load r = 0; g = 255; } debugoverlay->AddBoxOverlay( center, mins, maxs, QAngle( 0, 0, 0 ), r, g, 0, 16, 0 ); debugoverlay->AddTextOverlayRGB( center, 0, 0, r, g, 0, 64, "%s:(%d)", GetEffectName(), m_nActiveParticles ); } return 1; }