Jump to content

[c++] Performance and threads


Slastraf
 Share

Recommended Posts

I have coded a basic terrain generator which takes a perlin noise and builds a mesh from that.
The problem is this is an expensive task for real time. So I put the whole function which calculates the chunks in a second thread which is handled in the game loop.
This has not helped much with the performance, as I am using Leadwerks functions inside the thread which still accesses the game world and makes it freeze for a split second. Is there any way to calculate the mesh in a different thread and then "load" it into the world ?
An explanatory video below.
Thanks

Link to comment
Share on other sites

What is actually causing the little pause? Is it the creation of the flat mesh itself? Is it manipulating the terrain mesh in 1 iteration? Off the top of my head I would copy the flat terrain mesh, which should be instant and I don't think cause a pause, and then as you're manipulating the vertices of the terrain that would have to be done over multiple frames so there is no noticeable pause. I think I did something like this back in the day and it was easiest to do in lua because of coroutines running over multiple frames. I was able to manipulate a handful of terrain vertices every loop before I'd yield out of the coroutine to give cycles back to the game so it didn't cause a noticeable pause.

  • Like 1
Link to comment
Share on other sites

Just now, Rick said:

What is actually causing the little pause? Is it the creation of the flat mesh itself? Is it manipulating the terrain mesh it 1 iteration? Off the top of my head I would copy the flat terrain mesh, which should be instant and I don't think cause a pause, and then as you're manipulating the vertices of the terrain that would have to be done over multiple frames so there is no noticeable pause. I think I did something like this back in the day and it was easiest to do in lua because of coroutines running over multiple frames. I was able to manipulate a handful of terrain vertices every loop before I'd yield out of the coroutine to give cycles back to the game so it didn't cause a noticeable pause.

I generate new vertices, traingles for every new mesh completely new. Agreeably this takes long. To copy it over and iterate all verts to put them on the generated position could be much faster. The chunks don't have that many verts so it takes less than a few frames. How to access mesh information ? 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...