feat: Optimize rendering and physics with dirty chunk tracking and adaptive update rates
This commit introduces several performance optimizations: - Implement chunk-based dirty rendering - Add adaptive physics update rates - Return modification status from element update functions - Reduce unnecessary rendering and physics calculations - Track world movement for efficient re-rendering The key changes include: 1. Adding `dirtyChunks` and `worldMoved` tracking 2. Modifying element update functions to return modification status 3. Implementing adaptive physics update rates based on FPS 4. Skipping rendering for unchanged chunks 5. Reducing computational overhead in physics and rendering loops These optimizations should significantly improve the simulation's performance, especially with large numbers of elements.
This commit is contained in:
@@ -5,26 +5,33 @@ function updateTreeSeed(x, y) {
|
||||
setPixel(x, y, EMPTY);
|
||||
setPixel(x, y + 1, TREE_SEED);
|
||||
moveMetadata(x, y, x, y + 1);
|
||||
return true;
|
||||
}
|
||||
else if (getPixel(x - 1, y + 1) === EMPTY) {
|
||||
setPixel(x, y, EMPTY);
|
||||
setPixel(x - 1, y + 1, TREE_SEED);
|
||||
moveMetadata(x, y, x - 1, y + 1);
|
||||
return true;
|
||||
}
|
||||
else if (getPixel(x + 1, y + 1) === EMPTY) {
|
||||
setPixel(x, y, EMPTY);
|
||||
setPixel(x + 1, y + 1, TREE_SEED);
|
||||
moveMetadata(x, y, x + 1, y + 1);
|
||||
return true;
|
||||
}
|
||||
// Seeds can float on water
|
||||
else if (getPixel(x, y + 1) === WATER) {
|
||||
// Just float, don't do anything
|
||||
return false;
|
||||
}
|
||||
// If seed is on dirt or grass, it can grow into a tree
|
||||
else if (getPixel(x, y + 1) === DIRT || getPixel(x, y + 1) === GRASS) {
|
||||
// Start growing a tree
|
||||
growTree(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function growTree(x, y) {
|
||||
|
||||
Reference in New Issue
Block a user