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-2013 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 __SceneManagerEnumerator_H__ |
---|
29 | #define __SceneManagerEnumerator_H__ |
---|
30 | |
---|
31 | #include "OgrePrerequisites.h" |
---|
32 | |
---|
33 | #include "OgreSceneManager.h" |
---|
34 | #include "OgreSingleton.h" |
---|
35 | #include "OgreIteratorWrappers.h" |
---|
36 | #include "OgreHeaderPrefix.h" |
---|
37 | |
---|
38 | namespace Ogre { |
---|
39 | |
---|
40 | /** \addtogroup Core |
---|
41 | * @{ |
---|
42 | */ |
---|
43 | /** \addtogroup Scene |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | /// Factory for default scene manager |
---|
47 | class _OgreExport DefaultSceneManagerFactory : public SceneManagerFactory |
---|
48 | { |
---|
49 | protected: |
---|
50 | void initMetaData(void) const; |
---|
51 | public: |
---|
52 | DefaultSceneManagerFactory() {} |
---|
53 | ~DefaultSceneManagerFactory() {} |
---|
54 | /// Factory type name |
---|
55 | static const String FACTORY_TYPE_NAME; |
---|
56 | SceneManager* createInstance(const String& instanceName); |
---|
57 | void destroyInstance(SceneManager* instance); |
---|
58 | }; |
---|
59 | /// Default scene manager |
---|
60 | class _OgreExport DefaultSceneManager : public SceneManager |
---|
61 | { |
---|
62 | public: |
---|
63 | DefaultSceneManager(const String& name); |
---|
64 | ~DefaultSceneManager(); |
---|
65 | const String& getTypeName(void) const; |
---|
66 | }; |
---|
67 | |
---|
68 | /** Enumerates the SceneManager classes available to applications. |
---|
69 | @remarks |
---|
70 | As described in the SceneManager class, SceneManagers are responsible |
---|
71 | for organising the scene and issuing rendering commands to the |
---|
72 | RenderSystem. Certain scene types can benefit from different |
---|
73 | rendering approaches, and it is intended that subclasses will |
---|
74 | be created to special case this. |
---|
75 | @par |
---|
76 | In order to give applications easy access to these implementations, |
---|
77 | this class has a number of methods to create or retrieve a SceneManager |
---|
78 | which is appropriate to the scene type. |
---|
79 | @par |
---|
80 | SceneManagers are created by SceneManagerFactory instances. New factories |
---|
81 | for new types of SceneManager can be registered with this class to make |
---|
82 | them available to clients. |
---|
83 | @par |
---|
84 | Note that you can still plug in your own custom SceneManager without |
---|
85 | using a factory, should you choose, it's just not as flexible that way. |
---|
86 | Just instantiate your own SceneManager manually and use it directly. |
---|
87 | */ |
---|
88 | class _OgreExport SceneManagerEnumerator : public Singleton<SceneManagerEnumerator>, public SceneMgtAlloc |
---|
89 | { |
---|
90 | public: |
---|
91 | /// Scene manager instances, indexed by instance name |
---|
92 | typedef map<String, SceneManager*>::type Instances; |
---|
93 | /// List of available scene manager types as meta data |
---|
94 | typedef vector<const SceneManagerMetaData*>::type MetaDataList; |
---|
95 | private: |
---|
96 | /// Scene manager factories |
---|
97 | typedef list<SceneManagerFactory*>::type Factories; |
---|
98 | Factories mFactories; |
---|
99 | Instances mInstances; |
---|
100 | /// Stored separately to allow iteration |
---|
101 | MetaDataList mMetaDataList; |
---|
102 | /// Factory for default scene manager |
---|
103 | DefaultSceneManagerFactory mDefaultFactory; |
---|
104 | /// Count of creations for auto-naming |
---|
105 | unsigned long mInstanceCreateCount; |
---|
106 | /// Currently assigned render system |
---|
107 | RenderSystem* mCurrentRenderSystem; |
---|
108 | |
---|
109 | |
---|
110 | public: |
---|
111 | SceneManagerEnumerator(); |
---|
112 | ~SceneManagerEnumerator(); |
---|
113 | |
---|
114 | /** Register a new SceneManagerFactory. |
---|
115 | @remarks |
---|
116 | Plugins should call this to register as new SceneManager providers. |
---|
117 | */ |
---|
118 | void addFactory(SceneManagerFactory* fact); |
---|
119 | |
---|
120 | /** Remove a SceneManagerFactory. |
---|
121 | */ |
---|
122 | void removeFactory(SceneManagerFactory* fact); |
---|
123 | |
---|
124 | /** Get more information about a given type of SceneManager. |
---|
125 | @remarks |
---|
126 | The metadata returned tells you a few things about a given type |
---|
127 | of SceneManager, which can be created using a factory that has been |
---|
128 | registered already. |
---|
129 | @param typeName The type name of the SceneManager you want to enquire on. |
---|
130 | If you don't know the typeName already, you can iterate over the |
---|
131 | metadata for all types using getMetaDataIterator. |
---|
132 | */ |
---|
133 | const SceneManagerMetaData* getMetaData(const String& typeName) const; |
---|
134 | |
---|
135 | typedef ConstVectorIterator<MetaDataList> MetaDataIterator; |
---|
136 | /** Iterate over all types of SceneManager available for construction, |
---|
137 | providing some information about each one. |
---|
138 | */ |
---|
139 | MetaDataIterator getMetaDataIterator(void) const; |
---|
140 | |
---|
141 | /** Create a SceneManager instance of a given type. |
---|
142 | @remarks |
---|
143 | You can use this method to create a SceneManager instance of a |
---|
144 | given specific type. You may know this type already, or you may |
---|
145 | have discovered it by looking at the results from getMetaDataIterator. |
---|
146 | @note |
---|
147 | This method throws an exception if the named type is not found. |
---|
148 | @param typeName String identifying a unique SceneManager type |
---|
149 | @param instanceName Optional name to given the new instance that is |
---|
150 | created. If you leave this blank, an auto name will be assigned. |
---|
151 | */ |
---|
152 | SceneManager* createSceneManager(const String& typeName, |
---|
153 | const String& instanceName = StringUtil::BLANK); |
---|
154 | |
---|
155 | /** Create a SceneManager instance based on scene type support. |
---|
156 | @remarks |
---|
157 | Creates an instance of a SceneManager which supports the scene types |
---|
158 | identified in the parameter. If more than one type of SceneManager |
---|
159 | has been registered as handling that combination of scene types, |
---|
160 | in instance of the last one registered is returned. |
---|
161 | @note This method always succeeds, if a specific scene manager is not |
---|
162 | found, the default implementation is always returned. |
---|
163 | @param typeMask A mask containing one or more SceneType flags |
---|
164 | @param instanceName Optional name to given the new instance that is |
---|
165 | created. If you leave this blank, an auto name will be assigned. |
---|
166 | */ |
---|
167 | SceneManager* createSceneManager(SceneTypeMask typeMask, |
---|
168 | const String& instanceName = StringUtil::BLANK); |
---|
169 | |
---|
170 | /** Destroy an instance of a SceneManager. */ |
---|
171 | void destroySceneManager(SceneManager* sm); |
---|
172 | |
---|
173 | /** Get an existing SceneManager instance that has already been created, |
---|
174 | identified by the instance name. |
---|
175 | @param instanceName The name of the instance to retrieve. |
---|
176 | */ |
---|
177 | SceneManager* getSceneManager(const String& instanceName) const; |
---|
178 | |
---|
179 | /** Identify if a SceneManager instance already exists. |
---|
180 | @param instanceName The name of the instance to retrieve. |
---|
181 | */ |
---|
182 | bool hasSceneManager(const String& instanceName) const; |
---|
183 | |
---|
184 | typedef MapIterator<Instances> SceneManagerIterator; |
---|
185 | /** Get an iterator over all the existing SceneManager instances. */ |
---|
186 | SceneManagerIterator getSceneManagerIterator(void); |
---|
187 | |
---|
188 | /** Notifies all SceneManagers of the destination rendering system. |
---|
189 | */ |
---|
190 | void setRenderSystem(RenderSystem* rs); |
---|
191 | |
---|
192 | /// Utility method to control shutdown of the managers |
---|
193 | void shutdownAll(void); |
---|
194 | /** Override standard Singleton retrieval. |
---|
195 | @remarks |
---|
196 | Why do we do this? Well, it's because the Singleton |
---|
197 | implementation is in a .h file, which means it gets compiled |
---|
198 | into anybody who includes it. This is needed for the |
---|
199 | Singleton template to work, but we actually only want it |
---|
200 | compiled into the implementation of the class based on the |
---|
201 | Singleton, not all of them. If we don't change this, we get |
---|
202 | link errors when trying to use the Singleton-based class from |
---|
203 | an outside dll. |
---|
204 | @par |
---|
205 | This method just delegates to the template version anyway, |
---|
206 | but the implementation stays in this single compilation unit, |
---|
207 | preventing link errors. |
---|
208 | */ |
---|
209 | static SceneManagerEnumerator& getSingleton(void); |
---|
210 | /** Override standard Singleton retrieval. |
---|
211 | @remarks |
---|
212 | Why do we do this? Well, it's because the Singleton |
---|
213 | implementation is in a .h file, which means it gets compiled |
---|
214 | into anybody who includes it. This is needed for the |
---|
215 | Singleton template to work, but we actually only want it |
---|
216 | compiled into the implementation of the class based on the |
---|
217 | Singleton, not all of them. If we don't change this, we get |
---|
218 | link errors when trying to use the Singleton-based class from |
---|
219 | an outside dll. |
---|
220 | @par |
---|
221 | This method just delegates to the template version anyway, |
---|
222 | but the implementation stays in this single compilation unit, |
---|
223 | preventing link errors. |
---|
224 | */ |
---|
225 | static SceneManagerEnumerator* getSingletonPtr(void); |
---|
226 | |
---|
227 | }; |
---|
228 | |
---|
229 | /** @} */ |
---|
230 | /** @} */ |
---|
231 | |
---|
232 | } |
---|
233 | |
---|
234 | #include "OgreHeaderSuffix.h" |
---|
235 | |
---|
236 | #endif |
---|