# 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-2005 The OGRE Team
    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 */
    00025 #ifndef __ResourceBackgroundQueue_H__
    00026 #define __ResourceBackgroundQueue_H__
    00027
    00028
    00029 #include "OgrePrerequisites.h"
    00030 #include "OgreCommon.h"
    00031 #include "OgreSingleton.h"
    00032
    00033 #if OGRE_THREAD_SUPPORT
    00034 #   include <boost/thread/thread.hpp>
    00035 #   include <boost/thread/condition.hpp>
    00036 #endif
    00037
    00038 namespace Ogre {
    00039
    00041     typedef unsigned long BackgroundProcessTicket;
    00042
    00055     class _OgreExport ResourceBackgroundQueueListener
    00056     {
    00057     public:
    00062         virtual void operationCompleted(BackgroundProcessTicket ticket) = 0;
    00063     };
    00064
    00090     class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>
    00091     {
    00092     protected:
    00094         enum RequestType
    00095         {
    00096             RT_INITIALISE_GROUP,
    00097             RT_INITIALISE_ALL_GROUPS,
    00098             RT_LOAD_GROUP,
    00099             RT_LOAD_RESOURCE,
    00100             RT_SHUTDOWN
    00101         };
    00103         struct Request
    00104         {
    00105             BackgroundProcessTicket ticketID;
    00106             RequestType type;
    00107             String resourceName;
    00108             String resourceType;
    00109             String groupName;
    00110             bool isManual;
    00111             ManualResourceLoader* loader;
    00112             const NameValuePairList* loadParams;
    00113             ResourceBackgroundQueueListener* listener;
    00114         };
    00115         typedef std::list<Request> RequestQueue;
    00116         typedef std::map<BackgroundProcessTicket, Request*> RequestTicketMap;
    00117
    00119         RequestQueue mRequestQueue;
    00120
    00122         RequestTicketMap mRequestTicketMap;
    00123
    00125         unsigned long mNextTicketID;
    00126
    00127 #if OGRE_THREAD_SUPPORT
    00128
    00129         boost::thread* mThread;
    00131         boost::condition mCondition;
    00133         static void threadFunc(void);
    00135         BackgroundProcessTicket addRequest(Request& req);
    00136 #else
    00137
    00138         void* mThread;
    00139 #endif
    00140
    00142         OGRE_AUTO_MUTEX
    00143
    00144     public:
    00145         ResourceBackgroundQueue();
    00146         virtual ~ResourceBackgroundQueue();
    00147
    00149         virtual void initialise(void);
    00150
    00152         virtual void shutdown(void);
    00153
    00162         virtual BackgroundProcessTicket initialiseResourceGroup(
    00163             const String& name, ResourceBackgroundQueueListener* listener = 0);
    00164
    00173         virtual BackgroundProcessTicket initialiseAllResourceGroups(
    00174             ResourceBackgroundQueueListener* listener = 0);
    00182         virtual BackgroundProcessTicket loadResourceGroup(const String& name,
    00183             ResourceBackgroundQueueListener* listener = 0);
    00184
    00185
    00201         virtual BackgroundProcessTicket load(
    00202             const String& resType, const String& name,
    00203             const String& group, bool isManual = false,
    00204             ManualResourceLoader* loader = 0,
    00205             const NameValuePairList* loadParams = 0,
    00206             ResourceBackgroundQueueListener* listener = 0);
    00207
    00216         virtual bool isProcessComplete(BackgroundProcessTicket ticket);
    00217
    00233         static ResourceBackgroundQueue& getSingleton(void);
    00249         static ResourceBackgroundQueue* getSingletonPtr(void);
    00250
    00251
    00252     };
    00253
    00254
    00255 }
    00256
    00257 #endif
    00258

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:51 2006