VoxelFarm::CClipmapView Class Reference

Represents a moving view within a world. Computes new scenes as the view moves. More...

#include <ClipmapView.h>

Classes

class  IEvents
 Events interface. More...
 
class  IRemoteView
 The IRemoteView interface allows the clipmap view object to request data for cells. The clipmap view will determine which new cells are required for the next scene and will request them using this interface. More...
 

Public Types

typedef void UpdateViewerState()
 Prototype for event callback to update viewer position. This is called right before the view is rendered. If desired this event can be used to query user input control right before rendering, so input lag is minimized.
 
typedef CCellDataCreateCellData(CellId cell)
 Prototype for event callback to create a celldata object. The client application must return a differe type of celldata object depending on the graphics API.
 
typedef TMap< CellId, CCellData * > CellDataCache
 Type definition for a map that allows caching CCellData objects.
 

Public Member Functions

 CClipmapView (CMaterialLibrary *materialLibrary, CGenerator *generator, CBlockData *blockData)
 
void enterCriticalSection ()
 Acquires the critical section for the data that is shared by all threads using the view.
 
void leaveCriticalSection ()
 Releases the critical section for the data that is shared by all threads using the view.
 
void disposeScene (Scene *old, Scene *current)
 Disposes a scene. Cells in the scene will be moved to the garbage list.
 
CCellDatagetNextCellToBake ()
 Returns the next cell to be processed by the host.
 
void notifyCellBaked (CCellData *cellData)
 Notifies the host has processed the cell.
 
CCellDatagetNextCellToBakeSeams ()
 Returns the next cell to have its seams processed by the host.
 
void notifyCellBakedSeams (CCellData *cellData)
 Notifies the host has processed seams for the cell.
 
CCellDatagetNextCellToDestroy ()
 Returns the next cell which its information has to be destroyed by the host.
 
void notifyCellDestroyed (CCellData *cellData)
 Notifies the host has destroyed the application data the cell.
 
bool cellIsEmpty (CellId cell)
 
bool sceneLoop (LODStats &stats)
 Performs a scene loop iteration, which discovers if a new scene is needed and proceeds to request it.
 
void recomputeScene ()
 
bool contourLoop (CGenerator *threadGenerator, ContourThreadContext *tc, CCellData::ThreadContext *tcCellData, LODStats stats)
 Performs a contour loop iteration. This will load the voxel data for pending Cells in the requested scene and build the corresponding CCellData objects.
 
void sceneFade (bool &sceneChanged)
 Morphs from the previous scene into the next.
 
void garbageCollect ()
 Performs garbage collection.
 
unsigned char * createVoxelOccupancyData (ContourVoxelData *data)
 Creates a leaner data structure to track voxel occupancy. Each voxel is stored in one bit.
 
void addBlock (LODStats &stats, int buildCursorSize, const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3], const int hitHint[3], TSet< CellId > &changedCells)
 Adds a block at the given edition coordinates.
 
void addBlock (LODStats &stats)
 Adds a block at the current edition coordinates.
 
void removeBlock (LODStats &stats, int buildCursorSize, const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3])
 Removes a block at the given edition coordinates.
 
void removeBlock (LODStats &stats)
 Removes a block at the current edition coordinates.
 
void repairBlock (LODStats &stats, int buildCursorSize, const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3])
 Erases a block at the given edition coordinates.
 
void repairBlock (LODStats &stats)
 Erases a block at the current edition coordinates.
 
void smoothBlock (const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3], int iterations, float blendWeight)
 Smooth block at the given edition coordinates.
 
void smoothBlock ()
 Smooth block at the current edition coordinates.
 
void addSmoothBlock ()
 Adds a smooth block at the current edition coordinates.
 
void stampModel (const double size[3], Algebra::Quaternion rotations, const double position[3], Architecture::CArchitectureManager *architectureManager, int moduleId, Architecture::CPaletteDesc *palette, Architecture::PaletteType type, IMeshStamMaterialSource *materials)
 Stamp a model from architecture. More...
 
