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