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.

102 lines
4.5 KiB

  1. //========= Copyright 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 "mapsweptplayerhull.h"
  30. #include "DispShore.h"
  31. // memdbgon must be the last include file in a .cpp file!!!
  32. #include <tier0/memdbgon.h>
  33. typedef CMapClass *HELPERFACTORY(CHelperInfo *, CMapEntity *);
  34. typedef struct
  35. {
  36. char *pszName;
  37. HELPERFACTORY *pfnFactory;
  38. } HelperFactoryMap_t;
  39. static HelperFactoryMap_t HelperFactoryMap[] =
  40. {
  41. "sprite", CMapSprite::CreateMapSprite, // Sprite, gets its render mode from the SPR file, has a selection handle.
  42. "iconsprite", CMapSprite::CreateMapSprite, // Masked alpha sprite, no selection handle.
  43. "studio", CMapStudioModel::CreateMapStudioModel, // Studio model with an axial bounding box.
  44. "studioprop", CMapStudioModel::CreateMapStudioModel, // Studio model with an oriented bounding box.
  45. "lightprop", CMapStudioModel::CreateMapStudioModel, // Studio model with an oriented bounding box, reverses pitch.
  46. "quadbounds", CMapQuadBounds::CreateQuadBounds, // Extracts the verts from a quad face of a brush.
  47. "animator", CMapAnimator::CreateMapAnimator, // Previews the motion of a moving entity (keyframe follower).
  48. "keyframe", CMapKeyFrame::CreateMapKeyFrame, // Autonames when cloned and draws lines to the next keyframe.
  49. "decal", CMapDecal::CreateMapDecal, // Decal that automatically attaches to nearby faces.
  50. "wirebox", CMapAlignedBox::Create, // Wireframe box that can extract its mins & maxs.
  51. "line", CMapLine::Create, // Line drawn between any two entities.
  52. "nodelink", CMapLine::Create, // Line drawn between any two navigation nodes.
  53. "lightcone", CMapLightCone::Create, // Faceted cone showing light angles and falloff.
  54. "frustum", CMapFrustum::Create, // Wireframe frustum.
  55. "sphere", CMapSphere::Create, // Wireframe sphere indicating a radius.
  56. "overlay", CMapOverlay::CreateMapOverlay, // A decal with manipulatable vertices.
  57. "light", CMapLight::CreateMapLight, // Light source for lighting preview.
  58. "sidelist", CMapSideList::CreateMapSideList, // List of CMapFace pointers set by face ID.
  59. "origin", CMapPointHandle::Create, // Handle used to manipulate the origin of an entity.
  60. "vecline", CMapPointHandle::Create, // Handle used to manipulate another point that draws a line back to its parent entity.
  61. "axis", CMapAxisHandle::Create, // Handle used to manipulate the axis of an entity.
  62. "cylinder", CMapCylinder::Create, // Wireframe cylinder with separate radii at each end
  63. "sweptplayerhull", CMapSweptPlayerHull::Create, // A swept player sized hull between two points (ladders)
  64. "overlay_transition", CMapOverlayTransition::Create, // Notes!!
  65. "instance", CMapInstance::Create, // A map instance used for rendering the sub-map
  66. };
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Creates a helper from a helper info object.
  69. // Input : pHelperInfo - holds information about the helper to be created and
  70. // arguments to be passed to the helper when it is created.
  71. // pParent - The entity that will be the helper's parent.
  72. // Output : Returns a pointer to the newly created helper.
  73. //-----------------------------------------------------------------------------
  74. CMapClass *CHelperFactory::CreateHelper(CHelperInfo *pHelperInfo, CMapEntity *pParent)
  75. {
  76. //
  77. // Look up the helper factory function in the factory function table.
  78. //
  79. for (int i = 0; i < sizeof(HelperFactoryMap) / sizeof(HelperFactoryMap[0]); i++)
  80. {
  81. //
  82. // If the function was found in the table, create the helper and return it.
  83. //
  84. if (!stricmp(HelperFactoryMap[i].pszName, pHelperInfo->GetName()))
  85. {
  86. CMapClass *pHelper = HelperFactoryMap[i].pfnFactory(pHelperInfo, pParent);
  87. return(pHelper);
  88. }
  89. }
  90. return(NULL);
  91. }