Add support to reload the config (#868)

This commit is contained in:
David Markowitz
2022-12-04 14:25:58 -08:00
committed by GitHub
parent de3e53de6c
commit e8ba3357e8
11 changed files with 150 additions and 66 deletions

View File

@@ -9,7 +9,7 @@
#include "dLogger.h"
#include "dConfig.h"
void dpWorld::Initialize(unsigned int zoneID) {
void dpWorld::Initialize(unsigned int zoneID, bool generateNewNavMesh) {
phys_sp_tilecount = std::atoi(Game::config->GetValue("phys_sp_tilecount").c_str());
phys_sp_tilesize = std::atoi(Game::config->GetValue("phys_sp_tilesize").c_str());
@@ -21,13 +21,37 @@ void dpWorld::Initialize(unsigned int zoneID) {
m_Grid = new dpGrid(phys_sp_tilecount, phys_sp_tilesize);
}
m_NavMesh = new dNavMesh(zoneID);
if (generateNewNavMesh) m_NavMesh = new dNavMesh(zoneID);
Game::logger->Log("dpWorld", "Physics world initialized!");
m_ZoneID = zoneID;
}
void dpWorld::Reload() {
if (m_Grid) {
m_Grid->SetDeleteGrid(false);
auto oldGridCells = m_Grid->GetCells();
delete m_Grid;
m_Grid = nullptr;
Initialize(m_ZoneID, false);
for (auto column : oldGridCells) {
for (auto row : column) {
for (auto entity : row) {
AddEntity(entity);
}
}
}
Game::logger->Log("dpWorld", "Successfully reloaded physics world!");
} else {
Game::logger->Log("dpWorld", "No physics world to reload!");
}
}
dpWorld::~dpWorld() {
if (m_Grid) {
// Triple check this is true
m_Grid->SetDeleteGrid(true);
delete m_Grid;
m_Grid = nullptr;
}
@@ -103,14 +127,14 @@ bool dpWorld::ShouldUseSP(unsigned int zoneID) {
// Only large maps should be added as tiling likely makes little difference on small maps.
switch (zoneID) {
case 1100: // Avant Gardens
case 1200: // Nimbus Station
case 1300: // Gnarled Forest
case 1400: // Forbidden Valley
case 1800: // Crux Prime
case 1900: // Nexus Tower
case 2000: // Ninjago
return true;
case 1100: // Avant Gardens
case 1200: // Nimbus Station
case 1300: // Gnarled Forest
case 1400: // Forbidden Valley
case 1800: // Crux Prime
case 1900: // Nexus Tower
case 2000: // Ninjago
return true;
}
return false;