2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// HeiGen.h
|
|
|
|
|
|
|
|
/*
|
|
|
|
Interfaces to the various height generators:
|
|
|
|
- cHeiGenFlat
|
|
|
|
- cHeiGenClassic
|
|
|
|
- cHeiGenBiomal
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-01-25 05:12:29 -05:00
|
|
|
#include "ComposableGenerator.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Noise.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cHeiGenFlat :
|
|
|
|
public cTerrainHeightGen
|
|
|
|
{
|
|
|
|
public:
|
2013-10-11 04:18:01 -04:00
|
|
|
cHeiGenFlat(void) : m_Height(5) {}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int m_Height;
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
// cTerrainHeightGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
2013-10-11 04:18:01 -04:00
|
|
|
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// A simple cache that stores N most recently generated chunks' heightmaps; N being settable upon creation
|
|
|
|
class cHeiGenCache :
|
|
|
|
public cTerrainHeightGen
|
|
|
|
{
|
|
|
|
public:
|
2013-10-11 04:18:01 -04:00
|
|
|
cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize); // Doesn't take ownership of a_HeiGenToCache
|
2012-06-14 09:06:06 -04:00
|
|
|
~cHeiGenCache();
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
// cTerrainHeightGen overrides:
|
2013-05-05 12:27:08 -04:00
|
|
|
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
2013-10-11 04:18:01 -04:00
|
|
|
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
2013-05-05 12:27:08 -04:00
|
|
|
|
2013-05-06 08:20:25 -04:00
|
|
|
/// Retrieves height at the specified point in the cache, returns true if found, false if not found
|
|
|
|
bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height);
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
protected:
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
cTerrainHeightGen & m_HeiGenToCache;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
struct sCacheData
|
|
|
|
{
|
|
|
|
int m_ChunkX;
|
|
|
|
int m_ChunkZ;
|
|
|
|
cChunkDef::HeightMap m_HeightMap;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
// To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data
|
|
|
|
int m_CacheSize;
|
|
|
|
int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array
|
|
|
|
sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used
|
|
|
|
|
|
|
|
// Cache statistics
|
|
|
|
int m_NumHits;
|
|
|
|
int m_NumMisses;
|
|
|
|
int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits)
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cHeiGenClassic :
|
|
|
|
public cTerrainHeightGen
|
|
|
|
{
|
|
|
|
public:
|
2013-10-11 04:18:01 -04:00
|
|
|
cHeiGenClassic(int a_Seed);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int m_Seed;
|
|
|
|
cNoise m_Noise;
|
|
|
|
float m_HeightFreq1, m_HeightAmp1;
|
|
|
|
float m_HeightFreq2, m_HeightAmp2;
|
|
|
|
float m_HeightFreq3, m_HeightAmp3;
|
|
|
|
|
|
|
|
float GetNoise(float x, float y);
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
// cTerrainHeightGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
2013-10-11 04:18:01 -04:00
|
|
|
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cHeiGenBiomal :
|
|
|
|
public cTerrainHeightGen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen) :
|
|
|
|
m_Noise(a_Seed),
|
|
|
|
m_BiomeGen(a_BiomeGen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
|
|
|
|
|
|
|
|
cNoise m_Noise;
|
|
|
|
cBiomeGen & m_BiomeGen;
|
|
|
|
|
|
|
|
// Per-biome terrain generator parameters:
|
|
|
|
struct sGenParam
|
|
|
|
{
|
|
|
|
float m_HeightFreq1, m_HeightAmp1;
|
|
|
|
float m_HeightFreq2, m_HeightAmp2;
|
|
|
|
float m_HeightFreq3, m_HeightAmp3;
|
|
|
|
float m_BaseHeight;
|
|
|
|
} ;
|
|
|
|
static const sGenParam m_GenParam[biNumBiomes];
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
// cTerrainHeightGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
2013-10-11 04:18:01 -04:00
|
|
|
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-22 16:12:04 -04:00
|
|
|
NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors);
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|