OGRE: OgreResourceBackgroundQueue.h Source File - OGRE Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# OgreResourceBackgroundQueue.h

Go to the documentation of this file.

    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* r)
    00162                 : resource(r), opListener(0), ticket(0)
    00163             {}
    00164
    00165             QueuedNotification(Listener* l, BackgroundProcessTicket t)
    00166                 : resource(0), opListener(l), ticket(t)
    00167             {}
    00168
    00169             // Type 1 - Resource::Listener kind
    00170             Resource* resource;
    00171             // Type 2 - ResourceBackgroundQueue::Listener kind
    00172             Listener* opListener;
    00173             BackgroundProcessTicket ticket;
    00174         };
    00175         typedef std::list<QueuedNotification> NotificationQueue;
    00177         NotificationQueue mNotificationQueue;
    00179         OGRE_MUTEX(mNotificationQueueMutex)
    00180
    00181
    00182         bool mStartThread;
    00183
    00184 #if OGRE_THREAD_SUPPORT
    00186         boost::thread* mThread;
    00188         boost::condition mCondition;
    00190         static void threadFunc(void);
    00192         BackgroundProcessTicket addRequest(Request& req);
    00194         bool mShuttingDown;
    00195 #else
    00197         void* mThread;
    00198 #endif
    00199
    00201         OGRE_AUTO_MUTEX
    00202
    00217         virtual void queueFireBackgroundOperationComplete(Listener* listener,
    00218             BackgroundProcessTicket ticket);
    00219
    00220     public:
    00221         ResourceBackgroundQueue();
    00222         virtual ~ResourceBackgroundQueue();
    00223
    00240         void setStartBackgroundThread(bool startThread) { mStartThread = startThread; }
    00241
    00246         bool getStartBackgroundThread(void) { return mStartThread; }
    00250         virtual void initialise(void);
    00251
    00255         virtual void shutdown(void);
    00256
    00265         virtual BackgroundProcessTicket initialiseResourceGroup(
    00266             const String& name, Listener* listener = 0);
    00267
    00276         virtual BackgroundProcessTicket initialiseAllResourceGroups(
    00277             Listener* listener = 0);
    00286         virtual BackgroundProcessTicket loadResourceGroup(const String& name,
    00287             Listener* listener = 0);
    00288
    00289
    00296         virtual BackgroundProcessTicket unload(
    00297             const String& resType, const String& name,
    00298             Listener* listener = 0);
    00299
    00306         virtual BackgroundProcessTicket unload(
    00307             const String& resType, ResourceHandle handle,
    00308             Listener* listener = 0);
    00309
    00316         virtual BackgroundProcessTicket unloadResourceGroup(const String& name,
    00317             Listener* listener = 0);
    00318
    00319
    00335         virtual BackgroundProcessTicket load(
    00336             const String& resType, const String& name,
    00337             const String& group, bool isManual = false,
    00338             ManualResourceLoader* loader = 0,
    00339             const NameValuePairList* loadParams = 0,
    00340             Listener* listener = 0);
    00354         virtual bool isProcessComplete(BackgroundProcessTicket ticket);
    00355
    00370         bool _doNextQueuedBackgroundProcess();
    00371
    00387         void _initThread();
    00388
    00402         virtual void _queueFireBackgroundLoadingComplete(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 Thu Mar 6 09:46:26 2008