Counter Strike : Global Offensive Source Code
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.

272 lines
8.6 KiB

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