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.

159 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef GAMEDATA_H
  7. #define GAMEDATA_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #pragma warning(push, 1)
  12. #pragma warning(disable:4701 4702 4530)
  13. #include <fstream>
  14. #pragma warning(pop)
  15. #include "TokenReader.h"
  16. #include "GDClass.h"
  17. #include "InputOutput.h"
  18. #include "UtlString.h"
  19. #include "utlvector.h"
  20. class MDkeyvalue;
  21. class GameData;
  22. class KeyValues;
  23. enum TEXTUREFORMAT;
  24. typedef void (*GameDataMessageFunc_t)(int level, PRINTF_FORMAT_STRING const char *fmt, ...);
  25. // FGD-based AutoMaterialExclusion data
  26. struct FGDMatExlcusions_s
  27. {
  28. char szDirectory[MAX_PATH]; // Where we store the material exclusion directories
  29. bool bUserGenerated; // If the user specified this ( default: false -- FGD defined )
  30. };
  31. // FGD-based AutoVisGroup data
  32. struct FGDVisGroupsBaseClass_s
  33. {
  34. char szClass[MAX_PATH]; // i.e. Scene Logic, Sounds, etc "Custom\Point Entities\Lights"
  35. CUtlStringList szEntities; // i.e. func_viscluster
  36. };
  37. struct FGDAutoVisGroups_s
  38. {
  39. char szParent[MAX_PATH]; // i.e. Custom, SFM, etc
  40. CUtlVector< FGDVisGroupsBaseClass_s > m_Classes; // i.e. Scene Logic, Sounds, etc
  41. };
  42. #define MAX_DIRECTORY_SIZE 32
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Contains the set of data that is loaded from a single FGD file.
  45. //-----------------------------------------------------------------------------
  46. class GameData
  47. {
  48. public:
  49. typedef enum
  50. {
  51. NAME_FIXUP_PREFIX = 0,
  52. NAME_FIXUP_POSTFIX,
  53. NAME_FIXUP_NONE
  54. } TNameFixup;
  55. GameData();
  56. ~GameData();
  57. BOOL Load(const char *pszFilename);
  58. GDclass *ClassForName(const char *pszName, int *piIndex = NULL);
  59. void ClearData();
  60. inline int GetMaxMapCoord(void);
  61. inline int GetMinMapCoord(void);
  62. inline int GetClassCount();
  63. inline GDclass *GetClass(int nIndex);
  64. GDclass *BeginInstanceRemap( const char *pszClassName, const char *pszInstancePrefix, Vector &Origin, QAngle &Angle );
  65. bool RemapKeyValue( const char *pszKey, const char *pszInValue, char *pszOutValue, TNameFixup NameFixup );
  66. bool RemapNameField( const char *pszInValue, char *pszOutValue, TNameFixup NameFixup );
  67. bool LoadFGDMaterialExclusions( TokenReader &tr );
  68. bool LoadFGDAutoVisGroups( TokenReader &tr );
  69. CUtlVector< FGDMatExlcusions_s > m_FGDMaterialExclusions;
  70. CUtlVector< FGDAutoVisGroups_s > m_FGDAutoVisGroups;
  71. private:
  72. bool ParseMapSize(TokenReader &tr);
  73. CUtlVector<GDclass *> m_Classes;
  74. int m_nMinMapCoord; // Min & max map bounds as defined by the FGD.
  75. int m_nMaxMapCoord;
  76. // Instance Remapping
  77. Vector m_InstanceOrigin; // the origin offset of the instance
  78. QAngle m_InstanceAngle; // the rotation of the the instance
  79. matrix3x4_t m_InstanceMat; // matrix of the origin and rotation of rendering
  80. char m_InstancePrefix[ 128 ]; // the prefix used for the instance name remapping
  81. GDclass *m_InstanceClass; // the entity class that is being remapped
  82. };
  83. //-----------------------------------------------------------------------------
  84. //-----------------------------------------------------------------------------
  85. inline int GameData::GetClassCount()
  86. {
  87. return m_Classes.Count();
  88. }
  89. //-----------------------------------------------------------------------------
  90. //-----------------------------------------------------------------------------
  91. inline GDclass *GameData::GetClass(int nIndex)
  92. {
  93. if (nIndex >= m_Classes.Count())
  94. return NULL;
  95. return m_Classes.Element(nIndex);
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Purpose:
  99. //-----------------------------------------------------------------------------
  100. int GameData::GetMinMapCoord(void)
  101. {
  102. return m_nMinMapCoord;
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Purpose:
  106. //-----------------------------------------------------------------------------
  107. int GameData::GetMaxMapCoord(void)
  108. {
  109. return m_nMaxMapCoord;
  110. }
  111. void GDSetMessageFunc(GameDataMessageFunc_t pFunc);
  112. bool GDError(TokenReader &tr, PRINTF_FORMAT_STRING const char *error, ...);
  113. bool GDSkipToken(TokenReader &tr, trtoken_t ttexpecting = TOKENNONE, const char *pszExpecting = NULL);
  114. bool GDGetToken(TokenReader &tr, char *pszStore, int nSize, trtoken_t ttexpecting = TOKENNONE, const char *pszExpecting = NULL);
  115. bool GDGetTokenDynamic(TokenReader &tr, char **pszStore, trtoken_t ttexpecting, const char *pszExpecting = NULL);
  116. #endif // GAMEDATA_H