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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#ifndef MAPENTITY_H
#define MAPENTITY_H
#pragma once
#include "MapClass.h"
#include "MapFace.h" // FIXME: For PLANE definition.
#include "EditGameClass.h"
class CMapAnimator;
class CRender2D;
class CManifest;
enum LogicalConnection_t
{
LOGICAL_CONNECTION_INPUT = 0,
LOGICAL_CONNECTION_OUTPUT,
};
int CompareEntityNames(const char *szName1, const char *szName2);
#define ENTITY_FLAG_IS_LIGHT 1
#define ENTITY_FLAG_SHOW_IN_LPREVIEW2 2
#define ENTITY_FLAG_IS_INSTANCE 4
class CMapEntity : public CMapClass, public CEditGameClass
{
friend CManifest;
public:
DECLARE_MAPCLASS(CMapEntity,CMapClass);
CMapEntity();
~CMapEntity();
void Debug(void);
size_t GetSize();
int m_EntityTypeFlags; // for fast checks w/o using class name
//
// For flags field.
//
enum
{
flagPlaceholder = 0x01, // No solids - just a point entity
};
enum alignType_e
{
ALIGN_TOP,
ALIGN_BOTTOM,
};
bool NameMatches(const char *szName);
bool ClassNameMatches(const char *szName);
virtual bool ShouldAppearInRaytracedLightingPreview(void)
{
return ( m_EntityTypeFlags & ENTITY_FLAG_SHOW_IN_LPREVIEW2 ) != 0;
}
static inline void ShowEntityNames(bool bShow) { s_bShowEntityNames = bShow; }
static inline bool GetShowEntityNames(void) { return s_bShowEntityNames; }
static inline void ShowEntityConnections(bool bShow) { s_bShowEntityConnections = bShow; }
static inline bool GetShowEntityConnections(void) { return s_bShowEntityConnections; }
static inline void ShowUnconnectedEntities(bool bShow) { s_bShowUnconnectedEntities = bShow; }
static inline bool GetShowUnconnectedEntities(void) { return s_bShowUnconnectedEntities; }
void ReplaceTargetname(const char *szOldName, const char *szNewName);
void CalculateTypeFlags( void );
virtual void SignalChanged(void ); // object has changed
inline void SetPlaceholder(BOOL bSet)
{
if (bSet)
{
flags |= flagPlaceholder;
}
else
{
flags &= ~flagPlaceholder;
}
}
inline BOOL IsPlaceholder(void)
{
return((flags & flagPlaceholder) ? TRUE : FALSE);
}
bool UpdateObjectColor();
//
// CMapClass overrides.
//
bool IsCulledByCordon(const Vector &vecMins, const Vector &vecMaxs);
//
// Serialization.
//
ChunkFileResult_t LoadVMF(CChunkFile *pFile);
ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
int SerializeRMF(std::fstream&, BOOL);
int SerializeMAP(std::fstream&, BOOL);
virtual void PostloadWorld(CMapWorld *pWorld);
virtual ChunkFileResult_t SaveEditorData(CChunkFile *pFile);
//
// Rendering.
//
virtual void Render2D(CRender2D *pRender);
virtual void RenderLogical( CRender2D *pRender );
virtual bool IsLogical();
virtual bool IsVisibleLogical(void);
virtual void SetLogicalPosition( const Vector2D &vecPosition );
virtual const Vector2D& GetLogicalPosition( );
virtual void GetRenderLogicalBox( Vector2D &mins, Vector2D &maxs );
void GetLogicalConnectionPosition( LogicalConnection_t i, Vector2D &vecPosition );
virtual bool ShouldSnapToHalfGrid();
virtual void SetOrigin(Vector& o);
virtual void CalcBounds(BOOL bFullUpdate = FALSE);
inline void SetClass(GDclass *pClass) { CEditGameClass::SetClass(pClass); } // Works around a namespace issue.
virtual void SetClass(LPCTSTR pszClassname, bool bLoading = false);
virtual void AlignOnPlane( Vector& pos, PLANE *plane, alignType_e align );
//
// Hit testing/selection.
//
virtual CMapClass *PrepareSelection(SelectMode_t eSelectMode);
virtual bool HitTest2D(CMapView2D *pView, const Vector2D &point, HitInfo_t &HitData);
virtual bool HitTestLogical(CMapViewLogical *pView, const Vector2D &point, HitInfo_t &nHitData);
//
// Notifications.
//
virtual void OnClone(CMapClass *pClone, CMapWorld *pWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
virtual void OnPreClone(CMapClass *pClone, CMapWorld *pWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
virtual void OnAddToWorld(CMapWorld *pWorld);
virtual void OnRemoveFromWorld(CMapWorld *pWorld, bool bNotifyChildren );
virtual void OnNotifyDependent(CMapClass *pObject, Notify_Dependent_t eNotifyType);
virtual void OnPrePaste( CMapClass *pCopy, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList );
virtual void OnPaste( CMapClass *pCopyObject, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList );
virtual void UpdateDependencies(CMapWorld *pWorld, CMapClass *pObject);
virtual bool OnApply( void );
//
// Keyvalue access. We need to know any time one of our keyvalues changes.
//
virtual void SetKeyValue(LPCSTR pszKey, LPCSTR pszValue);
virtual void DeleteKeyValue(LPCTSTR pszKey);
int GetNodeID(void);
int SetNodeID(int nNodeID);
void NotifyChildKeyChanged(CMapClass *pChild, const char *szKey, const char *szValue);
virtual CMapEntity *FindChildByKeyValue( LPCSTR key, LPCSTR value, bool *bIsInInstance = NULL, VMatrix *InstanceMatrix = NULL );
virtual CMapClass *Copy(bool bUpdateDependencies);
virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);
virtual void AddChild(CMapClass *pChild);
bool HasSolidChildren(void);
void AssignNodeID(void);
const char* GetDescription();
bool IsScaleable() { return !IsPlaceholder(); }
// animation
bool GetTransformMatrix( VMatrix& matrix );
BOOL IsAnimationController( void ) { return IsMoveClass(); }
//-----------------------------------------------------------------------------
// Purpose: If the first child of this entity is of type MapClass, this function
// returns a pointer to that child.
// Output : Returns a pointer to the MapClass that is a child of this
// entity, NULL if the first child of this entity is not MapClass.
//-----------------------------------------------------------------------------
template< class MapClass >
MapClass *GetChildOfType( MapClass *null )
{
FOR_EACH_OBJ( m_Children, pos )
{
MapClass *pChild = dynamic_cast<MapClass*>( m_Children.Element(pos) );
if ( pChild != NULL )
{
return pChild;
}
}
return NULL;
}
//
// CMapAtom implementation.
//
virtual void GetRenderColor( CRender2D *pRender, unsigned char &red, unsigned char &green, unsigned char &blue);
virtual color32 GetRenderColor( CRender2D *pRender );
// char const* GetKeyValue( char *symbol )
// {
// return m_KeyValues.GetValue(symbol );
// }
private:
void EnsureUniqueNodeID(CMapWorld *pWorld);
void OnKeyValueChanged(const char *pszKey, const char *pszOldValue, const char *pszValue);
//
// Each CMapEntity may have one or more helpers as its children, depending
// on its class definition in the FGD file.
//
void AddBoundBoxForClass(GDclass *pClass, bool bLoading);
void AddHelper(CMapClass *pHelper, bool bLoading);
void AddHelpersForClass(GDclass *pClass, bool bLoading);
void RemoveHelpers(bool bRemoveSolids);
void UpdateHelpers(bool bLoading);
// Safely sets the move parent. Will assert and not set it if pEnt is equal to this ent,
// or if this ent is already a parent of pEnt.
void SetMoveParent( CMapEntity *pEnt );
//
// Chunk and key value handlers for loading.
//
static ChunkFileResult_t LoadSolidCallback(CChunkFile *pFile, CMapEntity *pEntity);
static ChunkFileResult_t LoadEditorCallback(CChunkFile *pFile, CMapEntity *pEntity);
static ChunkFileResult_t LoadHiddenCallback(CChunkFile *pFile, CMapEntity *pEntity);
static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CMapEntity *pEntity);
static ChunkFileResult_t LoadEditorKeyCallback(const char *szKey, const char *szValue, CMapEntity *pEntity);
static bool s_bShowEntityNames; // Whether to render entity names in the 2D views.
static bool s_bShowEntityConnections; // Whether to render lines indicating entity connections in the 2D views.
static bool s_bShowUnconnectedEntities; // Whether to render unconnected entities in logical views
WORD flags; // flagPlaceholder
CMapEntity *m_pMoveParent; // for entity movement hierarchy
CMapAnimator *m_pAnimatorChild;
Vector2D m_vecLogicalPosition; // Position in logical space
};
typedef CUtlVector<CMapEntity*> CMapEntityList;
bool MapEntityList_HasInput(const CMapEntityList *pList, const char *szInput, InputOutputType_t eType = iotInvalid);
#endif // MAPENTITY_H
|