Thread:LOTRMod/@comment-26767096-20170228190157/@comment-25101690-20170302004239

LOTRMod wrote: The map image is loaded as a BufferedImage, which is essentially a very long array of ARGB values. With the width and height of the image being known, it can be interpreted as a 2D array. Then, when the game is generating a biome, it can convert the world coordinates of that chunk into pixel coordinates, look up the corresponding RGB value in the array, look up that RGB value in the table of biome colours, and thus retrieve the biome. There is no OpenGL here, because there is nothing actually being rendered. It's just numbers.

Crossbows have a custom item renderer which rotates them when they're loaded. That does use OpenGL rotations. (And it was a huge pain to get the orientation looking right.)

The road labels are rendered in the following way: as the road itself is being rendered, a sequence of black pixels or 'road points', every Nth pixel will be chosen to have a label above it. The angle at which the label is rendered has to match up with the curvature of the road, so I use the two adjacent points to calculate a finite-difference approximation of the derivative of the curve and relate that to the angle by taking the arctangent.

The difficult part was determing exactly how many road points to skip between labels. Because you don't want to have labels overlapping each other, but you don't want them too spread out. And this has to be maintained as you zoom in and out, so the numbers have to scale. And you don't want a road label overlapping onto a waypoint label. And because of the way the road curves are generated, not all roads have the same number of points within a given distance. And so on...

That was the part that took several days to get right.

For the rivers, the basic idea is as follows: they used to be biomes on the map like any other, but I decided it would be better if they are instead biome-variants of the surrounding biome. (Biome variants - which are not 'variant biomes' but 'variants overlaid onto biomes' had already been in the mod for over a year.)

Why? Well, for one thing, water colour depends on biome, and this avoids having to create Mordor River biomes and Mirkwood River and Dead Marshes River and Pertorogwaith River and so on for every biome with an unusual water colour. It also means that other biome-dependent things like grass colour and mob spawning and achievements work correctly in rivers, instead of having rivers be 'neutral zones' between biomes. I hope you can see where I'm going with this.

So since beta 29 the blue river pixels on the map are not generated as biomes like any other biomes are. Instead, during world generation the mod first removes those pixels from the Biome Layer, copies them to the Biome Variant Layer, and then it has to fill in the gaps on the Biome Layer. This is done by searching the surrounding biomes and deciding which to fill the gap with based on which biome occurs most.

But it's not as easy as it sounds. It was incredibly difficult to design an algorithm that worked consistently well when scaling up the rivers to generate, especially with diagonal rivers. In the first tests, diagonal rivers would either be completely broken, or much wider than other rivers. And there were also problems with rivers meeting lakes.



In fact, this was probably the reason Beta 29 took so long. I was trying to make the rivers work for about a month, and at one point I gave up completely, and started again later on. I consider it nothing short of a miracle that I somehow stumbled across an algorithm that works well.

TL;DR you asked for it :^) Why did you not use two source files - one for the biome and one for variants such as rivers?