Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cVoronoiMap Class Reference

#include <VoronoiMap.h>

Collaboration diagram for cVoronoiMap:
Collaboration graph
[legend]

Public Member Functions

 cVoronoiMap (int a_Seed, int a_CellSize=128, int a_JitterSize=128)
 
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. More...
 
int GetValueAt (int a_X, int a_Y)
 Returns the value in the cell into which the specified point lies. More...
 
int GetValueAt (int a_X, int a_Y, int &a_MinDistance)
 Returns the value in the cell into which the specified point lies, and the distance to the nearest Voronoi seed. More...
 
int GetValueAt (int a_X, int a_Y, int &a_NearestSeedX, int &a_NearestSeedY, int &a_MinDist2)
 Returns the value in the cell into which the specified point lies, and the distances to the 2 nearest Voronoi seeds. More...
 
void SetCellSize (int a_CellSize)
 Sets both the cell size and jitter size used for generating the Voronoi seeds. More...
 
void SetJitterSize (int a_JitterSize)
 Sets the jitter size. More...
 
void SetOddRowOffset (int a_OddRowOffset)
 Sets the offset that is added to each odd row of cells. More...
 

Protected Member Functions

void UpdateCell (int a_CellX, int a_CellZ)
 Updates the cached cell seeds to match the specified cell. More...
 

Protected Attributes

int m_CellSize
 Size of the Voronoi cells (avg X / Y distance between the seeds). More...
 
int m_CurrentCellX
 The X coordinate of the currently cached cell neighborhood. More...
 
int m_CurrentCellZ
 The Z coordinate of the currently cached cell neighborhood. More...
 
int m_JitterSize
 The amount that the cell seeds may be offset from the grid. More...
 
cNoise m_Noise1
 The noise used for generating Voronoi seeds. More...
 
cNoise m_Noise2
 
cNoise m_Noise3
 
int m_OddRowOffset
 The constant amount that the cell seeds of every odd row will be offset from the grid. More...
 
int m_SeedX [5][5]
 The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords. More...
 
int m_SeedZ [5][5]
 The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords. More...
 

Detailed Description

Definition at line 18 of file VoronoiMap.h.

Constructor & Destructor Documentation

◆ cVoronoiMap()

cVoronoiMap::cVoronoiMap ( int  a_Seed,
int  a_CellSize = 128,
int  a_JitterSize = 128 
)

Definition at line 13 of file VoronoiMap.cpp.

Member Function Documentation

◆ FindNearestSeeds()

void cVoronoiMap::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 at line 131 of file VoronoiMap.cpp.

◆ GetValueAt() [1/3]

int cVoronoiMap::GetValueAt ( int  a_X,
int  a_Y 
)

Returns the value in the cell into which the specified point lies.

Definition at line 60 of file VoronoiMap.cpp.

◆ GetValueAt() [2/3]

int cVoronoiMap::GetValueAt ( int  a_X,
int  a_Y,
int &  a_MinDistance 
)

Returns the value in the cell into which the specified point lies, and the distance to the nearest Voronoi seed.

Definition at line 70 of file VoronoiMap.cpp.

◆ GetValueAt() [3/3]

int cVoronoiMap::GetValueAt ( int  a_X,
int  a_Y,
int &  a_NearestSeedX,
int &  a_NearestSeedY,
int &  a_MinDist2 
)

Returns the value in the cell into which the specified point lies, and the distances to the 2 nearest Voronoi seeds.

Uses a cache.

Definition at line 82 of file VoronoiMap.cpp.

◆ SetCellSize()

void cVoronoiMap::SetCellSize ( int  a_CellSize)

Sets both the cell size and jitter size used for generating the Voronoi seeds.

Definition at line 29 of file VoronoiMap.cpp.

◆ SetJitterSize()

void cVoronoiMap::SetJitterSize ( int  a_JitterSize)

Sets the jitter size.

Clamps it to current cell size.

Definition at line 42 of file VoronoiMap.cpp.

◆ SetOddRowOffset()

void cVoronoiMap::SetOddRowOffset ( int  a_OddRowOffset)

Sets the offset that is added to each odd row of cells.

This offset makes the voronoi cells align to a non-grid. Clamps the value to [-m_CellSize, +m_CellSize].

Definition at line 51 of file VoronoiMap.cpp.

◆ UpdateCell()

void cVoronoiMap::UpdateCell ( int  a_CellX,
int  a_CellZ 
)
protected

Updates the cached cell seeds to match the specified cell.

Noop if cell pos already matches. Updates m_SeedX and m_SeedZ.

Definition at line 183 of file VoronoiMap.cpp.

Member Data Documentation

◆ m_CellSize

int cVoronoiMap::m_CellSize
protected

Size of the Voronoi cells (avg X / Y distance between the seeds).

Expected to be at least 2.

Definition at line 63 of file VoronoiMap.h.

◆ m_CurrentCellX

int cVoronoiMap::m_CurrentCellX
protected

The X coordinate of the currently cached cell neighborhood.

Definition at line 75 of file VoronoiMap.h.

◆ m_CurrentCellZ

int cVoronoiMap::m_CurrentCellZ
protected

The Z coordinate of the currently cached cell neighborhood.

Definition at line 78 of file VoronoiMap.h.

◆ m_JitterSize

int cVoronoiMap::m_JitterSize
protected

The amount that the cell seeds may be offset from the grid.

Expected to be at least 1 and less than m_CellSize.

Definition at line 67 of file VoronoiMap.h.

◆ m_Noise1

cNoise cVoronoiMap::m_Noise1
protected

The noise used for generating Voronoi seeds.

Definition at line 58 of file VoronoiMap.h.

◆ m_Noise2

cNoise cVoronoiMap::m_Noise2
protected

Definition at line 59 of file VoronoiMap.h.

◆ m_Noise3

cNoise cVoronoiMap::m_Noise3
protected

Definition at line 60 of file VoronoiMap.h.

◆ m_OddRowOffset

int cVoronoiMap::m_OddRowOffset
protected

The constant amount that the cell seeds of every odd row will be offset from the grid.

This allows us to have non-rectangular grids. Expected to be between -m_CellSize and +m_CellSize.

Definition at line 72 of file VoronoiMap.h.

◆ m_SeedX

int cVoronoiMap::m_SeedX[5][5]
protected

The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords.

Definition at line 81 of file VoronoiMap.h.

◆ m_SeedZ

int cVoronoiMap::m_SeedZ[5][5]
protected

The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords.

Definition at line 84 of file VoronoiMap.h.


The documentation for this class was generated from the following files: