Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize grid updates #40

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

gverger
Copy link

@gverger gverger commented Jul 21, 2022

Instead of going through all cells to get their tile options, we keep the grid (like a cache of options), and only modify cells that might have changed, leaving aside cells we are sure are unchanged.

Idea:
We start from the picked cell, and we check its neighbours. For each neighbour (up, right, down, left), if the list of options has changed, we add its own neighbours to the list of cells to check. If it didn't change, we just skip its neighbours.

It is more accurate than going through the old grid because it propagates changes until we arrive to a stable state.
In the old way, we only check cells once, according to the state at t-1. It seems to me it is reducing the options of the last pick only.

Bonus: since the drawing of cells now a lot of time compared to choosing the next tile, we can have several updates per draw, which speeds considerably the process.

Here with 1 update per tick, DIM = 25, size = 400x400
wfc-25-1

Here with 10 updates per tick, DIM = 50, size = 800x800
wfc

Here with 1000 updates per tick, DIM = 200, size = 800x800
wfc-200-1000

@gverger gverger mentioned this pull request Jul 21, 2022
@shiffman
Copy link
Member

Many apologies!!! I know it's been almost 3 years since these PRs! I am releasing a new video next week on the overlapping model and did some work to refactor this repository. Would you like to resubmit this? I'm open to incorporating it into the new structure. If you (very understandably) don't have time to look at this again, I'm glad to sort it out!

instead of going through all cells to get their tile options, we keep a
cache of options, and only modify cells that might have changed.

Idea:
We start from the picked cell, and we check its neighbours. For each
neighbour (up, right, down, left), if the list of options has changed,
we add its own neighbours to the list of cells to check. If it didn't
change, we just skip its neighbours.

It is even better than going through the old grid because it propagates
changes until we come to a stable state. In the old way, we only check
cells once, according to the state at t-1, which can miss some option
reductions and lead to infeasibility.
@gverger
Copy link
Author

gverger commented Jan 26, 2025

Hey @shiffman ,
don't apologize, that's the nature of open source, you never asked me to add anything to your repo anyway, so you don't owe me anything 😄

I solved the conflicts, it's been a while I didn't touch any javascript, but fortunately your changes were small

Keep up the good work and the good mood!

@shiffman
Copy link
Member

This is great! I'm thinking of doing a follow-up video where I'm go over a whole variety of improvements and incorporate them into the examples. (The new "overlapping model" video is coming out on Tuesday.) I'm going to leave this open for now and link to it from the community contributions in the README. Then when I do the new video I'll go over the code and merge this in!

@shiffman
Copy link
Member

Added to the README in #46!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants