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.

110 lines
4.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ====
  2. //
  3. // Purpose: Implements a factory for entity helpers. When an entity is created,
  4. // the helpers from its class definition in the FGD are each instantiated
  5. // and added as children of the entity.
  6. //
  7. //=============================================================================
  8. #include "stdafx.h"
  9. #include "HelperFactory.h"
  10. #include "fgdlib/HelperInfo.h"
  11. #include "MapAlignedBox.h"
  12. #include "MapAnimator.h"
  13. #include "MapAxisHandle.h"
  14. #include "MapDecal.h"
  15. #include "MapFrustum.h"
  16. #include "MapKeyFrame.h"
  17. #include "MapLightCone.h"
  18. #include "MapLine.h"
  19. #include "MapSprite.h"
  20. #include "MapSphere.h"
  21. #include "MapStudioModel.h"
  22. #include "MapOverlay.h"
  23. #include "MapPointHandle.h"
  24. #include "MapQuadBounds.h"
  25. #include "MapLight.h"
  26. #include "MapSideList.h"
  27. #include "MapCylinder.h"
  28. #include "MapInstance.h"
  29. #include "MapOccluder.h"
  30. #include "MapViewer.h"
  31. #include "maplineoccluder.h"
  32. #include "mapsweptplayerhull.h"
  33. #include "mapworldtext.h"
  34. #include "DispShore.h"
  35. // memdbgon must be the last include file in a .cpp file!!!
  36. #include <tier0/memdbgon.h>
  37. typedef CMapClass *HELPERFACTORY(CHelperInfo *, CMapEntity *);
  38. typedef struct
  39. {
  40. char *pszName;
  41. HELPERFACTORY *pfnFactory;
  42. } HelperFactoryMap_t;
  43. static HelperFactoryMap_t HelperFactoryMap[] =
  44. {
  45. "sprite", CMapSprite::CreateMapSprite, // Sprite, gets its render mode from the SPR file, has a selection handle.
  46. "iconsprite", CMapSprite::CreateMapSprite, // Masked alpha sprite, no selection handle.
  47. "studio", CMapStudioModel::CreateMapStudioModel, // Studio model with an axial bounding box.
  48. "studioprop", CMapStudioModel::CreateMapStudioModel, // Studio model with an oriented bounding box.
  49. "lightprop", CMapStudioModel::CreateMapStudioModel, // Studio model with an oriented bounding box, reverses pitch.
  50. "quadbounds", CMapQuadBounds::CreateQuadBounds, // Extracts the verts from a quad face of a brush.
  51. "animator", CMapAnimator::CreateMapAnimator, // Previews the motion of a moving entity (keyframe follower).
  52. "keyframe", CMapKeyFrame::CreateMapKeyFrame, // Autonames when cloned and draws lines to the next keyframe.
  53. "decal", CMapDecal::CreateMapDecal, // Decal that automatically attaches to nearby faces.
  54. "wirebox", CMapAlignedBox::Create, // Wireframe box that can extract its mins & maxs.
  55. "line", CMapLine::Create, // Line drawn between any two entities.
  56. "nodelink", CMapLine::Create, // Line drawn between any two navigation nodes.
  57. "lightcone", CMapLightCone::Create, // Faceted cone showing light angles and falloff.
  58. "frustum", CMapFrustum::Create, // Wireframe frustum.
  59. "sphere", CMapSphere::Create, // Wireframe sphere indicating a radius.
  60. "overlay", CMapOverlay::CreateMapOverlay, // A decal with manipulatable vertices.
  61. "light", CMapLight::CreateMapLight, // Light source for lighting preview.
  62. "sidelist", CMapSideList::CreateMapSideList, // List of CMapFace pointers set by face ID.
  63. "origin", CMapPointHandle::Create, // Handle used to manipulate the origin of an entity.
  64. "vecline", CMapPointHandle::Create, // Handle used to manipulate another point that draws a line back to its parent entity.
  65. "axis", CMapAxisHandle::Create, // Handle used to manipulate the axis of an entity.
  66. "cylinder", CMapCylinder::Create, // Wireframe cylinder with separate radii at each end
  67. "sweptplayerhull", CMapSweptPlayerHull::Create, // A swept player sized hull between two points (ladders)
  68. "overlay_transition", CMapOverlayTransition::Create, // Notes!!
  69. "instance", CMapInstance::Create, // A map instance used for rendering the sub-map
  70. "occluder", CMapOccluder::Create, // FoW Occluder
  71. "line_occluder", CMapLineOccluder::Create, // FoW Line Occluder
  72. "viewer", CMapViewer::Create, // FoW Viewer
  73. "worldtext", CWorldTextHelper::CreateWorldText, // Text string oriented in world space
  74. };
  75. //-----------------------------------------------------------------------------
  76. // Purpose: Creates a helper from a helper info object.
  77. // Input : pHelperInfo - holds information about the helper to be created and
  78. // arguments to be passed to the helper when it is created.
  79. // pParent - The entity that will be the helper's parent.
  80. // Output : Returns a pointer to the newly created helper.
  81. //-----------------------------------------------------------------------------
  82. CMapClass *CHelperFactory::CreateHelper(CHelperInfo *pHelperInfo, CMapEntity *pParent)
  83. {
  84. //
  85. // Look up the helper factory function in the factory function table.
  86. //
  87. for (int i = 0; i < sizeof(HelperFactoryMap) / sizeof(HelperFactoryMap[0]); i++)
  88. {
  89. //
  90. // If the function was found in the table, create the helper and return it.
  91. //
  92. if (!stricmp(HelperFactoryMap[i].pszName, pHelperInfo->GetName()))
  93. {
  94. CMapClass *pHelper = HelperFactoryMap[i].pfnFactory(pHelperInfo, pParent);
  95. return(pHelper);
  96. }
  97. }
  98. return(NULL);
  99. }