Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

267 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef MAPENTITY_H
  7. #define MAPENTITY_H
  8. #pragma once
  9. #include "MapClass.h"
  10. #include "MapFace.h" // FIXME: For PLANE definition.
  11. #include "EditGameClass.h"
  12. class CMapAnimator;
  13. class CRender2D;
  14. class CManifest;
  15. enum LogicalConnection_t
  16. {
  17. LOGICAL_CONNECTION_INPUT = 0,
  18. LOGICAL_CONNECTION_OUTPUT,
  19. };
  20. int CompareEntityNames(const char *szName1, const char *szName2);
  21. #define ENTITY_FLAG_IS_LIGHT 1
  22. #define ENTITY_FLAG_SHOW_IN_LPREVIEW2 2
  23. #define ENTITY_FLAG_IS_INSTANCE 4
  24. class CMapEntity : public CMapClass, public CEditGameClass
  25. {
  26. friend CManifest;
  27. public:
  28. DECLARE_MAPCLASS(CMapEntity,CMapClass);
  29. CMapEntity();
  30. ~CMapEntity();
  31. void Debug(void);
  32. size_t GetSize();
  33. int m_EntityTypeFlags; // for fast checks w/o using class name
  34. //
  35. // For flags field.
  36. //
  37. enum
  38. {
  39. flagPlaceholder = 0x01, // No solids - just a point entity
  40. };
  41. enum alignType_e
  42. {
  43. ALIGN_TOP,
  44. ALIGN_BOTTOM,
  45. };
  46. bool NameMatches(const char *szName);
  47. bool ClassNameMatches(const char *szName);
  48. virtual bool ShouldAppearInRaytracedLightingPreview(void)
  49. {
  50. return ( m_EntityTypeFlags & ENTITY_FLAG_SHOW_IN_LPREVIEW2 ) != 0;
  51. }
  52. static inline void ShowEntityNames(bool bShow) { s_bShowEntityNames = bShow; }
  53. static inline bool GetShowEntityNames(void) { return s_bShowEntityNames; }
  54. static inline void ShowEntityConnections(bool bShow) { s_bShowEntityConnections = bShow; }
  55. static inline bool GetShowEntityConnections(void) { return s_bShowEntityConnections; }
  56. static inline void ShowUnconnectedEntities(bool bShow) { s_bShowUnconnectedEntities = bShow; }
  57. static inline bool GetShowUnconnectedEntities(void) { return s_bShowUnconnectedEntities; }
  58. void ReplaceTargetname(const char *szOldName, const char *szNewName);
  59. void CalculateTypeFlags( void );
  60. virtual void SignalChanged(void ); // object has changed
  61. inline void SetPlaceholder(BOOL bSet)
  62. {
  63. if (bSet)
  64. {
  65. flags |= flagPlaceholder;
  66. }
  67. else
  68. {
  69. flags &= ~flagPlaceholder;
  70. }
  71. }
  72. inline BOOL IsPlaceholder(void)
  73. {
  74. return((flags & flagPlaceholder) ? TRUE : FALSE);
  75. }
  76. bool UpdateObjectColor();
  77. //
  78. // CMapClass overrides.
  79. //
  80. bool IsCulledByCordon(const Vector &vecMins, const Vector &vecMaxs);
  81. //
  82. // Serialization.
  83. //
  84. ChunkFileResult_t LoadVMF(CChunkFile *pFile);
  85. ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  86. int SerializeRMF(std::fstream&, BOOL);
  87. int SerializeMAP(std::fstream&, BOOL);
  88. virtual void PostloadWorld(CMapWorld *pWorld);
  89. virtual ChunkFileResult_t SaveEditorData(CChunkFile *pFile);
  90. //
  91. // Rendering.
  92. //
  93. virtual void Render2D(CRender2D *pRender);
  94. virtual void RenderLogical( CRender2D *pRender );
  95. virtual bool IsLogical();
  96. virtual bool IsVisibleLogical(void);
  97. virtual void SetLogicalPosition( const Vector2D &vecPosition );
  98. virtual const Vector2D& GetLogicalPosition( );
  99. virtual void GetRenderLogicalBox( Vector2D &mins, Vector2D &maxs );
  100. void GetLogicalConnectionPosition( LogicalConnection_t i, Vector2D &vecPosition );
  101. virtual bool ShouldSnapToHalfGrid();
  102. virtual void SetOrigin(Vector& o);
  103. virtual void CalcBounds(BOOL bFullUpdate = FALSE);
  104. inline void SetClass(GDclass *pClass) { CEditGameClass::SetClass(pClass); } // Works around a namespace issue.
  105. virtual void SetClass(LPCTSTR pszClassname, bool bLoading = false);
  106. virtual void AlignOnPlane( Vector& pos, PLANE *plane, alignType_e align );
  107. //
  108. // Hit testing/selection.
  109. //
  110. virtual CMapClass *PrepareSelection(SelectMode_t eSelectMode);
  111. virtual bool HitTest2D(CMapView2D *pView, const Vector2D &point, HitInfo_t &HitData);
  112. virtual bool HitTestLogical(CMapViewLogical *pView, const Vector2D &point, HitInfo_t &nHitData);
  113. //
  114. // Notifications.
  115. //
  116. virtual void OnClone(CMapClass *pClone, CMapWorld *pWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
  117. virtual void OnPreClone(CMapClass *pClone, CMapWorld *pWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
  118. virtual void OnAddToWorld(CMapWorld *pWorld);
  119. virtual void OnRemoveFromWorld(CMapWorld *pWorld, bool bNotifyChildren );
  120. virtual void OnNotifyDependent(CMapClass *pObject, Notify_Dependent_t eNotifyType);
  121. virtual void OnPrePaste( CMapClass *pCopy, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList );
  122. virtual void OnPaste( CMapClass *pCopyObject, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList );
  123. virtual void UpdateDependencies(CMapWorld *pWorld, CMapClass *pObject);
  124. virtual bool OnApply( void );
  125. //
  126. // Keyvalue access. We need to know any time one of our keyvalues changes.
  127. //
  128. virtual void SetKeyValue(LPCSTR pszKey, LPCSTR pszValue);
  129. virtual void DeleteKeyValue(LPCTSTR pszKey);
  130. int GetNodeID(void);
  131. int SetNodeID(int nNodeID);
  132. void NotifyChildKeyChanged(CMapClass *pChild, const char *szKey, const char *szValue);
  133. virtual CMapEntity *FindChildByKeyValue( LPCSTR key, LPCSTR value, bool *bIsInInstance = NULL, VMatrix *InstanceMatrix = NULL );
  134. virtual CMapClass *Copy(bool bUpdateDependencies);
  135. virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);
  136. virtual void AddChild(CMapClass *pChild);
  137. bool HasSolidChildren(void);
  138. void AssignNodeID(void);
  139. const char* GetDescription();
  140. bool IsScaleable() { return !IsPlaceholder(); }
  141. // animation
  142. bool GetTransformMatrix( VMatrix& matrix );
  143. BOOL IsAnimationController( void ) { return IsMoveClass(); }
  144. //-----------------------------------------------------------------------------
  145. // Purpose: If the first child of this entity is of type MapClass, this function
  146. // returns a pointer to that child.
  147. // Output : Returns a pointer to the MapClass that is a child of this
  148. // entity, NULL if the first child of this entity is not MapClass.
  149. //-----------------------------------------------------------------------------
  150. template< class MapClass >
  151. MapClass *GetChildOfType( MapClass *null )
  152. {
  153. FOR_EACH_OBJ( m_Children, pos )
  154. {
  155. MapClass *pChild = dynamic_cast<MapClass*>( m_Children.Element(pos) );
  156. if ( pChild != NULL )
  157. {
  158. return pChild;
  159. }
  160. }
  161. return NULL;
  162. }
  163. //
  164. // CMapAtom implementation.
  165. //
  166. virtual void GetRenderColor( CRender2D *pRender, unsigned char &red, unsigned char &green, unsigned char &blue);
  167. virtual color32 GetRenderColor( CRender2D *pRender );
  168. // char const* GetKeyValue( char *symbol )
  169. // {
  170. // return m_KeyValues.GetValue(symbol );
  171. // }
  172. private:
  173. void EnsureUniqueNodeID(CMapWorld *pWorld);
  174. void OnKeyValueChanged(const char *pszKey, const char *pszOldValue, const char *pszValue);
  175. //
  176. // Each CMapEntity may have one or more helpers as its children, depending
  177. // on its class definition in the FGD file.
  178. //
  179. void AddBoundBoxForClass(GDclass *pClass, bool bLoading);
  180. void AddHelper(CMapClass *pHelper, bool bLoading);
  181. void AddHelpersForClass(GDclass *pClass, bool bLoading);
  182. void RemoveHelpers(bool bRemoveSolids);
  183. void UpdateHelpers(bool bLoading);
  184. // Safely sets the move parent. Will assert and not set it if pEnt is equal to this ent,
  185. // or if this ent is already a parent of pEnt.
  186. void SetMoveParent( CMapEntity *pEnt );
  187. //
  188. // Chunk and key value handlers for loading.
  189. //
  190. static ChunkFileResult_t LoadSolidCallback(CChunkFile *pFile, CMapEntity *pEntity);
  191. static ChunkFileResult_t LoadEditorCallback(CChunkFile *pFile, CMapEntity *pEntity);
  192. static ChunkFileResult_t LoadHiddenCallback(CChunkFile *pFile, CMapEntity *pEntity);
  193. static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CMapEntity *pEntity);
  194. static ChunkFileResult_t LoadEditorKeyCallback(const char *szKey, const char *szValue, CMapEntity *pEntity);
  195. static bool s_bShowEntityNames; // Whether to render entity names in the 2D views.
  196. static bool s_bShowEntityConnections; // Whether to render lines indicating entity connections in the 2D views.
  197. static bool s_bShowUnconnectedEntities; // Whether to render unconnected entities in logical views
  198. WORD flags; // flagPlaceholder
  199. CMapEntity *m_pMoveParent; // for entity movement hierarchy
  200. CMapAnimator *m_pAnimatorChild;
  201. Vector2D m_vecLogicalPosition; // Position in logical space
  202. };
  203. typedef CUtlVector<CMapEntity*> CMapEntityList;
  204. bool MapEntityList_HasInput(const CMapEntityList *pList, const char *szInput, InputOutputType_t eType = iotInvalid);
  205. #endif // MAPENTITY_H