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.

165 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A particle system definition
  4. //
  5. //=============================================================================
  6. #ifndef DMEPARTICLESYSTEMDEFINITION_H
  7. #define DMEPARTICLESYSTEMDEFINITION_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. #include "datamodel/dmattribute.h"
  13. #include "datamodel/dmattributevar.h"
  14. #include "datamodel/dmehandle.h"
  15. #include "particles/particles.h"
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class CDmeEditorTypeDictionary;
  20. class CDmeParticleSystemDefinition;
  21. //-----------------------------------------------------------------------------
  22. // Base class for particle functions inside a particle system definition
  23. //-----------------------------------------------------------------------------
  24. class CDmeParticleFunction : public CDmElement
  25. {
  26. DEFINE_ELEMENT( CDmeParticleFunction, CDmElement );
  27. public:
  28. virtual const char *GetFunctionType() const { return NULL; }
  29. virtual void Resolve();
  30. virtual void OnElementUnserialized();
  31. // Used for backward compat
  32. void AddMissingFields( const DmxElementUnpackStructure_t *pUnpack );
  33. // Returns the editor type dictionary
  34. CDmeEditorTypeDictionary* GetEditorTypeDictionary();
  35. // Marks a particle system as a new instance
  36. // This is basically a workaround to prevent newly-copied particle functions
  37. // from recompiling themselves a zillion times
  38. void MarkNewInstance();
  39. protected:
  40. void UpdateAttributes( const DmxElementUnpackStructure_t *pUnpack );
  41. private:
  42. // Defines widgets to edit this bad boy
  43. CDmeHandle< CDmeEditorTypeDictionary > m_hTypeDictionary;
  44. bool m_bSkipNextResolve;
  45. };
  46. //-----------------------------------------------------------------------------
  47. // Something that updates particles
  48. //-----------------------------------------------------------------------------
  49. class CDmeParticleOperator : public CDmeParticleFunction
  50. {
  51. DEFINE_ELEMENT( CDmeParticleOperator, CDmeParticleFunction );
  52. public:
  53. // Sets the particle operator
  54. void SetFunction( IParticleOperatorDefinition *pDefinition );
  55. // Returns the function type
  56. virtual const char *GetFunctionType() const;
  57. private:
  58. CDmaString m_FunctionName;
  59. };
  60. //-----------------------------------------------------------------------------
  61. // A child of a particle system
  62. //-----------------------------------------------------------------------------
  63. class CDmeParticleChild : public CDmeParticleFunction
  64. {
  65. DEFINE_ELEMENT( CDmeParticleChild, CDmeParticleFunction );
  66. public:
  67. // Sets the particle operator
  68. void SetChildParticleSystem( CDmeParticleSystemDefinition *pDef, IParticleOperatorDefinition *pDefinition );
  69. // Returns the function type
  70. virtual const char *GetFunctionType() const;
  71. CDmaElement< CDmeParticleSystemDefinition > m_Child;
  72. };
  73. //-----------------------------------------------------------------------------
  74. // Represents an editable entity; draws its helpers
  75. //-----------------------------------------------------------------------------
  76. class CDmeParticleSystemDefinition : public CDmElement
  77. {
  78. DEFINE_ELEMENT( CDmeParticleSystemDefinition, CDmElement );
  79. public:
  80. virtual void OnElementUnserialized();
  81. virtual void Resolve();
  82. // Add, remove
  83. CDmeParticleFunction* AddOperator( ParticleFunctionType_t type, const char *pFunctionName );
  84. CDmeParticleFunction* AddChild( CDmeParticleSystemDefinition *pChild );
  85. void RemoveFunction( ParticleFunctionType_t type, CDmeParticleFunction *pParticleFunction );
  86. void RemoveFunction( ParticleFunctionType_t type, int nIndex );
  87. // Find
  88. int FindFunction( ParticleFunctionType_t type, CDmeParticleFunction *pParticleFunction );
  89. int FindFunction( ParticleFunctionType_t type, const char *pFunctionName );
  90. // Iteration
  91. int GetParticleFunctionCount( ParticleFunctionType_t type ) const;
  92. CDmeParticleFunction *GetParticleFunction( ParticleFunctionType_t type, int nIndex );
  93. // Reordering
  94. void MoveFunctionUp( ParticleFunctionType_t type, CDmeParticleFunction *pElement );
  95. void MoveFunctionDown( ParticleFunctionType_t type, CDmeParticleFunction *pElement );
  96. // Returns the editor type dictionary
  97. CDmeEditorTypeDictionary* GetEditorTypeDictionary();
  98. // Recompiles the particle system when a change occurs
  99. void RecompileParticleSystem();
  100. // Marks a particle system as a new instance
  101. // This is basically a workaround to prevent newly-copied particle functions
  102. // from recompiling themselves a zillion times
  103. void MarkNewInstance();
  104. // Should we use name-based lookup?
  105. bool UseNameBasedLookup() const;
  106. private:
  107. CDmaElementArray< CDmeParticleFunction > m_ParticleFunction[PARTICLE_FUNCTION_COUNT];
  108. CDmaVar< bool > m_bPreventNameBasedLookup;
  109. // Defines widgets to edit this bad boy
  110. CDmeHandle< CDmeEditorTypeDictionary > m_hTypeDictionary;
  111. };
  112. //-----------------------------------------------------------------------------
  113. // Should we use name-based lookup?
  114. //-----------------------------------------------------------------------------
  115. inline bool CDmeParticleSystemDefinition::UseNameBasedLookup() const
  116. {
  117. return !m_bPreventNameBasedLookup;
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Human readable string for the particle functions
  121. //-----------------------------------------------------------------------------
  122. const char *GetParticleFunctionTypeName( ParticleFunctionType_t type );
  123. #endif // DMEPARTICLESYSTEMDEFINITION_H