//--------------------------------------------------------------------- WorkQueue::Response* TerrainPagedWorldSection::handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ) { if(mPagesInLoading.empty()) { mHasRunningTasks = false; req->abortRequest(); return OGRE_NEW WorkQueue::Response(req, true, Any()); } unsigned long currentTime = Root::getSingletonPtr()->getTimer()->getMilliseconds(); if(currentTime < mNextLoadingTime) { // Wait until the next page is to be loaded -> we are in background thread here OGRE_THREAD_SLEEP(mNextLoadingTime - currentTime); } PageID pageID = mPagesInLoading.front(); // call the TerrainDefiner from the background thread long x, y; // pageID is the same as a packed index mTerrainGroup->unpackIndex(pageID, &x, &y); if(!mTerrainDefiner) mTerrainDefiner = OGRE_NEW TerrainDefiner(); mTerrainDefiner->define(mTerrainGroup, x, y); // continue loading in main thread return OGRE_NEW WorkQueue::Response(req, true, Any()); }
void World::syncLoad() { while (mChunksLoading || mLayerLoadPending) { OGRE_THREAD_SLEEP(0); Ogre::Root::getSingleton().getWorkQueue()->processResponses(); } }
EmberTerrainGroup::~EmberTerrainGroup() { while (sLoadingTaskNum > 0) { S_LOG_VERBOSE("Sleeping 2 milliseconds while waiting for tasks to complete in EmberTerrainGroup destructor."); OGRE_THREAD_SLEEP(2); Root::getSingleton().getWorkQueue()->processResponses(); } }
//-------------------------------------------------------------------------- void MeshLodTests::blockedWaitForLodGeneration(const MeshPtr& mesh) { bool success = false; const int timeout = 5000; WorkQueue* wq = Root::getSingleton().getWorkQueue(); for (int i = 0; i < timeout; i++) { OGRE_THREAD_SLEEP(1); wq->processResponses(); // Injects the Lod if ready if (mesh->getNumLodLevels() != 1) { success = true; break; } } // timeout CPPUNIT_ASSERT(success); }
//--------------------------------------------------------------------- TerrainPagedWorldSection::~TerrainPagedWorldSection() { //remove the pending tasks, but keep the front one, as it may have been in running if(!mPagesInLoading.empty()) mPagesInLoading.erase( ++mPagesInLoading.begin(), mPagesInLoading.end() ); while(!mPagesInLoading.empty()) { OGRE_THREAD_SLEEP(50); Root::getSingleton().getWorkQueue()->processResponses(); } WorkQueue* wq = Root::getSingleton().getWorkQueue(); wq->removeRequestHandler(mWorkQueueChannel, this); wq->removeResponseHandler(mWorkQueueChannel, this); OGRE_DELETE mTerrainGroup; if(mTerrainDefiner) OGRE_DELETE mTerrainDefiner; }
Vector4* SnowTerrain::getTerrainNormalData() { PixelBox* terrainNormals; // load from normals file if(mSnowConfig->terrainSettings.normalsDataFile.length() > 0) { // get terrain normal data using image Ogre::Image img; img.load(mSnowConfig->terrainSettings.normalsDataFile, "General"); //img.flipAroundY(); //img.flipAroundX(); size_t size = img.getWidth(); assert(img.getWidth() == img.getHeight()); if (img.getWidth() != mTerrainSize || img.getHeight() != mTerrainSize) img.resize(mTerrainSize, mTerrainSize); terrainNormals = &img.getPixelBox(); Vector4* floats = convertNormalsToFloats(terrainNormals, true); //OGRE_FREE(terrainNormals->data, Ogre::MEMCATEGORY_GENERAL); // need to swap z and y vector due to different vertical axis in normal map and world space! for(size_t i = 0;i<mTerrainSize*mTerrainSize;i++) { Vector4 v = floats[i]; floats[i].z = v.y; floats[i].y = v.z; } return floats; } else { // need to wait until terrain is loaded while (getTerrain()->isDerivedDataUpdateInProgress()) { // we need to wait for this to finish OGRE_THREAD_SLEEP(50); Root::getSingleton().getWorkQueue()->processResponses(); } // Get terrain normal data using official method //terrainNormals = getTerrain()->calculateNormals(Ogre::Rect(0,0,mTerrainSize,mTerrainSize),Rect(0,0,mTerrainSize,mTerrainSize)); Ogre::Image img; getTerrain()->getTerrainNormalMap()->convertToImage(img); //img.flipAroundY(); img.flipAroundX(); //img.save("test_normals.bmp"); terrainNormals = &img.getPixelBox(); Vector4* floats = convertNormalsToFloats(terrainNormals, true); //OGRE_FREE(terrainNormals->data, Ogre::MEMCATEGORY_GENERAL); return floats; } }