3 #include "VoxelLayer.h"
6 #include "ExternalMutex.h"
16 virtual void getHeights(
double xo,
double zo,
double xsize,
double zsize,
double* heights,
bool* ocean,
int size,
int pageX,
int pageZ,
int pageSize) = 0;
33 double xsize,
double zsize,
63 int pageX = x/pageScale;
64 int pageZ = z/pageScale;
65 bool& pageLoaded = pageIndex[pageZ*pageIndexSize + pageX];
68 heightmap->getHeights(xo, zo, xsize, zsize, heights, oceanMap, size, pageX*pageScale, pageZ*pageScale, pageSize);
71 double height = heights[z*size + x];
77 int pageX = x/pageScale;
78 int pageZ = z/pageScale;
79 bool& pageLoaded = pageIndex[pageZ*pageIndexSize + pageX];
82 heightmap->getHeights(xo, zo, xsize, zsize, heights, oceanMap, size, pageX*pageScale, pageZ*pageScale, pageSize);
85 bool ocean = oceanMap[z*size + x];
88 static inline double biLinearInterpolate(
double p[2][2],
double x,
double y)
90 double h0 = p[0][0] + x*(p[1][0] - p[0][0]);
91 double h1 = p[0][1] + x*(p[1][1] - p[0][1]);
92 return h0 + y*(h1 - h0);
95 inline double getWaterHeight(
double x,
double z,
int pageXc,
int pageZc,
double pageSize)
97 double tileXd = (x - pageXc*pageSize)*this->size/pageSize;
98 double tileZd = (z - pageZc*pageSize)*this->size/pageSize;
99 int tileX = (int)tileXd;
100 int tileZ = (int)tileZd;
101 if (tileX < 0 || tileX >= this->size || tileZ < 0 || tileZ >= this->size)
106 int tileIdx = tileZ*this->size + tileX;
107 double waterHeight = this->waterHeight[tileIdx];
109 bool hasValue = waterHeight > 0.0;
111 for (
int iTileZ = 0; iTileZ < 2; iTileZ++)
112 for (
int iTileX = 0; iTileX < 2; iTileX++)
114 if (tileX + iTileX < 0 || tileX + iTileX >= this->size ||
115 tileZ + iTileZ < 0 || tileZ + iTileZ >= this->size)
117 k[iTileX][iTileZ] = waterHeight;
121 int idx = (tileZ + iTileZ)*this->size + tileX + iTileX;
122 double h = this->waterHeight[idx];
123 k[iTileX][iTileZ] = h;
124 hasValue |= (h > 0.0);
133 waterHeight = biLinearInterpolate(k, tileXd - tileX, tileZd - tileZ);
136 inline double getRiverDensity(
double x,
double z,
int pageXc,
int pageZc,
double pageSize)
138 double tileXd = (x - pageXc*pageSize)*this->size/pageSize;
139 double tileZd = (z - pageZc*pageSize)*this->size/pageSize;
140 int tileX = (int)tileXd;
141 int tileZ = (int)tileZd;
142 if (tileX < 0 || tileX >= this->size || tileZ < 0 || tileZ >= this->size)
147 int tileIdx = tileZ*this->size + tileX;
148 double waterHeight = (this->riverMap[tileIdx])? 1.0 : 0;
151 for (
int iTileZ = 0; iTileZ < 2; iTileZ++)
152 for (
int iTileX = 0; iTileX < 2; iTileX++)
154 if (tileX + iTileX < 0 || tileX + iTileX >= this->size ||
155 tileZ + iTileZ < 0 || tileZ + iTileZ >= this->size)
157 k[iTileX][iTileZ] = waterHeight;
161 int idx = (tileZ + iTileZ)*this->size + tileX + iTileX;
162 k[iTileX][iTileZ] = (this->riverMap[idx])? 1.0 : 0;
166 waterHeight = biLinearInterpolate(k, tileXd - tileX, tileZd - tileZ);
179 return pageIndex[z*pageIndexSize + x];
190 virtual void getHeights(
double xo,
double zo,
double xsize,
double zsize,
double* heights,
bool* ocean,
int size,
int pageX,
int pageZ,
int pageSize);
200 virtual void getHeights(
double xo,
double zo,
double xsize,
double zsize,
double* heights,
bool* ocean,
int size,
int pageX,
int pageZ,
int pageSize);
208 static const int TILE_LOD = 14;
210 static const int TILE_SIZE = 512;
213 static const int PAGE_SIZE = 32;
219 TMap<CellId, CHydroTile*> pages;
221 TSet<CellId> pendingCells;
222 TVector<CellId> pendingQueue;
223 MaterialId waterMaterial;
228 CHydroTile* getTile(
int level,
int xc,
int yc,
int zc);
238 void* threadContext)
override;
242 virtual void runJobs()
override;
261 virtual void getOceanHeight(
CellId cell,
double* heights,
int size,
bool& empty,
bool& full) = 0;
267 static const int OCEAN_PAGE_SIZE =
BLOCK_SIZE;
271 MaterialId waterMaterial;
281 void* threadContext)
override;
299 virtual void getExtents(
301 double& x0,
double& z0,
double& x1,
double& z1,
303 int& xsize,
int& zsize,
305 double& seaLevel) = 0;
312 virtual void getExtents(
314 double& x0,
double& z0,
double& x1,
double& z1,
320 double& springLevel) = 0;
340 virtual void getWaterHeight(
CellId cell,
double* heights,
int size,
bool& empty,
bool& full) = 0;
347 static const int WATER_PAGE_SIZE =
BLOCK_SIZE;
351 MaterialId waterMaterial;
361 void* threadContext)
override;
void computeStaticWater(IStaticWaterDataExtents *source, bool *oceanMask, IHydroHeightmapPage *heightmap, double *heights, bool *lakeMask)
CHydroTile(int size, int pageSize, IHydroHeightmapPage *heightmap, double xo, double zo, double xsize, double zsize, double seaLevel, double springLevel)
virtual void runJobs() override
Processes pending generation requests. This is called by the contouring loop. Pending cells will be g...
virtual void disposeThreadContext(void *threadContext)
Destroys the specified thread context.
Contains all classes and functions for the VoxelFarm engine.
virtual void getContourData(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext) override
Returns voxel data for the specified cell (IVoxelLayer)
An interface for a 3D mask. A mask can be used to control the application of other features...
const int BLOCK_SIZE
Actual number of voxels in one Cell Dim once the margin is considered.
void computeOceanMask(IOceanDataExtents *source, double *heights, bool *mask)
double getWaterHeight(double x, double z, int pageXc, int pageZc, double pageSize)
Returns the water level in any point inside the tile.
virtual void * createThreadContext()
The voxel layer can use this method to return a structure that will be unique for each calling thread...
This class is used to request the ocean mask for a given area (in world coordinates) ...
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
Cells Scene
A Scene is a set of cells.
virtual void planJobs(Scene *scene) override
Processes a scene to get new entities from it. This is called by the scene creation loop...
An interface for a voxel layer. By implementing this interface, very different modules can contribute...
virtual void * createThreadContext()
The voxel layer can use this method to return a structure that will be unique for each calling thread...
virtual void disposeThreadContext(void *threadContext)
Destroys the specified thread context.
This class is used to request the static water mask for a given area (in world coordinates) ...
It generates the water information for an area.
virtual double getMaskValue(double x, double y, double z)
Returns the mask strength value for the specified 3D point. The value must be between 0 and 1...
virtual void getContourData(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext) override
Returns voxel data for the specified cell (IVoxelLayer)
Defines the world elevation at any XZ point. Contains a collection of biomes.
bool & getPage(int x, int z)
Calculates the page index for a given cell coordinates.
bool isOcean(int x, int z)
Returns if a cell in the tile is in the ocean.
virtual int getStatsContourId() override
Returns the stats ID to be used for measuring performance of the getContourData() method...
virtual int getStatsContourId() override
Returns the stats ID to be used for measuring performance of the getContourData() method...
virtual int getStatsContourId() override
Returns the stats ID to be used for measuring performance of the getContourData() method...
double getHeight(int x, int z)
virtual void getContourData(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext) override
Returns voxel data for the specified cell (IVoxelLayer)
void generate(CellId masterCell)
Generates the water information for the tile.
void computeOceanHeightmap(IOceanDataExtents *source, int margin, bool *oceanMask, unsigned short *heights)