Add block-to-mesh mapping system for improved mesh tracking#384
Add block-to-mesh mapping system for improved mesh tracking#384tracygardner wants to merge 1 commit intomainfrom
Conversation
Replace linear scans in getBlockKeyFromBlock, getBlockKeyFromBlockID, getMeshFromBlockKey, and getMeshesFromBlockKey with direct Map lookups. - Add blockToKeyMap, blockIdToKeyMap, and blockKeyMeshesMap to generators.js - Maintain all 5 Maps together at every assignment site (17 locations) - Clear all Maps at both generator init/init2 reset sites - Register meshes via registerMeshForBlockKey in api/shapes.js, api/mesh.js, api/csg.js, and api/camera.js at each metadata.blockKey assignment - Rewrite the 4 lookup functions in blockmesh.js to use Map.get() / Set iteration - Clean up reverse Maps in deleteMeshFromBlock on disposal https://claude.ai/code/session_011y6sJ1hJUwznDNwHzcphiQ
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
Summary
This PR introduces a comprehensive block-to-mesh mapping system to replace inefficient object lookups. The changes add three new Map-based data structures to track relationships between blocks, block IDs, and their associated meshes, along with a registration function to maintain these mappings.
Key Changes
blockToKeyMap,blockIdToKeyMap, andblockKeyMeshesMapto provide O(1) lookup performance instead of O(n) array searchesregisterMeshForBlockKey()to centralize mesh registration across all mesh creation pointsgetBlockKeyFromBlock(),getBlockKeyFromBlockID(),getMeshFromBlockKey(), andgetMeshesFromBlockKey()to use Map lookups instead of array filteringgetMeshFromBlockKey()andgetMeshesFromBlockKey()to filter out disposed meshesdeleteMeshFromBlock()to properly clean up all three mapping structuresinit()andinit2()generator initialization functionsImplementation Details
blockKeyMeshesMapuses a Set to handle multiple meshes per block keyregisterMeshForBlockKey()to maintain consistencyhttps://claude.ai/code/session_011y6sJ1hJUwznDNwHzcphiQ