• Create Account

#ActualDrakken255

Posted 14 August 2012 - 08:25 AM

Starting new threads is expensive! You definitely should not be doing that every frame.

Lol thanks for the tip. Given my landscape is an [,] array of chunks, how do I pass the new coords pointing to a chunk to an existing and maybe running thread? Or would it be best to compile a list of chunks needing an init, and let the loader thread check it? Regardless of which is best, I will still need a little help getting threads to work right.

EDIT: Ok. So I set up a Queue and a worker thread that loads chunks, and it works beautifully! Barely ANY frame drops! Now to decrease the instance data size... kalle_h, phil_t, either one of you have Skype?

#4Drakken255

Posted 14 August 2012 - 08:18 AM

Starting new threads is expensive! You definitely should not be doing that every frame.

Lol thanks for the tip. Given my landscape is an [,] array of chunks, how do I pass the new coords pointing to a chunk to an existing and maybe running thread? Or would it be best to compile a list of chunks needing an init, and let the loader thread check it? Regardless of which is best, I will still need a little help getting threads to work right.

EDIT: Ok. So I set up a Queue and a worker thread that loads chunks, but now about every second and a half, regardless of where I am, where I am facing, whether or not I'm moving, my framerate drops for a quarter of a second. My chunk loading thread method is as such:

private void LoadChunks()
{
while (isRunning)
{
{
world.Landscape[(int)chunkPosition.X, (int)chunkPosition.Y].Generate(world.Content, world.Rand);
world.Landscape[(int)chunkPosition.X, (int)chunkPosition.Y].GenerateInstanceInfo();
}
else
{
}
}
}


This really started happening when I had to modify my Block class to handle the possibility for neighboring blocks being part of a null chunk without throwing an exception. The current implementation of this is such that if the neighboring chunk is null, or the chunk isn't null but hasn't been generated, set the face facing that chunk to draw.

#3Drakken255

Posted 14 August 2012 - 05:41 AM

Starting new threads is expensive! You definitely should not be doing that every frame.

Lol thanks for the tip. Given my landscape is an [,] array of chunks, how do I pass the new coords pointing to a chunk to an existing and maybe running thread? Or would it be best to compile a list of chunks needing an init, and let the loader thread check it? Regardless of which is best, I will still need a little help getting threads to work right.

EDIT: Is it thread safe to use a Queue of coordinates and never lock the var? I would assume not, because it would be possible to write to and retrieve from and remove from at the same time.

#2Drakken255

Posted 14 August 2012 - 05:41 AM

Starting new threads is expensive! You definitely should not be doing that every frame.

Lol thanks for the tip. Given my landscape is an [,] array of chunks, how do I pass the new coords pointing to a chunk to an existing and maybe running thread? Or would it be best to compile a list of chunks needing an init, and let the loader thread check it? Regardless of which is best, I will still need a little help getting threads to work right.

EDIT: Is it thread safe to use a Queue of coordinates and never lock the var? I would assume not, because it would be possible to write to and retrieve from and remove from at the same time.

#1Drakken255

Posted 13 August 2012 - 04:49 AM

Starting new threads is expensive! You definitely should not be doing that every frame.

Lol thanks for the tip. Given my landscape is an [,] array of chunks, how do I pass the new coords pointing to a chunk to an existing and maybe running thread? Or would it be best to compile a list of chunks needing an init, and let the loader thread check it? Regardless of which is best, I will still need a little help getting threads to work right.

PARTNERS