Permalink
Browse files

Add "oceanShading" mod option to disable 32-color globe shading for h…

…ybrids.
  • Loading branch information...
SupSuper committed Jan 11, 2019
1 parent 05d82fd commit a84c8a7a71f9acf842147c20763b3f6fcfe47e51
Showing with 49 additions and 48 deletions.
  1. +42 −44 src/Geoscape/Globe.cpp
  2. +3 −2 src/Geoscape/Globe.h
  3. +1 −0 src/Mod/Mod.cpp
  4. +3 −2 src/Mod/RuleGlobe.cpp
@@ -61,6 +61,7 @@ const double Globe::ROTATE_LONGITUDE = 0.10;
const double Globe::ROTATE_LATITUDE = 0.06;

Uint8 Globe::OCEAN_COLOR;
bool Globe::OCEAN_SHADING;
Uint8 Globe::COUNTRY_LABEL_COLOR;
Uint8 Globe::LINE_COLOR;
Uint8 Globe::CITY_LABEL_COLOR;
@@ -172,7 +173,7 @@ struct Ocean

struct CreateShadow
{
static inline Uint8 getShadowValue(const Uint8& dest, const Cord& earth, const Cord& sun, const Sint16& noise)
static inline Uint8 getShadowValue(const Cord& earth, const Cord& sun, const Sint16& noise)
{
Cord temp = earth;
//diff
@@ -196,48 +197,50 @@ struct CreateShadow

temp.x -= noise;

if (temp.x > 0.)
return Clamp(temp.x, 0., 31.);
}

static inline Uint8 getOceanShadow(const Uint8& shadow)
{
return Globe::OCEAN_COLOR + shadow;
}

static inline Uint8 getLandShadow(const Uint8& dest, const Uint8& shadow)
{
if (shadow == 0) return dest;
const int s = shadow / 3;
const int e = dest + s;
const int d = dest & helper::ColorGroup;
if (e > d + helper::ColorShade)
return d + helper::ColorShade;
return e;
}

static inline bool isOcean(const Uint8& dest)
{
return Globe::OCEAN_SHADING && dest >= Globe::OCEAN_COLOR && dest < Globe::OCEAN_COLOR + 32;
}

static inline void func(Uint8& dest, const Cord& earth, const Cord& sun, const Sint16& noise, const int&)
{
if (dest && earth.z)
{
const Sint16 val = (temp.x> 31)? 31 : (Sint16)temp.x;
const int d = dest & helper::ColorGroup;
if (d == Globe::OCEAN_COLOR || d == Globe::OCEAN_COLOR + 16)
const Uint8 shadow = getShadowValue(earth, sun, noise);
//this pixel is ocean
if (isOcean(dest))
{
//this pixel is ocean
return Globe::OCEAN_COLOR + val;
dest = getOceanShadow(shadow);
}
//this pixel is land
else
{
//this pixel is land
if (dest==0) return val;
const int s = val / 3;
const int e = dest+s;
if (e > d + helper::ColorShade)
return d + helper::ColorShade;
return e;
dest = getLandShadow(dest, shadow);
}
}
else
{
const int d = dest & helper::ColorGroup;
if (d == Globe::OCEAN_COLOR || d == Globe::OCEAN_COLOR + 16)
{
//this pixel is ocean
return Globe::OCEAN_COLOR;
}
else
{
//this pixel is land
return dest;
}
}
}

static inline void func(Uint8& dest, const Cord& earth, const Cord& sun, const Sint16& noise, const int&)
{
if (dest && earth.z)
dest = getShadowValue(dest, earth, sun, noise);
else
dest = 0;
}
}
};

@@ -1044,18 +1047,13 @@ void Globe::XuLine(Surface* surface, Surface* src, double x1, double y1, double
tcol=src->getPixel((int)x0,(int)y0);
if (tcol)
{
const int d = tcol & helper::ColorGroup;
if (d == OCEAN_COLOR || d == OCEAN_COLOR + 16)
if (CreateShadow::isOcean(tcol))
{
//this pixel is ocean
tcol = OCEAN_COLOR + shade + 8;
tcol = CreateShadow::getOceanShadow(shade + 8);
}
else
{
const int e = tcol + shade;
if (e > d + helper::ColorShade)
tcol = d + helper::ColorShade;
else tcol = e;
tcol = CreateShadow::getLandShadow(tcol, shade * 3);
}
surface->setPixel((int)x0,(int)y0,tcol);
}
@@ -1826,14 +1824,14 @@ void Globe::getPolygonTextureAndShade(double lon, double lat, int *texture, int
7, 7, 8, 8, 9, 9,10,11,
11,12,12,13,13,14,15,15};

*shade = worldshades[ CreateShadow::getShadowValue(0, Cord(0.,0.,1.), getSunDirection(lon, lat), 0) ];
*shade = worldshades[ CreateShadow::getShadowValue(Cord(0.,0.,1.), getSunDirection(lon, lat), 0) ];
Polygon *t = getPolygonFromLonLat(lon,lat);
*texture = (t==NULL)? -1 : t->getTexture();
}

/**
* Checks if the globe is zoomed in to it's maximum.
* @return Returns true if globe is at max zoom, otherwise returns false.
* Returns the current globe zoom factor.
* @return Current zoom (0-5).
*/
size_t Globe::getZoom() const
{
@@ -106,12 +106,13 @@ class Globe : public InteractiveSurface
/// Set up the radius of earth and stuff.
void setupRadii(int width, int height);
public:

static Uint8 OCEAN_COLOR;
static bool OCEAN_SHADING;
static Uint8 COUNTRY_LABEL_COLOR;
static Uint8 LINE_COLOR;
static Uint8 CITY_LABEL_COLOR;
static Uint8 BASE_LABEL_COLOR;
static Uint8 OCEAN_COLOR;

/// Creates a new globe at the specified position and size.
Globe(Game* game, int cenX, int cenY, int width, int height, int x = 0, int y = 0);
/// Cleans up the globe.
@@ -163,6 +163,7 @@ void Mod::resetGlobalStatics()
DEBRIEF_MUSIC_BAD = "GMMARS";

Globe::OCEAN_COLOR = Palette::blockOffset(12);
Globe::OCEAN_SHADING = true;
Globe::COUNTRY_LABEL_COLOR = 239;
Globe::LINE_COLOR = 162;
Globe::CITY_LABEL_COLOR = 138;
@@ -128,15 +128,16 @@ void RuleGlobe::load(const YAML::Node &node)
}
}
}

Globe::COUNTRY_LABEL_COLOR = node["countryColor"].as<int>(Globe::COUNTRY_LABEL_COLOR);
Globe::CITY_LABEL_COLOR = node["cityColor"].as<int>(Globe::CITY_LABEL_COLOR);
Globe::BASE_LABEL_COLOR = node["baseColor"].as<int>(Globe::BASE_LABEL_COLOR);
Globe::LINE_COLOR = node["lineColor"].as<int>(Globe::LINE_COLOR);

Globe::LINE_COLOR = node["lineColor"].as<int>(Globe::LINE_COLOR);
if (node["oceanPalette"])
{
Globe::OCEAN_COLOR = Palette::blockOffset(node["oceanPalette"].as<int>(Globe::OCEAN_COLOR));
}
Globe::OCEAN_SHADING = node["oceanShading"].as<bool>(Globe::OCEAN_SHADING);
}

/**

0 comments on commit a84c8a7

Please sign in to comment.