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
154154
155155 void VoxelSystem::setupNewVoxelsForDrawing() {
156156 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+
157164 if (_tree->isDirty()) {
158165 _callsToTreesToArrays++;
159166 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
@@ -164,6 +171,12 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 4 unmodified lines
164171 if (_voxelsUpdated) {
165172 _voxelsDirty=true;
166173 }
174+
175+ if (_voxelsDirty) {
176+ // copy the newly written data to the arrays designated for reading
177+ copyWrittenDataToReadArrays();
178+ }
179+
167180 double end = usecTimestampNow();
168181 double elapsedmsec = (end - start)/1000.0;
169182 if (_renderWarningsOn && elapsedmsec > 1) {
@@ -174,11 +187,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 4 unmodified lines
174187 printLog("WARNING! newTreeToArrays() took %lf milliseconds %ld voxels updated\n", elapsedmsec, _voxelsUpdated);
175188 }
176189 }
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;
182193 }
183194
184195 void VoxelSystem::copyWrittenDataToReadArrays() {
@@ -277,6 +288,8 @@ void VoxelSystem::init() { · 92 unmodified lines
277288
278289 _renderWarningsOn = false;
279290 _callsToTreesToArrays = 0;
291+ _setupNewVoxelsForDrawingLastFinished = 0;
292+ _setupNewVoxelsForDrawingLastElapsed = 0;
280293
281294 // When we change voxels representations in the arrays, we'll update this
282295 _voxelsDirty = false;