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