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 iSector; 00051 struct iShader; 00052 struct iTextureHandle; 00053 struct iTextureManager; 00054 struct iTextureWrapper; 00055 struct iSharedVariable; 00056 struct iSndSysData; 00057 struct iSndSysWrapper; 00058 struct iSndSysStream; 00059 00060 // The keep type flags for collections. 00061 #define KEEP_ALL 0 00062 #define KEEP_USED 1 00063 00069 struct iMissingLoaderData : public virtual iBase 00070 { 00071 SCF_INTERFACE (iMissingLoaderData, 1, 0, 0); 00072 00079 virtual iMaterialWrapper* MissingMaterial (const char* name, 00080 const char* filename) = 0; 00081 00088 virtual iTextureWrapper* MissingTexture (const char* name, 00089 const char* filename) = 0; 00090 00097 virtual iShader* MissingShader (const char* name) = 0; 00098 00105 virtual iMeshFactoryWrapper* MissingFactory (const char* name) = 0; 00106 00113 virtual iMeshWrapper* MissingMesh (const char* name) = 0; 00114 00121 virtual iSector* MissingSector (const char* name) = 0; 00122 00129 virtual iLight* MissingLight (const char* name) = 0; 00130 }; 00131 00135 struct csLoadResult 00136 { 00138 bool success; 00139 00153 csRef<iBase> result; 00154 }; 00155 00159 class csLoaderReturn : public scfImplementation1<csLoaderReturn, iThreadReturn> 00160 { 00161 public: 00162 csLoaderReturn(iThreadManager* tm) : scfImplementationType(this), 00163 finished(false), success(false), waitLock(0), wait(0), tm(tm) 00164 { 00165 } 00166 00167 virtual ~csLoaderReturn() 00168 { 00169 } 00170 00171 bool IsFinished() 00172 { 00173 CS::Threading::MutexScopedLock lock(updateLock); 00174 return finished; 00175 } 00176 00177 bool WasSuccessful() 00178 { 00179 CS::Threading::MutexScopedLock lock(updateLock); 00180 return success; 00181 } 00182 00183 void* GetResultPtr() 00184 { CS_ASSERT_MSG("csLoaderReturn does not implement a void* result", false); return NULL; } 00185 00186 csRef<iBase> GetResultRefPtr() { return result; } 00187 00188 void MarkFinished() 00189 { 00190 if(waitLock) 00191 waitLock->Lock(); 00192 00193 { 00194 CS::Threading::MutexScopedLock ulock(updateLock); 00195 00196 finished = true; 00197 if(wait) 00198 { 00199 wait->NotifyAll(); 00200 } 00201 } 00202 00203 if(waitLock) 00204 waitLock->Unlock(); 00205 } 00206 00207 void MarkSuccessful() 00208 { 00209 CS::Threading::MutexScopedLock lock(updateLock); 00210 success = true; 00211 } 00212 00213 void SetResult(void* result) 00214 { CS_ASSERT_MSG("csLoaderReturn does not implement a void* result", false); } 00215 00216 void SetResult(csRef<iBase> result) { this->result = result; } 00217 00218 void Copy(iThreadReturn* other) 00219 { 00220 result = other->GetResultRefPtr(); 00221 } 00222 00223 void Wait(bool process = true) 00224 { 00225 if(tm.IsValid()) 00226 { 00227 csRefArray<iThreadReturn> rets; 00228 rets.Push(this); 00229 tm->Wait(rets, process); 00230 } 00231 } 00232 00233 void SetWaitPtrs(CS::Threading::Condition* c, CS::Threading::Mutex* m) 00234 { 00235 CS::Threading::MutexScopedLock lock(updateLock); 00236 wait = c; 00237 waitLock = m; 00238 } 00239 00240 void SetJob(iJob* j) 00241 { 00242 job = j; 00243 } 00244 00245 iJob* GetJob() const 00246 { 00247 return job; 00248 } 00249 00250 private: 00252 bool finished; 00253 00255 bool success; 00256 00258 CS::Threading::Mutex* waitLock; 00259 CS::Threading::Condition* wait; 00260 CS::Threading::Mutex updateLock; 00261 00275 csRef<iBase> result; 00276 00277 // Reference to the thread manager. 00278 csRef<iThreadManager> tm; 00279 00280 // Pointer to the thread job. 00281 csRef<iJob> job; 00282 }; 00283 00284 struct iSectorLoaderIterator : public virtual iBase 00285 { 00286 SCF_INTERFACE (iSectorLoaderIterator, 1, 0, 0); 00287 00288 virtual iSector* Next() = 0; 00289 00290 virtual bool HasNext() const = 0; 00291 }; 00292 00293 struct iMeshFactLoaderIterator : public virtual iBase 00294 { 00295 SCF_INTERFACE (iMeshFactLoaderIterator, 1, 0, 0); 00296 00297 virtual iMeshFactoryWrapper* Next() = 0; 00298 00299 virtual bool HasNext() const = 0; 00300 }; 00301 00302 struct iMeshLoaderIterator : public virtual iBase 00303 { 00304 SCF_INTERFACE (iMeshLoaderIterator, 1, 0, 0); 00305 00306 virtual iMeshWrapper* Next() = 0; 00307 00308 virtual bool HasNext() const = 0; 00309 }; 00310 00311 struct iCamposLoaderIterator : public virtual iBase 00312 { 00313 SCF_INTERFACE (iCamposLoaderIterator, 1, 0, 0); 00314 00315 virtual iCameraPosition* Next() = 0; 00316 00317 virtual bool HasNext() const = 0; 00318 }; 00319 00320 struct iTextureLoaderIterator : public virtual iBase 00321 { 00322 SCF_INTERFACE (iTextureLoaderIterator, 1, 0, 0); 00323 00324 virtual iTextureWrapper* Next() = 0; 00325 00326 virtual bool HasNext() const = 0; 00327 }; 00328 00329 struct iMaterialLoaderIterator : public virtual iBase 00330 { 00331 SCF_INTERFACE (iMaterialLoaderIterator, 1, 0, 0); 00332 00333 virtual iMaterialWrapper* Next() = 0; 00334 00335 virtual bool HasNext() const = 0; 00336 }; 00337 00338 struct iSharedVarLoaderIterator : public virtual iBase 00339 { 00340 SCF_INTERFACE (iSharedVarLoaderIterator, 1, 0, 0); 00341 00342 virtual iSharedVariable* Next() = 0; 00343 00344 virtual bool HasNext() const = 0; 00345 }; 00346 00350 #define CS_LOADER_NONE 0 00351 #define CS_LOADER_CREATE_DUMMY_MATS 1 00352 00356 struct iThreadedLoader : public virtual iBase 00357 { 00358 SCF_INTERFACE (iThreadedLoader, 2, 3, 0); 00359 00363 virtual csPtr<iSectorLoaderIterator> GetLoaderSectors() = 0; 00364 00368 virtual csPtr<iMeshFactLoaderIterator> GetLoaderMeshFactories() = 0; 00369 00373 virtual csPtr<iMeshLoaderIterator> GetLoaderMeshes() = 0; 00374 00378 virtual csPtr<iCamposLoaderIterator> GetLoaderCameraPositions() = 0; 00379 00383 virtual csPtr<iTextureLoaderIterator> GetLoaderTextures() = 0; 00384 00388 virtual csPtr<iMaterialLoaderIterator> GetLoaderMaterials() = 0; 00389 00393 virtual csPtr<iSharedVarLoaderIterator> GetLoaderSharedVariables() = 0; 00394 00404 THREADED_INTERFACE4(LoadImage, const char* cwd, const char* Filename, int Format = CS_IMGFMT_INVALID, 00405 bool do_verbose = false); 00406 00414 THREADED_INTERFACE4(LoadImage, const char* cwd, csRef<iDataBuffer> buf, int Format = CS_IMGFMT_INVALID, 00415 bool do_verbose = false); 00416 00430 THREADED_INTERFACE6(LoadTexture, const char* cwd, const char* Filename, int Flags = CS_TEXTURE_3D, 00431 csRef<iTextureManager> tm = 0, csRef<iImage>* image = 0, bool do_verbose = false); 00432 00446 THREADED_INTERFACE6(LoadTexture, const char* cwd, csRef<iDataBuffer> buf, int Flags = CS_TEXTURE_3D, 00447 csRef<iTextureManager> texman = 0, csRef<iImage>* image = 0, bool do_verbose = false); 00448 00472 THREADED_INTERFACE9(LoadTexture, const char* cwd, const char *Name, csRef<iDataBuffer> buf, 00473 int Flags = CS_TEXTURE_3D, csRef<iTextureManager> texman = 0, bool reg = true, 00474 bool create_material = true, bool free_image = true, bool do_verbose = false); 00475 00477 00502 THREADED_INTERFACE11(LoadTexture, const char* cwd, const char *Name, const char *FileName, 00503 int Flags = CS_TEXTURE_3D, csRef<iTextureManager> texman = 0, bool reg = true, 00504 bool create_material = true, bool free_image = true, csRef<iCollection> Collection = 0, 00505 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00507 00509 THREADED_INTERFACE3(LoadSoundSysData, const char* cwd, const char *fname, 00510 bool do_verbose = false); 00511 00518 THREADED_INTERFACE4(LoadSoundStream, const char* cwd, const char *fname, int mode3d, 00519 bool do_verbose = false); 00520 00527 THREADED_INTERFACE4(LoadSoundWrapper, const char* cwd, const char *name, const char *fname, 00528 bool do_verbose = false); 00529 00530 00536 THREADED_INTERFACE4(LoadMeshObjectFactory, const char* cwd, const char* fname, csRef<iStreamSource> ssource = 0, 00537 bool do_verbose = false); 00538 00545 THREADED_INTERFACE4(LoadMeshObject, const char* cwd, const char* fname, csRef<iStreamSource> ssource = 0, 00546 bool do_verbose = false); 00547 00548 00552 THREADED_INTERFACE4(LoadShader, const char* cwd, const char* filename, bool registerShader = true, 00553 bool do_verbose = false); 00554 00556 00593 THREADED_INTERFACE8(LoadMapFile, const char* cwd, const char* filename, bool clearEngine = true, 00594 csRef<iCollection> collection = 0, csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, 00595 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00597 00599 00635 THREADED_INTERFACE8(LoadMap, const char* cwd, csRef<iDocumentNode> world_node, bool clearEngine = true, 00636 csRef<iCollection> collection = 0, csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, 00637 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00639 00641 00663 THREADED_INTERFACE7(LoadLibraryFile, const char* cwd, const char* filename, csRef<iCollection> collection = 0, 00664 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00665 bool do_verbose = false); 00667 00669 00691 THREADED_INTERFACE7(LoadLibrary, const char* cwd, csRef<iDocumentNode> lib_node, csRef<iCollection> collection = 0, 00692 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00693 bool do_verbose = false); 00694 //@) 00695 00697 00740 THREADED_INTERFACE7(LoadFile, const char* cwd, const char* fname, csRef<iCollection> collection = 0, 00741 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00742 bool do_verbose = false); 00744 00746 00789 THREADED_INTERFACE7(LoadBuffer, const char* cwd, csRef<iDataBuffer> buffer, csRef<iCollection> collection = 0, 00790 csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, uint keepFlags = KEEP_ALL, 00791 bool do_verbose = false); 00793 00795 00836 THREADED_INTERFACE8(LoadNode, const char* cwd, csRef<iDocumentNode> node, csRef<iCollection> collection = 0, 00837 csRef<iSector> sector = 0, csRef<iStreamSource> ssource = 0, csRef<iMissingLoaderData> missingdata = 0, 00838 uint keepFlags = KEEP_ALL, bool do_verbose = false); 00840 00842 virtual void AddSectorToList(iSector* obj) = 0; 00843 virtual void AddMeshFactToList(iMeshFactoryWrapper* obj) = 0; 00844 virtual void AddMeshToList(iMeshWrapper* obj) = 0; 00845 virtual void AddCamposToList(iCameraPosition* obj) = 0; 00846 virtual void AddTextureToList(iTextureWrapper* obj) = 0; 00847 virtual void AddMaterialToList(iMaterialWrapper* obj) = 0; 00848 virtual void AddSharedVarToList(iSharedVariable* obj) = 0; 00849 00850 virtual void MarkSyncDone() = 0; 00851 00852 // Get/Set loader flags. 00853 virtual const int& GetFlags () const = 0; 00854 virtual void SetFlags (int flags) = 0; 00855 }; 00856 00860 struct iLoader : public virtual iBase 00861 { 00862 SCF_INTERFACE (iLoader, 5, 0, 0); 00863 00865 00872 virtual csPtr<iImage> LoadImage (const char* Filename, 00873 int Format = CS_IMGFMT_INVALID) = 0; 00886 virtual csPtr<iTextureHandle> LoadTexture (const char* Filename, 00887 int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 00888 csRef<iImage>* image=0) = 0; 00889 00891 virtual csPtr<iSndSysData> LoadSoundSysData (const char *fname) = 0; 00892 00899 virtual csPtr<iSndSysStream> LoadSoundStream (const char *fname, 00900 int mode3d) = 0; 00901 00908 virtual iSndSysWrapper* LoadSoundWrapper (const char *name, 00909 const char *fname) = 0; 00910 00918 virtual csPtr<iImage> LoadImage (iDataBuffer* buf, 00919 int Format = CS_IMGFMT_INVALID) = 0; 00933 virtual csPtr<iTextureHandle> LoadTexture (iDataBuffer* buf, 00934 int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 00935 csRef<iImage>* image=0) = 0; 00959 virtual iTextureWrapper* LoadTexture (const char *Name, 00960 iDataBuffer* buf, 00961 int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 00962 bool reg = true, bool create_material = true, 00963 bool free_image = true) = 0; 00964 00970 virtual csPtr<iMeshFactoryWrapper> LoadMeshObjectFactory ( 00971 const char* fname, iStreamSource* ssource = 0) = 0; 00978 virtual csPtr<iMeshWrapper> LoadMeshObject (const char* fname, 00979 iStreamSource* ssource = 0) = 0; 00980 00984 virtual csRef<iShader> LoadShader (const char* filename, bool registerShader = true) = 0; 00985 00987 01012 virtual iTextureWrapper* LoadTexture (const char *Name, 01013 const char *FileName, int Flags = CS_TEXTURE_3D, iTextureManager *tm = 0, 01014 bool reg = true, bool create_material = true, bool free_image = true, 01015 iCollection* Collection = 0, uint keepFlags = KEEP_ALL) = 0; 01017 01019 01056 virtual bool LoadMapFile (const char* filename, bool clearEngine = true, 01057 iCollection* collection = 0, bool curRegOnly = true, 01058 bool checkDupes = false, iStreamSource* ssource = 0, 01059 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01061 01063 01099 virtual bool LoadMap (iDocumentNode* world_node, bool clearEngine = true, 01100 iCollection* collection = 0, bool curRegOnly = true, 01101 bool checkDupes = false, iStreamSource* ssource = 0, 01102 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01104 01106 01128 virtual bool LoadLibraryFile (const char* filename, iCollection* collection = 0, 01129 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01130 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01132 01134 01156 virtual bool LoadLibrary (iDocumentNode* lib_node, iCollection* collection = 0, 01157 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01158 iMissingLoaderData* missingdata = 0, uint keepFlags = KEEP_ALL) = 0; 01159 //@) 01160 01162 01208 virtual csLoadResult Load (const char* fname, iCollection* collection = 0, 01209 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01210 const char* override_name = 0, iMissingLoaderData* missingdata = 0, 01211 uint keepFlags = KEEP_ALL) = 0; 01213 01215 01261 virtual csLoadResult Load (iDataBuffer* buffer, iCollection* collection = 0, 01262 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01263 const char* override_name = 0, iMissingLoaderData* missingdata = 0, 01264 uint keepFlags = KEEP_ALL) = 0; 01266 01268 01313 virtual csLoadResult Load (iDocumentNode* node, iCollection* collection = 0, 01314 bool searchCollectionOnly = true, bool checkDupes = false, iStreamSource* ssource = 0, 01315 const char* override_name = 0, iMissingLoaderData* missingdata = 0, 01316 uint keepFlags = KEEP_ALL) = 0; 01318 }; 01319 01322 #include "csutil/deprecated_warn_on.h" 01323 01324 #endif // __CS_IMAP_PARSER_H__ 01325
Generated for Crystal Space 2.0 by doxygen 1.6.1