Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreParticleSystemManager.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

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