From 8e2914813740edff09f39e2c42281b1df7b0e245 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sun, 4 Feb 2024 16:39:00 -0800 Subject: [PATCH] actually use clamped value --- dPhysics/dpGrid.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dPhysics/dpGrid.cpp b/dPhysics/dpGrid.cpp index f498c491..6e38be92 100644 --- a/dPhysics/dpGrid.cpp +++ b/dPhysics/dpGrid.cpp @@ -30,8 +30,8 @@ void dpGrid::Add(dpEntity* entity) { int cellZ = (int)std::round(entity->m_Position.z) / dpGrid::CELL_SIZE + NUM_CELLS / 2; // Clamp values to the range [0, NUM_CELLS - 1] - std::clamp(cellX, 0, NUM_CELLS - 1); - std::clamp(cellZ, 0, NUM_CELLS - 1); + cellX = std::clamp(cellX, 0, NUM_CELLS - 1); + cellZ = std::clamp(cellZ, 0, NUM_CELLS - 1); //Add to cell: m_Cells[cellX][cellZ].push_back(entity); @@ -49,11 +49,11 @@ void dpGrid::Move(dpEntity* entity, float x, float z) { int cellZ = (int)std::round(z) / dpGrid::CELL_SIZE + NUM_CELLS / 2; // Clamp values to the range [0, NUM_CELLS - 1] - std::clamp(cellX, 0, NUM_CELLS - 1); - std::clamp(cellZ, 0, NUM_CELLS - 1); + cellX = std::clamp(cellX, 0, NUM_CELLS - 1); + cellZ = std::clamp(cellZ, 0, NUM_CELLS - 1); - std::clamp(oldCellX, 0, NUM_CELLS - 1); - std::clamp(oldCellZ, 0, NUM_CELLS - 1); + oldCellX = std::clamp(oldCellX, 0, NUM_CELLS - 1); + oldCellZ = std::clamp(oldCellZ, 0, NUM_CELLS - 1); if (oldCellX == cellX && oldCellZ == cellZ) return; @@ -77,8 +77,8 @@ void dpGrid::Delete(dpEntity* entity) { int oldCellZ = (int)std::round(entity->m_Position.z) / dpGrid::CELL_SIZE + NUM_CELLS / 2; // Clamp values to the range [0, NUM_CELLS - 1] - std::clamp(oldCellX, 0, NUM_CELLS - 1); - std::clamp(oldCellZ, 0, NUM_CELLS - 1); + cellX = std::clamp(oldCellX, 0, NUM_CELLS - 1); + cellZ = std::clamp(oldCellZ, 0, NUM_CELLS - 1); auto& cell = m_Cells[oldCellX][oldCellZ]; auto toRemove = std::find(cell.begin(), cell.end(), entity);