History

more optimizations of render pipeline

ZappoMan committed 13 years ago

Commit 34a059d1 parent 771c6045 files · +30 −5Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+18−5
@@ -154,6 +154,13 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 153 unmodified lines
154 154
155void VoxelSystem::setupNewVoxelsForDrawing() {155void VoxelSystem::setupNewVoxelsForDrawing() {
156 double start = usecTimestampNow();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 if (_tree->isDirty()) {164 if (_tree->isDirty()) {
158 _callsToTreesToArrays++;165 _callsToTreesToArrays++;
159 _voxelsUpdated = newTreeToArrays(_tree->rootNode);166 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
@@ -164,6 +171,12 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 4 unmodified lines
164 if (_voxelsUpdated) {171 if (_voxelsUpdated) {
165 _voxelsDirty=true;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 double end = usecTimestampNow();180 double end = usecTimestampNow();
168 double elapsedmsec = (end - start)/1000.0;181 double elapsedmsec = (end - start)/1000.0;
169 if (_renderWarningsOn && elapsedmsec > 1) {182 if (_renderWarningsOn && elapsedmsec > 1) {
@@ -174,11 +187,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 4 unmodified lines
174 printLog("WARNING! newTreeToArrays() took %lf milliseconds %ld voxels updated\n", elapsedmsec, _voxelsUpdated);187 printLog("WARNING! newTreeToArrays() took %lf milliseconds %ld voxels updated\n", elapsedmsec, _voxelsUpdated);
175 }188 }
176 }189 }
177 190
178 if (_voxelsDirty) {191 _setupNewVoxelsForDrawingLastFinished = end;
179 // copy the newly written data to the arrays designated for reading192 _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
180 copyWrittenDataToReadArrays();
181 }
182}193}
183 194
184void VoxelSystem::copyWrittenDataToReadArrays() {195void VoxelSystem::copyWrittenDataToReadArrays() {
@@ -277,6 +288,8 @@ void VoxelSystem::init() { · 92 unmodified lines
277 288
278 _renderWarningsOn = false;289 _renderWarningsOn = false;
279 _callsToTreesToArrays = 0;290 _callsToTreesToArrays = 0;
291 _setupNewVoxelsForDrawingLastFinished = 0;
292 _setupNewVoxelsForDrawingLastElapsed = 0;
280 293
281 // When we change voxels representations in the arrays, we'll update this294 // When we change voxels representations in the arrays, we'll update this
282 _voxelsDirty = false;295 _voxelsDirty = false;