/src/ogre/OgreMain/include/OgreParticleSystemManager.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __ParticleSystemManager_H__ |
29 | | #define __ParticleSystemManager_H__ |
30 | | |
31 | | |
32 | | #include "OgrePrerequisites.h" |
33 | | #include "OgreSingleton.h" |
34 | | #include "OgreHeaderPrefix.h" |
35 | | |
36 | | namespace Ogre { |
37 | | |
38 | | // Forward decl |
39 | | class ParticleSystemFactory; |
40 | | |
41 | | /** \addtogroup Core |
42 | | * @{ |
43 | | */ |
44 | | /** \addtogroup Effects |
45 | | * @{ |
46 | | */ |
47 | | /** Manages particle systems, particle system scripts (templates) and the |
48 | | available emitter & affector factories. |
49 | | |
50 | | This singleton class is responsible for managing particle |
51 | | systems. Although, the user interface to creating them is via |
52 | | SceneManager. Remember that like all other MovableObject |
53 | | subclasses, ParticleSystems do not get rendered until they are |
54 | | attached to a SceneNode object. |
55 | | |
56 | | This class also manages factories for ParticleEmitter and |
57 | | ParticleAffector classes. To enable easy extensions to the types of |
58 | | emitters (particle sources) and affectors (particle modifiers), the |
59 | | ParticleSystemManager lets plugins or applications register factory |
60 | | classes which submit new subclasses to ParticleEmitter and |
61 | | ParticleAffector. The actual implementations, |
62 | | such as cone, sphere and box-shaped emitters, and simple affectors such |
63 | | as constant directional force and colour faders are provided by the @ref ParticleFX Plugin shipped with %Ogre. |
64 | | However using this registration process, a custom plugin can create any behaviour required. |
65 | | |
66 | | This class also manages the loading and parsing of particle system |
67 | | scripts, which are text files describing named particle system |
68 | | templates. Instances of particle systems using these templates can |
69 | | then be created easily through the SceneManager::createParticleSystem method. |
70 | | */ |
71 | | class _OgreExport ParticleSystemManager : public Singleton<ParticleSystemManager> |
72 | | { |
73 | | friend class ParticleSystemFactory; |
74 | | public: |
75 | | typedef std::map<String, ParticleSystem*> ParticleTemplateMap; |
76 | | typedef std::map<String, ParticleAffectorFactory*> ParticleAffectorFactoryMap; |
77 | | typedef std::map<String, ParticleEmitterFactory*> ParticleEmitterFactoryMap; |
78 | | typedef std::map<String, ParticleSystemRendererFactory*> ParticleSystemRendererFactoryMap; |
79 | | private: |
80 | | OGRE_AUTO_MUTEX; |
81 | | |
82 | | /// Templates based on scripts |
83 | | ParticleTemplateMap mSystemTemplates; |
84 | | |
85 | | /// Factories for named emitter types (can be extended using plugins) |
86 | | ParticleEmitterFactoryMap mEmitterFactories; |
87 | | |
88 | | /// Factories for named affector types (can be extended using plugins) |
89 | | ParticleAffectorFactoryMap mAffectorFactories; |
90 | | |
91 | | /// Map of renderer types to factories |
92 | | ParticleSystemRendererFactoryMap mRendererFactories; |
93 | | |
94 | | StringVector mScriptPatterns; |
95 | | |
96 | | // Factory instance |
97 | | ParticleSystemFactory* mFactory; |
98 | | |
99 | | /// Internal implementation of createSystem |
100 | | ParticleSystem* createSystemImpl(const String& name, size_t quota, |
101 | | const String& resourceGroup); |
102 | | /// Internal implementation of createSystem |
103 | | ParticleSystem* createSystemImpl(const String& name, const String& templateName); |
104 | | |
105 | | public: |
106 | | |
107 | | ParticleSystemManager(); |
108 | | virtual ~ParticleSystemManager(); |
109 | | |
110 | | /** Adds a new 'factory' object for emitters to the list of available emitter types. |
111 | | |
112 | | This method allows plugins etc to add new particle emitter types to Ogre. Particle emitters |
113 | | are sources of particles, and generate new particles with their start positions, colours and |
114 | | momentums appropriately. Plugins would create new subclasses of ParticleEmitter which |
115 | | emit particles a certain way, and register a subclass of ParticleEmitterFactory to create them (since multiple |
116 | | emitters can be created for different particle systems). |
117 | | @par |
118 | | All particle emitter factories have an assigned name which is used to identify the emitter |
119 | | type. This must be unique. |
120 | | @par |
121 | | Note that the object passed to this function will not be destroyed by the ParticleSystemManager, |
122 | | since it may have been allocated on a different heap in the case of plugins. The caller must |
123 | | destroy the object later on, probably on plugin shutdown. |
124 | | @param factory |
125 | | Pointer to a ParticleEmitterFactory subclass created by the plugin or application code. |
126 | | */ |
127 | | void addEmitterFactory(ParticleEmitterFactory* factory); |
128 | | |
129 | | /** Adds a new 'factory' object for affectors to the list of available affector types. |
130 | | |
131 | | This method allows plugins etc to add new particle affector types to Ogre. Particle |
132 | | affectors modify the particles in a system a certain way such as affecting their direction |
133 | | or changing their colour, lifespan etc. Plugins would |
134 | | create new subclasses of ParticleAffector which affect particles a certain way, and register |
135 | | a subclass of ParticleAffectorFactory to create them. |
136 | | @par |
137 | | All particle affector factories have an assigned name which is used to identify the affector |
138 | | type. This must be unique. |
139 | | @par |
140 | | Note that the object passed to this function will not be destroyed by the ParticleSystemManager, |
141 | | since it may have been allocated on a different heap in the case of plugins. The caller must |
142 | | destroy the object later on, probably on plugin shutdown. |
143 | | @param factory |
144 | | Pointer to a ParticleAffectorFactory subclass created by the plugin or application code. |
145 | | */ |
146 | | void addAffectorFactory(ParticleAffectorFactory* factory); |
147 | | |
148 | | /** Registers a factory class for creating ParticleSystemRenderer instances. |
149 | | @par |
150 | | Note that the object passed to this function will not be destroyed by the ParticleSystemManager, |
151 | | since it may have been allocated on a different heap in the case of plugins. The caller must |
152 | | destroy the object later on, probably on plugin shutdown. |
153 | | @param factory |
154 | | Pointer to a ParticleSystemRendererFactory subclass created by the plugin or application code. |
155 | | */ |
156 | | void addRendererFactory(ParticleSystemRendererFactory* factory); |
157 | | |
158 | | /** Adds a new particle system template to the list of available templates. |
159 | | |
160 | | Instances of particle systems in a scene are not normally unique - often you want to place the |
161 | | same effect in many places. This method allows you to register a ParticleSystem as a named template, |
162 | | which can subsequently be used to create instances using the createSystem method. |
163 | | @par |
164 | | Note that particle system templates can either be created programmatically by an application |
165 | | and registered using this method, or they can be defined in a script file (*.particle) which is |
166 | | loaded by the engine at startup, very much like Material scripts. |
167 | | @param name |
168 | | The name of the template. Must be unique across all templates. |
169 | | @param sysTemplate |
170 | | A pointer to a particle system to be used as a template. The manager |
171 | | will take over ownership of this pointer. |
172 | | |
173 | | */ |
174 | | void addTemplate(const String& name, ParticleSystem* sysTemplate); |
175 | | |
176 | | /** Removes a specified template from the ParticleSystemManager. |
177 | | |
178 | | This method removes a given template from the particle system manager, optionally deleting |
179 | | the template if the deleteTemplate method is called. Throws an exception if the template |
180 | | could not be found. |
181 | | @param name |
182 | | The name of the template to remove. |
183 | | @param deleteTemplate |
184 | | Whether or not to delete the template before removing it. |
185 | | */ |
186 | | void removeTemplate(const String& name, bool deleteTemplate = true); |
187 | | |
188 | | /** Removes a specified template from the ParticleSystemManager. |
189 | | |
190 | | This method removes all templates from the ParticleSystemManager. |
191 | | @param deleteTemplate |
192 | | Whether or not to delete the templates before removing them. |
193 | | */ |
194 | | void removeAllTemplates(bool deleteTemplate = true); |
195 | | |
196 | | |
197 | | /** Removes all templates that belong to a specific Resource Group from the ParticleSystemManager. |
198 | | |
199 | | This method removes all templates that belong in a particular resource group from the ParticleSystemManager. |
200 | | @param resourceGroup |
201 | | Resource group to delete templates for |
202 | | */ |
203 | | void removeTemplatesByResourceGroup(const String& resourceGroup); |
204 | | |
205 | | /** Create a new particle system template. |
206 | | |
207 | | This method is similar to the addTemplate method, except this just creates a new template |
208 | | and returns a pointer to it to be populated. Use this when you don't already have a system |
209 | | to add as a template and just want to create a new template which you will build up in-place. |
210 | | @param name |
211 | | The name of the template. Must be unique across all templates. |
212 | | @param resourceGroup |
213 | | The name of the resource group which will be used to |
214 | | load any dependent resources. |
215 | | |
216 | | */ |
217 | | ParticleSystem* createTemplate(const String& name, const String& resourceGroup); |
218 | | |
219 | | /** Retrieves a particle system template for possible modification. |
220 | | |
221 | | Modifying a template does not affect the settings on any ParticleSystems already created |
222 | | from this template. |
223 | | */ |
224 | | ParticleSystem* getTemplate(const String& name); |
225 | | |
226 | | /** Internal method for creating a new emitter from a factory. |
227 | | |
228 | | Used internally by the engine to create new ParticleEmitter instances from named |
229 | | factories. Applications should use the ParticleSystem::addEmitter method instead, |
230 | | which calls this method to create an instance. |
231 | | @param emitterType |
232 | | String name of the emitter type to be created. A factory of this type must have been registered. |
233 | | @param psys |
234 | | The particle system this is being created for |
235 | | */ |
236 | | ParticleEmitter* _createEmitter(const String& emitterType, ParticleSystem* psys); |
237 | | |
238 | | /** Internal method for destroying an emitter. |
239 | | |
240 | | Because emitters are created by factories which may allocate memory from separate heaps, |
241 | | the memory allocated must be freed from the same place. This method is used to ask the factory |
242 | | to destroy the instance passed in as a pointer. |
243 | | @param emitter |
244 | | Pointer to emitter to be destroyed. On return this pointer will point to invalid (freed) memory. |
245 | | */ |
246 | | void _destroyEmitter(ParticleEmitter* emitter); |
247 | | |
248 | | /** Internal method for creating a new affector from a factory. |
249 | | |
250 | | Used internally by the engine to create new ParticleAffector instances from named |
251 | | factories. Applications should use the ParticleSystem::addAffector method instead, |
252 | | which calls this method to create an instance. |
253 | | @param affectorType |
254 | | String name of the affector type to be created. A factory of this type must have been registered. |
255 | | @param psys |
256 | | The particle system it is being created for |
257 | | */ |
258 | | ParticleAffector* _createAffector(const String& affectorType, ParticleSystem* psys); |
259 | | |
260 | | /** Internal method for destroying an affector. |
261 | | |
262 | | Because affectors are created by factories which may allocate memory from separate heaps, |
263 | | the memory allocated must be freed from the same place. This method is used to ask the factory |
264 | | to destroy the instance passed in as a pointer. |
265 | | @param affector |
266 | | Pointer to affector to be destroyed. On return this pointer will point to invalid (freed) memory. |
267 | | */ |
268 | | void _destroyAffector(ParticleAffector* affector); |
269 | | |
270 | | /** Internal method for creating a new renderer from a factory. |
271 | | |
272 | | Used internally by the engine to create new ParticleSystemRenderer instances from named |
273 | | factories. Applications should use the ParticleSystem::setRenderer method instead, |
274 | | which calls this method to create an instance. |
275 | | @param rendererType |
276 | | String name of the renderer type to be created. A factory of this type must have been registered. |
277 | | */ |
278 | | ParticleSystemRenderer* _createRenderer(const String& rendererType); |
279 | | |
280 | | /** Internal method for destroying a renderer. |
281 | | |
282 | | Because renderer are created by factories which may allocate memory from separate heaps, |
283 | | the memory allocated must be freed from the same place. This method is used to ask the factory |
284 | | to destroy the instance passed in as a pointer. |
285 | | @param renderer |
286 | | Pointer to renderer to be destroyed. On return this pointer will point to invalid (freed) memory. |
287 | | */ |
288 | | void _destroyRenderer(ParticleSystemRenderer* renderer); |
289 | | |
290 | | /** Init method to be called by OGRE system. |
291 | | |
292 | | Due to dependencies between various objects certain initialisation tasks cannot be done |
293 | | on construction. OGRE will call this method when the rendering subsystem is initialised. |
294 | | */ |
295 | | void _initialise(void); |
296 | | |
297 | | typedef MapIterator<ParticleAffectorFactoryMap> ParticleAffectorFactoryIterator; |
298 | | typedef MapIterator<ParticleEmitterFactoryMap> ParticleEmitterFactoryIterator; |
299 | | typedef MapIterator<ParticleSystemRendererFactoryMap> ParticleRendererFactoryIterator; |
300 | | /** Return an iterator over the affector factories currently registered */ |
301 | | ParticleAffectorFactoryIterator getAffectorFactoryIterator(void); |
302 | | /** Return an iterator over the emitter factories currently registered */ |
303 | | ParticleEmitterFactoryIterator getEmitterFactoryIterator(void); |
304 | | /** Return an iterator over the renderer factories currently registered */ |
305 | | ParticleRendererFactoryIterator getRendererFactoryIterator(void); |
306 | | |
307 | | |
308 | | typedef MapIterator<ParticleTemplateMap> ParticleSystemTemplateIterator; |
309 | | /** Gets an iterator over the list of particle system templates. */ |
310 | | ParticleSystemTemplateIterator getTemplateIterator(void) |
311 | 0 | { |
312 | 0 | return ParticleSystemTemplateIterator( |
313 | 0 | mSystemTemplates.begin(), mSystemTemplates.end()); |
314 | 0 | } |
315 | | |
316 | | /** Get an instance of ParticleSystemFactory (internal use). */ |
317 | 0 | ParticleSystemFactory* _getFactory(void) { return mFactory; } |
318 | | |
319 | | /// @copydoc Singleton::getSingleton() |
320 | | static ParticleSystemManager& getSingleton(void); |
321 | | /// @copydoc Singleton::getSingleton() |
322 | | static ParticleSystemManager* getSingletonPtr(void); |
323 | | |
324 | | }; |
325 | | /** @} */ |
326 | | /** @} */ |
327 | | |
328 | | } |
329 | | |
330 | | #include "OgreHeaderSuffix.h" |
331 | | |
332 | | #endif |
333 | | |