45 #include <Terrain/OgreTerrainPaging.h>
46 #include <Terrain/OgreTerrainGroup.h>
55 , m_geometry_manager(0)
62 , m_paged_detail_factor(0.0f)
64 , m_hydrax_water(nullptr)
65 , m_cache_entry(entry)
89 if (m_sky_manager !=
nullptr)
91 delete(m_sky_manager);
92 m_sky_manager =
nullptr;
96 if (SkyX_manager !=
nullptr)
99 SkyX_manager =
nullptr;
102 if (m_main_light !=
nullptr)
105 m_main_light =
nullptr;
108 if (m_hydrax_water !=
nullptr)
113 if (m_object_manager !=
nullptr)
115 delete(m_object_manager);
116 m_object_manager =
nullptr;
119 if (m_geometry_manager !=
nullptr)
121 delete(m_geometry_manager);
122 m_geometry_manager =
nullptr;
125 if (m_shadow_manager !=
nullptr)
127 delete(m_shadow_manager);
128 m_shadow_manager =
nullptr;
131 if (m_collisions !=
nullptr)
133 delete(m_collisions);
134 m_collisions =
nullptr;
149 this->setGravity(this->m_def.gravity);
151 loading_window->SetProgress(10,
_L(
"Initializing Object Subsystem"));
154 loading_window->SetProgress(14,
_L(
"Initializing Shadow Subsystem"));
157 loading_window->SetProgress(17,
_L(
"Initializing Geometry Subsystem"));
160 loading_window->SetProgress(23,
_L(
"Initializing Camera Subsystem"));
164 loading_window->SetProgress(25,
_L(
"Initializing Sky Subsystem"));
165 this->initSkySubSystem();
167 loading_window->SetProgress(27,
_L(
"Initializing Light Subsystem"));
172 loading_window->SetProgress(29,
_L(
"Initializing Fog Subsystem"));
176 loading_window->SetProgress(31,
_L(
"Initializing Vegetation Subsystem"));
177 this->initVegetation();
179 this->fixCompositorClearColor();
181 loading_window->SetProgress(40,
_L(
"Loading Terrain Geometry"));
182 if (!this->m_geometry_manager->InitTerrain(this->m_def.ogre_ter_conf_filename))
187 loading_window->SetProgress(60,
_L(
"Initializing Collision Subsystem"));
188 this->m_collisions =
new Collisions(this->getMaxTerrainSize());
190 loading_window->SetProgress(75,
_L(
"Initializing Script Subsystem"));
191 this->initScripting();
192 this->initAiPresets();
194 loading_window->SetProgress(77,
_L(
"Initializing Water Subsystem"));
197 loading_window->SetProgress(80,
_L(
"Loading Terrain Objects"));
198 this->loadTerrainObjects();
201 this->initTerrainCollisions();
203 loading_window->SetProgress(90,
_L(
"Initializing terrain light properties"));
204 this->m_geometry_manager->UpdateMainLightPosition();
205 this->m_collisions->finishLoadingTerrain();
207 this->LoadTelepoints();
211 loading_window->SetProgress(92,
_L(
"Initializing Overview Map Subsystem"));
214 LOG(
" ===== LOADING TERRAIN ACTORS " + m_cache_entry->fname);
215 loading_window->SetProgress(95,
_L(
"Loading Terrain Actors"));
216 this->LoadPredefinedActors();
218 LOG(
" ===== TERRAIN LOADING DONE " + m_cache_entry->fname);
233 m_sight_range = 5000;
240 if (m_sight_range < UNLIMITED_SIGHTRANGE && App::gfx_sky_mode->getEnum<GfxSkyMode>() !=
GfxSkyMode::SKYX)
260 m_sky_manager =
new SkyManager();
263 if (!m_def.caelum_config.empty() && ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(m_def.caelum_config))
266 m_sky_manager->LoadCaelumScript(m_def.caelum_config, m_def.caelum_fog_start, m_def.caelum_fog_end);
271 m_sky_manager->LoadCaelumScript(
"ror_default_sky");
280 if (!m_def.skyx_config.empty() && ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(m_def.skyx_config))
287 if (!m_def.cubemap_config.empty())
305 m_main_light = m_sky_manager->GetSkyMainLight();
310 m_main_light = SkyX_manager->getMainLight();
319 m_main_light->setType(Light::LT_DIRECTIONAL);
320 m_main_light->setDirection(Ogre::Vector3(0.785, -0.423, 0.453).normalisedCopy());
322 m_main_light->setDiffuseColour(m_def.ambient_color);
323 m_main_light->setSpecularColour(m_def.ambient_color);
324 m_main_light->setCastShadows(
true);
325 m_main_light->setShadowFarDistance(1000.0f);
326 m_main_light->setShadowNearClipDistance(-1);
332 if (m_sight_range >= UNLIMITED_SIGHTRANGE)
343 m_paged_detail_factor = 0.2f;
346 m_paged_detail_factor = 0.5f;
349 m_paged_detail_factor = 1.0f;
352 m_paged_detail_factor = 0.0f;
361 if (CompositorManager::getSingleton().hasCompositorChain(
App::GetCameraManager()->GetCamera()->getViewport()))
363 CompositorInstance* co = CompositorManager::getSingleton().getCompositorChain(
App::GetCameraManager()->GetCamera()->getViewport())->_getOriginalSceneCompositor();
366 CompositionTechnique* ct = co->getTechnique();
369 CompositionTargetPass* ctp = ct->getOutputTargetPass();
372 CompositionPass* p = ctp->getPass(0);
375 p->setClearColour(Ogre::ColourValue::Black);
390 if (!m_def.has_water)
398 if (!m_def.hydrax_conf_file.empty() && ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(m_def.hydrax_conf_file))
400 m_hydrax_water =
new HydraxWater(m_def.water_height, m_def.hydrax_conf_file);
405 m_hydrax_water =
new HydraxWater(m_def.water_height);
408 m_water = std::unique_ptr<IWater>(m_hydrax_water);
411 TerrainGroup::TerrainIterator ti = m_geometry_manager->getTerrainGroup()->getTerrainIterator();
412 while (ti.hasMoreElements())
414 Ogre::Terrain* t = ti.getNext()->instance;
415 MaterialPtr ptr = t->getMaterial();
416 m_hydrax_water->GetHydrax()->getMaterialManager()->addDepthTechnique(ptr->createTechnique());
421 m_water = std::unique_ptr<IWater>(
new Water(this->getMaxTerrainSize()));
422 m_water->SetStaticWaterHeight(m_def.water_height);
423 m_water->SetWaterBottomHeight(m_def.water_bottom_height);
430 m_shadow_manager->loadConfiguration();
435 for (std::string tobj_filename : m_def.tobj_files)
437 m_object_manager->LoadTObjFile(tobj_filename);
443 if (!m_def.traction_map_file.empty())
445 m_collisions->setupLandUse(m_def.traction_map_file.c_str());
451 #ifdef USE_ANGELSCRIPT
457 for (std::string as_filename : m_def.as_files)
459 loaded |= this->getObjectManager()->LoadTerrainScript(as_filename);
470 #endif //USE_ANGELSCRIPT
483 m_cur_gravity = value;
493 return m_collisions->getCollisionAAB();
498 if (!m_geometry_manager)
499 return Vector3::ZERO;
500 return m_geometry_manager->getMaxTerrainSize();
505 return m_geometry_manager->getHeightAt(
x,
z);
510 return m_geometry_manager->getNormalAt(
x,
y,
z);
515 return m_sky_manager;
523 return m_geometry_manager->isFlat();
528 if (m_object_manager)
529 m_object_manager->LoadTelepoints();
534 if (m_object_manager)
535 m_object_manager->LoadPredefinedActors();
540 if (m_object_manager)
541 return m_object_manager->HasPredefinedActors();
547 return m_object_manager->getProceduralManager();
552 return m_cache_entry->fname;
557 return m_cache_entry->resource_group;
560 void RoR::Terrain::addSurveyMapEntity(
const std::string& type,
const std::string& filename,
const std::string& resource_group,
const std::string& caption,
const Ogre::Vector3& pos,
float angle,
int id)
562 m_object_manager->m_map_entities.push_back(
SurveyMapEntity(type, caption, filename, resource_group, pos, Ogre::Radian(angle),
id));
572 return m_object_manager->m_map_entities;