Thursday, March 31, 2011

Threading and a new video.

I've fixed the threading issue I had.  The solution came in the form of compartmentalization.

Before my change, I had a giant allCubes Dictionary that stored every single cube in the game.  There was another Dictionary called _terrain that stored each chunk by it's Vector3 location.  The chunk class had a list of cubes that cross-referenced the allCubes Dictionary.  Sounds more complicated than it is.

Anyway, whenever I added/removed a cube or chunk I had to update that huge dictionary.  When you have 2 million cubes in the dictionary, you're going to be referencing it constantly.  This is why adding/deleting from it was causing so many issues.

I could have written a thread-safe dictionary or I could have used ConcurrentDictionary, but I felt that having the giant allCubes dictionary was a bad approach to begin with.  By moving those cubes into the chunk class and referencing them from there, I've compartmentalized the areas that I'm constantly accessing.  I can add/remove cubes from each individual chunk without bothering another one.  That, my friends, is good business.

I didn't do this from the beginning mainly because I was short sighted.  Simple as that.

I also fixed my texture issue.  Switching my sampler from a linear wrap to a point clamp stopped the shader from reading too far out.

Now that chunk loading/unloading has been completed, I'm going to work on adding/removing cubes.  I've been thinking about it a lot and I think I'm going to add a Dictionary called changes inside of each chunk class.  I'll use the Vector3 position of the change for the key and create a change class that will store the type of change.  That way I only have to save that changes dictionary and reference it when I rebuild the chunk each time.  There's no need to store the entire chunk when I know it's going to be consistent.

I'm also going to keep working on the character controller.  I don't know why but I hate programming a character controller.  Everytime I go to start it I find something else I can do.  Eventually I'm going to want to go past Version .01a though and I can't do that without a character controller.

So here's the latest terrain video.  No audio but at least it's pretty.


Hergonan said...

Pleeeease make the video larger or at least allowfullscreen=true

Roy said...

If you view it on YouTube, you can watch it in all its glory.