Skip to content

Commit

Permalink
Initial noisemap implementation
Browse files Browse the repository at this point in the history
Base noisemap class, with random and combination
noisemaps inheriting from.
  • Loading branch information
samuelsleight committed Sep 9, 2013
1 parent df70a5c commit 83194f8
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 600 deletions.
1 change: 0 additions & 1 deletion premake4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ project "worldgen"
links { "noise" }
objdir "build/obj"
buildoptions { "-std=c++11" }
defines { "WG_BUILD_OPS" }

configuration "debug"
flags { "Symbols", "ExtraWarnings" }
Expand Down
62 changes: 0 additions & 62 deletions src/constraint.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions src/generator.cpp

This file was deleted.

58 changes: 0 additions & 58 deletions src/inc/constraint.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions src/inc/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define WG_NS namespace wg {
#define WG_NS_END }

#define WG_DEF_CHUNK 20

#define WG_DEF_SEED "0"
#define WG_DEF_GRID 1
#define WG_DEF_OCTAVES noise::module::DEFAULT_PERLIN_OCTAVE_COUNT
Expand Down
53 changes: 0 additions & 53 deletions src/inc/generator.hpp

This file was deleted.

101 changes: 41 additions & 60 deletions src/inc/noisemap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,46 @@
#ifndef WG_NOISEMAP_HPP
#define WG_NOISEMAP_HPP

#include <memory>
#include <vector>
#include <string>
#include <vector>
#include <utility>

#include "defines.hpp"
#include "generator.hpp"
#include <noise/module/perlin.h>

#include <noise/noise.h>
#include "defines.hpp"

WG_NS

class NoiseMap : public std::enable_shared_from_this<NoiseMap> {
class World;

class NoiseMap {
protected:
NoiseMap(bool combination);

public:
typedef std::shared_ptr<NoiseMap> Ptr;
bool isCombination() { return combination; }
bool isGenerated() { return generated; }

static Ptr create() { return Ptr(new NoiseMap()); }
static Ptr combination() { return Ptr(new NoiseMap(true)); }
double getValue(int x, int y) { return noiseVals[y][x]; }
std::vector<std::vector<double>> getValues() { return noiseVals; }

private:
bool combination, generated;
std::vector<std::vector<double>> noiseVals;

~NoiseMap();
}; // class NoiseMap;

Ptr setSeed(std::string seed) { this->seed = seed; return shared_from_this(); }
Ptr setGridSize(double value) { this->gridSizeX = value; this->gridSizeY = value; return shared_from_this(); }
Ptr setGridSize(double width, double height) { this->gridSizeX = width; this->gridSizeY = height; return shared_from_this(); }
Ptr setGridWidth(double value) { this->gridSizeX = value; return shared_from_this(); }
Ptr setGridHeight(double value) { this->gridSizeY = value; return shared_from_this(); }
Ptr setOctaves(int value) { this->octaves = value; return shared_from_this(); }
Ptr setFrequency(double value) { this->frequency = value; return shared_from_this(); }
Ptr setPersistence(double value) { this->persistence = value; return shared_from_this(); }
Ptr setLacunarity(double value) { this->lacunarity = value; return shared_from_this(); }
class RandomNoiseMap : public NoiseMap {
public:
RandomNoiseMap* setSeed(std::string seed) { this->seed = seed; return this; }
RandomNoiseMap* setGridSize(double value) { this->gridSizeX = value; this->gridSizeY = value; return this; }
RandomNoiseMap* setGridSize(double width, double height) { this->gridSizeX = width; this->gridSizeY = height; return this; }
RandomNoiseMap* setGridWidth(double value) { this->gridSizeX = value; return this; }
RandomNoiseMap* setGridHeight(double value) { this->gridSizeY = value; return this; }
RandomNoiseMap* setOctaves(int value) { this->octaves = value; return this; }
RandomNoiseMap* setFrequency(double value) { this->frequency = value; return this; }
RandomNoiseMap* setPersistence(double value) { this->persistence = value; return this; }
RandomNoiseMap* setLacunarity(double value) { this->lacunarity = value; return this; }

std::string getSeed() { return seed; }
double getGridWidth() { return gridSizeX; }
Expand All @@ -58,21 +69,11 @@ class NoiseMap : public std::enable_shared_from_this<NoiseMap> {
double getFrequency() { return frequency; }
double getPersistence() { return persistence; }
double getLacunarity() { return lacunarity; }
bool isGenerated() { return generated; }
bool isGenerated(int chunkWidth, int chunkHeight, int chunkX, int chunkY);

Ptr add(Ptr noiseMap, int factor);

Ptr generate(int width, int height, int chunkX = 0, int chunkY = 0);

double getValue(int x, int y) { return noiseVals[y][x]; }
std::vector<std::vector<double>> getValues() { return noiseVals; }

private:
friend class Constraint;
friend class World;

NoiseMap();
NoiseMap(bool combination);
RandomNoiseMap();

std::string seed;
double gridSizeX, gridSizeY;
Expand All @@ -81,41 +82,21 @@ class NoiseMap : public std::enable_shared_from_this<NoiseMap> {
double persistence;
double lacunarity;

bool isCombination;
std::vector<std::pair<Ptr, int>> combinations;
}; // class RandomNoiseMap : public NoiseMap;

void genNormal();
void genCombination();
class CombinationNoiseMap : public NoiseMap {
public:
CombinationNoiseMap* add(NoiseMap* mapToAdd, int factor);

bool generated;
private:
friend class World;

std::vector<std::vector<double>> noiseVals;
CombinationNoiseMap();

int chunkX, chunkY, chunkWidth, chunkHeight;
std::vector<std::pair<NoiseMap*, int>> combinations;

}; // class NoiseMap;
}; // class CombinationNoiseMap : public NoiseMap;

WG_NS_END

#include "constraint.hpp"

wg::Constraint operator<(wg::NoiseMap::Ptr lhs, double rhs);
wg::Constraint operator>(wg::NoiseMap::Ptr lhs, double rhs);

#ifdef WG_BUILD_OPS
#ifndef WG_IMP_NOISEMAP

wg::Constraint operator<(wg::NoiseMap::Ptr lhs, double rhs) {
return wg::Constraint(lhs, wg::Constraint::Type::LT, rhs);

} // Constraint operator<(NoiseMap::Ptr lhs, double rhs);

wg::Constraint operator>(wg::NoiseMap::Ptr lhs, double rhs) {
return wg::Constraint(lhs, wg::Constraint::Type::GT, rhs);

} // Constraint operator<(NoiseMap::Ptr lhs, double rhs);

#endif // WG_IMP_NOISEMAP
#endif // WG_BUILD_OPS

#endif // WG_NOISEMAP_HPP
Loading

0 comments on commit 83194f8

Please sign in to comment.