-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_engine_tool.cpp
More file actions
141 lines (113 loc) · 5.29 KB
/
Copy pathexample_engine_tool.cpp
File metadata and controls
141 lines (113 loc) · 5.29 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "appframework/IAppSystem.h"
#include "toolframework/itooldictionary.h"
#include "toolframework/itoolsystem.h"
#include "toolframework/ienginetool.h"
#include "tier0/dbg.h"
#include "tier0/platform.h"
#include "tier1/interface.h"
#include "tier1/tier1.h"
#include "tier1/convar.h"
#include "mathlib/vector.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// CExampleTool
//-----------------------------------------------------------------------------
class CExampleTool : public IToolSystem
{
public:
virtual char const *GetToolName() { return "Example Engine Tool"; }
virtual bool Init() { Msg( "IToolSystem::Init\n" ); return true; }
virtual void Shutdown() { Msg( "IToolSystem::Shutdown\n" ); }
virtual bool ServerInit( CreateInterfaceFn serverFactory ) { Msg( "IToolSystem::ServerInit\n" ); m_serverFactory = serverFactory; return true; }
virtual bool ClientInit( CreateInterfaceFn clientFactory ) { Msg( "IToolSystem::ClientInit\n" ); m_clientFactory = clientFactory; return true; }
virtual void ServerShutdown() { Msg( "IToolSystem::ServerShutdown\n" ); }
virtual void ClientShutdown() { Msg( "IToolSystem::ClientShutdown\n" ); }
virtual bool CanQuit() { return true; }
virtual void PostMessage( HTOOLHANDLE hEntity, KeyValues *message ) {}
virtual void Think( bool finalTick ) {}
virtual void OnToolActivate() { Msg( "IToolSystem::OnToolActivate\n" ); }
virtual void OnToolDeactivate() { Msg( "IToolSystem::OnToolDeactivate\n" ); }
virtual void ServerLevelInitPreEntity() { Msg( "IToolSystem::ServerLevelInitPreEntity\n" ); }
virtual void ServerLevelInitPostEntity() { Msg( "IToolSystem::ServerLevelInitPostEntity\n" ); }
virtual void ServerLevelShutdownPreEntity() { Msg( "IToolSystem::ServerLevelShutdownPreEntity\n" ); }
virtual void ServerLevelShutdownPostEntity() { Msg( "IToolSystem::ServerLevelShutdownPostEntity\n" ); }
virtual void ServerFrameUpdatePreEntityThink() {}
virtual void ServerFrameUpdatePostEntityThink() {}
virtual void ServerPreClientUpdate() {}
virtual void ServerPreSetupVisibility() {}
virtual const char *GetEntityData( const char *pActualEntityData ) { return pActualEntityData; }
virtual void ClientLevelInitPreEntity() { Msg( "IToolSystem::ClientLevelInitPreEntity\n" ); }
virtual void ClientLevelInitPostEntity() { Msg( "IToolSystem::ClientLevelInitPostEntity\n" ); }
virtual void ClientLevelShutdownPreEntity() { Msg( "IToolSystem::ClientLevelShutdownPreEntity\n" ); }
virtual void ClientLevelShutdownPostEntity() { Msg( "IToolSystem::ClientLevelShutdownPostEntity\n" ); }
virtual void ClientPreRender() {}
virtual void ClientPostRender() {}
virtual void AdjustEngineViewport( int &x, int &y, int &width, int &height ) {}
virtual bool SetupEngineView( Vector &origin, QAngle &angles, float &fov )
{
if ( !m_bOwnCamera )
return false;
angles.y = fmodf( (float)Plat_FloatTime() * 30.0f, 360.0f );
return true;
}
virtual bool SetupAudioState( AudioState_t &audioState ) { return false; }
virtual bool ShouldGameRenderView() { return true; }
virtual bool IsThirdPersonCamera() { return m_bOwnCamera; }
virtual bool IsToolRecording() { return false; }
virtual IMaterialProxy *LookupProxy( const char *proxyName ) { return NULL; }
virtual bool TrapKey( ButtonCode_t key, bool down )
{
if ( key == KEY_F8 && down )
{
m_bOwnCamera = !m_bOwnCamera;
Msg( "camera override %s\n", m_bOwnCamera ? "ON" : "OFF" );
return true;
}
return false;
}
virtual bool GetSoundSpatialization( int iUserData, int guid, SpatializationInfo_t &info ) { return true; }
virtual void RenderFrameBegin() {}
virtual void RenderFrameEnd() {}
virtual void HostRunFrameBegin() {}
virtual void HostRunFrameEnd() {}
virtual void VGui_PreRender( int paintMode ) {}
virtual void VGui_PostRender( int paintMode ) {}
virtual void VGui_PreSimulate() {}
virtual void VGui_PostSimulate() {}
private:
CreateInterfaceFn m_serverFactory = NULL;
CreateInterfaceFn m_clientFactory = NULL;
bool m_bOwnCamera = false;
};
//-----------------------------------------------------------------------------
// CExampleToolDictionary
//-----------------------------------------------------------------------------
class CExampleToolDictionary : public CBaseAppSystem< IToolDictionary >
{
public:
virtual bool Connect( CreateInterfaceFn factory )
{
ConnectTier1Libraries( &factory, 1 );
ConVar_Register( 0 );
m_pEngineTool = (IEngineTool *)factory( VENGINETOOL_INTERFACE_VERSION, NULL );
return true;
}
virtual void Disconnect()
{
ConVar_Unregister();
DisconnectTier1Libraries();
}
virtual InitReturnVal_t Init() { Msg( "IToolDictionary::Init\n" ); return INIT_OK; }
virtual void Shutdown() { Msg( "IToolDictionary::Shutdown\n" ); }
virtual void CreateTools() {}
virtual int GetToolCount() const { return 1; }
virtual IToolSystem *GetTool( int index ) { return ( index == 0 ) ? &m_tool : NULL; }
IEngineTool *EngineTool() const { return m_pEngineTool; }
private:
CExampleTool m_tool;
IEngineTool *m_pEngineTool = NULL;
};
static CExampleToolDictionary g_ExampleToolDictionary;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CExampleToolDictionary, IToolDictionary,
VTOOLDICTIONARY_INTERFACE_VERSION, g_ExampleToolDictionary );