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

Previously active chunks list removal problem #9

Open
smoneuse opened this issue May 3, 2020 · 1 comment
Open

Previously active chunks list removal problem #9

smoneuse opened this issue May 3, 2020 · 1 comment

Comments

@smoneuse
Copy link

smoneuse commented May 3, 2020

Hello ! Thanks for this tutorial ! It's really great !!

I think there is a problem in this part of the code.
As you said in one of your video, when you remove an element from the list, the indexes are recalculated.
In your checkViewDistance method, you use an index to find the chunk that needs to be kept. that's ok, but why does the for loop goes on (with the indexes recalculated) once the chunk is found ?

In my opinion, it you be better if there was this code : (with a break once the chunk found)

                    for (int i=0; i< previouslyActiveChunks.Count; i++) {
                        if (previouslyActiveChunks[i].Equals(chunks[x, z].coord)) {
                            previouslyActiveChunks.RemoveAt(i);
                            break;                            
                        }
                    }

Or even better, as the method Equals exists for the ChunkCoord class :
previouslyActiveChunks.Remove(chunks[x, z].coord);

Thanks again for your videos !! A real pleasure to watch !!
Cheers from France !

@smoneuse
Copy link
Author

smoneuse commented May 6, 2020

For some reason I don't figure yet, some ChunksCoords are present multiple times in previouslyActiveChunks.
I think this is due to activeChunks Add() calls in various places in the code, with new Instances of ChunkCoord...

However, maybe the better way for this issue is to browse the list from end to beginning :

                for (int i = previouslyActiveChunks.Count - 1; i >= 0; i--) {
                    if (previouslyActiveChunks[i].Equals(new ChunkCoord(x, z))) { 
                        previouslyActiveChunks.RemoveAt(i);
                    }
                }

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

No branches or pull requests

1 participant