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-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __ResourceBackgroundQueue_H__ 00029 #define __ResourceBackgroundQueue_H__ 00030 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreCommon.h" 00034 #include "OgreSingleton.h" 00035 #include "OgreResource.h" 00036 #include "OgreWorkQueue.h" 00037 #include "OgreHeaderPrefix.h" 00038 00039 namespace Ogre { 00047 00048 typedef WorkQueue::RequestID BackgroundProcessTicket; 00049 00051 struct BackgroundProcessResult 00052 { 00054 bool error; 00056 String message; 00057 00058 BackgroundProcessResult() : error(false) {} 00059 }; 00060 00061 00081 class _OgreExport ResourceBackgroundQueue : public Singleton<ResourceBackgroundQueue>, public ResourceAlloc, 00082 public WorkQueue::RequestHandler, public WorkQueue::ResponseHandler 00083 { 00084 public: 00093 class _OgreExport Listener 00094 { 00095 public: 00102 virtual void operationCompleted(BackgroundProcessTicket ticket, const BackgroundProcessResult& result) = 0; 00104 virtual ~Listener() {} 00105 00106 }; 00107 00108 protected: 00109 00110 uint16 mWorkQueueChannel; 00112 enum RequestType 00113 { 00114 RT_INITIALISE_GROUP = 0, 00115 RT_INITIALISE_ALL_GROUPS = 1, 00116 RT_PREPARE_GROUP = 2, 00117 RT_PREPARE_RESOURCE = 3, 00118 RT_LOAD_GROUP = 4, 00119 RT_LOAD_RESOURCE = 5, 00120 RT_UNLOAD_GROUP = 6, 00121 RT_UNLOAD_RESOURCE = 7 00122 }; 00124 struct ResourceRequest 00125 { 00126 RequestType type; 00127 String resourceName; 00128 ResourceHandle resourceHandle; 00129 String resourceType; 00130 String groupName; 00131 bool isManual; 00132 ManualResourceLoader* loader; 00133 NameValuePairList* loadParams; 00134 Listener* listener; 00135 BackgroundProcessResult result; 00136 00137 _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceRequest& r) 00138 { (void)r; return o; } 00139 }; 00140 00141 typedef set<BackgroundProcessTicket>::type OutstandingRequestSet; 00142 OutstandingRequestSet mOutstandingRequestSet; 00143 00145 struct ResourceResponse 00146 { 00147 ResourceResponse(ResourcePtr r, const ResourceRequest& req) 00148 : resource(r), request(req) 00149 {} 00150 00151 ResourcePtr resource; 00152 ResourceRequest request; 00153 00154 _OgreExport friend std::ostream& operator<<(std::ostream& o, const ResourceResponse& r) 00155 { (void)r; return o; } 00156 }; 00157 00158 BackgroundProcessTicket addRequest(ResourceRequest& req); 00159 00160 public: 00161 ResourceBackgroundQueue(); 00162 virtual ~ResourceBackgroundQueue(); 00163 00167 virtual void initialise(void); 00168 00172 virtual void shutdown(void); 00173 00182 virtual BackgroundProcessTicket initialiseResourceGroup( 00183 const String& name, Listener* listener = 0); 00184 00193 virtual BackgroundProcessTicket initialiseAllResourceGroups( 00194 Listener* listener = 0); 00203 virtual BackgroundProcessTicket prepareResourceGroup(const String& name, 00204 Listener* listener = 0); 00205 00214 virtual BackgroundProcessTicket loadResourceGroup(const String& name, 00215 Listener* listener = 0); 00216 00217 00224 virtual BackgroundProcessTicket unload( 00225 const String& resType, const String& name, 00226 Listener* listener = 0); 00227 00234 virtual BackgroundProcessTicket unload( 00235 const String& resType, ResourceHandle handle, 00236 Listener* listener = 0); 00237 00244 virtual BackgroundProcessTicket unloadResourceGroup(const String& name, 00245 Listener* listener = 0); 00246 00247 00263 virtual BackgroundProcessTicket prepare( 00264 const String& resType, const String& name, 00265 const String& group, bool isManual = false, 00266 ManualResourceLoader* loader = 0, 00267 const NameValuePairList* loadParams = 0, 00268 Listener* listener = 0); 00269 00285 virtual BackgroundProcessTicket load( 00286 const String& resType, const String& name, 00287 const String& group, bool isManual = false, 00288 ManualResourceLoader* loader = 0, 00289 const NameValuePairList* loadParams = 0, 00290 Listener* listener = 0); 00304 virtual bool isProcessComplete(BackgroundProcessTicket ticket); 00305 00308 void abortRequest( BackgroundProcessTicket ticket ); 00309 00311 bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ); 00313 WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ); 00315 bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ); 00317 void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ); 00318 00334 static ResourceBackgroundQueue& getSingleton(void); 00350 static ResourceBackgroundQueue* getSingletonPtr(void); 00351 00352 }; 00353 00357 } 00358 00359 #include "OgreHeaderSuffix.h" 00360 00361 #endif 00362
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45