CodingTrain / CodingTrain/Wave-Function-Collapse

Speed Up by only calculating entropy of cells adjacent to collapsed cells (+ naive backtracking demo)

Đang mở
#38 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
218
Fork
64
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

i was trying to draw a large grid (64x64) and it was slow, so i tweaked the `draw()` function to skip calculating validOptions for cells that weren't adjacent to any other collapsed cells

```
// if ZERO adjacent cells are collapsed, skip for now...
let at_least_one_collapsed = false;
for(neighbor of [
j > 0 ? grid[i + (j - 1) * DIM] : null, // up
i < DIM - 1 ? grid[i + 1 + j * DIM] : null, // right
j < DIM - 1 ? grid[i + (j + 1) * DIM] : null, // down
i > 0 ? grid[i - 1 + j * DIM] : null // left
]){
if(neighbor?.collapsed){
at_least_one_collapsed = true;
}
}
if(!at_least_one_collapsed){
nextGrid[index] = new Cell(tiles.length, index); //grid[index];
continue;
}
```

you can test it out on CodePen here: https://codepen.io/jakedowns/pen/PoRbeGQ

I also implemented naive backtracking, naive in the sense that it goes backwards step by step, instead of kind of propagating re-picking options in the local neighborhood of a cell with 0 options. that would be the more efficient way. gonna try to implement that next...

https://twitter.com/i/status/1547662617749045250

https://user-images.githubusercontent.com/1683122/179131109-84e6a5e7-0d79-4005-9073-d4cbae7e23e8.mp4

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.