void raiseBlock ()
 Raise block at the current edition coordinates.
 
void raiseBlock (const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3], int iterations, float blendWeight)
 Raise block at the given edition coordinates.
 
void processModifiedCells (const TSet< CellId > &modifiedCells, bool deleting=false)
 
void copyToClipboard (IClipboard *clipboard, CellId c1, int x1, int y1, int z1, CellId c2, int x2, int y2, int z2)
 Copy voxels to the Clipboard. More...
 
void pasteFromClipboard (IClipboard *clipboard, CellId c, int x, int y, int z)
 Paste voxels from clipboard into block layer. More...
 
void stampMesh (double worldPos[3], IMeshStampSource *mesh, IMeshStamMaterialSource *materials, const Algebra::Matrix &transform)
 It stamps a polygonal mesh into block layer. More...
 
void stampMesh (IMeshStampSource *mesh, IMeshStamMaterialSource *materials, const Algebra::Matrix &transform)
 It stamps a polygonal mesh into block layer at the cursor location. More...
 
void stampVoxels (double worldPos[3], unsigned int *data, int xsize, int ysize, int zsize, IMeshStamMaterialSource *materials)
 It stamps a block of voxels data into block layer. More...
 
void stampVoxels (unsigned int *data, int xsize, int ysize, int zsize, IMeshStamMaterialSource *materials)
 It stamps a block of voxels data into block layer at the cursor location. More...
 
void clearBoxArea (const double kernel[8][3], bool fullErase)
 Clears a box of voxels in the block layer.
 
void stampMesh (IMeshStampSource *mesh, Physics::CNoiseBrush *noise, Physics::CVoxelBuffer *nVoxBuffer, IMeshStamMaterialSource *materials, const Algebra::Matrix &transform)
 
void setLineOfSight (double x0, double y0, double z0, double x1, double y1, double z1)
 
void getViewPosition (double *p0, double *p1=nullptr) const
 Get the current camera position relative to the user's location & optional view target.
 
void getViewDirection (double dir[3]) const
 Get the current view direction.
 
void getViewWorldPosition (double pos[3]) const
 Get the current view position in world.
 
void getBuildCursorSize (int sizes[3]) const
 Get the current size of the build cursor.
 
VoxelFarm::Algebra::Vector getViewPosition () const
 Get the current camera position relative to the user's location.
 
VoxelFarm::Algebra::Vector getViewDirection () const
 Get the current view direction.
 
VoxelFarm::Algebra::Vector getViewWorldPosition () const
 Get the current view position in world.
 
void hitPosChanged ()
 Request the system to computes the location of the edition coordinates.
 
bool updateHitPos (BuildCursorMode buildCursorMode, const int buildCursorSizes[3], const double dir[3], const double hitPos[3], double hitNormal[3], CellId &cellHitId, int hitCell[3], int hitHint[3])
 Computes the location of the next block addition or removal.
 
void updateHitPos ()
 Computes the location of the next block addition or removal.
 
double getMeshHeight (double x, double y, double z, bool &approximated, int &material, int medium=0)
 Computes the vertical position using meshes. This is used to implement walking.
 
bool detectCollisionAABB (double boxcenter[3], double boxhalfsize[3])
 Detects collision of axis aligned bounding box against the view's geometry.
 
bool detectCollisionEllipsoid (double center[3], double radV, double radH, double pi[3], double push[3])
 Detects collision of axis aligned ellipsoid against the view's geometry.
 
void beginChanges ()
 Marks the start of an edition transaction. A call to undo() will restore to this state.
 
void endChanges ()
 Marks the end of an edition transaction.
 
void undo ()
 Reverts the last edition transaction.
 
void setRemoteView (IRemoteView *remoteView)
 Assigns the remote view interface handler.
 
