OGRE: OgreResourceBackgroundQueue.h Source File - OGRE Documentation

# 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 namespace Ogre {
    00039
    00041     typedef unsigned long BackgroundProcessTicket;
    00042
    00044     struct BackgroundProcessResult
    00045     {
    00047         bool error;
    00049         String message;
    00050
    00051         BackgroundProcessResult() : error(false) {}
    00052     };
    00053
    00054
    00088     class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>, public ResourceAlloc
    00089     {
    00090     public:
    00099         class _OgreExport Listener
    00100         {
    00101         public:
    00108             virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) = 0;
    00117             virtual void operationCompletedInThread(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) {}
    00119             virtual ~Listener() {}
    00120
    00121         };
    00123         OGRE_MUTEX(initMutex)
    00125         OGRE_THREAD_SYNCHRONISER(initSync)
    00126
    00127     protected:
    00129         enum RequestType
    00130         {
    00131             RT_INITIALISE_GROUP,
    00132             RT_INITIALISE_ALL_GROUPS,
    00133             RT_PREPARE_GROUP,
    00134             RT_PREPARE_RESOURCE,
    00135             RT_LOAD_GROUP,
    00136             RT_LOAD_RESOURCE,
    00137             RT_UNLOAD_GROUP,
    00138             RT_UNLOAD_RESOURCE,
    00139             RT_SHUTDOWN
    00140         };
    00142         struct Request
    00143         {
    00144             BackgroundProcessTicket ticketID;
    00145             RequestType type;
    00146             String resourceName;
    00147             ResourceHandle resourceHandle;
    00148             String resourceType;
    00149             String groupName;
    00150             bool isManual;
    00151             ManualResourceLoader* loader;
    00152             const NameValuePairList* loadParams;
    00153             Listener* listener;
    00154             BackgroundProcessResult result;
    00155         };
    00156         typedef std::list<Request> RequestQueue;
    00157         typedef std::map<BackgroundProcessTicket, Request*> RequestTicketMap;
    00158
    00160         RequestQueue mRequestQueue;
    00161
    00163         RequestTicketMap mRequestTicketMap;
    00164
    00166         unsigned long mNextTicketID;
    00167
    00169         struct QueuedNotification
    00170         {
    00171             QueuedNotification(Resource* r, bool load)
    00172                 : load(load), resource(r)
    00173             {}
    00174
    00175             QueuedNotification(const Request &req)
    00176                 : load(false), resource(0), req(req)
    00177             {}
    00178
    00179             bool load;
    00180             // Type 1 - Resource::Listener kind
    00181             Resource* resource;
    00182             // Type 2 - ResourceBackgroundQueue::Listener kind
    00183             Request req;
    00184         };
    00185         typedef std::list<QueuedNotification> NotificationQueue;
    00187         NotificationQueue mNotificationQueue;
    00189         OGRE_MUTEX(mNotificationQueueMutex)
    00190
    00191
    00192         bool mStartThread;
    00193
    00194 #if OGRE_THREAD_SUPPORT
    00196         boost::thread* mThread;
    00198         boost::condition mCondition;
    00200         static void threadFunc(void);
    00202         BackgroundProcessTicket addRequest(Request& req);
    00204         bool mShuttingDown;
    00205 #else
    00207         void* mThread;
    00208 #endif
    00209
    00211         OGRE_AUTO_MUTEX
    00212
    00227         virtual void queueFireBackgroundOperationComplete(Request *req);
    00228
    00229     public:
    00230         ResourceBackgroundQueue();
    00231         virtual ~ResourceBackgroundQueue();
    00232
    00249         void setStartBackgroundThread(bool startThread) { mStartThread = startThread; }
    00250
    00255         bool getStartBackgroundThread(void) { return mStartThread; }
    00259         virtual void initialise(void);
    00260
    00264         virtual void shutdown(void);
    00265
    00274         virtual BackgroundProcessTicket initialiseResourceGroup(
    00275             const String& name, Listener* listener = 0);
    00276
    00285         virtual BackgroundProcessTicket initialiseAllResourceGroups(
    00286             Listener* listener = 0);
    00295         virtual BackgroundProcessTicket prepareResourceGroup(const String& name,
    00296             Listener* listener = 0);
    00297
    00306         virtual BackgroundProcessTicket loadResourceGroup(const String& name,
    00307             Listener* listener = 0);
    00308
    00309
    00316         virtual BackgroundProcessTicket unload(
    00317             const String& resType, const String& name,
    00318             Listener* listener = 0);
    00319
    00326         virtual BackgroundProcessTicket unload(
    00327             const String& resType, ResourceHandle handle,
    00328             Listener* listener = 0);
    00329
    00336         virtual BackgroundProcessTicket unloadResourceGroup(const String& name,
    00337             Listener* listener = 0);
    00338
    00339
    00355         virtual BackgroundProcessTicket prepare(
    00356             const String& resType, const String& name,
    00357             const String& group, bool isManual = false,
    00358             ManualResourceLoader* loader = 0,
    00359             const NameValuePairList* loadParams = 0,
    00360             Listener* listener = 0);
    00361
    00377         virtual BackgroundProcessTicket load(
    00378             const String& resType, const String& name,
    00379             const String& group, bool isManual = false,
    00380             ManualResourceLoader* loader = 0,
    00381             const NameValuePairList* loadParams = 0,
    00382             Listener* listener = 0);
    00396         virtual bool isProcessComplete(BackgroundProcessTicket ticket);
    00397
    00412         bool _doNextQueuedBackgroundProcess();
    00413
    00429         void _initThread();
    00430
    00444         virtual void _queueFireBackgroundPreparingComplete(Resource* res);
    00445
    00459         virtual void _queueFireBackgroundLoadingComplete(Resource* res);
    00460
    00468         virtual void _fireOnFrameCallbacks(void);
    00469
    00485         static ResourceBackgroundQueue& getSingleton(void);
    00501         static ResourceBackgroundQueue* getSingletonPtr(void);
    00502
    00503
    00504     };
    00505
    00506
    00507 }
    00508
    00509 #endif
    00510

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:19 2009