summaryrefslogtreecommitdiff
path: root/public/movieobjects/dmeparticlesystemdefinition.h
blob: d2bee4ffa1a6958b883cb388d7594cf36f1b1040 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A particle system definition
//
//=============================================================================

#ifndef DMEPARTICLESYSTEMDEFINITION_H
#define DMEPARTICLESYSTEMDEFINITION_H
#ifdef _WIN32
#pragma once
#endif

#include "datamodel/dmelement.h"
#include "datamodel/dmattribute.h"
#include "datamodel/dmattributevar.h"
#include "datamodel/dmehandle.h"
#include "particles/particles.h"


//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeEditorTypeDictionary;
class CDmeParticleSystemDefinition;


//-----------------------------------------------------------------------------
// Base class for particle functions inside a particle system definition
//-----------------------------------------------------------------------------
class CDmeParticleFunction : public CDmElement
{
	DEFINE_ELEMENT( CDmeParticleFunction, CDmElement );

public:
	virtual const char *GetFunctionType() const { return NULL; }
	virtual void Resolve();
	virtual void OnElementUnserialized();

	// Used for backward compat
	void AddMissingFields( const DmxElementUnpackStructure_t *pUnpack );

	// Returns the editor type dictionary
	CDmeEditorTypeDictionary* GetEditorTypeDictionary();

	// Marks a particle system as a new instance
	// This is basically a workaround to prevent newly-copied particle functions
	// from recompiling themselves a zillion times
	void MarkNewInstance();

protected:
	void UpdateAttributes( const DmxElementUnpackStructure_t *pUnpack );

private:
	// Defines widgets to edit this bad boy
	CDmeHandle< CDmeEditorTypeDictionary > m_hTypeDictionary;
	bool m_bSkipNextResolve;
};


//-----------------------------------------------------------------------------
// Something that updates particles
//-----------------------------------------------------------------------------
class CDmeParticleOperator : public CDmeParticleFunction
{
	DEFINE_ELEMENT( CDmeParticleOperator, CDmeParticleFunction );

public:
	// Sets the particle operator
	void SetFunction( IParticleOperatorDefinition *pDefinition );

	// Returns the function type
	virtual const char *GetFunctionType() const;

private:
	CDmaString m_FunctionName;
};


//-----------------------------------------------------------------------------
// A child of a particle system
//-----------------------------------------------------------------------------
class CDmeParticleChild : public CDmeParticleFunction
{
	DEFINE_ELEMENT( CDmeParticleChild, CDmeParticleFunction );

public:
	// Sets the particle operator
	void SetChildParticleSystem( CDmeParticleSystemDefinition *pDef, IParticleOperatorDefinition *pDefinition );

	// Returns the function type
	virtual const char *GetFunctionType() const;

	CDmaElement< CDmeParticleSystemDefinition > m_Child;
};



//-----------------------------------------------------------------------------
// Represents an editable entity; draws its helpers
//-----------------------------------------------------------------------------
class CDmeParticleSystemDefinition : public CDmElement
{
	DEFINE_ELEMENT( CDmeParticleSystemDefinition, CDmElement );

public:
	virtual void OnElementUnserialized();
	virtual void Resolve();

	// Add, remove
	CDmeParticleFunction* AddOperator( ParticleFunctionType_t type, const char *pFunctionName );
	CDmeParticleFunction* AddChild( CDmeParticleSystemDefinition *pChild );
	void RemoveFunction( ParticleFunctionType_t type, CDmeParticleFunction *pParticleFunction );
	void RemoveFunction( ParticleFunctionType_t type, int nIndex );

	// Find
	int FindFunction( ParticleFunctionType_t type, CDmeParticleFunction *pParticleFunction );
	int FindFunction( ParticleFunctionType_t type, const char *pFunctionName );

	// Iteration
	int GetParticleFunctionCount( ParticleFunctionType_t type ) const;
	CDmeParticleFunction *GetParticleFunction( ParticleFunctionType_t type, int nIndex );

	// Reordering
	void MoveFunctionUp( ParticleFunctionType_t type, CDmeParticleFunction *pElement );
	void MoveFunctionDown( ParticleFunctionType_t type, CDmeParticleFunction *pElement );

	// Returns the editor type dictionary
	CDmeEditorTypeDictionary* GetEditorTypeDictionary();

	// Recompiles the particle system when a change occurs
	void RecompileParticleSystem();

	// Marks a particle system as a new instance
	// This is basically a workaround to prevent newly-copied particle functions
	// from recompiling themselves a zillion times
	void MarkNewInstance();

	// Should we use name-based lookup?
	bool UseNameBasedLookup() const;

private:
	CDmaElementArray< CDmeParticleFunction > m_ParticleFunction[PARTICLE_FUNCTION_COUNT];
	CDmaVar< bool > m_bPreventNameBasedLookup;

	// Defines widgets to edit this bad boy
	CDmeHandle< CDmeEditorTypeDictionary > m_hTypeDictionary;
};


//-----------------------------------------------------------------------------
// Should we use name-based lookup?
//-----------------------------------------------------------------------------
inline bool CDmeParticleSystemDefinition::UseNameBasedLookup() const
{
	return !m_bPreventNameBasedLookup;
}


//-----------------------------------------------------------------------------
// Human readable string for the particle functions
//-----------------------------------------------------------------------------
const char *GetParticleFunctionTypeName( ParticleFunctionType_t type );


#endif // DMEPARTICLESYSTEMDEFINITION_H