Browse Source

Added code and data licenses; started work on a terrain generation model

master
Macoy Madson 6 years ago
parent
commit
9298d585d5
12 changed files with 362 additions and 2 deletions
  1. +2
    -0
      .gitignore
  2. +10
    -0
      LICENSE.txt
  3. +1
    -0
      assets/LICENSE.txt
  4. +1
    -0
      data/LICENSE.txt
  5. +2
    -1
      data/files.ept
  6. +21
    -0
      data/scripts/world/defaultGen.ept
  7. BIN
      src/experimentation/fastTerrain
  8. +140
    -0
      src/world/noiseGeneration.cpp
  9. +41
    -0
      src/world/noiseGeneration.hpp
  10. +135
    -0
      src/world/terrainGeneration.cpp
  11. +8
    -0
      src/world/terrainGeneration.hpp
  12. +1
    -1
      src/world/world.cpp

+ 2
- 0
.gitignore View File

@ -29,3 +29,5 @@
#Stuff only I want
LOCAL_*
*~

+ 10
- 0
LICENSE.txt View File

@ -0,0 +1,10 @@
The MIT License (MIT)
Copyright (c) 2015 Macoy Madson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 1
- 0
assets/LICENSE.txt View File

@ -0,0 +1 @@
This content is licensed under the Creative Commons Attribution NonCommercial-ShareAlike 4.0 International Public License. Please see http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode for the full license.

+ 1
- 0
data/LICENSE.txt View File

@ -0,0 +1 @@
This content is licensed under the Creative Commons Attribution NonCommercial-ShareAlike 4.0 International Public License. Please see http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode for the full license.

+ 2
- 1
data/files.ept View File

@ -25,5 +25,6 @@ specialScripts:
worldDefaults:
//tileSet=data/images/castle.png;
tileSet=limitedTileMap;
//tileSet=limitedTileMap;
tileSet=tileMap;
defaultMap=data/maps/default.map;

+ 21
- 0
data/scripts/world/defaultGen.ept View File

@ -0,0 +1,21 @@
<defaultWorldGen.1>
//Values to tweak the terrain generation
terrain:
algorithm=2;
biomes=false;
oceanRange={0, 100};
oceanTileRange={0, 3};
beachRange={101, 120};
beachTileRange={4, 5};
grassRange={121, 184};
grassTileRange={6, 8};
mountainRange={185, 244};
mountainTileRange={9, 11};
iceRange={245, 255};
iceTileRange={12, 12};

BIN
src/experimentation/fastTerrain View File


+ 140
- 0
src/world/noiseGeneration.cpp View File

@ -0,0 +1,140 @@
#ifndef NOISEGENERATION_CPP
#define NOISEGENERATION_CPP
#include "noiseGeneration.hpp"
//Creates a TerrainGenSettings from a .ept spec
TerrainGenSettings createTerrainGenSettingsFromSpec(eptFile* spec)
{
}
void getElevationAt(CellIndex cell, int x, int y, TerrainGenSettings* terrainGenSettings)
{
float noiseX = x + (CELL_WIDTH * cellID.x);
float noiseY = y + (CELL_HEIGHT * cellID.y);
noiseX /= 2; //TODO: Raise this value for more accurate floats far away?
noiseY /= 2;
const float SCALE = 0.001;
//TODO: Put all these values in a text file
float value = scaled_octave_noise_3d(10, 0.55, SCALE, 0, 255, noiseX, noiseY, seed);
return value;
}
void generateCellTerrain(int worldID, int seed, int algorithm, CellIndex cell, std::vector<std::vector<tile> >* cellTiles)
{
//I doubt there will be very many, so I'll just put it in switch
switch (algorithm)
{
//Simplex noise world; expects 0-255 colors (terrain.png); no biomes
case 2:
for (int y = 0; y < CELL_HEIGHT; ++y)
{
for (int x = 0; x < CELL_WIDTH; ++x)
{
float value = getElevationAt(cell, x, y);
//Winter bands
if (value > 142)
{
//value += 100 / (((int)(y+1) % 100) + 1);
//int yInt = (int) y;
float factor = fabs(sin(noiseY * SCALE));
const float SNOW_AMOUNT = 1.9;
factor -= SNOW_AMOUNT - factor; //1.3
if (factor < 0) factor = 0;
const float SNOW_FALLOFF = 1000;
value += SNOW_FALLOFF * factor; //Winter climates
if (value > 254) value = 254;
if (value < 142) value = 142;
}
//TEMP DELETE ME!
//value = 150;
if (value > 185) //Mountains are on multiple layers
{
//Ground and onground are solid black
tiles[0][x + (y * CELL_WIDTH)].x = 185;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
tiles[1][x + (y * CELL_WIDTH)].x = 185;
tiles[1][x + (y * CELL_WIDTH)].y = 0;
//Above ground is elevation
tiles[2][x + (y * CELL_WIDTH)].x = value;
tiles[2][x + (y * CELL_WIDTH)].y = 0;
}
else
{
tiles[0][x + (y * CELL_WIDTH)].x = value;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
tiles[1][x + (y * CELL_WIDTH)].x = 255;
tiles[1][x + (y * CELL_WIDTH)].y = 255;
tiles[2][x + (y * CELL_WIDTH)].x = 255;
tiles[2][x + (y * CELL_WIDTH)].y = 255;
}
}
}
std::cout << "Done generating " << tiles.size() << " of " << NUM_LAYERS << " layers addr " << &tiles[0] << " \n";
break;
//Simplex noise (no biome); limited colors (3 for each range)
case 3:
for (int y = 0; y < CELL_HEIGHT; ++y)
{
for (int x = 0; x < CELL_WIDTH; ++x)
{
float value = getElevationAt(cell, x, y);
//Winter bands
if (value > 142)
{
//value += 100 / (((int)(y+1) % 100) + 1);
//int yInt = (int) y;
float factor = fabs(sin(noiseY * SCALE));
const float SNOW_AMOUNT = 1.9;
factor -= SNOW_AMOUNT - factor; //1.3
if (factor < 0) factor = 0;
const float SNOW_FALLOFF = 1000;
value += SNOW_FALLOFF * factor; //Winter climates
if (value > 254) value = 254;
if (value < 142) value = 142;
}
//TEMP DELETE ME!
//value = 150;
if (value > 185) //Mountains are on multiple layers
{
//Ground and onground are solid black
tiles[0][x + (y * CELL_WIDTH)].x = 9;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
tiles[1][x + (y * CELL_WIDTH)].x = 9;
tiles[1][x + (y * CELL_WIDTH)].y = 0;
//Above ground is elevation (the 0.04... maps 0 - 70 to 0 - 3)
float limitedValue = (value - 185) * 0.042857143;
limitedValue += 9;
tiles[2][x + (y * CELL_WIDTH)].x = (unsigned char)limitedValue;
tiles[2][x + (y * CELL_WIDTH)].y = 0;
}
else
{
//The 0.04.... maps 0 - 185 to 0-8
float limitedValue = value * 0.043243243;
tiles[0][x + (y * CELL_WIDTH)].x = (unsigned char)limitedValue;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
//Empty air for all other biomes
tiles[1][x + (y * CELL_WIDTH)].x = 255;
tiles[1][x + (y * CELL_WIDTH)].y = 255;
tiles[2][x + (y * CELL_WIDTH)].x = 255;
tiles[2][x + (y * CELL_WIDTH)].y = 255;
}
}
}
std::cout << "Done generating " << tiles.size() << " of " << NUM_LAYERS << " layers addr " << &tiles[0] << " \n";
break;
default:
std::cout << algorithm << " is not a valid algorithm (Cell.generate())\n";
break;
}
calculateDifficulty();
generated = true;
}
//Wrapper function to simplex noise lib
float scaledOctaveNoise3d(float octaves, float persistence, float scale, float x, float y, float z)
{
return scaled_octave_noise_3d(octaves, persistence, scale, x, y, z);
}
#endif

+ 41
- 0
src/world/noiseGeneration.hpp View File

@ -0,0 +1,41 @@
#ifndef NOISEGENERATION_HPP
#define NOISEGENERATION_HPP
#include <base2.0/ept/eptParser.hpp>
#include "../utilities/simplexnoise.h"
#include "coord.hpp"
//Settings to tell the terrain generation algorithm how to convert from
//noise values to Tiles
struct TileConversionSettings
{
};
//Settings for the terrain generation algorithm
struct TerrainGenSettings
{
int algorithm; //Which algorithm to use (TODO: Make enum)
float seed; //Since seed is just put in Z, it can be float
float positionScale; //Points are multiplied by this value before
//passed to the noise function
float octaves; //Number of octaves of noise to use
float persistence; //How much persistence between octaves of noise
//Settings for how to convert from simplex value to tile
TileConversionSettings tileConversionSettings;
eptFile* spec; //The spec where this information came from
};
//Creates a TerrainGenSettings from a .ept spec.
TerrainGenSettings createTerrainGenSettingsFromSpec(eptFile* spec, float seed);
//Wrapper funcs for simplex noise (TODO: MOVE TO BASE, DAMMIT!)
float scaledOctaveNoise3d(float octaves, float persistence, float scale, float x, float y, float z);
//Generate a single Cell's tiles
void generateCellTerrain(CellIndex cellIndex, std::vector<std::vector<tile> >* tiles, TerrainGenSettings* terrainGenSettings);
#endif

+ 135
- 0
src/world/terrainGeneration.cpp View File

@ -0,0 +1,135 @@
#ifndef NOISEGENERATION_CPP
#define NOISEGENERATION_CPP
#include "noiseGeneration.hpp"
void getValueAt(
void generateCellTerrain(int worldID, int seed, int algorithm, std::vector<std::vector<tile> >* cellTiles)
{
//I doubt there will be very many, so I'll just put it in switch
switch (algorithm)
{
//Simplex noise world; expects 0-255 colors (terrain.png); no biomes
case 2:
for (int y = 0; y < CELL_HEIGHT; ++y)
{
for (int x = 0; x < CELL_WIDTH; ++x)
{
float noiseX = x + (CELL_WIDTH * cellID.x);
float noiseY = y + (CELL_HEIGHT * cellID.y);
noiseX /= 2; //TODO: Raise this value for more accurate floats far away?
noiseY /= 2;
const float SCALE = 0.001;
//TODO: Put all these values in a text file
float value = scaled_octave_noise_3d(10, 0.55, SCALE, 0, 255, noiseX, noiseY, seed);
//Winter bands
if (value > 142)
{
//value += 100 / (((int)(y+1) % 100) + 1);
//int yInt = (int) y;
float factor = fabs(sin(noiseY * SCALE));
const float SNOW_AMOUNT = 1.9;
factor -= SNOW_AMOUNT - factor; //1.3
if (factor < 0) factor = 0;
const float SNOW_FALLOFF = 1000;
value += SNOW_FALLOFF * factor; //Winter climates
if (value > 254) value = 254;
if (value < 142) value = 142;
}
//TEMP DELETE ME!
//value = 150;
if (value > 185) //Mountains are on multiple layers
{
//Ground and onground are solid black
tiles[0][x + (y * CELL_WIDTH)].x = 185;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
tiles[1][x + (y * CELL_WIDTH)].x = 185;
tiles[1][x + (y * CELL_WIDTH)].y = 0;
//Above ground is elevation
tiles[2][x + (y * CELL_WIDTH)].x = value;
tiles[2][x + (y * CELL_WIDTH)].y = 0;
}
else
{
tiles[0][x + (y * CELL_WIDTH)].x = value;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
tiles[1][x + (y * CELL_WIDTH)].x = 255;
tiles[1][x + (y * CELL_WIDTH)].y = 255;
tiles[2][x + (y * CELL_WIDTH)].x = 255;
tiles[2][x + (y * CELL_WIDTH)].y = 255;
}
}
}
std::cout << "Done generating " << tiles.size() << " of " << NUM_LAYERS << " layers addr " << &tiles[0] << " \n";
break;
//Simplex noise (no biome); limited colors (3 for each range)
case 3:
for (int y = 0; y < CELL_HEIGHT; ++y)
{
for (int x = 0; x < CELL_WIDTH; ++x)
{
float noiseX = x + (CELL_WIDTH * cellID.x);
float noiseY = y + (CELL_HEIGHT * cellID.y);
noiseX /= 2; //TODO: Raise this value for more accurate floats far away?
noiseY /= 2;
const float SCALE = 0.001;
//TODO: Put all these values in a text file
float value = scaled_octave_noise_3d(10, 0.55, SCALE, 0, 255, noiseX, noiseY, seed);
//Winter bands
if (value > 142)
{
//value += 100 / (((int)(y+1) % 100) + 1);
//int yInt = (int) y;
float factor = fabs(sin(noiseY * SCALE));
const float SNOW_AMOUNT = 1.9;
factor -= SNOW_AMOUNT - factor; //1.3
if (factor < 0) factor = 0;
const float SNOW_FALLOFF = 1000;
value += SNOW_FALLOFF * factor; //Winter climates
if (value > 254) value = 254;
if (value < 142) value = 142;
}
//TEMP DELETE ME!
//value = 150;
if (value > 185) //Mountains are on multiple layers
{
//Ground and onground are solid black
tiles[0][x + (y * CELL_WIDTH)].x = 9;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
tiles[1][x + (y * CELL_WIDTH)].x = 9;
tiles[1][x + (y * CELL_WIDTH)].y = 0;
//Above ground is elevation (the 0.04... maps 0 - 70 to 0 - 3)
float limitedValue = (value - 185) * 0.042857143;
limitedValue += 9;
tiles[2][x + (y * CELL_WIDTH)].x = (unsigned char)limitedValue;
tiles[2][x + (y * CELL_WIDTH)].y = 0;
}
else
{
//The 0.04.... maps 0 - 185 to 0-8
float limitedValue = value * 0.043243243;
tiles[0][x + (y * CELL_WIDTH)].x = (unsigned char)limitedValue;
tiles[0][x + (y * CELL_WIDTH)].y = 0;
//Empty air for all other biomes
tiles[1][x + (y * CELL_WIDTH)].x = 255;
tiles[1][x + (y * CELL_WIDTH)].y = 255;
tiles[2][x + (y * CELL_WIDTH)].x = 255;
tiles[2][x + (y * CELL_WIDTH)].y = 255;
}
}
}
std::cout << "Done generating " << tiles.size() << " of " << NUM_LAYERS << " layers addr " << &tiles[0] << " \n";
break;
default:
std::cout << algorithm << " is not a valid algorithm (Cell.generate())\n";
break;
}
calculateDifficulty();
generated = true;
}
//Wrapper function to simplex noise lib
float scaledOctaveNoise3d(float octaves, float persistence, float scale, float x, float y, float z)
{
return scaled_octave_noise_3d(octaves, persistence, scale, x, y, z);
}
#endif

+ 8
- 0
src/world/terrainGeneration.hpp View File

@ -0,0 +1,8 @@
#ifndef NOISEGENERATION_HPP
#define NOISEGENERATION_HPP
#include "../utilities/simplexnoise.h"
#include "coord.hpp"
//Wrapper funcs for simplex noise
float scaledOctaveNoise3d(float octaves, float persistence, float scale, float x, float y, float z);
#endif

+ 1
- 1
src/world/world.cpp View File

@ -10,7 +10,7 @@
//Where world should search for itself and its files
const std::string WORLDS_PATH = "worlds/";
//Tells cell which world generation algorithm to use to make its tiles
const int WORLD_GEN_ALGORITHM = 3;
const int WORLD_GEN_ALGORITHM = 2;
const unsigned int MAX_INTERSECTING_CELLS = 10;
const int UPDATE_CLOSE_DISTANCE_X = 2048;
const int UPDATE_CLOSE_DISTANCE_Y = 2048;


Loading…
Cancel
Save