Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -154,6 +154,13 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 153 unmodified lines | ||
| 154 | 154 | |
| 155 | 155 | void VoxelSystem::setupNewVoxelsForDrawing() { |
| 156 | 156 | double start = usecTimestampNow(); |
| 157 | + | |
| 158 | + double sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished); | |
| 159 | + | |
| 160 | + if (sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed,SIXTY_FPS_IN_MILLISECONDS)) { | |
| 161 | + return; // bail early, it hasn't been long enough since the last time we ran | |
| 162 | + } | |
| 163 | + | |
| 157 | 164 | if (_tree->isDirty()) { |
| 158 | 165 | _callsToTreesToArrays++; |
| 159 | 166 | _voxelsUpdated = newTreeToArrays(_tree->rootNode); |
| @@ -164,6 +171,12 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 4 unmodified lines | ||
| 164 | 171 | if (_voxelsUpdated) { |
| 165 | 172 | _voxelsDirty=true; |
| 166 | 173 | } |
| 174 | + | |
| 175 | + if (_voxelsDirty) { | |
| 176 | + // copy the newly written data to the arrays designated for reading | |
| 177 | + copyWrittenDataToReadArrays(); | |
| 178 | + } | |
| 179 | + | |
| 167 | 180 | double end = usecTimestampNow(); |
| 168 | 181 | double elapsedmsec = (end - start)/1000.0; |
| 169 | 182 | if (_renderWarningsOn && elapsedmsec > 1) { |
| @@ -174,11 +187,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 4 unmodified lines | ||
| 174 | 187 | printLog("WARNING! newTreeToArrays() took %lf milliseconds %ld voxels updated\n", elapsedmsec, _voxelsUpdated); |
| 175 | 188 | } |
| 176 | 189 | } |
| 177 | − | |
| 178 | − if (_voxelsDirty) { | |
| 179 | − // copy the newly written data to the arrays designated for reading | |
| 180 | − copyWrittenDataToReadArrays(); | |
| 181 | − } | |
| 190 | + | |
| 191 | + _setupNewVoxelsForDrawingLastFinished = end; | |
| 192 | + _setupNewVoxelsForDrawingLastElapsed = elapsedmsec; | |
| 182 | 193 | } |
| 183 | 194 | |
| 184 | 195 | void VoxelSystem::copyWrittenDataToReadArrays() { |
| @@ -277,6 +288,8 @@ void VoxelSystem::init() { · 92 unmodified lines | ||
| 277 | 288 | |
| 278 | 289 | _renderWarningsOn = false; |
| 279 | 290 | _callsToTreesToArrays = 0; |
| 291 | + _setupNewVoxelsForDrawingLastFinished = 0; | |
| 292 | + _setupNewVoxelsForDrawingLastElapsed = 0; | |
| 280 | 293 | |
| 281 | 294 | // When we change voxels representations in the arrays, we'll update this |
| 282 | 295 | _voxelsDirty = false; |