Skip to content

Commit

Permalink
0.0.027 -> 0.0.028: U2 - Elevation
Browse files Browse the repository at this point in the history
Change LOCAL_MAP_SIZE to (2^n)+1 to work with fractals.
Add height to WorldTile
Add shading to local tiles based on height.
Add fractal heightmap generation to generateLocal, including special algorithm for mountains.
  • Loading branch information
RyanBabij committed Jul 26, 2018
1 parent 1f23482 commit 4f1ba78
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CompileCount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/
#include <string>

const std::string COMPILE_COUNT = "5067";
const std::string COMPILE_COUNT = "5123";
#endif
4 changes: 2 additions & 2 deletions Driver_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int lastline = 0;

bool FAST_COUT = false;

const std::string VERSION = "0.0.027 Win32 dev";
const std::string VERSION = "0.0.028 Win32 dev";
const std::string G_WINDOW_TITLE = "WorldSim";

const std::string SAVE_FOLDER_PATH = "savedata";
Expand Down Expand Up @@ -59,7 +59,7 @@ bool FOG_OF_WAR = true;
/* Size of each city in tiles. Size is CITY_SIZE * CITY_SIZE.
Realistically it should be 3000, however I might need to reduce it
depending on scaling and performance considerations. */
const int LOCAL_MAP_SIZE = 400;
const int LOCAL_MAP_SIZE = 513;

int TIME_SCALE = 60; /* How many seconds of gametime pass per logic tick. */

Expand Down
4 changes: 4 additions & 0 deletions LocalTile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class LocalTile: public HasTexture
int seed;
enumBiome baseTerrain;

int height;

bool isUphill [8]; /* Clockwise starting north */

// Vector of objects on this tile.
Vector <WorldObject*> vObject;

Expand Down
42 changes: 42 additions & 0 deletions World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,48 @@ void World::generateLocal(const int _localX, const int _localY)
enumBiome globalBaseTerrain = aWorldTile(localX,localY).biome;



// GENERATE HEIGHTMAP
DiamondSquareAlgorithmCustomRange dsa2;
dsa2.maxValue=5;

ArrayS2 <int> aLocalHeight;
aLocalHeight.init(LOCAL_MAP_SIZE,LOCAL_MAP_SIZE,0);

// If we are generating a mountain, set a summit in the middle which is 3x3 tiles.
if ( globalBaseTerrain == MOUNTAIN )
{
aLocalHeight(LOCAL_MAP_SIZE/2,LOCAL_MAP_SIZE/2) = 100;
aLocalHeight((LOCAL_MAP_SIZE/2)+1,LOCAL_MAP_SIZE/2) = 100;
aLocalHeight((LOCAL_MAP_SIZE/2)-1,LOCAL_MAP_SIZE/2) = 100;

aLocalHeight(LOCAL_MAP_SIZE/2,(LOCAL_MAP_SIZE/2)-1) = 100;
aLocalHeight((LOCAL_MAP_SIZE/2)+1,(LOCAL_MAP_SIZE/2)-1) = 100;
aLocalHeight((LOCAL_MAP_SIZE/2)-1,(LOCAL_MAP_SIZE/2)-1) = 100;

aLocalHeight(LOCAL_MAP_SIZE/2,(LOCAL_MAP_SIZE/2)+1) = 100;
aLocalHeight((LOCAL_MAP_SIZE/2)+1,(LOCAL_MAP_SIZE/2)+1) = 100;
aLocalHeight((LOCAL_MAP_SIZE/2)-1,(LOCAL_MAP_SIZE/2)+1) = 100;

aLocalHeight.fillBorder(1);
dsa2.maxValue=100;
dsa2.generate(&aLocalHeight,0,0,0.9,10);

for ( int _y=0;_y<LOCAL_MAP_SIZE;++_y)
{
for ( int _x=0;_x<LOCAL_MAP_SIZE;++_x)
{
aLocalHeight(_x,_y) = aLocalHeight(_x,_y)/20;
}
}
//aLocalHeight.setBorder(1);
}
else
{
////HEIGHTMAP TABLE FREESTEPS SMOOTHING
dsa2.generate(&aLocalHeight,0,0,0.75,100);
}


// Take the seed for this world tile and expand it into a subseed for every local tile */
random.seed(aSeed(localX,localY));
Expand All @@ -1068,6 +1109,7 @@ void World::generateLocal(const int _localX, const int _localY)
aLocalTile(_x,_y).baseTerrain = globalBaseTerrain;
aLocalTile(_x,_y).seed = random.randInt(PORTABLE_INT_MAX-1);
aLocalTile(_x,_y).clearObjects();
aLocalTile(_x,_y).height = aLocalHeight(_x,_y);

if (random.oneIn(100))
{
Expand Down
25 changes: 22 additions & 3 deletions World_Viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,27 @@ void switchTarget(World_Local* _worldLocal)
{
if ( nextPixel>=mainViewX1 && currentPixel <= mainViewX2 && floor(currentPixel) != floor(nextPixel) )
{
LocalTile* localTile = &world->aLocalTile(localXTile,localYTile);

Renderer::placeTexture4(floor(currentPixel), floor(currentSubY), floor(nextPixel), floor(nextSubY), world->aLocalTile(localXTile,localYTile).currentTexture(), false);

//Renderer::placeTexture4(floor(currentPixel), floor(currentSubY), floor(nextPixel), floor(nextSubY), localTile->currentTexture(), false);
//if (localTile->height < 5 )
//{
unsigned char lightValue = localTile->height*15;
glColor3ub(180+lightValue,180+lightValue,180+lightValue);
Renderer::placeTexture4(currentPixel, currentSubY, ceil(nextPixel), ceil(nextSubY), localTile->currentTexture(), false);
glColor3ub(255,255,255);
//}
//else
// {
// Renderer::placeTexture4(currentPixel, currentSubY, ceil(nextPixel), ceil(nextSubY), localTile->currentTexture(), false);
// }



for(int i=0;i<world->aLocalTile(localXTile,localYTile).vObject.size();++i)
{
Renderer::placeTexture4(floor(currentPixel), floor(currentSubY), floor(nextPixel), floor(nextSubY), world->aLocalTile(localXTile,localYTile).vObject(i)->currentTexture(), false);
Renderer::placeTexture4(currentPixel, currentSubY, ceil(nextPixel), ceil(nextSubY), world->aLocalTile(localXTile,localYTile).vObject(i)->currentTexture(), false);
}

// if ( localBaseBiome == OCEAN )
Expand Down Expand Up @@ -808,7 +823,9 @@ void switchTarget(World_Local* _worldLocal)

if (world->aSeed(tileX,tileY) % 4 == 0)
{
glColor4f(2.0f, 2.0f, 2.0f, 1.0f);
Renderer::placeTexture4(currentX, currentY, currentX+tileSize, currentY+tileSize, &TEX_WORLD_TERRAIN_GRASS_00, false);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
else if (world->aSeed(tileX,tileY) % 4 == 1)
{
Expand Down Expand Up @@ -912,13 +929,15 @@ void switchTarget(World_Local* _worldLocal)

if(world->isSafe(tileX,tileY)==true && world->isLand(tileX,tileY)==true && world->aTerrain(tileX,tileY) == FOREST)
{
Renderer::placeTexture4(currentX, currentY, currentX+tileSize, currentY+tileSize, &TEX_WORLD_TERRAIN_FOREST_TREE, false);
Renderer::placeTexture4(currentX, currentY, currentX+tileSize, currentY+tileSize, &TEX_WORLD_TERRAIN_FOREST_TREES, false);
}

if(world->isSafe(tileX,tileY)==true && world->isLand(tileX,tileY)==true && world->aTerrain(tileX,tileY) == MOUNTAIN)
{
//Renderer::placeTexture4(currentX, currentY, currentX+tileSize, currentY+tileSize, &TEX_WORLD_TERRAIN_GRASS_00, false);
glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
Renderer::placeTexture4(currentX, currentY, currentX+tileSize, currentY+tileSize, &TEX_WORLD_TERRAIN_MOUNTAIN_00, false);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}

if(world->isSafe(tileX,tileY)==true && world->isLand(tileX,tileY)==true && world->aTerrain(tileX,tileY) == DESERT)
Expand Down

0 comments on commit 4f1ba78

Please sign in to comment.