nresourceserver.h
Go to the documentation of this file.00001 #ifndef N_RESOURCESERVER_H 00002 #define N_RESOURCESERVER_H 00003 //------------------------------------------------------------------------------ 00015 #include "kernel/nroot.h" 00016 #include "resource/nresource.h" 00017 #include "kernel/nref.h" 00018 00019 //------------------------------------------------------------------------------ 00020 class nResourceServer : public nRoot 00021 { 00022 public: 00024 nResourceServer(); 00026 virtual ~nResourceServer(); 00028 static nResourceServer* Instance(); 00030 virtual nResource* FindResource(const nString& rsrcName, nResource::Type rsrcType); 00032 virtual nResource* NewResource(const nString& className, const nString& rsrcName, nResource::Type rsrcType); 00034 virtual void UnloadResources(int resTypeMask); 00036 virtual bool LoadResources(int resTypeMask); 00038 virtual void OnLost(int resTypeMask); 00040 virtual void OnRestored(int resTypeMask); 00042 nRoot* GetResourcePool(nResource::Type rsrcType); 00044 nString GetResourceId(const nString& rsrcName); 00046 int GetNumResources(nResource::Type rsrcType); 00048 int GetResourceByteSize(nResource::Type rsrcType); 00049 00050 protected: 00051 friend class nResource; 00052 static nResourceServer* Singleton; 00053 00055 void AddLoaderJob(nResource* res); 00057 void RemLoaderJob(nResource* res); 00059 void StartLoaderThread(); 00061 void ShutdownLoaderThread(); 00063 static int N_THREADPROC LoaderThreadFunc(nThread* thread); 00065 static void ThreadWakeupFunc(nThread* thread); 00066 00067 int uniqueId; 00068 nRef<nRoot> meshPool; 00069 nRef<nRoot> texPool; 00070 nRef<nRoot> shdPool; 00071 nRef<nRoot> animPool; 00072 nRef<nRoot> sndResPool; 00073 nRef<nRoot> sndInstPool; 00074 nRef<nRoot> fontPool; 00075 nRef<nRoot> bundlePool; 00076 nRef<nRoot> dbPool; 00077 nRef<nRoot> otherPool; 00078 00079 nThreadSafeList jobList; // list for outstanding background loader jobs 00080 nThread* loaderThread; // background thread for handling async resource loading 00081 00082 nClass* resourceClass; 00083 }; 00084 00085 //------------------------------------------------------------------------------ 00088 inline 00089 nResourceServer* 00090 nResourceServer::Instance() 00091 { 00092 n_assert(0 != Singleton); 00093 return Singleton; 00094 } 00095 00096 //------------------------------------------------------------------------------ 00097 #endif