diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /mp/src/game/client/baseanimatedtextureproxy.cpp | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'mp/src/game/client/baseanimatedtextureproxy.cpp')
| -rw-r--r-- | mp/src/game/client/baseanimatedtextureproxy.cpp | 276 |
1 files changed, 138 insertions, 138 deletions
diff --git a/mp/src/game/client/baseanimatedtextureproxy.cpp b/mp/src/game/client/baseanimatedtextureproxy.cpp index af16d78c..4365e866 100644 --- a/mp/src/game/client/baseanimatedtextureproxy.cpp +++ b/mp/src/game/client/baseanimatedtextureproxy.cpp @@ -1,138 +1,138 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//=============================================================================//
-#include "cbase.h"
-#include "baseanimatedtextureproxy.h"
-#include "materialsystem/imaterial.h"
-#include "materialsystem/imaterialvar.h"
-#include "materialsystem/itexture.h"
-#include "tier1/KeyValues.h"
-#include "toolframework_client.h"
-
-// memdbgon must be the last include file in a .cpp file!!!
-#include "tier0/memdbgon.h"
-
-// forward declarations
-void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
-
-//-----------------------------------------------------------------------------
-// Constructor, destructor:
-//-----------------------------------------------------------------------------
-
-CBaseAnimatedTextureProxy::CBaseAnimatedTextureProxy()
-{
- Cleanup();
-}
-
-CBaseAnimatedTextureProxy::~CBaseAnimatedTextureProxy()
-{
- Cleanup();
-}
-
-
-//-----------------------------------------------------------------------------
-// Initialization, shutdown
-//-----------------------------------------------------------------------------
-bool CBaseAnimatedTextureProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
-{
- char const* pAnimatedTextureVarName = pKeyValues->GetString( "animatedTextureVar" );
- if( !pAnimatedTextureVarName )
- return false;
-
- bool foundVar;
- m_AnimatedTextureVar = pMaterial->FindVar( pAnimatedTextureVarName, &foundVar, false );
- if( !foundVar )
- return false;
-
- char const* pAnimatedTextureFrameNumVarName = pKeyValues->GetString( "animatedTextureFrameNumVar" );
- if( !pAnimatedTextureFrameNumVarName )
- return false;
-
- m_AnimatedTextureFrameNumVar = pMaterial->FindVar( pAnimatedTextureFrameNumVarName, &foundVar, false );
- if( !foundVar )
- return false;
-
- m_FrameRate = pKeyValues->GetFloat( "animatedTextureFrameRate", 15 );
- m_WrapAnimation = !pKeyValues->GetInt( "animationNoWrap", 0 );
- return true;
-}
-
-void CBaseAnimatedTextureProxy::Cleanup()
-{
- m_AnimatedTextureVar = NULL;
- m_AnimatedTextureFrameNumVar = NULL;
-}
-
-
-//-----------------------------------------------------------------------------
-// Does the dirty deed
-//-----------------------------------------------------------------------------
-void CBaseAnimatedTextureProxy::OnBind( void *pEntity )
-{
- Assert ( m_AnimatedTextureVar );
-
- if( m_AnimatedTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE )
- {
- return;
- }
- ITexture *pTexture;
- pTexture = m_AnimatedTextureVar->GetTextureValue();
- int numFrames = pTexture->GetNumAnimationFrames();
-
- if ( numFrames <= 0 )
- {
- Assert( !"0 frames in material calling animated texture proxy" );
- return;
- }
-
- // NOTE: Must not use relative time based methods here
- // because the bind proxy can be called many times per frame.
- // Prevent multiple Wrap callbacks to be sent for no wrap mode
- float startTime = GetAnimationStartTime(pEntity);
- float deltaTime = gpGlobals->curtime - startTime;
- float prevTime = deltaTime - gpGlobals->frametime;
-
- // Clamp..
- if (deltaTime < 0.0f)
- deltaTime = 0.0f;
- if (prevTime < 0.0f)
- prevTime = 0.0f;
-
- float frame = m_FrameRate * deltaTime;
- float prevFrame = m_FrameRate * prevTime;
-
- int intFrame = ((int)frame) % numFrames;
- int intPrevFrame = ((int)prevFrame) % numFrames;
-
- // Report wrap situation...
- if (intPrevFrame > intFrame)
- {
- if (m_WrapAnimation)
- {
- AnimationWrapped( pEntity );
- }
- else
- {
- // Only sent the wrapped message once.
- // when we're in non-wrapping mode
- if (prevFrame < numFrames)
- AnimationWrapped( pEntity );
- intFrame = numFrames - 1;
- }
- }
-
- m_AnimatedTextureFrameNumVar->SetIntValue( intFrame );
-
- if ( ToolsEnabled() )
- {
- ToolFramework_RecordMaterialParams( GetMaterial() );
- }
-}
-
-IMaterial *CBaseAnimatedTextureProxy::GetMaterial()
-{
- return m_AnimatedTextureVar->GetOwningMaterial();
-}
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#include "cbase.h" +#include "baseanimatedtextureproxy.h" +#include "materialsystem/imaterial.h" +#include "materialsystem/imaterialvar.h" +#include "materialsystem/itexture.h" +#include "tier1/KeyValues.h" +#include "toolframework_client.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// forward declarations +void ToolFramework_RecordMaterialParams( IMaterial *pMaterial ); + +//----------------------------------------------------------------------------- +// Constructor, destructor: +//----------------------------------------------------------------------------- + +CBaseAnimatedTextureProxy::CBaseAnimatedTextureProxy() +{ + Cleanup(); +} + +CBaseAnimatedTextureProxy::~CBaseAnimatedTextureProxy() +{ + Cleanup(); +} + + +//----------------------------------------------------------------------------- +// Initialization, shutdown +//----------------------------------------------------------------------------- +bool CBaseAnimatedTextureProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) +{ + char const* pAnimatedTextureVarName = pKeyValues->GetString( "animatedTextureVar" ); + if( !pAnimatedTextureVarName ) + return false; + + bool foundVar; + m_AnimatedTextureVar = pMaterial->FindVar( pAnimatedTextureVarName, &foundVar, false ); + if( !foundVar ) + return false; + + char const* pAnimatedTextureFrameNumVarName = pKeyValues->GetString( "animatedTextureFrameNumVar" ); + if( !pAnimatedTextureFrameNumVarName ) + return false; + + m_AnimatedTextureFrameNumVar = pMaterial->FindVar( pAnimatedTextureFrameNumVarName, &foundVar, false ); + if( !foundVar ) + return false; + + m_FrameRate = pKeyValues->GetFloat( "animatedTextureFrameRate", 15 ); + m_WrapAnimation = !pKeyValues->GetInt( "animationNoWrap", 0 ); + return true; +} + +void CBaseAnimatedTextureProxy::Cleanup() +{ + m_AnimatedTextureVar = NULL; + m_AnimatedTextureFrameNumVar = NULL; +} + + +//----------------------------------------------------------------------------- +// Does the dirty deed +//----------------------------------------------------------------------------- +void CBaseAnimatedTextureProxy::OnBind( void *pEntity ) +{ + Assert ( m_AnimatedTextureVar ); + + if( m_AnimatedTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) + { + return; + } + ITexture *pTexture; + pTexture = m_AnimatedTextureVar->GetTextureValue(); + int numFrames = pTexture->GetNumAnimationFrames(); + + if ( numFrames <= 0 ) + { + Assert( !"0 frames in material calling animated texture proxy" ); + return; + } + + // NOTE: Must not use relative time based methods here + // because the bind proxy can be called many times per frame. + // Prevent multiple Wrap callbacks to be sent for no wrap mode + float startTime = GetAnimationStartTime(pEntity); + float deltaTime = gpGlobals->curtime - startTime; + float prevTime = deltaTime - gpGlobals->frametime; + + // Clamp.. + if (deltaTime < 0.0f) + deltaTime = 0.0f; + if (prevTime < 0.0f) + prevTime = 0.0f; + + float frame = m_FrameRate * deltaTime; + float prevFrame = m_FrameRate * prevTime; + + int intFrame = ((int)frame) % numFrames; + int intPrevFrame = ((int)prevFrame) % numFrames; + + // Report wrap situation... + if (intPrevFrame > intFrame) + { + if (m_WrapAnimation) + { + AnimationWrapped( pEntity ); + } + else + { + // Only sent the wrapped message once. + // when we're in non-wrapping mode + if (prevFrame < numFrames) + AnimationWrapped( pEntity ); + intFrame = numFrames - 1; + } + } + + m_AnimatedTextureFrameNumVar->SetIntValue( intFrame ); + + if ( ToolsEnabled() ) + { + ToolFramework_RecordMaterialParams( GetMaterial() ); + } +} + +IMaterial *CBaseAnimatedTextureProxy::GetMaterial() +{ + return m_AnimatedTextureVar->GetOwningMaterial(); +} |