Skip to content

Commit

Permalink
add corner case Biome code with hard wired colors for some Biomes
Browse files Browse the repository at this point in the history
add ID to BiomeInfo for faster Biome detection, other precomputation
could be possible
  • Loading branch information
EtlamGit committed Dec 26, 2016
1 parent 6fd090d commit 67705c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
48 changes: 43 additions & 5 deletions biomeidentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Copyright (c) 2016, EtlamGit
static BiomeInfo unknownBiome;

BiomeInfo::BiomeInfo()
: name("Unknown Biome")
: id(-1)
, name("Unknown Biome")
, enabled(false)
, watermodifier(255,255,255)
, enabledwatermodifier(false)
Expand Down Expand Up @@ -65,9 +66,11 @@ This method is inspired from Mineways, Copyright (c) 2014, Eric Haines
QColor BiomeInfo::getBiomeColor( float temperature, float humidity, int elevation, T_BiomeCorner *corners )
{
// check elevation
elevation = (elevation < 0) ? 0 : elevation;
// todo: probably negative values are allowed with latest Minecraft versions
// elevation = (elevation < 0) ? 0 : elevation;

// get local temperature and humidity
// perlin noise generator omitted due to performance reasons
temperature = clamp( temperature - (float)elevation*0.00166667f, 0.0f, 1.0f );
humidity = clamp( humidity, 0.0f, 1.0f );
humidity *= temperature; // scale by temperature to stay in triangle
Expand Down Expand Up @@ -95,12 +98,46 @@ QColor BiomeInfo::getBiomeColor( float temperature, float humidity, int elevatio

QColor BiomeInfo::getBiomeGrassColor( int elevation )
{
return getBiomeColor( this->temperature, this->humidity, elevation, grassCorners );
// remove variants from ID
int id = this->id & 0x7f;
// swampland
if (id == 6) {
// perlin noise generator omitted due to performance reasons
// otherwise the random temperature distribution selects
// (below -0.1°C) ‭4C.76.3C‬ or ‭6A.70.39 (above -0.1°C)
return QColor::QColor(0x6a,0x70,0x39); // hard wired
}
// roofed forest
else if (id == 29) {
QColor color = getBiomeColor( this->temperature, this->humidity, elevation, grassCorners );
// average with 0x28340A
color.setRed ( (color.red() + 0x28)>>1 );
color.setGreen( (color.green() + 0x34)>>1 );
color.setBlue ( (color.blue() + 0x0A)>>1 );
return color;
}
// mesa
else if ((id == 37) || (id == 38) || (id == 39)) {
return QColor::QColor(0x90,0x81,0x4d); // hard wired
} else
// standard way
return getBiomeColor( this->temperature, this->humidity, elevation, grassCorners );
}

QColor BiomeInfo::getBiomeFoliageColor( int elevation )
{
return getBiomeColor( this->temperature, this->humidity, elevation, foliageCorners );
// remove variants from ID
int id = this->id & 0x7f;
// swampland
if (id == 6) {
return QColor::QColor(0x6a,0x70,0x39); // hard wired
}
// mesa
else if ((id == 37) || (id == 38) || (id == 39)) {
return QColor::QColor(0x9e,0x81,0x4d); // hard wired
} else
// standard way
return getBiomeColor( this->temperature, this->humidity, elevation, foliageCorners );
}

QColor BiomeInfo::getBiomeWaterColor( QColor watercolor )
Expand All @@ -111,7 +148,7 @@ QColor BiomeInfo::getBiomeWaterColor( QColor watercolor )
int g = (int)( watercolor.green() * watermodifier.green() / 255 );
int b = (int)( watercolor.blue() * watermodifier.blue() / 255 );
// return combined modified color
return QColor::QColor(r, g, b );
return QColor::QColor(r, g, b);
} else
return watercolor;
}
Expand Down Expand Up @@ -171,6 +208,7 @@ int BiomeIdentifier::addDefinitions(JSONArray *defs, int pack) {

BiomeInfo *biome = new BiomeInfo();
biome->enabled = true;
biome->id = id;
if (b->has("name"))
biome->name = b->at("name")->asString();

Expand Down
1 change: 1 addition & 0 deletions biomeidentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class BiomeInfo {

// public members
public:
int id;
QString name;
bool enabled;
QColor colors[16];
Expand Down

0 comments on commit 67705c8

Please sign in to comment.