Saturday, March 21, 2009

Using terrain mods to level ground for buildings

One of my pet peeves for quite a while is that most of the buildings in the game stand on uneven ground and have the terrain poking through their floor. This is an effect of the way we use Mercator to create a dynamic terrain, so that it's never guaranteed to be any level area in it.
And that's where the terrain mods come into play. By using terrain mods we can alter the terrain at specified areas. There are a couple of different types of "mods" we can apply, and for this problem the "level mod" seems most suited. It will make sure that the terrain specified is altered so that's it's leveled to a specified height.
There are two ways of specifying this height. Either we use a fixed height, telling the system for example that the area should be leveled to a height of 20 meters. Or we use a offset height, so that the height specified is relative to the position of the entity to which the terrain mod is attached. For this case the latter is more suitable, since we want the terrain to be leveled to the same height as the entity.
The clip below shows how this can be done in real time on the server. We first create a house, which when positioned on uneven ground will have the terrain poking through the floor. By adding a level terrain mod, with an offset positioning of 0 meters, the terrain will be altered so that it's level under the house. As we move the house, the terrain mod is moved as well.

Higher quality version here.

The level mod has one disadvantage however in that it will both raise and lower the terrain to the specified height. In this case, we would want it to lower the terrain, but not always raise it. It would be nice then to have floor functionality, so that terrain that is higher is lowered, but lower terrain is unaltered. The current terrain mods available don't allow for this yet however. If we would implement it it would also need a change in the terrain mod interface in the Mercator library, since the TerrainMods currently doesn't know about the existing terrain.

Switching topics, I'm glad to announce that for the second year Worldforge was accepted to the Google Summer of Code. The last year we had three students who all performed splendidly, and the whole program was a great experience. I'm really looking forward to this year. We're now in the phase where we're accepting students' applications. If you're a student which would rather spend your summer getting paid for writing FOSS code for virtual worlds than turning hamburgers or digging ditches, please take a look.

Monday, March 09, 2009

Completed terrain area editing

Initially I planned to have gotten the terrain area editing completed some weeks ago. However, when I started looking into the existing entity editor code I found that it was lacking in some areas, mainly the structure which made it cumbersome to add new adapters and to have it be easily extendable and handle suggestions of both attribute names and attributes types. So I spent a couple of days refactoring the entity editor to turn it into a better shape. It paid off in the end, since it's now much easier to extend it. And the lua code, which was quite haphazardly written, is now much better.
The main visible improvement is that we now have the ability to suggest an attribute name, not just a type. This will help with editing, since any author then won't need to keep track of the names of the important attributes.
The new terrain area adapter allows you to add new areas to any entity, and to edit any existing area. You can add or delete new points, and you can alter the layer which is to be used.
I've put together a small movie of this in action. In it I show how you easily can create a new entity (in this case a barrel), add an area to it, alter and edit the area, and then remove the entity from the world.

Higher res version over here (be sure to try the HQ version).

The nice thing about the area editing is that it's implemented as a general feature, so now that we have support for editing terrain areas, it should be easy to also add support for editing terrain mods, which in much of their functionality are similiar to terrain areas (the former alters the heightmap while the latter alters the terrain layers).