void EmberTerrainGroup::handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ)
{
	--sLoadingTaskNum;

	LoadRequest lreq = any_cast<LoadRequest>(res->getRequest()->getData());

	if (res->succeeded()) {
		TerrainSlot* slot = lreq.slot;
		Ogre::Terrain* terrain = slot->instance;
		if (terrain) {
			terrain->setPosition(getTerrainSlotPosition(slot->x, slot->y));

			if (mAutoUpdateLod) {
				terrain->load(-1, false);
			} else {
				terrain->load(0, true);
			}

			for (int i = -1; i <= 1; ++i) {
				for (int j = -1; j <= 1; ++j) {
					if (i != 0 || j != 0) {
						connectNeighbour(slot, i, j);
					}
				}

			}
		}
	} else {
		S_LOG_FAILURE("Failed to prepare terrain at " << lreq.slot->x << ", " << lreq.slot->y << ". Error: " << res->getMessages());
		lreq.slot->freeInstance();
	}
}
Exemple #2
0
TerrainGenerator::TerrainGenerator(Ogre::SceneManager *scene) 
  : terrains_imported_(false),
    scene_manager_(scene)
{
  /*mCamera->setPosition(Ogre::Vector3(1683, 50, 2116));
  mCamera->lookAt(Ogre::Vector3(1963, 50, 1660));
  mCamera->setNearClipDistance(0.1);
  mCamera->setFarClipDistance(50000);*/

  Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC);
  Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(7);

  Ogre::Light* light = scene_manager_->createLight("tstLight");
  light->setDiffuseColour(Ogre::ColourValue::White);
  light->setSpecularColour(Ogre::ColourValue(1, 1, 1));

  scene_manager_->setAmbientLight(Ogre::ColourValue(0.9, 0.9, 0.9));
  light->setAttenuation(100000, 1, 1, 1);
  terrain_globals_ = OGRE_NEW Ogre::TerrainGlobalOptions();

  terrain_group_ = OGRE_NEW Ogre::TerrainGroup(scene_manager_, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f);
  terrain_group_->setFilenameConvention(Ogre::String("BasicTutorial3Terrain"), Ogre::String("dat"));
  terrain_group_->setOrigin(Ogre::Vector3::ZERO);



  configureTerrainDefaults(light);

  for (long x = 0; x <= 0; ++x)
      for (long y = 0; y <= 0; ++y)
          defineTerrain(x, y);

  // sync load since we want everything in place when we start
  terrain_group_->loadAllTerrains(true);

  if (terrains_imported_)
  {
      Ogre::TerrainGroup::TerrainIterator ti = terrain_group_->getTerrainIterator();
      while(ti.hasMoreElements())
      {
          Ogre::Terrain* t = ti.getNext()->instance;
          t->setPosition(Ogre::Vector3(0, -315, 0));
          initBlendMaps(t);
      }
  }

  terrain_group_->freeTemporaryResources();
  
  scene_manager_->setSkyDome(true, "Examples/CloudySky", 5, 8);

  //Optional skybox
  //Graphics::instance()->getSceneManager()->setSkyDome(true, "Examples/CloudySky", 5, 8);
}