void notifyRemoteCellsReady (CellId *cells, int count)
 Notifies the view data for some cells is ready.
 
void notifyRemoteCellsChanged (CellId *cells, int count)
 Notifies the view some cells have changed.
 
void setEvents (IEvents *events)
 Set event interface.
 
void updateOffsets ()
 
void beginFill ()
 It initializes the fill tool.
 
void updateFillScope ()
 It updates the fill scope based on the cursor position.
 
void endFill (IMeshStamMaterialSource *material)
 It ends the fill tool by stamping the designed box into a block layer.
 
double pitch ()
 Camera rotation over the X axis (-90 is UP)
 
void pitch (double ang)
 
double yaw ()
 Camera rotation over the Y axis.
 
void yaw (double ang)
 
double roll ()
 Camera rotation over the Z axis.
 
void roll (double ang)
 

Public Attributes

CMaterialLibrarymaterialLibrary
 Points to the material library to be used by the view.
 
CGeneratorgenerator
 Points to the generator object to be used by the view. This object is able to generate voxel data from a number of abstract layers (IVoxelLayer).
 
CBlockDatablockData
 Points to the an object that holds the user data. These are voxels that have been input by the user.
 
bool recomputing
 
UpdateViewerStateupdateViewerState
 Pointer to UpdateViewerState event callback.
 
CreateCellDatacreateCellData
 Create celldata object event callback.
 
CBillboardCache billboardCache
 A cache storage for billboards and material instances.
 
bool started
 Flags where the view has begun to produce scenes.
 
bool resolutionSwitch
 Flags a clipmap resolution switch is required.
 
int sceneResolution
 The current clipmap resolution.
 
int maxSceneResolution
 Desired clipmap resolution.
 
int lastSceneResolution
 Previous clipmap resolution.
 
bool firstLoad
 Signals whether the view has just loaded.
 
int radiusLOD0
 
bool compressMeshes
 
double speed
 Speed at which the view moves.
 
double heading
 The direction on which the viewer is moving.
 
bool moving
 Signals whether the viewer is moving or not.
 
bool approximatedPos
 Signals whether the vertical position is accurate, based on the best octree level possible.
 
double xpos
 Viewer coordinates along the X axis.
 
double ypos
 Viewer coordinates along the Y axis.
 
double zpos
 Viewer coordinates along the Z axis.
 
double xspeed
 
double yspeed
 
double zspeed
 
double xoffs
 Additional offset for Viewer coordinates along the X axis.
 
double yoffs
 Additional offset for Viewer coordinates along the Y axis.
 
double zoffs
 Additional offset for Viewer coordinates along the Z axis.
 
double zoom
 Zoom level.
 
double slopeDamp
 Dampenning to Viewer speed caused by high slope.
 
double lastXpos
 Previous position along the X axis.
 
double lastYpos
 Previous position along the Y axis.
 
double lastZpos
 Previous position along the Z axis.
 
double time
 Time vector (used for animating grass)
 
double sceneBounds [2][3]
 
double nextSceneBounds [2][3]
 
MapIndexmapIndex
 Current MapIndex object in use.
 
Scenescene
 Current Scene.
 
ScenenewScene
 A new Scene was just built.
 
ScenenextScene
 The next Scene down the pipeline.
 
double sceneXpos
 X coordinates for the current scene.
 
double sceneYpos
 Y coordinates for the current scene.
 
double sceneZpos
 Z coordinates for the current scene.
 
double sceneFadeIn
 Scene morph progress.
 
SceneoldScene
 Previous Scene that was just replaced.
 
double oldSceneXpos
 X coordinates for previous Scene.
 
double oldSceneYpos
 Y coordinates for previous Scene.
 
double oldSceneZpos
 Z coordinates for previous Scene.
 
unsigned int sceneTime
 Stats about scene build time.
 
unsigned int sceneCnt
 Number of scences built.
 
