00001 #ifndef _RR_VRSTERRAINLOADER_H_ 00002 #define _RR_VRSTERRAINLOADER_H_ 00003 00004 #include <vrs/container/dataiterator.h> 00005 #include <vrs/color.h> 00006 00007 #include <random_utils/ThreadSafeObject.h> 00008 00009 #include "TerrainLoader.h" 00010 00011 namespace VRS 00012 { 00013 class PolygonSet; 00014 class Translation; 00015 class Mesh; 00016 } // namespace VRS 00017 00018 struct SDL_cond; 00019 struct SDL_mutex; 00020 struct SDL_Thread; 00021 00022 00023 namespace random_racer 00024 { 00025 00026 class ControlPointContainer; 00027 class MeshBeautifier; 00028 class ODETerrainLoader; 00029 00037 class VRSTerrainLoader : public TerrainLoader, 00038 private random_utils::ThreadSafeObject 00039 { 00040 friend class ODETerrainLoader; 00041 00042 // the thread related stuff 00043 SDL_Thread* m_worker; 00044 00045 SDL_mutex* m_controlMutex; 00046 SDL_mutex* m_generateWakeMutex; 00047 SDL_mutex* m_vertexMutex; 00048 00049 SDL_cond* m_replaceWakeCond; 00050 SDL_cond* m_generateWakeCond; 00051 00052 int m_signalWhenDoneWith; 00053 bool m_workerIsWaiting; 00054 00055 bool m_terminateWorker; 00056 00060 VRS::SO<TerrainGenerator> m_generator; 00061 00065 struct TerrainPart 00066 { 00070 double x, y; 00071 00076 bool isDone; 00077 00081 std::vector<VRS::Vector> points; 00082 }; 00083 00084 TerrainPart m_terrainCache[4]; 00085 00086 VRS::SO<VRS::Translation> m_translation; 00087 VRS::SO<VRS::Mesh> m_mesh; 00088 VRS::SO<VRS::DataIterator<VRS::Vector> > m_vertexIter, m_textureIter; 00089 VRS::SO<VRS::DataIterator<VRS::Color> > m_colorIter; 00090 00091 VRS::SO<MeshBeautifier> m_beautifier; 00092 00101 static int workerWrapper(void* self); 00102 00107 int generate(); 00108 00109 public: 00120 VRSTerrainLoader( 00121 VRS::SO<VRS::SceneThing> thing, 00122 VRS::SO<ControlPointContainer> container, 00123 double boxSize, 00124 double viewSize); 00125 00129 virtual ~VRSTerrainLoader(); 00130 00138 virtual void replaceTerrain( 00139 const VRS::Vector& position, const VRS::Vector& center); 00140 00145 void beautifyMesh(); 00146 00150 VRS::SO<VRS::Mesh> mesh(); 00151 00156 VRS::Vector heightAt(double, double); 00157 00161 void terminate(); 00162 }; 00163 00164 } // namespace random_racer 00165 00166 00167 #endif // _RR_VRSTERRAINLOADER_H_
1.5.1