Cuberite
A lightweight, fast and extensible game server for Minecraft
VoronoiMap.h
Go to the documentation of this file.
1 
2 // VoronoiMap.h
3 
4 // Declares the cVoronoiMap class that implements a Voronoi algorithm over a noise to produce a map
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "Noise/Noise.h"
13 
14 
15 
16 
17 
19 {
20 public:
21  cVoronoiMap(int a_Seed, int a_CellSize = 128, int a_JitterSize = 128);
22 
24  void SetCellSize(int a_CellSize);
25 
27  void SetJitterSize(int a_JitterSize);
28 
32  void SetOddRowOffset(int a_OddRowOffset);
33 
35  int GetValueAt(int a_X, int a_Y);
36 
39  int GetValueAt(int a_X, int a_Y, int & a_MinDistance);
40 
43  int GetValueAt(
44  int a_X, int a_Y, // Coords to query
45  int & a_NearestSeedX, int & a_NearestSeedY, // Coords of the closest cell's seed
46  int & a_MinDist2 // Distance to the second closest cell's seed
47  );
48 
50  void FindNearestSeeds(
51  int a_X, int a_Y,
52  int & a_NearestSeedX, int & a_NearestSeedY,
53  int & a_SecondNearestSeedX, int & a_SecondNearestSeedY
54  );
55 
56 protected:
61 
64 
68 
73 
76 
79 
81  int m_SeedX[5][5];
82 
84  int m_SeedZ[5][5];
85 
86 
89  void UpdateCell(int a_CellX, int a_CellZ);
90 } ;
91 
92 
93 
94 
Definition: Noise.h:20
int m_CurrentCellZ
The Z coordinate of the currently cached cell neighborhood.
Definition: VoronoiMap.h:78
int m_SeedX[5][5]
The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords.
Definition: VoronoiMap.h:81
void SetCellSize(int a_CellSize)
Sets both the cell size and jitter size used for generating the Voronoi seeds.
Definition: VoronoiMap.cpp:29
int m_CellSize
Size of the Voronoi cells (avg X / Y distance between the seeds).
Definition: VoronoiMap.h:63
int m_JitterSize
The amount that the cell seeds may be offset from the grid.
Definition: VoronoiMap.h:67
void FindNearestSeeds(int a_X, int a_Y, int &a_NearestSeedX, int &a_NearestSeedY, int &a_SecondNearestSeedX, int &a_SecondNearestSeedY)
Finds the nearest and second nearest seeds, returns their coords.
Definition: VoronoiMap.cpp:131
cVoronoiMap(int a_Seed, int a_CellSize=128, int a_JitterSize=128)
Definition: VoronoiMap.cpp:13
void SetJitterSize(int a_JitterSize)
Sets the jitter size.
Definition: VoronoiMap.cpp:42
int m_CurrentCellX
The X coordinate of the currently cached cell neighborhood.
Definition: VoronoiMap.h:75
int m_SeedZ[5][5]
The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords.
Definition: VoronoiMap.h:84
void UpdateCell(int a_CellX, int a_CellZ)
Updates the cached cell seeds to match the specified cell.
Definition: VoronoiMap.cpp:183
void SetOddRowOffset(int a_OddRowOffset)
Sets the offset that is added to each odd row of cells.
Definition: VoronoiMap.cpp:51
cNoise m_Noise2
Definition: VoronoiMap.h:59
int m_OddRowOffset
The constant amount that the cell seeds of every odd row will be offset from the grid.
Definition: VoronoiMap.h:72
cNoise m_Noise3
Definition: VoronoiMap.h:60
cNoise m_Noise1
The noise used for generating Voronoi seeds.
Definition: VoronoiMap.h:58
int GetValueAt(int a_X, int a_Y)
Returns the value in the cell into which the specified point lies.
Definition: VoronoiMap.cpp:60