unsigned int renderTime
 Time spent rendering.
 
unsigned int renderCnt
 Number of frames rendered.
 
ExternalMutex::Mutex dataLock
 Critical section to allow multiple threads to collaborate loading and disposing Scenes.
 
CellDataCache cellCache
 A cache of recently built and used CCellData objects.
 
TMap< CellId, unsigned char * > voxelCache
 Voxel occupancy cache.
 
TDeque< CellIddownloadQueue
 List of Cells to be downloaded accordint to priority.
 
TSet< CellIddownloadQueueSet
 Set of Cells to be downloaded accordint to priority.
 
TDeque< CellIdprocessQueue
 List of Cells to be processed.
 
TVector< CCellData * > bakeQueue
 List of Cells to be baked.
 
TSet< CellIdpendingCells
 List of Cells int the downloading/generation and processing pipeline.
 
TSet< CellIdemptyCells
 Set of Cells the engine knows they are empty.
 
TSet< CCellData * > garbageCells
 Set of Cells soon to be disposed unless they are recalled.
 
TSet< CCellData * > deadMeat
 Set of Cells to be disposed.
 
TSet< CCellData * > disposedCells
 
TSet< CellIdseamCreateQueue
 
TSet< CellIdseamInProgress
 
TVector< CCellData * > seamBakeQueue
 
TSet< CellIdseamPendingCells
 
TSet< CellIdseamRequested
 
TSet< CellIdpendingEditionCells
 List of Cells queued for edition purposes.
 
TSet< CellIdeditionInProgress
 
TSet< CellIdpendingBakeEditionCells
 
int scenePendingTotal
 Amount of Cells pending processing.
 
int lastCellGeneration
 Generation of last batch of Cells.
 
bool invalidateRenderCache
 Signal any rendering caching should be invalidated.
 
bool cellsPendingUpdate
 Signal there are cells pending an update. This often happens when the user builds or carves cells.
 
bool cellsPendingBaking
 
double lineOfSightX0
 Line of sight start X coordinate.
 
double lineOfSightY0
 Line of sight start Y coordinate.
 
double lineOfSightZ0
 Line of sight start Z coordinate.
 
double lineOfSightX1
 Line of sight end X coordinate.
 
double lineOfSightY1
 Line of sight end Y coordinate.
 
double lineOfSightZ1
 Line of sight end Z coordinate.
 
int hitPosXi
 Edition point X coordinate in voxels.
 
int hitPosYi
 Edition point Y coordinate in voxels.
 
int hitPosZi
 Edition point Z coordinate in voxels.
 
VoxelHitInfo hitInfo
 Voxel targeted for build/carve.
 
int buildMaterial
 Material that will be added at the edition point.
 
bool snapToGrid
 
BuildCursorMode buildCursorMode
 Defines cursor mode 0 - add, 1 - smooth.
 
int buildCursorSize
 Edition cursor size in voxels.
 
int buildCursorSizeX
 Edition cursor size X in voxels.
 
int buildCursorSizeY
 Edition cursor size Y in voxels.
 
int buildCursorSizeZ
 Edition cursor size Z in voxels.
 
bool computeLods
 Set to true if LODs should be re-computed.
 
bool fillMode
 It signals whether the fill tool is in use.
 
double fillScope [8][3]
 It defines the scope for the fill tool. The first 4 points are the starting face for the box and the latest 4 points are the ending face.
 
double fillWorldPos [3]
 Position of the starting face in world units.
 
int fillStartDir [3]
 Direction of the starting face in only one axis (x, y or z)
 
int fillEndDir [3]
 Direction of the ending face in only one axis (x, y or z)
 
int totalCells
 Total processed cells.
 
int totalDownload
 Total downloaded size in sizes.
 
int totalDownloadCount
 Total downloaded cells.
 
int totalDownloadTime
 Total download time.
 
time_t lastSceneTime
 
TList< std::pair< int, Scene * > > createdScenes
 
double cShiftX
 Camera Shift in X.
 
double cShiftY
 Camera Shift in Y.
 
double cShiftZ
 Camera Shift in Z.
 

Static Public Attributes

static const int GARBAGE_MAX_AGE = 5
 Number of generations before Cells go to garbage.
 
static const int VOXEL_OCCUPANCY_BLOCK = BLOCK_SIZE/2
 
static const int VOXEL_OCCUPANCY_BLOCK_DATASIZE = VOXEL_OCCUPANCY_BLOCK*VOXEL_OCCUPANCY_BLOCK*VOXEL_OCCUPANCY_BLOCK
 

Detailed Description

Represents a moving view within a world. Computes new scenes as the view moves.

Definition at line 65 of file ClipmapView.h.

Member Function Documentation

void VoxelFarm::CClipmapView::copyToClipboard ( IClipboard clipboard,
CellId  c1,
int  x1,
int  y1,
int  z1,
CellId  c2,
int  x2,
int  y2,
int  z2 
)

Copy voxels to the Clipboard.

Parameters
clipboardClipboard interface
c1Start coordinate for copy area
c2End coordinate for copy area
void VoxelFarm::CClipmapView::pasteFromClipboard ( IClipboard clipboard,
CellId  c,
int  x,
int  y,
int  z 
)

Paste voxels from clipboard into block layer.

Parameters
clipboardClipboard interface
cCoordinate for paste location
void VoxelFarm::CClipmapView::setLineOfSight ( double  x0,
double  y0,
double  z0,
double  x1,
double  y1,
double  z1 
)

Sets the line of sight for the view. This is required for the view to be able to compute the location of the build cursor. Note: kind of weird that the view cares where the build cursor is, seems like that should be at application level.

void VoxelFarm::CClipmapView::stampMesh ( double  worldPos[3],
IMeshStampSource mesh,
IMeshStamMaterialSource materials,
const Algebra::Matrix transform 
)

It stamps a polygonal mesh into block layer.

Parameters
worldPosPosition for stamping the data in world units
meshPolygonal mesh to be stamped
materialsIt translates a material depending of the position
transformA matrix for transforming the mesh.
void VoxelFarm::CClipmapView::stampMesh ( IMeshStampSource mesh,
IMeshStamMaterialSource materials,
const Algebra::Matrix transform 
)

It stamps a polygonal mesh into block layer at the cursor location.

Parameters
meshPosition for stamping in world units
materialsIt translates a material depending of the position
transformA matrix for transforming the mesh.
void VoxelFarm::CClipmapView::stampModel ( const double  size[3],
Algebra::Quaternion  rotations,
const double  position[3],
Architecture::CArchitectureManager architectureManager,
int  moduleId,
Architecture::CPaletteDesc palette,
Architecture::PaletteType  type,
IMeshStamMaterialSource materials 
)

Stamp a model from architecture.

Parameters
sizeSize of area to stamp
rotationsRotation of box
positionOrigin of box
architectureManagerArchitecture source
moduleId?
palette?
type?
materials?
void VoxelFarm::CClipmapView::stampVoxels ( double  worldPos[3],
unsigned int *  data,
int  xsize,
int  ysize,
int  zsize,
IMeshStamMaterialSource materials 
)

It stamps a block of voxels data into block layer.

Parameters
worldPosPosition for stamping the data in world units
dataBlock of voxels data
xsizeSize of the block of data
materialsA matrix for transforming the mesh.
void VoxelFarm::CClipmapView::stampVoxels ( unsigned int *  data,
int  xsize,
int  ysize,
int  zsize,
IMeshStamMaterialSource materials 
)

It stamps a block of voxels data into block layer at the cursor location.

Parameters
dataBlock of voxels data
xsizeSize of the block of data
materialsA matrix for transforming the mesh.

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