forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorldDimsProxy.cpp
78 lines (62 loc) · 1.79 KB
/
WorldDimsProxy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "materialsystem/imaterialproxy.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include "c_world.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 );
class CWorldDimsProxy : public IMaterialProxy
{
public:
CWorldDimsProxy();
virtual ~CWorldDimsProxy();
virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
virtual void OnBind( void *pC_BaseEntity );
virtual void Release( void ) { delete this; }
virtual IMaterial *GetMaterial();
public:
IMaterialVar *m_pMinsVar;
IMaterialVar *m_pMaxsVar;
};
CWorldDimsProxy::CWorldDimsProxy()
{
m_pMinsVar = m_pMaxsVar = NULL;
}
CWorldDimsProxy::~CWorldDimsProxy()
{
}
bool CWorldDimsProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
{
m_pMinsVar = pMaterial->FindVar( "$world_mins", NULL, false );
m_pMaxsVar = pMaterial->FindVar( "$world_maxs", NULL, false );
return true;
}
void CWorldDimsProxy::OnBind( void *pC_BaseEntity )
{
if ( m_pMinsVar && m_pMaxsVar )
{
C_World *pWorld = GetClientWorldEntity();
if ( pWorld )
{
m_pMinsVar->SetVecValue( (const float*)&pWorld->m_WorldMins, 3 );
m_pMaxsVar->SetVecValue( (const float*)&pWorld->m_WorldMaxs, 3 );
}
}
if ( ToolsEnabled() )
{
ToolFramework_RecordMaterialParams( GetMaterial() );
}
}
IMaterial *CWorldDimsProxy::GetMaterial()
{
return m_pMinsVar->GetOwningMaterial();
}
EXPOSE_INTERFACE( CWorldDimsProxy, IMaterialProxy, "WorldDims" IMATERIAL_PROXY_INTERFACE_VERSION );