More Multithreading. Also Terrain Brushes

One advantage of doing multithreading for 0.12.0 was that it de-stigmatized it for me. So this week, rather than keep trying to optimize the lag I had created in the map editor, I did a thing and dumped it all on another thread.

Two other threads, actually. The erosion algorithm spits out a heightfield, which needs to be converted into vertices for rendering. Both of the erosion and the conversion are expensive functions, which is why they now both happen on other threads. I’ve become quite fond of the backbuffer pattern, in which I complete all the internal work on a backbuffer and flip it to a forebuffer copy for display and use by other parts of the program. The results are promising: not quite real-time but close enough to be workable, and the UI remains responsive throughout.

All that out of the way finally freed me up to start working on the map editor itself.

For the brushes, I needed the ability to pick a point on the 3d terrain with the cursor (okay yes, I could have just had players paint on a top-down map, but where’s the fun in that?). I’ve already done this in the game proper, of course, but remember how the in-game terrain is a) heavily optimized and b) a static, unchanging object? Yeah, the triangle-picking technique I used for that caused far too much lag on a dynamic heightfield to be viable in the map editor.

Instead, I took a different approach: ray-tracing from the cursor position to the terrain object and polling the height field for every pixel travelled. The result is nowhere near as accurate as triangle-picking, but it’s a lot faster and you’ll never be as close to the map editor terrain as you will to the in-game terrain.

And with that done, I started work on the brushes. I’ve got some simple raise/lower/flatten brushes in place, but no real UI for them yet. Still working on that part.


I blame my laptops touchpad for this. 

All things considered, this was a good week.


  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: