Generator.h
1 /************************************************************
2 * (C) Voxel Farm Inc. 2015
3 */
4 
5 #pragma once
6 
7 #include <map>
8 #include <vector>
9 #include "mapindex.h"
10 #include "TileSet.h"
11 #include "BlockData.h"
12 #include "InstanceManager.h"
13 #include "ArchitectureManager.h"
14 #include "MaterialLibrary.h"
15 #include "ExternalMutex.h"
16 
17 namespace VoxelFarm
18 {
20  class CGenerator
21  {
22  public:
24  CGenerator();
25  CGenerator(const CGenerator& other);
26  ~CGenerator(void);
27  public:
29  void deleteLayerGroups();
31  void generate(CellId cell, ContourVoxelData* data, bool& empty, LODStats stats, int group = 0);
33  void getVoxel(CellId cell, int x, int y, int z, MaterialId& material, double& dx, double& dy, double& dz);
35  void planJobs(Scene* scene, LODStats stats);
36  void runJobs(LODStats stats);
37  void removeCachedData(CellId cell);
39  void addVoxelLayer(IVoxelLayer* layer, bool newGroup = false);
41  int layerGroupCount();
42  private:
43  TVector<TVector<int>*> layerGroups;
44  TVector<IVoxelLayer*> layers;
45  TVector<void*> threadContexts;
46  bool threadContextsCreated;
47  public:
48  TMap<CellId, ContourVoxelData*> dataQueryCacheIndex;
49  protected:
50  struct LayerCache
51  {
52  int topLayer;
53  CellId cell;
54  ContourVoxelData data;
55  };
56  protected:
57  class CCache
58  {
59  public:
60  int cachePos;
61  int cacheSize;
62  LayerCache* layers;
63  ExternalMutex::Mutex cacheLock;
64  public:
65  CCache(int size);
66  ~CCache();
67  };
68  CCache* cache;
69  bool ownsCache;
70  public:
71  void setCacheSize(int size);
72  };
73 
77  CMaterialLibrary* materialLibrary,
79  Algebra::Vector* result,
81  CGenerator* generator,
83  CellId cell, int x, int y, int z
84  );
85 }
void planJobs(Scene *scene, LODStats stats)
Removes any generation cached data for the specified cell. The getVoxel function may be required to r...
Combines several voxel layers into the final dataset sent to the contouring phase.
Definition: Generator.h:20
CGenerator()
Constructs the Generator object.
int getGeneratorIntersections(CMaterialLibrary *materialLibrary, Algebra::Vector *result, CGenerator *generator, CellId cell, int x, int y, int z)
Returns all triangles that intercept a voxel.
Contains all classes and functions for the VoxelFarm engine.
Contains all materials available in the system.
int layerGroupCount()
It holds the number of groups of layers.
A 3D Vector.
Definition: Vector.h:34
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
Definition: mapindex.h:23
Cells Scene
A Scene is a set of cells.
Definition: scene.h:12
An interface for a voxel layer. By implementing this interface, very different modules can contribute...
Definition: VoxelLayer.h:535
void getVoxel(CellId cell, int x, int y, int z, MaterialId &material, double &dx, double &dy, double &dz)
Retrieves data for a given voxel.
void deleteLayerGroups()
deletes the layer groups
StatTracker LODStats[LEVELS][STAT_NULL]
Used to track stats across all LOD.
Definition: VoxelLayer.h:530
void addVoxelLayer(IVoxelLayer *layer, bool newGroup=false)
Adds a new group of layers.
void generate(CellId cell, ContourVoxelData *data, bool &empty, LODStats stats, int group=0)
Loads and mixes voxel data from different sources and places it in the specified buffer.