InstanceManager.h
1 /************************************************************
2 * (C) Voxel Farm Inc. 2015
3 */
4 
5 #pragma once
6 
7 #include "mapindex.h"
8 #include "BlockData.h"
9 #include "Biome.h"
10 #include <vector>
11 #include <map>
12 #include <string>
13 #include "VoxelLayer.h"
14 #include "ArchitectureManager.h"
15 #include "ExternalMutex.h"
16 
17 namespace VoxelFarm
18 {
20  const int MAX_INSTANCE_LOD = LEVELS;
22  const int MASTER_GENERATION_LEVEL = 10;
24  const int GENERATION_GRID_SIZE = 128;
25 
27  class ClassData
28  {
29  public:
31  short originX;
33  short originY;
35  short originZ;
37  short sizeX;
39  short sizeY;
41  short sizeZ;
42  unsigned int* data[MAX_INSTANCE_LOD];
44  unsigned int* indices[MAX_INSTANCE_LOD];
46  unsigned char* stream[MAX_INSTANCE_LOD];
50  short minX[MAX_INSTANCE_LOD];
52  short minY[MAX_INSTANCE_LOD];
54  short minZ[MAX_INSTANCE_LOD];
56  short maxX[MAX_INSTANCE_LOD];
58  short maxY[MAX_INSTANCE_LOD];
60  short maxZ[MAX_INSTANCE_LOD];
61 
62  bool vectorOverflow;
63  };
64 
66  struct InstanceData
67  {
69  int classId;
71  int x, y, z;
77  InstanceRotation rotationAngle;
78  };
79 
81  class CInstanceManager : public IVoxelLayer, public IMask
82  {
83  public:
85  virtual ~CInstanceManager(void);
86  protected:
87  Architecture::CArchitectureManager* architectureManager;
88  TVector<ClassData> classes;
89  TMap<CellId, TVector<int>> instances;
90  TMap<CellId, int*> instanceMap;
91  TVector<InstanceData> instanceData;
92  TMap<String, int> classMap;
93  TSet<CellId> generatedCells;
95  TSet<CellId> pendingCells;
96  private:
97  void addPendingCell(CellId cellId);
98  public:
100  int loadClassData(char* name, char* filename);
102  int loadClassData(VoxelFarm::IInputStream* reader, char* name, char* filename);
104  int loadClassDataRaw(const char* name, const char* data);
106  virtual void getContourData(
108  CellId cell,
110  ContourVoxelData* data,
112  bool& empty,
113  void* threadContext) override;
115  virtual void planJobs(Scene* scene) override;
117  virtual void runJobs() override;
118  virtual void* createThreadContext() override;
119  virtual void disposeThreadContext(void* threadContext) override;
120  virtual int getStatsContourId() override
121  {
122  return STAT_INSTANCES;
123  }
125  virtual int* generateInstances(CellId cell)
126  {
127  return NULL;
128  }
130  virtual double getMaskValue(double x, double y, double z) override;
131  };
132 
135  {
136  public:
137  CInstanceHeightMap(CHeightmap* heightmap, Architecture::CArchitectureManager* architectureManager);
138  ~CInstanceHeightMap(void);
139  private:
140  CHeightmap* heightmap;
141  public:
143  int* generateInstances(CellId cell);
144  };
145 
148  {
149  public:
150  CInstanceSimplexWorld(CSimplexWorld* simplexWorld, Architecture::CArchitectureManager* architectureManager);
151  ~CInstanceSimplexWorld(void);
152  public:
153  CSimplexWorld* simplexworld;
154  public:
156  int* generateInstances(CellId cell);
157  };
158 
159 }
virtual void runJobs() override
Processes pending generation requests. This is called by the contouring loop. Pending cells will be g...
unsigned char * stream[MAX_INSTANCE_LOD]
Buffer containing compressed data.
const int MAX_INSTANCE_LOD
Maximum cell level for which instances will be generated.
enum VoxelFarm::InstanceMirror_T InstanceMirror
Defines a rule for scattering instances.
unsigned int * indices[MAX_INSTANCE_LOD]
Buffer containing indices to compressed streams.
short sizeX
Voxel data size along X axis.
Contains all classes and functions for the VoxelFarm engine.
InstanceRotation rotationAngle
specify the rotation angle
An interface for a 3D mask. A mask can be used to control the application of other features...
Definition: VoxelLayer.h:581
virtual void * createThreadContext() override
The voxel layer can use this method to return a structure that will be unique for each calling thread...
virtual int getStatsContourId() override
Returns the stats ID to be used for measuring performance of the getContourData() method...
virtual void disposeThreadContext(void *threadContext) override
Destroys the specified thread context.
Architecture system. It keeps a list of entities, their classes and the mesh instances they have prod...
short sizeZ
Voxel data size along Z axis.
int * generateInstances(CellId cell)
Runs planting rules over one cell.
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
Definition: mapindex.h:23
virtual double getMaskValue(double x, double y, double z) override
Retrieves a mask value based on whether there are instances in that coordinate.
Cells Scene
A Scene is a set of cells.
Definition: scene.h:12
short originX
Offset to the center of the voxel data in the X axis.
An interface for a voxel layer. By implementing this interface, very different modules can contribute...
Definition: VoxelLayer.h:535
Handles instanced voxel data.
int x
world coordinates in voxels for the instance
int * materialMap
A list of material re-mappings for the instance.
short originZ
Offset to the center of the voxel data in the Z axis.
short sizeY
Voxel data size along Y axis.
An interface to abstract reading resource data.
Definition: ResourceIO.h:6
Defines the world elevation at any XZ point. Contains a collection of biomes.
Definition: Biome.h:254
int * generateInstances(CellId cell)
Runs planting rules over one cell.
Information about one instance.
virtual int * generateInstances(CellId cell)
Runs planting rules over one cell.
int classId
Indentifier to the class for the instance.
virtual void planJobs(Scene *scene) override
Processes a scene to get new entities from it. This is called by the scene creation loop...
Handles instanced voxel data.
short originY
Offset to the center of the voxel data in the Y axis.
virtual void getContourData(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext) override
Returns voxel data for the specified cell (IVoxelLayer)
Defines a voxel class that can be instanced many times over.
const int MASTER_GENERATION_LEVEL
Level at which the instance index will be kept.
Handles instanced voxel data.
InstanceMirror mirrorAxis
specify the mirror axis of the instance
int streamSize[MAX_INSTANCE_LOD]
Number of bytes in the compressed stream.
int loadClassDataRaw(const char *name, const char *data)
Load data for one class out of the provided raw data.
const int GENERATION_GRID_SIZE
Resolution of an instance index page.
int loadClassData(char *name, char *filename)
Load data for one class.