imap/loader.h
Go to the documentation of this file.00001 /* 00002 The Crystal Space geometry loader interface 00003 Copyright (C) 2000 by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_IMAP_PARSER_H__ 00021 #define __CS_IMAP_PARSER_H__ 00022 00029 #include "csutil/refarr.h" 00030 #include "csutil/refcount.h" 00031 #include "csutil/scf_interface.h" 00032 #include "csutil/threading/condition.h" 00033 00034 #include "igraphic/image.h" 00035 #include "ivideo/txtmgr.h" 00036 #include "imap/streamsource.h" 00037 #include "iutil/job.h" 00038 #include "iutil/threadmanager.h" 00039 00040 #include "csutil/deprecated_warn_off.h" 00041 00042 struct iCameraPosition; 00043 struct iCollection; 00044 struct iDocumentNode; 00045 struct iImage; 00046 struct iLight; 00047 struct iMaterialWrapper; 00048 struct iMeshWrapper; 00049 struct iMeshFactoryWrapper; 00050 struct iLightFactory; 00051 struct iSector; 00052 struct iShader; 00053 struct iTextureHandle; 00054 struct iTextureManager; 00055 struct iTextureWrapper; 00056 struct iSharedVariable; 00057 struct iSndSysData; 00058 struct iSndSysWrapper; 00059 struct iSndSysStream; 00060 00061 // The keep type flags for collections. 00062 #define KEEP_ALL 0 00063 #define KEEP_USED 1 00064 00070 struct iMissingLoaderData : public virtual iBase 00071 { 00072 SCF_INTERFACE (iMissingLoaderData, 1, 0, 0); 00073 00080 virtual iMaterialWrapper* MissingMaterial (const char* name, 00081 const char* filename) = 0; 00082 00089 virtual iTextureWrapper* MissingTexture (const char* name, 00090 const char* filename) = 0; 00091 00098 virtual iShader* MissingShader (const char* name) = 0; 00099 00106 virtual iLightFactory* MissingLightFactory (const char* name) = 0; 00107 00114 virtual iMeshFactoryWrapper* MissingFactory (const char* name) = 0; 00115 00122 virtual iMeshWrapper* MissingMesh (const char* name) = 0; 00123 00130 virtual iSector* MissingSector (const char* name) = 0; 00131 00138 virtual iLight* MissingLight (const char* name) = 0; 00139 }; 00140 00144 struct csLoadResult 00145 { 00147 bool success; 00148 00162 csRef<iBase> result; 00163 }; 00164 00168 class csLoaderReturn : public scfImplementation1<csLoaderReturn, iThreadReturn> 00169 { 00170 public: 00171 csLoaderReturn(iThreadManager* tm) : scfImplementationType(this), 00172 finished(false), success(false), waitLock(0), wait(0), tm(tm) 00173 { 00174 } 00175 00176 virtual ~csLoaderReturn() 00177 { 00178 } 00179 00180 bool IsFinished() 00181 { 00182 CS::Threading::MutexScopedLock lock(updateLock); 00183 return finished; 00184 } 00185 00186 bool WasSuccessful() 00187 { 00188 CS::Threading::MutexScopedLock lock(updateLock); 00189 return success; 00190 } 00191 00192 void* GetResultPtr() 00193 { CS_ASSERT_MSG("csLoaderReturn does not implement a void* result", false); return NULL; } 00194 00195 csRef<iBase> GetResultRefPtr() { return result; } 00196 00197 void MarkFinished() 00198 { 00199 if(waitLock) 00200 waitLock->Lock(); 00201 00202 { 00203 CS::Threading::MutexScopedLock ulock(updateLock); 00204 00205 finished = true; 00206 if(wait) 00207 { 00208 wait->NotifyAll(); 00209 } 00210 } 00211 00212 if(waitLock) 00213 waitLock->Unlock(); 00214 } 00215 00216 void MarkSuccessful() 00217 { 00218 CS::Threading::MutexScopedLock lock(updateLock); 00219 success = true; 00220 } 00221 00222 void SetResult(void* result) 00223 { CS_ASSERT_MSG("csLoaderReturn does not implement a void* result", false); } 00224 00225 void SetResult(csRef<iBase> result) { this->result = result; } 00226 00227 void Copy(iThreadReturn* other) 00228 { 00229 result = other->GetResultRefPtr(); 00230 } 00231 00232 void Wait(bool process = true) 00233 { 00234 if(tm.IsValid()) 00235 { 00236 csRefArray<iThreadReturn> rets; 00237 rets.Push(this); 00238 tm->Wait(rets, process); 00239 } 00240 } 00241 00242 void SetWaitPtrs(CS::Threading::Condition* c, CS::Threading::Mutex* m) 00243 { 00244 CS::Threading::MutexScopedLock lock(updateLock); 00245 wait = c; 00246 waitLock = m; 00247 } 00248 00249 void SetJob(iJob* j) 00250 { 00251 job = j; 00252 } 00253 00254 iJob* GetJob() const 00255 { 00256 return job; 00257 } 00258 00259 private: 00261 bool finished; 00262 00264 bool success; 00265 00267 CS::Threading::Mutex* waitLock; 00268 CS::Threading::Condition* wait; 00269 CS::Threading::Mutex updateLock; 00270 00284 csRef<iBase> result; 00285 00286 // Reference to the thread manager. 00287 csRef<iThreadManager> tm; 00288 00289 // Pointer to the thread job. 00290 csRef<iJob> job; 00291 }; 00292 00293 struct iSectorLoaderIterator : public virtual iBase 00294 { 00295 SCF_INTERFACE (iSectorLoaderIterator, 1, 0, 0); 00296 00297 virtual iSector* Next() = 0; 00298 00299 virtual bool HasNext() const = 0; 00300 }; 00301 00302 struct iLightFactLoaderIterator : public virtual iBase 00303 { 00304 SCF_INTERFACE (iLightFactLoaderIterator, 1, 0, 0); 00305 00306 virtual iLightFactory* Next() = 0; 00307 00308 virtual bool HasNext() const = 0; 00309 }; 00310 00311 struct iMeshFactLoaderIterator : public virtual iBase 00312 { 00313 SCF_INTERFACE (iMeshFactLoaderIterator, 1, 0, 0); 00314 00315 virtual iMeshFactoryWrapper* Next() = 0; 00316 00317 virtual bool HasNext() const = 0; 00318 }; 00319 00320 struct iMeshLoaderIterator : public virtual iBase 00321 { 00322 SCF_INTERFACE (iMeshLoaderIterator, 1, 0, 0); 00323 00324 virtual iMeshWrapper* Next() = 0; 00325 00326 virtual bool HasNext() const = 0; 00327 }; 00328 00329 struct iCamposLoaderIterator : public virtual iBase 00330 { 00331 SCF_INTERFACE (iCamposLoaderIterator, 1, 0, 0); 00332 00333 virtual iCameraPosition* Next() = 0; 00334 00335 virtual bool HasNext() const = 0; 00336 }; 00337 00338 struct iTextureLoaderIterator : public virtual iBase 00339 { 00340 SCF_INTERFACE (iTextureLoaderIterator, 1, 0, 0); 00341 00342 virtual iTextureWrapper* Next() = 0; 00343 00344 virtual bool HasNext() const = 0; 00345 }; 00346 00347 struct iMaterialLoaderIterator : public virtual iBase 00348 { 00349 SCF_INTERFACE (iMaterialLoaderIterator, 1, 0, 0); 00350 00351 virtual iMaterialWrapper* Next() = 0; 00352 00353 virtual bool HasNext() const = 0; 00354 }; 00355 00356 struct iSharedVarLoaderIterator : public virtual iBase 00357 { 00358 SCF_INTERFACE (iSharedVarLoaderIterator, 1, 0, 0); 00359 00360 virtual iSharedVariable* Next() = 0; 00361 00362 virtual bool HasNext() const = 0; 00363 }; 00364 00368 #define CS_LOADER_NONE 0 00369 #define CS_LOADER_CREATE_DUMMY_MATS 1 00370 00374 struct iThreadedLoader : public virtual iBase 00375 { 00376 SCF_INTERFACE (iThreadedLoader, 2, 3, 1); 00377 00381 virtual csPtr<iSectorLoaderIterator> GetLoaderSectors() = 0; 00382 00386 virtual csPtr<iLightFactLoaderIterator> GetLoaderLightFactories() = 0; 00387 00391 virtual csPtr<iMeshFactLoaderIterator> GetLoaderMeshFactories() = 0; 00392 00396 virtual csPtr<iMeshLoaderIterator> GetLoaderMeshes() = 0; 00397 00401 virtual csPtr<iCamposLoaderIterator> GetLoaderCameraPositions() = 0; 00402 00406 virtual csPtr<iTextureLoaderIterator> GetLoaderTextures() = 0; 00407 00411 virtual csPtr<iMaterialLoaderIterator> GetLoaderMaterials() = 0; 00412 00416 virtual csPtr<iSharedVarLoaderIterator> GetLoaderSharedVariables() = 0; 00417 00427 THREADED_INTERFACE4(LoadImage, const char* cwd, const char* Filename, int Format = CS_IMGFMT_INVALID, 00428 bool do_verbose = false); 00429 00437 THREADED_INTERFACE4(LoadImage, const char* cwd, csRef<iDataBuffer> buf, int Format = CS_IMGFMT_INVALID, 00438 bool do_verbose = false); 00439 00453 THREADED_INTERFACE6(LoadTexture, const char* cwd, const char* Filename, int Flags = CS_TEXTURE_3D, 00454 csRef<iTextureManager> tm = 0, csRef<iImage>* image = 0, bool do_verbose = false); 00455 00469 THREADED_INTERFACE6(LoadTexture, const char* cwd, csRef<iDataBuffer> buf, int Flags = CS_TEXTURE_3D, 00470 csRef<iTextureManager> texman = 0, csRef<iImage>* image = 0, bool do_verbose = false); 00471 00495 THREADED_INTERFACE9(LoadTexture, const char* cwd, const char *Name, csRef<iDataBuffer> buf, 00496 int Flags = CS_TEXTURE_3D, csRef<iTextureManager> texman = 0, bool reg = true, 00497 bool create_material = true, bool free_image = true, bool do_verbose = false); 00498 00500 00525 THREADED_INTERFACE11(LoadTexture, const char* cwd, const char *Name, const char *FileName, 00526 int Flags = CS_TEXTURE_3D, csRef<iTextureManager> texman = 0, bool reg = true, 00527 bool create_material = true, bool free_image = true, csRef<iCollection> Collection = 0, 00528 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00530 00532 THREADED_INTERFACE3(LoadSoundSysData, const char* cwd, const char *fname, 00533 bool do_verbose = false); 00534 00541 THREADED_INTERFACE4(LoadSoundStream, const char* cwd, const char *fname, int mode3d, 00542 bool do_verbose = false); 00543 00550 THREADED_INTERFACE4(LoadSoundWrapper, const char* cwd, const char *name, const char *fname, 00551 bool do_verbose = false); 00552 00553 00559 THREADED_INTERFACE4(LoadLightFactory, const char* cwd, const char* fname, csRef<iStreamSource> ssource = 0, 00560 bool do_verbose = false); 00561 00567 THREADED_INTERFACE4(LoadMeshObjectFactory, const char* cwd, const char* fname, csRef<iStreamSource> ssource = 0, 00568 bool do_verbose = false); 00569 00576 THREADED_INTERFACE4(LoadMeshObject, const char* cwd, const char* fname, csRef<iStreamSource> ssource = 0, 00577 bool do_verbose = false); 00578 00579 00583 THREADED_INTERFACE4(LoadShader, const char* cwd, const char* filename, bool registerShader = true, 00584 bool do_verbose = false); 00585 00587 00624 THREADED_INTERFACE8(LoadMapFile, const char* cwd, const char* filename, bool clearEngine = true, 00625 csRef<iCollection> collection = 0, csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, 00626 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00628 00630 00666 THREADED_INTERFACE8(LoadMap, const char* cwd, csRef<iDocumentNode> world_node, bool clearEngine = true, 00667 csRef<iCollection> collection = 0, csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, 00668 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00670 00672 00694 THREADED_INTERFACE7(LoadLibraryFile, const char* cwd, const char* filename, csRef<iCollection> collection = 0, 00695 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00696 bool do_verbose = false); 00698 00700 00722 THREADED_INTERFACE7(LoadLibrary, const char* cwd, csRef<iDocumentNode> lib_node, csRef<iCollection> collection = 0, 00723 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00724 bool do_verbose = false); 00725 //@) 00726 00728 00771 THREADED_INTERFACE7(LoadFile, const char* cwd, const char* fname, csRef<iCollection> collection = 0, 00772 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00773 bool do_verbose = false); 00775 00777 00820 THREADED_INTERFACE7(LoadBuffer, const char* cwd, csRef<iDataBuffer> buffer, csRef<iCollection> collection = 0, 00821 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00822 bool do_verbose = false); 00824 00826 00867 THREADED_INTERFACE8(LoadNode, const char* cwd, csRef<iDocumentNode> node, csRef<iCollection> collection = 0, 00868 csRef<iSector> sector = 0, csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, 00869 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00871 00873 virtual void AddSectorToList(iSector* obj) = 0; 00874 virtual void AddMeshFactToList(iMeshFactoryWrapper* obj) = 0; 00875 virtual void AddLightFactToList(iLightFactory* obj) = 0; 00876 virtual void AddMeshToList(iMeshWrapper* obj) = 0; 00877 virtual void AddCamposToList(iCameraPosition* obj) = 0; 00878 virtual void AddTextureToList(iTextureWrapper* obj) = 0; 00879 virtual void AddMaterialToList(iMaterialWrapper* obj) = 0; 00880 virtual void AddSharedVarToList(iSharedVariable* obj) = 0; 00881 00882 virtual void MarkSyncDone() = 0; 00883 00884 // Get/Set loader flags. 00885 virtual const int& GetFlags () const = 0; 00886 virtual void SetFlags (int flags) = 0; 00887 }; 00888 00892 struct iLoader : public virtual iBase 00893 { 00894 SCF_INTERFACE (iLoader, 5, 0, 0); 00895 00897 00904 virtual csPtr<iImage> LoadImage (const char* Filename, 00905 int Format = CS_IMGFMT_INVALID) = 0; 00918 virtual csPtr<iTextureHandle> LoadTexture (const char* Filename, 00919 int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 00920 csRef<iImage>* image=0) = 0; 00921 00923 virtual csPtr<iSndSysData> LoadSoundSysData (const char *fname) = 0; 00924 00931 virtual csPtr<iSndSysStream> LoadSoundStream (const char *fname, 00932 int mode3d) = 0; 00933 00940 virtual iSndSysWrapper* LoadSoundWrapper (const char *name, 00941 const char *fname) = 0; 00942 00950 virtual csPtr<iImage> LoadImage (iDataBuffer* buf, 00951 int Format = CS_IMGFMT_INVALID) = 0; 00965 virtual csPtr<iTextureHandle> LoadTexture (iDataBuffer* buf, 00966 int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 00967 csRef<iImage>* image=0) = 0; 00991 virtual iTextureWrapper* LoadTexture (const char *Name, 00992 iDataBuffer* buf, 00993 int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 00994 bool reg = true, bool create_material = true, 00995 bool free_image = true) = 0; 00996 01002 virtual csPtr<iLightFactory> LoadLightFactory ( 01003 const char* fname, iStreamSource* ssource = 0) = 0; 01004 01010 virtual csPtr<iMeshFactoryWrapper> LoadMeshObjectFactory ( 01011 const char* fname, iStreamSource* ssource = 0) = 0; 01018 virtual csPtr<iMeshWrapper> LoadMeshObject (const char* fname, 01019 iStreamSource* ssource = 0) = 0; 01020 01024 virtual csRef<iShader> LoadShader (const char* filename, bool registerShader = true) = 0; 01025 01027 01052 virtual iTextureWrapper* LoadTexture (const char *Name, 01053 const char *FileName, int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 01054 bool reg = true, bool create_material = true, bool free_image = true, 01055 iCollection* Collection = 0, uint keepFlags = KEEP_ALL) = 0; 01057 01059 01096 virtual bool LoadMapFile (const char* filename, bool clearEngine = true, 01097 iCollection* collection = 0, bool curRegOnly = true, 01098 bool checkDupes = false, iStreamSource* ssource = 0, 01099 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01101 01103 01139 virtual bool LoadMap (iDocumentNode* world_node, bool clearEngine = true, 01140 iCollection* collection = 0, bool curRegOnly = true, 01141 bool checkDupes = false, iStreamSource* ssource = 0, 01142 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01144 01146 01168 virtual bool LoadLibraryFile (const char* filename, iCollection* collection = 0, 01169 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01170 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01172 01174 01196 virtual bool LoadLibrary (iDocumentNode* lib_node, iCollection* collection = 0, 01197 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01198 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01199 //@) 01200 01202 01248 virtual csLoadResult Load (const char* fname, iCollection* collection = 0, 01249 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01250 const char* override_name = 0, iMissingLoaderData* missingdata = 0, 01251 uint keepFlags = KEEP_ALL) = 0; 01253 01255 01301 virtual csLoadResult Load (iDataBuffer* buffer, iCollection* collection = 0, 01302 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01303 const char* override_name = 0, iMissingLoaderData* missingdata = 0, 01304 uint keepFlags = KEEP_ALL) = 0; 01306 01308 01353 virtual csLoadResult Load (iDocumentNode* node, iCollection* collection = 0, 01354 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01355 const char* override_name = 0, iMissingLoaderData* missingdata = 0, 01356 uint keepFlags = KEEP_ALL) = 0; 01358 }; 01359 01362 #include "csutil/deprecated_warn_on.h" 01363 01364 #endif // __CS_IMAP_PARSER_H__ 01365
Generated for Crystal Space 2.1 by doxygen 1.6.1
