Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -40,6 +40,8 @@ VoxelSystem::VoxelSystem() { · 39 unmodified lines | |||
| 40 | voxelsRendered = 0; | 40 | voxelsRendered = 0; |
| 41 | tree = new VoxelTree(); | 41 | tree = new VoxelTree(); |
| 42 | pthread_mutex_init(&bufferWriteLock, NULL); | 42 | pthread_mutex_init(&bufferWriteLock, NULL); |
| 43 | lastBufferCopy.tv_sec = 0; | ||
| 44 | lastBufferCopy.tv_usec = 0; | ||
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | VoxelSystem::~VoxelSystem() { | 47 | VoxelSystem::~VoxelSystem() { |
| @@ -185,11 +187,11 @@ VoxelSystem* VoxelSystem::clone() const { · 139 unmodified lines | |||
| 185 | 187 | ||
| 186 | void VoxelSystem::init() { | 188 | void VoxelSystem::init() { |
| 187 | // prep the data structures for incoming voxel data | 189 | // prep the data structures for incoming voxel data |
| 188 | writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 190 | writeVerticesEndPointer = writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 189 | readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 191 | readVerticesEndPointer = readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 190 | writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 192 | writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 191 | readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 193 | readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 192 | 194 | ||
| 193 | GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 195 | GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 194 | 196 | ||
| 195 | // populate the indicesArray | 197 | // populate the indicesArray |
| @@ -231,8 +233,9 @@ void VoxelSystem::render() { · 35 unmodified lines | |||
| 231 | 233 | ||
| 232 | glPushMatrix(); | 234 | glPushMatrix(); |
| 233 | 235 | ||
| 234 | 236 | double timeSinceLastDraw = usecTimestampNow() - usecTimestamp(&lastBufferCopy); | |
| 235 | if (readVerticesEndPointer != readVerticesArray) { | 237 | if (readVerticesEndPointer != readVerticesArray && timeSinceLastDraw >= 5000 * 1000) { |
| 238 | printf("The time since the last draw was %f\n", timeSinceLastDraw); | ||
| 236 | // try to lock on the buffer write | 239 | // try to lock on the buffer write |
| 237 | // just avoid pulling new data if it is currently being written | 240 | // just avoid pulling new data if it is currently being written |
| 238 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { | 241 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { |
| @@ -249,6 +252,8 @@ void VoxelSystem::render() { · 10 unmodified lines | |||
| 249 | 252 | ||
| 250 | pthread_mutex_unlock(&bufferWriteLock); | 253 | pthread_mutex_unlock(&bufferWriteLock); |
| 251 | } | 254 | } |
| 255 | |||
| 256 | gettimeofday(&lastBufferCopy, NULL); | ||
| 252 | } | 257 | } |
| 253 | 258 | ||
| 254 | // tell OpenGL where to find vertex and color information | 259 | // tell OpenGL where to find vertex and color information |