void Init() { SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME ); SetInflictorFilter( "prop_physics" ); SetGoal( 30 ); if ( IsPC() ) { // only in Ep2 for PC. (Shared across HLX for X360.) SetGameDirFilter( "ep2" ); } }
/* =========== ControllerMove =========== */ void CInput::ControllerMove( float frametime, CUserCmd *cmd ) { if ( IsPC() ) { if (!m_fCameraInterceptingMouse && m_fMouseActive) { MouseMove( cmd); } } JoyStickMove( frametime, cmd); }
void Init() { SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME ); SetInflictorFilter( "npc_manhack" ); SetGoal( 5 ); if ( IsPC() ) { // only in HL2 for PC. (Shared across HLX for X360.) SetGameDirFilter( "hl2" ); } }
void CTextureManager::ReloadFilesInList( IFileList *pFilesToReload ) { if ( !IsPC() ) return; for ( int i=m_TextureList.First(); i != m_TextureList.InvalidIndex(); i=m_TextureList.Next( i ) ) { ITextureInternal *pTex = m_TextureList[i]; pTex->ReloadFilesInList( pFilesToReload ); } }
void Init() { SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME ); SetAttackerFilter( "combine_mine" ); SetGoal( 1 ); if ( IsPC() ) { // only in Ep2 for PC. (Shared across HLX for X360.) SetGameDirFilter( "ep2" ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CMaterialSubRect::ParseMaterialVars( KeyValues &keyValues ) { KeyValues *pKeyValues = &keyValues; // I'm not quite sure how this can happen, but we'll see... const char *pShaderName = pKeyValues->GetName(); if ( !pShaderName ) { DevWarning( 1, "CMaterialSubRect::InitializeShader: Shader not specified in material %s.\n", GetName() ); Assert( 0 ); pShaderName = IsPC() ? "Wireframe_DX6" : "Wireframe_DX9"; } // Verify we have the correct "shader." There is only one type. if ( !Q_strcmp( pShaderName, "Subrect" ) ) { KeyValues *pVar = pKeyValues->GetFirstSubKey(); while ( pVar ) { if ( !Q_strcmp( pVar->GetName(), "$Pos" ) ) { sscanf( pVar->GetString(), "%f %f", &m_vecOffset.x, &m_vecOffset.y ); } if ( !Q_strcmp( pVar->GetName(), "$Size" ) ) { sscanf( pVar->GetString(), "%f %f", &m_vecSize.x, &m_vecSize.y ); } if ( !Q_strcmp( pVar->GetName(), "$Material" ) ) { m_pMaterialPage = static_cast<IMaterialInternal*>( MaterialSystem()->FindMaterial( pVar->GetString(), TEXTURE_GROUP_DECAL ) ); m_pMaterialPage = m_pMaterialPage->GetRealTimeVersion(); //always work with the realtime material internally } // if ( !Q_strcmp( pVar->GetName(), "$decalscale" ) ) // { // m_flDecalScale = pVar->GetFloat(); // } // Add var to list. IMaterialVar *pNewVar = CreateMaterialVarFromKeyValue( this, pVar ); if ( pNewVar ) { m_aMaterialVars.AddToTail( pNewVar ); } // Continue getting the keys until they are all found. pVar = pVar->GetNextKey(); } } }
void Init() { SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME ); SetInflictorFilter( "npc_grenade_frag" ); SetVictimFilter( "npc_combine_s" ); SetGoal( 1 ); if ( IsPC() ) { // only in Ep2 for PC. (Shared across HLX for X360.) SetGameDirFilter( "ep2" ); } }
virtual void Init() { SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME ); SetInflictorFilter( "prop_combine_ball" ); SetVictimFilter( "npc_combine_s" ); SetGoal( 1 ); if ( IsPC() ) { // only in Ep2 for PC. (Shared across HLX for X360.) SetGameDirFilter( "episodic" ); } }
virtual void Init() { SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME ); SetInflictorFilter( "prop_combine_ball" ); SetGoal( 1 ); m_pLastInflictor = NULL; m_iLocalCount = 0; if ( IsPC() ) { // only in Ep1 for PC. (Shared across HLX for X360.) SetGameDirFilter( "episodic" ); } }
/* =========== ControllerMove =========== */ void CInput::ControllerMove( float frametime, CUserCmd *cmd ) { if ( IsPC() ) { if ( !m_fCameraInterceptingMouse && m_fMouseActive ) { MouseMove( cmd); } } JoyStickMove( frametime, cmd); #ifdef C17_HAPTICS cliHaptics->HapticsMove ( frametime, cmd); // Haptics addition #endif }
//----------------------------------------------------------------------------- // Connect, disconnect //----------------------------------------------------------------------------- bool CEngineAPI::Connect( CreateInterfaceFn factory ) { // Store off the app system factory... g_AppSystemFactory = factory; if ( !BaseClass::Connect( factory ) ) return false; g_pFileSystem = g_pFullFileSystem; if ( !g_pFileSystem ) return false; g_pFileSystem->SetWarningFunc( Warning ); if ( !Shader_Connect( true ) ) return false; g_pPhysics = (IPhysics*)factory( VPHYSICS_INTERFACE_VERSION, NULL ); if ( IsPC() ) { avi = (IAvi*)factory( AVI_INTERFACE_VERSION, NULL ); if ( !avi ) return false; } bik = (IBik*)factory( BIK_INTERFACE_VERSION, NULL ); if ( !bik ) return false; if ( !g_pStudioRender || !g_pDataCache || !g_pPhysics || !g_pMDLCache || !g_pMatSystemSurface || !g_pInputSystem ) { Warning( "Engine wasn't able to acquire required interfaces!\n" ); return false; } if (!g_pStudioRender) { Sys_Error( "Unable to init studio render system version %s\n", STUDIO_RENDER_INTERFACE_VERSION ); return false; } g_pHammer = (IHammer*)factory( INTERFACEVERSION_HAMMER, NULL ); ConnectMDLCacheNotify(); return true; }
//----------------------------------------------------------------------------- // Purpose: For debugging startup times, etc. // Input : *fmt - // ... - //----------------------------------------------------------------------------- void COM_TimestampedLog( char const *fmt, ... ) { static float s_LastStamp = 0.0; static bool s_bShouldLog = false; static bool s_bChecked = false; static bool s_bFirstWrite = false; if ( !s_bChecked ) { // s_bShouldLog = ( IsX360() || CommandLine()->CheckParm( "-profile" ) ) ? true : false; s_bShouldLog = false; s_bChecked = true; } if ( !s_bShouldLog ) { return; } char string[1024]; va_list argptr; va_start( argptr, fmt ); _vsnprintf( string, sizeof( string ), fmt, argptr ); va_end( argptr ); float curStamp = Plat_FloatTime(); #if defined( _X360 ) XBX_rTimeStampLog( curStamp, string ); #endif if ( IsPC() ) { if ( !s_bFirstWrite ) { unlink( "timestamped.log" ); s_bFirstWrite = true; } FILE* fp = fopen( "timestamped.log", "at+" ); fprintf( fp, "%8.4f / %8.4f: %s\n", curStamp, curStamp - s_LastStamp, string ); fclose( fp ); } s_LastStamp = curStamp; }
// checks the registry for the low violence setting // Check "HKEY_CURRENT_USER\Software\Valve\Source\Settings" and "User Token 2" or "User Token 3" bool IsLowViolenceBuild( void ) { #if defined(_WIN32) HKEY hKey; char szValue[64]; unsigned long len = sizeof(szValue) - 1; bool retVal = false; if ( IsPC() && RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Valve\\Source\\Settings", NULL, KEY_READ, &hKey) == ERROR_SUCCESS ) { // User Token 2 if ( RegQueryValueEx( hKey, "User Token 2", NULL, NULL, (unsigned char*)szValue, &len ) == ERROR_SUCCESS ) { if ( Q_strlen( szValue ) > 0 ) { retVal = true; } } if ( !retVal ) { // reset "len" for the next check len = sizeof(szValue) - 1; // User Token 3 if ( RegQueryValueEx( hKey, "User Token 3", NULL, NULL, (unsigned char*)szValue, &len ) == ERROR_SUCCESS ) { if ( Q_strlen( szValue ) > 0 ) { retVal = true; } } } RegCloseKey(hKey); } return retVal; #elif _LINUX return false; #else #error "Fix me" #endif }
/* =========== ControllerMove =========== */ void CInput::ControllerMove( float frametime, CUserCmd *cmd ) { if ( IsPC() ) { if ( !m_fCameraInterceptingMouse && m_fMouseActive ) { MouseMove( cmd); } } JoyStickMove( frametime, cmd); #ifdef C17_HAPTICS cliHaptics->HapticsMove(frametime, cmd); // Haptics addition #endif // NVNT if we have a haptic device.. if(haptics && haptics->HasDevice()) { if(engine->IsPaused() || engine->IsLevelMainMenuBackground() || vgui::surface()->IsCursorVisible() || !engine->IsInGame()) { // NVNT send a menu process to the haptics system. haptics->MenuProcess(); return; } #ifdef CSTRIKE_DLL // NVNT cstrike fov grabing. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if(player){ haptics->UpdatePlayerFOV(player->GetFOV()); } #endif // NVNT calculate move with the navigation on the haptics system. haptics->CalculateMove(cmd->forwardmove, cmd->sidemove, frametime); // NVNT send a game process to the haptics system. haptics->GameProcess(); #if defined( WIN32 ) && !defined( _X360 ) // NVNT update our avatar effect. UpdateAvatarEffect(); #endif } }
void CHARACTER::ClearAffect(bool bSave) { TAffectFlag afOld = m_afAffectFlag; WORD wMovSpd = GetPoint(POINT_MOV_SPEED); WORD wAttSpd = GetPoint(POINT_ATT_SPEED); itertype(m_list_pkAffect) it = m_list_pkAffect.begin(); while (it != m_list_pkAffect.end()) { CAffect * pkAff = *it; if (bSave) { if ( IS_NO_CLEAR_ON_DEATH_AFFECT(pkAff->dwType) || IS_NO_SAVE_AFFECT(pkAff->dwType) ) { ++it; continue; } if (IsPC()) { SendAffectRemovePacket(GetDesc(), GetPlayerID(), pkAff->dwType, pkAff->bApplyOn); } } ComputeAffect(pkAff, false); it = m_list_pkAffect.erase(it); CAffect::Release(pkAff); } if (afOld != m_afAffectFlag || wMovSpd != GetPoint(POINT_MOV_SPEED) || wAttSpd != GetPoint(POINT_ATT_SPEED)) UpdatePacket(); CheckMaximumPoints(); if (m_list_pkAffect.empty()) event_cancel(&m_pkAffectEvent); }
//----------------------------------------------------------------------------- // Purpose: Finds which directory the platform resides in // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CGameUI::FindPlatformDirectory(char *platformDir, int bufferSize) { platformDir[0] = '\0'; if ( platformDir[0] == '\0' ) { // we're not under steam, so setup using path relative to game if ( IsPC() ) { if ( ::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), platformDir, bufferSize ) ) { char *lastslash = strrchr(platformDir, '\\'); // this should be just before the filename if ( lastslash ) { *lastslash = 0; Q_strncat(platformDir, "\\platform\\", bufferSize, COPY_ALL_CHARACTERS ); return true; } } } else { // xbox fetches the platform path from exisiting platform search path // path to executeable is not correct for xbox remote configuration if ( g_pFullFileSystem->GetSearchPath( "PLATFORM", false, platformDir, bufferSize ) ) { char *pSeperator = strchr( platformDir, ';' ); if ( pSeperator ) *pSeperator = '\0'; return true; } } Error( "Unable to determine platform directory\n" ); return false; } return (platformDir[0] != 0); }
void UpdateFullScreenDepthTexture( void ) { if( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() ) return; ITexture *pDepthTex = GetFullFrameDepthTexture(); CMatRenderContextPtr pRenderContext( materials ); if( IsX360() ) { pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, -1, NULL, NULL ); } else { pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, 0, NULL, NULL ); } pRenderContext->SetFullScreenDepthTextureValidityFlag( true ); if( r_depthoverlay.GetBool() ) { IMaterial *pMaterial = materials->FindMaterial( "debug/showz", TEXTURE_GROUP_OTHER, true ); pMaterial->IncrementReferenceCount(); IMaterialVar *BaseTextureVar = pMaterial->FindVar( "$basetexture", NULL, false ); IMaterialVar *pDepthInAlpha = NULL; if( IsPC() ) { pDepthInAlpha = pMaterial->FindVar( "$ALPHADEPTH", NULL, false ); pDepthInAlpha->SetIntValue( 1 ); } BaseTextureVar->SetTextureValue( pDepthTex ); pRenderContext->OverrideDepthEnable( true, false ); //don't write to depth, or else we'll never see translucents pRenderContext->DrawScreenSpaceQuad( pMaterial ); pRenderContext->OverrideDepthEnable( false, true ); pMaterial->DecrementReferenceCount(); } }
bool CHARACTER::RemoveAffect(CAffect * pkAff) { if (!pkAff) return false; // AFFECT_BUF_FIX m_list_pkAffect.remove(pkAff); // END_OF_AFFECT_BUF_FIX ComputeAffect(pkAff, false); // 백기 버그 수정. // 백기 버그는 버프 스킬 시전->둔갑->백기 사용(AFFECT_REVIVE_INVISIBLE) 후 바로 공격 할 경우에 발생한다. // 원인은 둔갑을 시전하는 시점에, 버프 스킬 효과를 무시하고 둔갑 효과만 적용되게 되어있는데, // 백기 사용 후 바로 공격하면 RemoveAffect가 불리게 되고, ComputePoints하면서 둔갑 효과 + 버프 스킬 효과가 된다. // ComputePoints에서 둔갑 상태면 버프 스킬 효과 안 먹히도록 하면 되긴 하는데, // ComputePoints는 광범위하게 사용되고 있어서 큰 변화를 주는 것이 꺼려진다.(어떤 side effect가 발생할지 알기 힘들다.) // 따라서 AFFECT_REVIVE_INVISIBLE가 RemoveAffect로 삭제되는 경우만 수정한다. // 시간이 다 되어 백기 효과가 풀리는 경우는 버그가 발생하지 않으므로 그와 똑같이 함. // (ProcessAffect를 보면 시간이 다 되어서 Affect가 삭제되는 경우, ComputePoints를 부르지 않는다.) if (AFFECT_REVIVE_INVISIBLE != pkAff->dwType) { ComputePoints(); } CheckMaximumPoints(); if (test_server) sys_log(0, "AFFECT_REMOVE: %s (flag %u apply: %u)", GetName(), pkAff->dwFlag, pkAff->bApplyOn); if (IsPC()) { SendAffectRemovePacket(GetDesc(), GetPlayerID(), pkAff->dwType, pkAff->bApplyOn); } CAffect::Release(pkAff); return true; }
bool old_bf_write::WriteBits(const void *pInData, int nBits) { #if defined( BB_PROFILING ) VPROF( "old_bf_write::WriteBits" ); #endif unsigned char *pOut = (unsigned char*)pInData; int nBitsLeft = nBits; // Bounds checking.. if ( (m_iCurBit+nBits) > m_nDataBits ) { SetOverflowFlag(); CallErrorHandler( BITBUFERROR_BUFFER_OVERRUN, GetDebugName() ); return false; } // Align output to dword boundary while (((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8) { WriteUBitLong( *pOut, 8, false ); ++pOut; nBitsLeft -= 8; } if ( IsPC() && (nBitsLeft >= 32) && (m_iCurBit & 7) == 0 ) { // current bit is byte aligned, do block copy int numbytes = nBitsLeft >> 3; int numbits = numbytes << 3; Q_memcpy( m_pData+(m_iCurBit>>3), pOut, numbytes ); pOut += numbytes; nBitsLeft -= numbits; m_iCurBit += numbits; }
//----------------------------------------------------------------------------- // Purpose: // Input : dt - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CEngine::FilterTime( float dt ) { // Dedicated's tic_rate regulates server frame rate. Don't apply fps filter here. // Only do this restriction on the client. Prevents clients from accomplishing certain // hacks by pausing their client for a period of time. if ( IsPC() && !sv.IsDedicated() && !CanCheat() && fps_max.GetFloat() < 30 ) { // Don't do anything if fps_max=0 (which means it's unlimited). if ( fps_max.GetFloat() != 0.0f ) { Warning( "sv_cheats is 0 and fps_max is being limited to a minimum of 30 (or set to 0).\n" ); fps_max.SetValue( 30.0f ); } } float fps = fps_max.GetFloat(); if ( fps > 0.0f ) { // Limit fps to withing tolerable range // fps = max( MIN_FPS, fps ); // red herring - since we're only checking if dt < 1/fps, clamping against MIN_FPS has no effect fps = min( MAX_FPS, fps ); float minframetime = 1.0 / fps; if ( #if !defined(SWDS) !demoplayer->IsPlayingTimeDemo() && #endif dt < minframetime ) { // framerate is too high return false; } } return true; }
ALLOC_CALL void * __cdecl _aligned_offset_recalloc_base( void * memblock, size_t size, size_t align, size_t offset) { Assert( IsPC() || 0 ); return NULL; }
FSReturnCode_t LocateGameInfoFile( const CFSSteamSetupInfo &fsInfo, char *pOutDir, int outDirLen ) { // Engine and Hammer don't want to search around for it. if ( fsInfo.m_bOnlyUseDirectoryName ) { if ( !fsInfo.m_pDirectoryName ) return SetupFileSystemError( false, FS_MISSING_GAMEINFO_FILE, "bOnlyUseDirectoryName=1 and pDirectoryName=NULL." ); bool bExists = DoesFileExistIn( fsInfo.m_pDirectoryName, GAMEINFO_FILENAME ); if ( IsX360() && !bExists ) { bExists = DoesFileExistIn( fsInfo.m_pDirectoryName, GAMEINFO_FILENAME_ALTERNATE ); } if ( !bExists ) { if ( IsX360() && CommandLine()->FindParm( "-basedir" ) ) { char basePath[MAX_PATH]; strcpy( basePath, CommandLine()->ParmValue( "-basedir", "" ) ); Q_AppendSlash( basePath, sizeof( basePath ) ); Q_strncat( basePath, fsInfo.m_pDirectoryName, sizeof( basePath ), COPY_ALL_CHARACTERS ); if ( DoesFileExistIn( basePath, GAMEINFO_FILENAME ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } if ( IsX360() && DoesFileExistIn( basePath, GAMEINFO_FILENAME_ALTERNATE ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } } return SetupFileSystemError( true, FS_MISSING_GAMEINFO_FILE, "Setup file '%s' doesn't exist in subdirectory '%s'.\nCheck your -game parameter or VCONFIG setting.", GAMEINFO_FILENAME, fsInfo.m_pDirectoryName ); } Q_strncpy( pOutDir, fsInfo.m_pDirectoryName, outDirLen ); return FS_OK; } // First, check for overrides on the command line or environment variables. const char *pProject = GetVProjectCmdLineValue(); if ( pProject ) { if ( DoesFileExistIn( pProject, GAMEINFO_FILENAME ) ) { Q_MakeAbsolutePath( pOutDir, outDirLen, pProject ); return FS_OK; } if ( IsX360() && DoesFileExistIn( pProject, GAMEINFO_FILENAME_ALTERNATE ) ) { Q_MakeAbsolutePath( pOutDir, outDirLen, pProject ); return FS_OK; } if ( IsX360() && CommandLine()->FindParm( "-basedir" ) ) { char basePath[MAX_PATH]; strcpy( basePath, CommandLine()->ParmValue( "-basedir", "" ) ); Q_AppendSlash( basePath, sizeof( basePath ) ); Q_strncat( basePath, pProject, sizeof( basePath ), COPY_ALL_CHARACTERS ); if ( DoesFileExistIn( basePath, GAMEINFO_FILENAME ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } if ( DoesFileExistIn( basePath, GAMEINFO_FILENAME_ALTERNATE ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } } if ( fsInfo.m_bNoGameInfo ) { // fsInfo.m_bNoGameInfo is set by the Steam dedicated server, before it knows which mod to use. // Steam dedicated server doesn't need a gameinfo.txt, because we'll ask which mod to use, even if // -game is supplied on the command line. Q_strncpy( pOutDir, "", outDirLen ); return FS_OK; } else { // They either specified vproject on the command line or it's in their registry. Either way, // we don't want to continue if they've specified it but it's not valid. goto ShowError; } } if ( fsInfo.m_bNoGameInfo ) { Q_strncpy( pOutDir, "", outDirLen ); return FS_OK; } // Ask the application if it can provide us with a game info directory { bool bBubbleDir = true; SuggestGameInfoDirFn_t pfnSuggestGameInfoDirFn = GetSuggestGameInfoDirFn(); if ( pfnSuggestGameInfoDirFn && ( * pfnSuggestGameInfoDirFn )( &fsInfo, pOutDir, outDirLen, &bBubbleDir ) && FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, bBubbleDir ) ) return FS_OK; } // Try to use the environment variable / registry if ( ( pProject = getenv( GAMEDIR_TOKEN ) ) != NULL && ( Q_MakeAbsolutePath( pOutDir, outDirLen, pProject ), 1 ) && FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, false ) ) return FS_OK; if ( IsPC() ) { Warning( "Warning: falling back to auto detection of vproject directory.\n" ); // Now look for it in the directory they passed in. if ( fsInfo.m_pDirectoryName ) Q_MakeAbsolutePath( pOutDir, outDirLen, fsInfo.m_pDirectoryName ); else Q_MakeAbsolutePath( pOutDir, outDirLen, "." ); if ( FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, true ) ) return FS_OK; // Use the CWD Q_getwd( pOutDir, outDirLen ); if ( FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, true ) ) return FS_OK; } ShowError: return SetupFileSystemError( true, FS_MISSING_GAMEINFO_FILE, "Unable to find %s. Solutions:\n\n" "1. Read http://www.valve-erc.com/srcsdk/faq.html#NoGameDir\n" "2. Run vconfig to specify which game you're working on.\n" "3. Add -game <path> on the command line where <path> is the directory that %s is in.\n", GAMEINFO_FILENAME, GAMEINFO_FILENAME ); }
FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) { if ( !initInfo.m_pFileSystem || !initInfo.m_pDirectoryName ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_LoadSearchPaths: Invalid parameters specified." ); KeyValues *pMainFile, *pFileSystemInfo, *pSearchPaths; FSReturnCode_t retVal = LoadGameInfoFile( initInfo.m_pDirectoryName, pMainFile, pFileSystemInfo, pSearchPaths ); if ( retVal != FS_OK ) return retVal; // All paths except those marked with |gameinfo_path| are relative to the base dir. char baseDir[MAX_PATH]; if ( !FileSystem_GetBaseDir( baseDir, sizeof( baseDir ) ) ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." ); initInfo.m_ModPath[0] = 0; #define GAMEINFOPATH_TOKEN "|gameinfo_path|" #define BASESOURCEPATHS_TOKEN "|all_source_engine_paths|" bool bLowViolence = IsLowViolenceBuild(); bool bFirstGamePath = true; for ( KeyValues *pCur=pSearchPaths->GetFirstValue(); pCur; pCur=pCur->GetNextValue() ) { const char *pPathID = pCur->GetName(); const char *pLocation = pCur->GetString(); if ( Q_stristr( pLocation, GAMEINFOPATH_TOKEN ) == pLocation ) { pLocation += strlen( GAMEINFOPATH_TOKEN ); FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, initInfo.m_pDirectoryName, pLocation, bLowViolence ); } else if ( Q_stristr( pLocation, BASESOURCEPATHS_TOKEN ) == pLocation ) { // This is a special identifier that tells it to add the specified path for all source engine versions equal to or prior to this version. // So in Orange Box, if they specified: // |all_source_engine_paths|hl2 // it would add the ep2\hl2 folder and the base (ep1-era) hl2 folder. // // We need a special identifier in the gameinfo.txt here because the base hl2 folder exists in different places. // In the case of a game or a Steam-launched dedicated server, all the necessary prior engine content is mapped in with the Steam depots, // so we can just use the path as-is. // In the case of an hldsupdatetool dedicated server, the base hl2 folder is "..\..\hl2" (since we're up in the 'orangebox' folder). pLocation += strlen( BASESOURCEPATHS_TOKEN ); // Add the Orange-box path (which also will include whatever the depots mapped in as well if we're // running a Steam-launched app). FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence ); if ( FileSystem_IsHldsUpdateToolDedicatedServer() ) { // If we're using the hldsupdatetool dedicated server, then go up a directory to get the ep1-era files too. char ep1EraPath[MAX_PATH]; V_snprintf( ep1EraPath, sizeof( ep1EraPath ), "..%c%s", CORRECT_PATH_SEPARATOR, pLocation ); FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, ep1EraPath, bLowViolence ); } } else { FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence ); } } pMainFile->deleteThis(); // // Set up search paths for add-ons // if ( IsPC() ) { #ifdef ENGINE_DLL FileSystem_UpdateAddonSearchPaths( initInfo.m_pFileSystem ); #endif } // these specialized tool paths are not used on 360 and cause a costly constant perf tax, so inhibited if ( IsPC() ) { // Create a content search path based on the game search path const char *pGameRoot = getenv( GAMEROOT_TOKEN ); const char *pContentRoot = getenv( CONTENTROOT_TOKEN ); if ( pGameRoot && pContentRoot ) { int nLen = initInfo.m_pFileSystem->GetSearchPath( "GAME", false, NULL, 0 ); char *pSearchPath = (char*)stackalloc( nLen * sizeof(char) ); initInfo.m_pFileSystem->GetSearchPath( "GAME", false, pSearchPath, nLen ); char *pPath = pSearchPath; while( pPath ) { char *pSemiColon = strchr( pPath, ';' ); if ( pSemiColon ) { *pSemiColon = 0; } Q_StripTrailingSlash( pPath ); Q_FixSlashes( pPath ); const char *pCurPath = pPath; pPath = pSemiColon ? pSemiColon + 1 : NULL; char pRelativePath[MAX_PATH]; char pContentPath[MAX_PATH]; if ( !Q_MakeRelativePath( pCurPath, pGameRoot, pRelativePath, sizeof(pRelativePath) ) ) continue; Q_ComposeFileName( pContentRoot, pRelativePath, pContentPath, sizeof(pContentPath) ); initInfo.m_pFileSystem->AddSearchPath( pContentPath, "CONTENT" ); } // Add the "platform" directory as a game searchable path char pPlatformPath[MAX_PATH]; Q_ComposeFileName( pGameRoot, "platform", pPlatformPath, sizeof(pPlatformPath) ); initInfo.m_pFileSystem->AddSearchPath( pPlatformPath, "GAME", PATH_ADD_TO_TAIL ); initInfo.m_pFileSystem->AddSearchPath( pContentRoot, "CONTENTROOT" ); initInfo.m_pFileSystem->AddSearchPath( pGameRoot, "GAMEROOT" ); } else { // Come up with some reasonable default int nLen = initInfo.m_pFileSystem->GetSearchPath( "MOD", false, NULL, 0 ); char *pSearchPath = (char*)stackalloc( nLen * sizeof(char) ); initInfo.m_pFileSystem->GetSearchPath( "MOD", false, pSearchPath, nLen ); char *pSemiColon = strchr( pSearchPath, ';' ); if ( pSemiColon ) { *pSemiColon = 0; } char pGameRootPath[MAX_PATH]; Q_strncpy( pGameRootPath, pSearchPath, sizeof(pGameRootPath) ); Q_StripTrailingSlash( pGameRootPath ); Q_StripFilename( pGameRootPath ); char pContentRootPath[MAX_PATH]; Q_strncpy( pContentRootPath, pGameRootPath, sizeof(pContentRootPath) ); char *pGame = Q_stristr( pContentRootPath, "game" ); if ( pGame ) { Q_strcpy( pGame, "content" ); } initInfo.m_pFileSystem->AddSearchPath( pContentRootPath, "CONTENTROOT" ); initInfo.m_pFileSystem->AddSearchPath( pGameRootPath, "GAMEROOT" ); } // Also, mark specific path IDs as "by request only". That way, we won't waste time searching in them // when people forget to specify a search path. initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "contentroot", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "gameroot", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "content", true ); } // Also, mark specific path IDs as "by request only". That way, we won't waste time searching in them // when people forget to specify a search path. initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "executable_path", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "gamebin", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "mod", true ); // Add the write path last. if ( initInfo.m_ModPath[0] != 0 ) { initInfo.m_pFileSystem->AddSearchPath( initInfo.m_ModPath, "DEFAULT_WRITE_PATH", PATH_ADD_TO_TAIL ); } #ifdef _DEBUG initInfo.m_pFileSystem->PrintSearchPaths(); #endif #if defined( ENABLE_RUNTIME_STACK_TRANSLATION ) && !defined( _X360 ) //copy search paths to stack tools so it can grab pdb's from all over. But only on P4 or Steam Beta builds if( (CommandLine()->FindParm( "-steam" ) == 0) || //not steam (CommandLine()->FindParm( "-internalbuild" ) != 0) ) //steam beta is ok { char szSearchPaths[4096]; //int CBaseFileSystem::GetSearchPath( const char *pathID, bool bGetPackFiles, char *pPath, int nMaxLen ) int iLength1 = initInfo.m_pFileSystem->GetSearchPath( "EXECUTABLE_PATH", false, szSearchPaths, 4096 ); if( iLength1 == 1 ) iLength1 = 0; int iLength2 = initInfo.m_pFileSystem->GetSearchPath( "GAMEBIN", false, szSearchPaths + iLength1, 4096 - iLength1 ); if( (iLength2 > 1) && (iLength1 > 1) ) { szSearchPaths[iLength1 - 1] = ';'; //replace first null terminator } const char *szAdditionalPath = CommandLine()->ParmValue( "-AdditionalPDBSearchPath" ); if( szAdditionalPath && szAdditionalPath[0] ) { int iLength = iLength1; if( iLength2 > 1 ) iLength += iLength2; if( iLength != 0 ) { szSearchPaths[iLength - 1] = ';'; //replaces null terminator } V_strncpy( &szSearchPaths[iLength], szAdditionalPath, 4096 - iLength ); } //Append the perforce symbol server last. Documentation says that "srv*\\perforce\symbols" should work, but it doesn't. //"symsrv*symsrv.dll*\\perforce\symbols" which the docs say is the same statement, works. { V_strncat( szSearchPaths, ";symsrv*symsrv.dll*\\\\perforce\\symbols", 4096 ); } SetStackTranslationSymbolSearchPath( szSearchPaths ); //MessageBox( NULL, szSearchPaths, "Search Paths", 0 ); } #endif return FS_OK; }
int CHARACTER::ProcessAffect() { bool bDiff = false; CAffect *pkAff = NULL; // // 프리미엄 처리 // for (int i = 0; i <= PREMIUM_MAX_NUM; ++i) { int aff_idx = i + AFFECT_PREMIUM_START; pkAff = FindAffect(aff_idx); if (!pkAff) continue; int remain = GetPremiumRemainSeconds(i); if (remain < 0) { RemoveAffect(aff_idx); bDiff = true; } else pkAff->lDuration = remain + 1; } ////////// HAIR_AFFECT pkAff = FindAffect(AFFECT_HAIR); if (pkAff) { // IF HAIR_LIMIT_TIME() < CURRENT_TIME() if ( this->GetQuestFlag("hair.limit_time") < get_global_time()) { // SET HAIR NORMAL this->SetPart(PART_HAIR, 0); // REMOVE HAIR AFFECT RemoveAffect(AFFECT_HAIR); } else { // INCREASE AFFECT DURATION ++(pkAff->lDuration); } } ////////// HAIR_AFFECT // CHorseNameManager::instance().Validate(this); TAffectFlag afOld = m_afAffectFlag; long lMovSpd = GetPoint(POINT_MOV_SPEED); long lAttSpd = GetPoint(POINT_ATT_SPEED); itertype(m_list_pkAffect) it; it = m_list_pkAffect.begin(); while (it != m_list_pkAffect.end()) { pkAff = *it; bool bEnd = false; if (pkAff->dwType >= GUILD_SKILL_START && pkAff->dwType <= GUILD_SKILL_END) { if (!GetGuild() || !GetGuild()->UnderAnyWar()) bEnd = true; } if (pkAff->lSPCost > 0) { if (GetSP() < pkAff->lSPCost) bEnd = true; else PointChange(POINT_SP, -pkAff->lSPCost); } // AFFECT_DURATION_BUG_FIX // 무한 효과 아이템도 시간을 줄인다. // 시간을 매우 크게 잡기 때문에 상관 없을 것이라 생각됨. if ( --pkAff->lDuration <= 0 ) { bEnd = true; } // END_AFFECT_DURATION_BUG_FIX if (bEnd) { it = m_list_pkAffect.erase(it); ComputeAffect(pkAff, false); bDiff = true; if (IsPC()) { SendAffectRemovePacket(GetDesc(), GetPlayerID(), pkAff->dwType, pkAff->bApplyOn); } CAffect::Release(pkAff); continue; } ++it; } if (bDiff) { if (afOld != m_afAffectFlag || lMovSpd != GetPoint(POINT_MOV_SPEED) || lAttSpd != GetPoint(POINT_ATT_SPEED)) { UpdatePacket(); } CheckMaximumPoints(); } if (m_list_pkAffect.empty()) return true; return false; }
//----------------------------------------------------------------------------- // Purpose: paints all the vgui elements //----------------------------------------------------------------------------- void CGameUI::RunFrame() { if ( IsX360() && m_bOpenProgressOnStart ) { StartProgressBar(); m_bOpenProgressOnStart = false; } int wide, tall; #if defined( TOOLFRAMEWORK_VGUI_REFACTOR ) // resize the background panel to the screen size vgui::VPANEL clientDllPanel = enginevguifuncs->GetPanel( PANEL_ROOT ); int x, y; vgui::ipanel()->GetPos( clientDllPanel, x, y ); vgui::ipanel()->GetSize( clientDllPanel, wide, tall ); staticPanel->SetBounds( x, y, wide,tall ); #else vgui::surface()->GetScreenSize(wide, tall); GetUiBaseModPanelClass().SetSize(wide, tall); #endif // Run frames g_VModuleLoader.RunFrame(); GetUiBaseModPanelClass().RunFrame(); // Play the start-up music the first time we run frame if ( IsPC() && m_iPlayGameStartupSound > 0 ) { m_iPlayGameStartupSound--; if ( !m_iPlayGameStartupSound ) { PlayGameStartupSound(); } } if ( IsPC() && m_bTryingToLoadFriends && m_iFriendsLoadPauseFrames-- < 1 && g_hMutex && g_hWaitMutex ) { // try and load Steam platform files unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0); if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED) { // we got the mutex, so load Friends/Serverbrowser // clear the loading flag m_bTryingToLoadFriends = false; g_VModuleLoader.LoadPlatformModules(&m_GameFactory, 1, false); // release the wait mutex Sys_ReleaseMutex(g_hWaitMutex); // notify the game of our game name const char *fullGamePath = engine->GetGameDirectory(); const char *pathSep = strrchr( fullGamePath, '/' ); if ( !pathSep ) { pathSep = strrchr( fullGamePath, '\\' ); } if ( pathSep ) { KeyValues *pKV = new KeyValues("ActiveGameName" ); pKV->SetString( "name", pathSep + 1 ); pKV->SetInt( "appid", engine->GetAppID() ); KeyValues *modinfo = new KeyValues("ModInfo"); if ( modinfo->LoadFromFile( g_pFullFileSystem, "gameinfo.txt" ) ) { pKV->SetString( "game", modinfo->GetString( "game", "" ) ); } modinfo->deleteThis(); g_VModuleLoader.PostMessageToAllModules( pKV ); } // notify the ui of a game connect if we're already in a game if (m_iGameIP) { SendConnectedToGameMessage(); } } } }
//----------------------------------------------------------------------------- // Purpose: Called to setup the game UI //----------------------------------------------------------------------------- void CGameUI::Start() { // determine Steam location for configuration if ( !FindPlatformDirectory( m_szPlatformDir, sizeof( m_szPlatformDir ) ) ) return; if ( IsPC() ) { // setup config file directory char szConfigDir[512]; Q_strncpy( szConfigDir, m_szPlatformDir, sizeof( szConfigDir ) ); Q_strncat( szConfigDir, "config", sizeof( szConfigDir ), COPY_ALL_CHARACTERS ); Msg( "Steam config directory: %s\n", szConfigDir ); g_pFullFileSystem->AddSearchPath(szConfigDir, "CONFIG"); g_pFullFileSystem->CreateDirHierarchy("", "CONFIG"); // user dialog configuration vgui::system()->SetUserConfigFile("InGameDialogConfig.vdf", "CONFIG"); g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM" ); } // localization g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt"); g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt"); Sys_SetLastError( SYS_NO_ERROR ); if ( IsPC() ) { g_hMutex = Sys_CreateMutex( "ValvePlatformUIMutex" ); g_hWaitMutex = Sys_CreateMutex( "ValvePlatformWaitMutex" ); if ( g_hMutex == NULL || g_hWaitMutex == NULL || Sys_GetLastError() == SYS_ERROR_INVALID_HANDLE ) { // error, can't get handle to mutex if (g_hMutex) { Sys_ReleaseMutex(g_hMutex); } if (g_hWaitMutex) { Sys_ReleaseMutex(g_hWaitMutex); } g_hMutex = NULL; g_hWaitMutex = NULL; Error("Steam Error: Could not access Steam, bad mutex\n"); return; } unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0); if (!(waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED)) { // mutex locked, need to deactivate Steam (so we have the Friends/ServerBrowser data files) // get the wait mutex, so that Steam.exe knows that we're trying to acquire ValveTrackerMutex waitResult = Sys_WaitForSingleObject(g_hWaitMutex, 0); if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED) { Sys_EnumWindows(SendShutdownMsgFunc, 1); } } // Delay playing the startup music until two frames // this allows cbuf commands that occur on the first frame that may start a map m_iPlayGameStartupSound = 2; // now we are set up to check every frame to see if we can friends/server browser m_bTryingToLoadFriends = true; m_iFriendsLoadPauseFrames = 1; } }
//----------------------------------------------------------------------------- // Purpose: Initialization //----------------------------------------------------------------------------- void CGameUI::Initialize( CreateInterfaceFn factory ) { MEM_ALLOC_CREDIT(); ConnectTier1Libraries( &factory, 1 ); ConnectTier2Libraries( &factory, 1 ); ConVar_Register( FCVAR_CLIENTDLL ); ConnectTier3Libraries( &factory, 1 ); enginesound = (IEngineSound *)factory(IENGINESOUND_CLIENT_INTERFACE_VERSION, NULL); engine = (IVEngineClient *)factory( VENGINE_CLIENT_INTERFACE_VERSION, NULL ); bik = (IBik*)factory( BIK_INTERFACE_VERSION, NULL ); #ifndef _X360 SteamAPI_InitSafe(); steamapicontext->Init(); #endif CGameUIConVarRef var( "gameui_xbox" ); m_bIsConsoleUI = var.IsValid() && var.GetBool(); vgui::VGui_InitInterfacesList( "GameUI", &factory, 1 ); vgui::VGui_InitMatSysInterfacesList( "GameUI", &factory, 1 ); // load localization file g_pVGuiLocalize->AddFile( "Resource/gameui_%language%.txt", "GAME", true ); // load mod info ModInfo().LoadCurrentGameInfo(); // load localization file for kb_act.lst g_pVGuiLocalize->AddFile( "Resource/valve_%language%.txt", "GAME", true ); bool bFailed = false; enginevguifuncs = (IEngineVGui *)factory( VENGINE_VGUI_VERSION, NULL ); enginesurfacefuncs = (vgui::ISurface *)factory(VGUI_SURFACE_INTERFACE_VERSION, NULL); gameuifuncs = (IGameUIFuncs *)factory( VENGINE_GAMEUIFUNCS_VERSION, NULL ); xboxsystem = (IXboxSystem *)factory( XBOXSYSTEM_INTERFACE_VERSION, NULL ); #ifdef _X360 xonline = (IXOnline *)factory( XONLINE_INTERFACE_VERSION, NULL ); #endif #ifdef SWARM_DLL g_pMatchExtSwarm = ( IMatchExtSwarm * ) factory( IMATCHEXT_SWARM_INTERFACE, NULL ); #endif #ifdef SDK_DLL g_pMatchExtSwarm = ( IMatchExtSwarm * ) factory( IMATCHEXT_SWARM_INTERFACE, NULL ); #endif bFailed = !enginesurfacefuncs || !gameuifuncs || !enginevguifuncs || !xboxsystem || #ifdef _X360 !xonline || #endif #ifdef SWARM_DLL !g_pMatchExtSwarm || #endif #ifdef SDK_DLL !g_pMatchExtSwarm || #endif !g_pMatchFramework; if ( bFailed ) { Error( "CGameUI::Initialize() failed to get necessary interfaces\n" ); } // setup base panel UI_BASEMOD_PANEL_CLASS& factoryBasePanel = ConstructUiBaseModPanelClass(); // explicit singleton instantiation factoryBasePanel.SetBounds( 0, 0, 640, 480 ); factoryBasePanel.SetPaintBorderEnabled( false ); factoryBasePanel.SetPaintBackgroundEnabled( true ); factoryBasePanel.SetPaintEnabled( true ); factoryBasePanel.SetVisible( true ); factoryBasePanel.SetMouseInputEnabled( IsPC() ); // factoryBasePanel.SetKeyBoardInputEnabled( IsPC() ); factoryBasePanel.SetKeyBoardInputEnabled( true ); vgui::VPANEL rootpanel = enginevguifuncs->GetPanel( PANEL_GAMEUIDLL ); factoryBasePanel.SetParent( rootpanel ); }
void DrawPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool hasFlashlight, VertexCompressionType_t vertexCompression ) { bool bSinglePassFlashlight = false; bool hasBump = params[BUMPMAP]->IsTexture(); bool hasDiffuseBumpmap = hasBump && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0); bool hasBaseTexture = params[BASETEXTURE]->IsTexture(); bool hasDetailTexture = /*!hasBump && */params[DETAIL]->IsTexture(); bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) != 0; bool bHasDetailAlpha = params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->GetIntValue() != 0; bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use bool bSeamlessMapping = params[SEAMLESS_SCALE]->GetFloatValue() != 0.0; bool bShaderSrgbRead = ( IsX360() && IS_PARAM_DEFINED( SHADERSRGBREAD360 ) && params[SHADERSRGBREAD360]->GetIntValue() ); SHADOW_STATE { int nShadowFilterMode = 0; // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState pShaderShadow->EnableAlphaTest( bIsAlphaTested ); if( hasFlashlight ) { if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats } SetAdditiveBlendingShadowState( BASETEXTURE, true ); pShaderShadow->EnableDepthWrites( false ); // Be sure not to write to dest alpha pShaderShadow->EnableAlphaWrites( false ); } else { SetDefaultBlendingShadowState( BASETEXTURE, true ); } unsigned int flags = VERTEX_POSITION; if( hasBaseTexture ) { pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, !bShaderSrgbRead ); } // if( hasLightmap ) { pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); } if( hasFlashlight ) { pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER7 ); flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T | VERTEX_NORMAL; } if( hasDetailTexture ) { pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); } if( hasBump ) { pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); } if( hasVertexColor ) { flags |= VERTEX_COLOR; } // Normalizing cube map pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // texcoord0 : base texcoord // texcoord1 : lightmap texcoord // texcoord2 : lightmap texcoord offset int numTexCoords = 2; if( hasBump ) { numTexCoords = 3; } pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); // Pre-cache pixel shaders bool hasSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ); pShaderShadow->EnableSRGBWrite( true ); int nLightingPreviewMode = IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER0 ) + 2 * IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER1 ); #ifndef _X360 if ( g_pHardwareConfig->HasFastVertexTextures() ) { DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs30 ); SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, false ); SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, false ); SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, hasFlashlight ); SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, false ); SET_STATIC_VERTEX_SHADER_COMBO( PARALLAX_MAPPING, 0 ); //( bumpmap_variant == 2 )?1:0); SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); //( bumpmap_variant == 2 )?1:0); SET_STATIC_VERTEX_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_VERTEX_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_VERTEX_SHADER_COMBO( FANCY_BLENDING, false ); SET_STATIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode != 0 ); SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs30 ); } else #endif { DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, false ); SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, false ); SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, hasFlashlight ); SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, false ); SET_STATIC_VERTEX_SHADER_COMBO( PARALLAX_MAPPING, 0 ); //( bumpmap_variant == 2 )?1:0); SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); //( bumpmap_variant == 2 )?1:0); SET_STATIC_VERTEX_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_VERTEX_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_VERTEX_SHADER_COMBO( FANCY_BLENDING, false ); SET_STATIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, nLightingPreviewMode != 0 ); #ifdef _X360 SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); #endif SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); } #ifndef _X360 if ( g_pHardwareConfig->HasFastVertexTextures() ) { DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps30 ); SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead ); SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps30 ); } else #endif if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead ); SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); } else { DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump ); SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSrgbRead ); SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); } // HACK HACK HACK - enable alpha writes all the time so that we have them for // underwater stuff. // But only do it if we're not using the alpha already for translucency pShaderShadow->EnableAlphaWrites( bFullyOpaque ); if( hasFlashlight ) { FogToBlack(); } else { DefaultFog(); } PI_BeginCommandBuffer(); PI_SetModulationVertexShaderDynamicState( ); PI_EndCommandBuffer(); } DYNAMIC_STATE { if( hasBaseTexture ) { BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); } else { pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE ); } // if( hasLightmap ) { pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); } bool bFlashlightShadows = false; bool bUberlight = false; if( hasFlashlight ) { VMatrix worldToTexture; ITexture *pFlashlightDepthTexture; FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); bFlashlightShadows = state.m_bEnableShadows; bUberlight = state.m_bUberlight; SetFlashLightColorFromState( state, pShaderAPI, bSinglePassFlashlight ); BindTexture( SHADER_SAMPLER2, state.m_pSpotlightTexture, state.m_nSpotlightTextureFrame ); if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() ) { BindTexture( SHADER_SAMPLER7, pFlashlightDepthTexture ); } } if( hasDetailTexture ) { BindTexture( SHADER_SAMPLER3, DETAIL, DETAILFRAME ); } if( hasBump ) { if( !g_pConfig->m_bFastNoBump ) { BindTexture( SHADER_SAMPLER4, BUMPMAP, BUMPFRAME ); } else { pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALMAP_FLAT ); } } pShaderAPI->BindStandardTexture( SHADER_SAMPLER6, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); // If we don't have a texture transform, we don't have // to set vertex shader constants or run vertex shader instructions // for the texture transform. bool bHasTextureTransform = !( params[BASETEXTURETRANSFORM]->MatrixIsIdentity() && params[BUMPTRANSFORM]->MatrixIsIdentity() ); bool bVertexShaderFastPath = !bHasTextureTransform; if( params[DETAIL]->IsTexture() ) { bVertexShaderFastPath = false; } if( pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) != 0 ) { bVertexShaderFastPath = false; } if( !bVertexShaderFastPath ) { if ( !bSeamlessMapping ) { SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); } if( hasBump && !bHasDetailAlpha ) { SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BUMPTRANSFORM ); Assert( !hasDetailTexture ); } } MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); if ( IsPC() ) { bool bWorldNormal = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_ENABLE_FIXED_LIGHTING ) == ENABLE_FIXED_LIGHTING_OUTPUTNORMAL_AND_DEPTH; if ( bWorldNormal ) { float vEyeDir[4]; pShaderAPI->GetWorldSpaceCameraDirection( vEyeDir ); float flFarZ = pShaderAPI->GetFarZ(); vEyeDir[0] /= flFarZ; // Divide by farZ for SSAO algorithm vEyeDir[1] /= flFarZ; vEyeDir[2] /= flFarZ; pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_12, vEyeDir ); } } #ifndef _X360 if (g_pHardwareConfig->HasFastVertexTextures() ) { DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs30 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs30 ); } else #endif { DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); } bool bWriteDepthToAlpha; bool bWriteWaterFogToAlpha; if( bFullyOpaque ) { bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); } else { //can't write a special value to dest alpha if we're actually using as-intended alpha bWriteDepthToAlpha = false; bWriteWaterFogToAlpha = false; } #ifndef _X360 if ( g_pHardwareConfig->HasFastVertexTextures() ) { DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps30 ); // Don't write fog to alpha if we're using translucency SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER_COMBO( UBERLIGHT, bUberlight ); SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps30 ); } else #endif if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); // Don't write fog to alpha if we're using translucency SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); } else { DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); // Don't write fog to alpha if we're using translucency SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z) && (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !bIsAlphaTested ); SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); } // always set the transform for detail textures since I'm assuming that you'll // always have a detailscale. if( hasDetailTexture ) { SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM, DETAILSCALE ); Assert( !( hasBump && !bHasDetailAlpha ) ); } SetPixelShaderConstantGammaToLinear( 7, SELFILLUMTINT ); float eyePos[4]; pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 ); pShaderAPI->SetPixelShaderFogParams( 11 ); if ( bSeamlessMapping ) { float map_scale[4]={ params[SEAMLESS_SCALE]->GetFloatValue(),0,0,0}; pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, map_scale ); } if( hasFlashlight ) { VMatrix worldToTexture; const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); // Set the flashlight attenuation factors float atten[4]; atten[0] = flashlightState.m_fConstantAtten; atten[1] = flashlightState.m_fLinearAtten; atten[2] = flashlightState.m_fQuadraticAtten; atten[3] = flashlightState.m_FarZAtten; pShaderAPI->SetPixelShaderConstant( 20, atten, 1 ); // Set the flashlight origin float pos[4]; pos[0] = flashlightState.m_vecLightOrigin[0]; pos[1] = flashlightState.m_vecLightOrigin[1]; pos[2] = flashlightState.m_vecLightOrigin[2]; pos[3] = flashlightState.m_FarZ; // didn't have this in main. . probably need this? pShaderAPI->SetPixelShaderConstant( 15, pos, 1 ); pShaderAPI->SetPixelShaderConstant( 16, worldToTexture.Base(), 4 ); if ( IsPC() && g_pHardwareConfig->HasFastVertexTextures() ) { SetupUberlightFromState( pShaderAPI, flashlightState ); } } } Draw(); }
void Draw_Eyes_Refract_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bDrawFlashlightAdditivePass, Eye_Refract_Vars_t &info, VertexCompressionType_t vertexCompression ) { bool bDiffuseWarp = IS_PARAM_DEFINED( info.m_nDiffuseWarpTexture ); bool bIntro = IS_PARAM_DEFINED( info.m_nIntro ) ? ( params[info.m_nIntro]->GetIntValue() ? true : false ) : false; SHADOW_STATE { SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Cornea normal pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Iris pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Cube reflection pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Ambient occlusion // Set stream format (note that this shader supports compression) unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; int nTexCoordCount = 1; int userDataSize = 0; pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); if ( bDiffuseWarp ) { pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Light warp } #if !defined( PLATFORM_X360 ) bool bWorldNormal = ( ENABLE_FIXED_LIGHTING_OUTPUTNORMAL_AND_DEPTH == ( IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER0 ) + 2 * IS_FLAG2_SET( MATERIAL_VAR2_USE_GBUFFER1 ))); #endif int nShadowFilterMode = 0; if ( bDrawFlashlightAdditivePass == true ) { if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats } pShaderShadow->EnableDepthWrites( false ); pShaderShadow->EnableAlphaWrites( false ); pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); // Additive blending pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Flashlight cookie } else { pShaderShadow->EnableAlphaWrites( true ); } #ifndef _X360 if ( !g_pHardwareConfig->HasFastVertexTextures() ) #endif { DECLARE_STATIC_VERTEX_SHADER( eye_refract_vs20 ); SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); SET_STATIC_VERTEX_SHADER_COMBO( INTRO, bIntro ? 1 : 0 ); SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); SET_STATIC_VERTEX_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); SET_STATIC_VERTEX_SHADER_COMBO( WORLD_NORMAL, 0 ); SET_STATIC_VERTEX_SHADER( eye_refract_vs20 ); if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { bool bSphereTexKillCombo = IS_PARAM_DEFINED( info.m_nSphereTexKillCombo ) ? ( params[info.m_nSphereTexKillCombo]->GetIntValue() ? true : false ) : ( kDefaultSphereTexKillCombo ? true : false ); bool bRayTraceSphere = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? ( params[info.m_nRaytraceSphere]->GetIntValue() ? true : false ) : ( kDefaultRaytraceSphere ? true : false ); DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps20b ); SET_STATIC_PIXEL_SHADER_COMBO( SPHERETEXKILLCOMBO, bSphereTexKillCombo ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( RAYTRACESPHERE, bRayTraceSphere ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); SET_STATIC_PIXEL_SHADER_COMBO( WORLD_NORMAL, 0 ); SET_STATIC_PIXEL_SHADER( eye_refract_ps20b ); if ( bDrawFlashlightAdditivePass == true ) { pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Shadow depth map pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER6 ); pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Noise map } } else { DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps20 ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( WORLD_NORMAL, 0 ); SET_STATIC_PIXEL_SHADER( eye_refract_ps20 ); } } #ifndef _X360 else { pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); // Screen space ambient occlusion // The vertex shader uses the vertex id stream SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_TESSELLATION ); DECLARE_STATIC_VERTEX_SHADER( eye_refract_vs30 ); SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); SET_STATIC_VERTEX_SHADER_COMBO( INTRO, bIntro ? 1 : 0 ); SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); SET_STATIC_VERTEX_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); SET_STATIC_VERTEX_SHADER_COMBO( WORLD_NORMAL, bWorldNormal ); SET_STATIC_VERTEX_SHADER( eye_refract_vs30 ); bool bSphereTexKillCombo = IS_PARAM_DEFINED( info.m_nSphereTexKillCombo ) ? ( params[info.m_nSphereTexKillCombo]->GetIntValue() ? true : false ) : ( kDefaultSphereTexKillCombo ? true : false ); bool bRayTraceSphere = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? ( params[info.m_nRaytraceSphere]->GetIntValue() ? true : false ) : ( kDefaultRaytraceSphere ? true : false ); DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps30 ); SET_STATIC_PIXEL_SHADER_COMBO( SPHERETEXKILLCOMBO, bSphereTexKillCombo ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( RAYTRACESPHERE, bRayTraceSphere ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); SET_STATIC_PIXEL_SHADER_COMBO( WORLD_NORMAL, bWorldNormal ); SET_STATIC_PIXEL_SHADER( eye_refract_ps30 ); if ( bDrawFlashlightAdditivePass == true ) { pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Shadow depth map pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Noise map } } #endif // On DX9, get the gamma read and write correct //pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false ); // Cornea normal pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // Iris pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); // Cube map reflection pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); // Ambient occlusion pShaderShadow->EnableSRGBWrite( true ); if ( bDiffuseWarp ) { pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); // Light Warp } if ( bDrawFlashlightAdditivePass == true ) { pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true ); // Flashlight cookie } // Fog if ( bDrawFlashlightAdditivePass == true ) { pShader->FogToBlack(); } else { pShader->FogToFogColor(); } // Per-instance state pShader->PI_BeginCommandBuffer(); if ( !bDrawFlashlightAdditivePass ) { pShader->PI_SetPixelShaderLocalLighting( PSREG_LIGHT_INFO_ARRAY ); } pShader->PI_SetVertexShaderAmbientLightCube(); pShader->PI_SetPixelShaderAmbientLightCubeLuminance( 10 ); pShader->PI_EndCommandBuffer(); } DYNAMIC_STATE { VMatrix worldToTexture; ITexture *pFlashlightDepthTexture = NULL; FlashlightState_t flashlightState; bool bFlashlightShadows = false; if ( bDrawFlashlightAdditivePass == true ) { flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); bFlashlightShadows = flashlightState.m_bEnableShadows; } bool bSinglePassFlashlight = false; pShader->BindTexture( SHADER_SAMPLER0, info.m_nCorneaTexture ); pShader->BindTexture( SHADER_SAMPLER1, info.m_nIris, info.m_nIrisFrame ); pShader->BindTexture( SHADER_SAMPLER2, info.m_nEnvmap ); pShader->BindTexture( SHADER_SAMPLER3, info.m_nAmbientOcclTexture ); if ( bDiffuseWarp ) { if ( r_lightwarpidentity.GetBool() ) { pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_IDENTITY_LIGHTWARP ); } else { pShader->BindTexture( SHADER_SAMPLER4, info.m_nDiffuseWarpTexture ); } } // On PC, we sample from ambient occlusion texture if ( IsPC() && g_pHardwareConfig->HasFastVertexTextures() ) { ITexture *pAOTexture = pShaderAPI->GetTextureRenderingParameter( TEXTURE_RENDERPARM_AMBIENT_OCCLUSION ); if ( pAOTexture ) { pShader->BindTexture( SHADER_SAMPLER8, pAOTexture ); } else { pShaderAPI->BindStandardTexture( SHADER_SAMPLER8, TEXTURE_WHITE ); } } if ( bDrawFlashlightAdditivePass == true ) pShader->BindTexture( SHADER_SAMPLER5, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nEyeOrigin ); pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nIrisU ); pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, info.m_nIrisV ); if ( bDrawFlashlightAdditivePass == true ) pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, flashlightState.m_vecLightOrigin.Base(), 1 ); LightState_t lightState = { 0, false, false }; if ( bDrawFlashlightAdditivePass == false ) { pShaderAPI->GetDX9LightState( &lightState ); } int nFixedLightingMode = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_ENABLE_FIXED_LIGHTING ); #ifndef _X360 if ( !g_pHardwareConfig->HasFastVertexTextures() ) #endif { DECLARE_DYNAMIC_VERTEX_SHADER( eye_refract_vs20 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); SET_DYNAMIC_VERTEX_SHADER_COMBO( TESSELLATION, 0 ); SET_DYNAMIC_VERTEX_SHADER( eye_refract_vs20 ); } #ifndef _X360 else { pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 ); if ( nFixedLightingMode == ENABLE_FIXED_LIGHTING_OUTPUTNORMAL_AND_DEPTH ) { float vEyeDir[4]; pShaderAPI->GetWorldSpaceCameraDirection( vEyeDir ); float flFarZ = pShaderAPI->GetFarZ(); vEyeDir[0] /= flFarZ; // Divide by farZ for SSAO algorithm vEyeDir[1] /= flFarZ; vEyeDir[2] /= flFarZ; pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, vEyeDir ); } TessellationMode_t nTessellationMode = pShaderAPI->GetTessellationMode(); if ( nTessellationMode != TESSELLATION_MODE_DISABLED ) { pShaderAPI->BindStandardVertexTexture( SHADER_VERTEXTEXTURE_SAMPLER1, TEXTURE_SUBDIVISION_PATCHES ); bool bHasDisplacement = false; // TODO float vSubDDimensions[4] = { 1.0f/pShaderAPI->GetSubDHeight(), bHasDisplacement && mat_displacementmap.GetBool() ? 1.0f : 0.0f, 0.0f, 0.0f }; pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vSubDDimensions ); } DECLARE_DYNAMIC_VERTEX_SHADER( eye_refract_vs30 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); SET_DYNAMIC_VERTEX_SHADER_COMBO( TESSELLATION, nTessellationMode ); SET_DYNAMIC_VERTEX_SHADER( eye_refract_vs30 ); } #endif // Special constant for DX9 eyes: { Dilation, Glossiness, x, x }; float vPSConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; vPSConst[0] = IS_PARAM_DEFINED( info.m_nDilation ) ? params[info.m_nDilation]->GetFloatValue() : kDefaultDilation; vPSConst[1] = IS_PARAM_DEFINED( info.m_nGlossiness ) ? params[info.m_nGlossiness]->GetFloatValue() : kDefaultGlossiness; vPSConst[2] = 0.0f; // NOT USED vPSConst[3] = IS_PARAM_DEFINED( info.m_nCorneaBumpStrength ) ? params[info.m_nCorneaBumpStrength]->GetFloatValue() : kDefaultCorneaBumpStrength; pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 ); pShaderAPI->SetPixelShaderConstant( 1, IS_PARAM_DEFINED( info.m_nEyeOrigin ) ? params[info.m_nEyeOrigin]->GetVecValue() : kDefaultEyeOrigin, 1 ); pShaderAPI->SetPixelShaderConstant( 2, IS_PARAM_DEFINED( info.m_nIrisU ) ? params[info.m_nIrisU]->GetVecValue() : kDefaultIrisU, 1 ); pShaderAPI->SetPixelShaderConstant( 3, IS_PARAM_DEFINED( info.m_nIrisV ) ? params[info.m_nIrisV]->GetVecValue() : kDefaultIrisV, 1 ); float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); pShaderAPI->SetPixelShaderConstant( 4, vEyePos, 1 ); float vAmbientOcclusion[4] = { 0.33f, 0.33f, 0.33f, 0.0f }; if ( IS_PARAM_DEFINED( info.m_nAmbientOcclColor ) ) { params[info.m_nAmbientOcclColor]->GetVecValue( vAmbientOcclusion, 3 ); } vAmbientOcclusion[3] = IS_PARAM_DEFINED( info.m_nAmbientOcclusion ) ? params[info.m_nAmbientOcclusion]->GetFloatValue() : 0.0f; float vPackedConst6[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; //vPackedConst6[0] Unused vPackedConst6[1] = IS_PARAM_DEFINED( info.m_nEyeballRadius ) ? params[info.m_nEyeballRadius]->GetFloatValue() : kDefaultEyeballRadius; //vPackedConst6[2] = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? params[info.m_nRaytraceSphere]->GetFloatValue() : kDefaultRaytraceSphere; vPackedConst6[3] = IS_PARAM_DEFINED( info.m_nParallaxStrength ) ? params[info.m_nParallaxStrength]->GetFloatValue() : kDefaultParallaxStrength; pShaderAPI->SetPixelShaderConstant( 6, vPackedConst6, 1 ); if ( bDrawFlashlightAdditivePass == true ) { SetFlashLightColorFromState( flashlightState, pShaderAPI, bSinglePassFlashlight ); if ( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows ) { pShader->BindTexture( SHADER_SAMPLER6, pFlashlightDepthTexture, 0 ); pShaderAPI->BindStandardTexture( SHADER_SAMPLER7, TEXTURE_SHADOW_NOISE_2D ); } } if ( nFixedLightingMode == ENABLE_FIXED_LIGHTING_OUTPUTNORMAL_AND_DEPTH ) { float vEyeDir[4]; pShaderAPI->GetWorldSpaceCameraDirection( vEyeDir ); float flFarZ = pShaderAPI->GetFarZ(); vEyeDir[0] /= flFarZ; // Divide by farZ for SSAO algorithm vEyeDir[1] /= flFarZ; vEyeDir[2] /= flFarZ; pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, vEyeDir ); } // Flashlight tax #ifndef _X360 if ( !g_pHardwareConfig->HasFastVertexTextures() ) #endif { if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps20b ); SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps20b ); } else // ps.2.0 { DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps20 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps20 ); } } #ifndef _X360 else { DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps30 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, nFixedLightingMode ? 0 : lightState.m_nNumLights ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, nFixedLightingMode ? false : bFlashlightShadows ); SET_DYNAMIC_PIXEL_SHADER_COMBO( UBERLIGHT, flashlightState.m_bUberlight ); SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps30 ); // Set constant to enable translation of VPOS to render target coordinates in ps_3_0 pShaderAPI->SetScreenSizeForVPOS(); SetupUberlightFromState( pShaderAPI, flashlightState ); } #endif pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); if ( bDrawFlashlightAdditivePass == true ) { float atten[4], pos[4], tweaks[4]; atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors atten[1] = flashlightState.m_fLinearAtten; atten[2] = flashlightState.m_fQuadraticAtten; atten[3] = flashlightState.m_FarZAtten; pShaderAPI->SetPixelShaderConstant( 7, atten, 1 ); pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin pos[1] = flashlightState.m_vecLightOrigin[1]; pos[2] = flashlightState.m_vecLightOrigin[2]; pShaderAPI->SetPixelShaderConstant( 8, pos, 1 ); pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, worldToTexture.Base(), 4 ); // Tweaks associated with a given flashlight tweaks[0] = ShadowFilterFromState( flashlightState ); tweaks[1] = ShadowAttenFromState( flashlightState ); pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); pShaderAPI->SetPixelShaderConstant( 9, tweaks, 1 ); // Dimensions of screen, used for screen-space noise map sampling float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; int nWidth, nHeight; pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); int nTexWidth, nTexHeight; pShaderAPI->GetStandardTextureDimensions( &nTexWidth, &nTexHeight, TEXTURE_SHADOW_NOISE_2D ); vScreenScale[0] = (float) nWidth / nTexWidth; vScreenScale[1] = (float) nHeight / nTexHeight; pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); vAmbientOcclusion[3] *= flashlightState.m_flAmbientOcclusion; } vAmbientOcclusion[3] = MIN( MAX( vAmbientOcclusion[3], 0.0f ), 1.0f ); pShaderAPI->SetPixelShaderConstant( 5, vAmbientOcclusion, 1 ); // Intro tax if ( bIntro ) { float curTime = params[info.m_nWarpParam]->GetFloatValue(); float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; if ( IS_PARAM_DEFINED( info.m_nEntityOrigin ) ) { params[info.m_nEntityOrigin]->GetVecValue( timeVec, 3 ); } pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, timeVec, 1 ); } } pShader->Draw(); }
bool CHARACTER::AddAffect(DWORD dwType, BYTE bApplyOn, long lApplyValue, DWORD dwFlag, long lDuration, long lSPCost, bool bOverride, bool IsCube ) { // CHAT_BLOCK if (dwType == AFFECT_BLOCK_CHAT && lDuration > 1) { ChatPacket(CHAT_TYPE_INFO, LC_TEXT("운영자 제제로 채팅이 금지 되었습니다.")); } // END_OF_CHAT_BLOCK if (lDuration == 0) { sys_err("Character::AddAffect lDuration == 0 type %d", lDuration, dwType); lDuration = 1; } CAffect * pkAff = NULL; if (IsCube) pkAff = FindAffect(dwType,bApplyOn); else pkAff = FindAffect(dwType); if (dwFlag == AFF_STUN) { if (m_posDest.x != GetX() || m_posDest.y != GetY()) { m_posDest.x = m_posStart.x = GetX(); m_posDest.y = m_posStart.y = GetY(); battle_end(this); SyncPacket(); } } // 이미 있는 효과를 덮어 쓰는 처리 if (pkAff && bOverride) { ComputeAffect(pkAff, false); // 일단 효과를 삭제하고 if (GetDesc()) SendAffectRemovePacket(GetDesc(), GetPlayerID(), pkAff->dwType, pkAff->bApplyOn); } else { // // 새 에펙를 추가 // // NOTE: 따라서 같은 type 으로도 여러 에펙트를 붙을 수 있다. // pkAff = CAffect::Acquire(); m_list_pkAffect.push_back(pkAff); } sys_log(1, "AddAffect %s type %d apply %d %d flag %u duration %d", GetName(), dwType, bApplyOn, lApplyValue, dwFlag, lDuration); sys_log(0, "AddAffect %s type %d apply %d %d flag %u duration %d", GetName(), dwType, bApplyOn, lApplyValue, dwFlag, lDuration); pkAff->dwType = dwType; pkAff->bApplyOn = bApplyOn; pkAff->lApplyValue = lApplyValue; pkAff->dwFlag = dwFlag; pkAff->lDuration = lDuration; pkAff->lSPCost = lSPCost; WORD wMovSpd = GetPoint(POINT_MOV_SPEED); WORD wAttSpd = GetPoint(POINT_ATT_SPEED); ComputeAffect(pkAff, true); if (pkAff->dwFlag || wMovSpd != GetPoint(POINT_MOV_SPEED) || wAttSpd != GetPoint(POINT_ATT_SPEED)) UpdatePacket(); StartAffectEvent(); if (IsPC()) { SendAffectAddPacket(GetDesc(), pkAff); if (IS_NO_SAVE_AFFECT(pkAff->dwType)) return true; TPacketGDAddAffect p; p.dwPID = GetPlayerID(); p.elem.dwType = pkAff->dwType; p.elem.bApplyOn = pkAff->bApplyOn; p.elem.lApplyValue = pkAff->lApplyValue; p.elem.dwFlag = pkAff->dwFlag; p.elem.lDuration = pkAff->lDuration; p.elem.lSPCost = pkAff->lSPCost; db_clientdesc->DBPacket(HEADER_GD_ADD_AFFECT, 0, &p, sizeof(p)); } return true; }