00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2006 Torus Knot Software Ltd 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 00024 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 #ifndef __ResourceBackgroundQueue_H__ 00030 #define __ResourceBackgroundQueue_H__ 00031 00032 00033 #include "OgrePrerequisites.h" 00034 #include "OgreCommon.h" 00035 #include "OgreSingleton.h" 00036 #include "OgreResource.h" 00037 00038 #if OGRE_THREAD_SUPPORT 00039 # include <boost/thread/thread.hpp> 00040 # include <boost/thread/condition.hpp> 00041 #endif 00042 00043 namespace Ogre { 00044 00046 typedef unsigned long BackgroundProcessTicket; 00047 00081 class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue> 00082 { 00083 public: 00092 class _OgreExport Listener 00093 { 00094 public: 00101 virtual void operationCompleted(BackgroundProcessTicket ticket) = 0; 00110 virtual void operationCompletedInThread(BackgroundProcessTicket ticket) {} 00112 virtual ~Listener() {} 00113 00114 }; 00116 OGRE_MUTEX(initMutex) 00118 OGRE_THREAD_SYNCHRONISER(initSync); 00119 00120 protected: 00122 enum RequestType 00123 { 00124 RT_INITIALISE_GROUP, 00125 RT_INITIALISE_ALL_GROUPS, 00126 RT_LOAD_GROUP, 00127 RT_LOAD_RESOURCE, 00128 RT_UNLOAD_GROUP, 00129 RT_UNLOAD_RESOURCE, 00130 RT_SHUTDOWN 00131 }; 00133 struct Request 00134 { 00135 BackgroundProcessTicket ticketID; 00136 RequestType type; 00137 String resourceName; 00138 ResourceHandle resourceHandle; 00139 String resourceType; 00140 String groupName; 00141 bool isManual; 00142 ManualResourceLoader* loader; 00143 const NameValuePairList* loadParams; 00144 Listener* listener; 00145 }; 00146 typedef std::list<Request> RequestQueue; 00147 typedef std::map<BackgroundProcessTicket, Request*> RequestTicketMap; 00148 00150 RequestQueue mRequestQueue; 00151 00153 RequestTicketMap mRequestTicketMap; 00154 00156 unsigned long mNextTicketID; 00157 00159 struct QueuedNotification 00160 { 00161 QueuedNotification(Resource::Listener* l, Resource* r) 00162 : resourceListener(l), resource(r), opListener(0), ticket(0) 00163 {} 00164 00165 QueuedNotification(Listener* l, BackgroundProcessTicket t) 00166 : resourceListener(0), resource(0), opListener(l), ticket(t) 00167 {} 00168 00169 // Type 1 - Resource::Listener kind 00170 Resource::Listener* resourceListener; 00171 Resource* resource; 00172 // Type 2 - ResourceBackgroundQueue::Listener kind 00173 Listener* opListener; 00174 BackgroundProcessTicket ticket; 00175 }; 00176 typedef std::list<QueuedNotification> NotificationQueue; 00178 NotificationQueue mNotificationQueue; 00180 OGRE_MUTEX(mNotificationQueueMutex) 00181 00182 00183 bool mStartThread; 00184 00185 #if OGRE_THREAD_SUPPORT 00187 boost::thread* mThread; 00189 boost::condition mCondition; 00191 static void threadFunc(void); 00193 BackgroundProcessTicket addRequest(Request& req); 00195 bool mShuttingDown; 00196 #else 00198 void* mThread; 00199 #endif 00200 00202 OGRE_AUTO_MUTEX 00203 00218 virtual void queueFireBackgroundOperationComplete(Listener* listener, 00219 BackgroundProcessTicket ticket); 00220 00221 public: 00222 ResourceBackgroundQueue(); 00223 virtual ~ResourceBackgroundQueue(); 00224 00241 void setStartBackgroundThread(bool startThread) { mStartThread = startThread; } 00242 00247 bool getStartBackgroundThread(void) { return mStartThread; } 00251 virtual void initialise(void); 00252 00256 virtual void shutdown(void); 00257 00266 virtual BackgroundProcessTicket initialiseResourceGroup( 00267 const String& name, Listener* listener = 0); 00268 00277 virtual BackgroundProcessTicket initialiseAllResourceGroups( 00278 Listener* listener = 0); 00287 virtual BackgroundProcessTicket loadResourceGroup(const String& name, 00288 Listener* listener = 0); 00289 00290 00297 virtual BackgroundProcessTicket unload( 00298 const String& resType, const String& name); 00299 00306 virtual BackgroundProcessTicket unload( 00307 const String& resType, ResourceHandle handle); 00308 00315 virtual BackgroundProcessTicket unloadResourceGroup(const String& name); 00316 00317 00333 virtual BackgroundProcessTicket load( 00334 const String& resType, const String& name, 00335 const String& group, bool isManual = false, 00336 ManualResourceLoader* loader = 0, 00337 const NameValuePairList* loadParams = 0, 00338 Listener* listener = 0); 00352 virtual bool isProcessComplete(BackgroundProcessTicket ticket); 00353 00368 bool _doNextQueuedBackgroundProcess(); 00369 00385 void _initThread(); 00386 00401 virtual void _queueFireBackgroundLoadingComplete(Resource::Listener* listener, 00402 Resource* res); 00403 00411 virtual void _fireBackgroundLoadingComplete(void); 00412 00428 static ResourceBackgroundQueue& getSingleton(void); 00444 static ResourceBackgroundQueue* getSingletonPtr(void); 00445 00446 00447 }; 00448 00449 00450 } 00451 00452 #endif 00453
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jun 10 10:35:49 2007