mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 17:43:52 +00:00
Add per-group spatial grid for WMO collision and reduce collision call frequency
Build a 2D triangle grid per WMO group at load time so getFloorHeight and checkWallCollision only test triangles in nearby cells instead of brute-forcing all triangles. Also reduce sweep steps (12→4), ground probes (3→1), camera floor probes (5→2), throttle isInsideWMO to every 10 frames, and early-out wall collision on first hit.
This commit is contained in:
parent
751e6fdbde
commit
974384c725
4 changed files with 179 additions and 73 deletions
|
|
@ -133,6 +133,11 @@ private:
|
|||
static constexpr float JUMP_BUFFER_TIME = 0.15f; // 150ms input buffer
|
||||
static constexpr float COYOTE_TIME = 0.10f; // 100ms grace after leaving ground
|
||||
|
||||
// Cached isInsideWMO result (throttled to avoid per-frame cost)
|
||||
bool cachedInsideWMO = false;
|
||||
int insideWMOCheckCounter = 0;
|
||||
glm::vec3 lastInsideWMOCheckPos = glm::vec3(0.0f);
|
||||
|
||||
// Swimming
|
||||
bool swimming = false;
|
||||
bool wasSwimming = false;
|
||||
|
|
|
|||
|
|
@ -270,6 +270,25 @@ private:
|
|||
// Collision geometry (positions only, for floor raycasting)
|
||||
std::vector<glm::vec3> collisionVertices;
|
||||
std::vector<uint16_t> collisionIndices;
|
||||
|
||||
// 2D spatial grid for fast triangle lookup (built at load time).
|
||||
// Bins triangles by their XY bounding box into grid cells.
|
||||
static constexpr float COLLISION_CELL_SIZE = 4.0f;
|
||||
int gridCellsX = 0;
|
||||
int gridCellsY = 0;
|
||||
glm::vec2 gridOrigin; // XY of bounding box min
|
||||
// cellTriangles[cellY * gridCellsX + cellX] = list of triangle start indices
|
||||
std::vector<std::vector<uint32_t>> cellTriangles;
|
||||
|
||||
// Build the spatial grid from collision geometry
|
||||
void buildCollisionGrid();
|
||||
|
||||
// Get triangle indices for a local-space XY point
|
||||
const std::vector<uint32_t>* getTrianglesAtLocal(float localX, float localY) const;
|
||||
|
||||
// Get triangle indices for a local-space XY range (for wall collision)
|
||||
void getTrianglesInRange(float minX, float minY, float maxX, float maxY,
|
||||
std::vector<uint32_t>& out) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -497,6 +516,7 @@ private:
|
|||
std::unordered_map<GridCell, std::vector<uint32_t>, GridCellHash> spatialGrid;
|
||||
std::unordered_map<uint32_t, size_t> instanceIndexById;
|
||||
mutable std::vector<size_t> candidateScratch;
|
||||
mutable std::vector<uint32_t> wallTriScratch; // Scratch for wall collision grid queries
|
||||
mutable std::unordered_set<uint32_t> candidateIdScratch;
|
||||
|
||||
// Parallel visibility culling
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue