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

@@ -6,6 +6,7 @@
dpGrid::dpGrid(int numCells, int cellSize) {
NUM_CELLS = numCells;
CELL_SIZE = cellSize;
m_DeleteGrid = true;
//dumb method but i can't be bothered
@@ -23,6 +24,7 @@ dpGrid::dpGrid(int numCells, int cellSize) {
}
dpGrid::~dpGrid() {
if (!this->m_DeleteGrid) return;
for (auto& x : m_Cells) { //x
for (auto& y : x) { //y
for (auto en : y) {

View File

@@ -23,6 +23,15 @@ public:
void Update(float deltaTime);
/**
* Sets the delete grid parameter to value. When false, the grid will not clean up memory.
*
* @param value Whether or not to delete entities on deletion of the grid.
*/
void SetDeleteGrid(bool value) { this->m_DeleteGrid = value; };
std::vector<std::vector<std::forward_list<dpEntity*>>> GetCells() { return this->m_Cells; };
private:
void HandleEntity(dpEntity* entity, dpEntity* other);
void HandleCell(int x, int z, float deltaTime);
@@ -31,4 +40,5 @@ private:
//cells on X, cells on Y for that X, then another vector that contains the entities within that cell.
std::vector<std::vector<std::forward_list<dpEntity*>>> m_Cells;
std::map<LWOOBJID, dpEntity*> m_GargantuanObjects;
bool m_DeleteGrid = true;
};

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;

View File

@@ -19,7 +19,8 @@ class dpGrid;
class dpWorld : public Singleton<dpWorld> {
public:
void Initialize(unsigned int zoneID);
void Initialize(unsigned int zoneID, bool generateNewNavMesh = true);
void Reload();
~dpWorld();
@@ -43,4 +44,5 @@ private:
std::vector<dpEntity*> m_DynamicEntites;
dNavMesh* m_NavMesh = nullptr;
uint32_t m_ZoneID = 0;
};