C++ Parallel Asynchonous task

Posted by Doodlemeat on Game Development See other posts from Game Development or by Doodlemeat
Published on 2014-06-11T13:34:19Z Indexed on 2014/06/11 15:43 UTC
Read the original article Hit count: 145

Filed under:
|

I am currently building a randomly generated terrain game where terrain is created automatically around the player. I am experiencing lag when the generated process is active, as I am running quite heavy tasks with post-processing and creating physics bodies.

Then I came to mind using a parallel asynchronous task to do the post-processing for me. But I have no idea how I am going to do that. I have searched for C++ std::async but I believe that is not what I want. In the examples I found, a task returned something. I want the task to change objects in the main program.

This is what I want:

// Main program

// Chunks that needs to be processed. 
// NOTE! These chunks are already generated, but need post-processing only!
std::vector<Chunk*> unprocessedChunks;

And then my task could look something like this, running like a loop constantly checking if there is chunks to process.

// Asynced task
if(unprocessedChunks.size() > 0)
{
    processChunk(unprocessedChunks.pop());
}

I know it's not far from easy as I wrote it, but it would be a huge help for me if you could push me at the right direction.

In Java, I could type something like this:

asynced_task = startAsyncTask(new PostProcessTask());

And that task would run until I do this:

asynced_task.cancel();

© Game Development or respective owner

Related posts about c++

Related posts about multithreading