Skip to content

Commit 548ee59

Browse files
authored
Merge pull request #5128 from austinEng/skip-levels
Skip LODs
2 parents 77d5f14 + 273fb43 commit 548ee59

12 files changed

+1539
-591
lines changed

Source/Core/Heap.js

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/*global define*/
2+
define([
3+
'./Check',
4+
'./defaultValue',
5+
'./defined',
6+
'./defineProperties'
7+
], function(
8+
Check,
9+
defaultValue,
10+
defined,
11+
defineProperties) {
12+
'use strict';
13+
14+
/**
15+
* @alias Heap
16+
* @constructor
17+
* @private
18+
*
19+
* @param {Function} comparator The comparator to use for the heap. If comparator(a, b) is less than 0, sort a to a lower index than b, otherwise sort to a higher index.
20+
*/
21+
function Heap(comparator) {
22+
//>>includeStart('debug', pragmas.debug);
23+
Check.defined('comparator', comparator);
24+
//>>includeEnd('debug');
25+
26+
this._comparator = comparator;
27+
this._data = [];
28+
this._length = 0;
29+
this._maximumSize = 0;
30+
}
31+
32+
defineProperties(Heap.prototype, {
33+
/**
34+
* Gets the internal data in the heap.
35+
*
36+
* @memberof Heap.prototype
37+
*
38+
* @type {Array}
39+
* @readonly
40+
*/
41+
data : {
42+
get : function() {
43+
return this._data;
44+
}
45+
},
46+
47+
/**
48+
* Gets the length of the heap.
49+
*
50+
* @memberof Heap.prototype
51+
*
52+
* @type {Number}
53+
* @readonly
54+
*/
55+
length : {
56+
get : function() {
57+
return this._length;
58+
}
59+
},
60+
61+
/**
62+
* Gets and sets the maximum size of the heap.
63+
*
64+
* @memberof Heap.prototype
65+
*
66+
* @type {Number}
67+
*/
68+
maximumSize : {
69+
get: function() {
70+
return this._maximumSize;
71+
},
72+
73+
set: function(value) {
74+
this._maximumSize = value;
75+
if (this._length > this._maximumSize && this._maximumSize > 0) {
76+
this._length = this._maximumSize;
77+
this._data.length = this._maximumSize;
78+
}
79+
}
80+
}
81+
});
82+
83+
function swap(data, a, b) {
84+
var temp = data[a];
85+
data[a] = data[b];
86+
data[b] = temp;
87+
}
88+
89+
/**
90+
* Resizes the internal array of the heap.
91+
*
92+
* @param {Number} [length] The length to resize internal array to. Defaults to the current size of the heap.
93+
*/
94+
Heap.prototype.reserve = function(length) {
95+
length = defaultValue(length, this._length);
96+
this._data.length = length;
97+
};
98+
99+
/**
100+
* Heapify. Update the heap so that index and all descendants satisfy the heap property.
101+
*
102+
* @param {Number} index The starting index to heapify from.
103+
*/
104+
Heap.prototype.heapify = function(index) {
105+
//>>includeStart('debug', pragmas.debug);
106+
Check.typeOf.number.greaterThanOrEquals('index', index, 0);
107+
//>>includeEnd('debug');
108+
109+
var length = this._length;
110+
var comparator = this._comparator;
111+
var data = this._data;
112+
var candidate = -1;
113+
114+
while (true) {
115+
var right = 2 * (index + 1);
116+
var left = right - 1;
117+
118+
if (left < length && comparator(data[left], data[index]) < 0) {
119+
candidate = left;
120+
} else {
121+
candidate = index;
122+
}
123+
124+
if (right < length && comparator(data[right], data[candidate]) < 0) {
125+
candidate = right;
126+
}
127+
if (candidate !== index) {
128+
swap(data, candidate, index);
129+
130+
index = candidate;
131+
} else {
132+
break;
133+
}
134+
}
135+
136+
if (this._length > this._maximumSize && this._maximumSize > 0) {
137+
this._length = this._maximumSize;
138+
this._data.length = this._maximumSize;
139+
}
140+
};
141+
142+
/**
143+
* Create a heap from an existing array. This will modify the original array.
144+
*
145+
* @param {Array} data The array to convert to a heap.
146+
*/
147+
Heap.prototype.buildHeap = function(data) {
148+
//>>includeStart('debug', pragmas.debug);
149+
Check.defined('data', data);
150+
//>>includeEnd('debug');
151+
152+
var length = data.length;
153+
this._data = data;
154+
this._length = length;
155+
156+
for (var i = Math.ceil(length / 2); i >= 0; --i) {
157+
this.heapify(i);
158+
}
159+
};
160+
161+
/**
162+
* Insert an element into the heap. If the length would grow greater than maximumSize
163+
* of the heap, extra elements are removed.
164+
*
165+
* @param {*} value The element to insert
166+
*/
167+
Heap.prototype.insert = function(value) {
168+
//>>includeStart('debug', pragmas.debug);
169+
Check.defined('value', value);
170+
//>>includeEnd('debug');
171+
172+
var data = this._data;
173+
var comparator = this._comparator;
174+
175+
var index = this._length++;
176+
if (index < data.length) {
177+
data[index] = value;
178+
} else {
179+
data.push(value);
180+
}
181+
182+
while (index !== 0) {
183+
var parent = Math.floor((index - 1) / 2);
184+
if (comparator(data[index], data[parent]) < 0) {
185+
swap(data, index, parent);
186+
index = parent;
187+
} else {
188+
break;
189+
}
190+
}
191+
192+
if (this._length > this._maximumSize && this._maximumSize > 0) {
193+
this._length = this._maximumSize;
194+
}
195+
};
196+
197+
/**
198+
* Remove the top element from the heap and return it.
199+
*
200+
* @returns {*} The top element of the heap.
201+
*/
202+
Heap.prototype.pop = function() {
203+
if (this._length === 0) {
204+
return undefined;
205+
}
206+
var data = this._data;
207+
var root = data[0];
208+
swap(data, 0, --this._length);
209+
this.heapify(0);
210+
return root;
211+
};
212+
213+
return Heap;
214+
});

Source/Core/ManagedArray.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*global define*/
2+
define([
3+
'./defaultValue',
4+
'./defined',
5+
'./defineProperties',
6+
'./Check'
7+
], function(
8+
defaultValue,
9+
defined,
10+
defineProperties,
11+
Check) {
12+
'use strict';
13+
14+
/**
15+
* A wrapper around arrays so that the internal length of the array can be manually managed.
16+
*
17+
* @alias ManagedArray
18+
* @constructor
19+
* @private
20+
*
21+
* @param {Number} [length=0] The initial length of the array.
22+
*/
23+
function ManagedArray(length) {
24+
length = defaultValue(length, 0);
25+
this._array = new Array(length);
26+
this._length = length;
27+
}
28+
29+
defineProperties(ManagedArray.prototype, {
30+
31+
/**
32+
* Gets or sets the length of the array.
33+
* If the set length is greater than the length of the internal array, the internal array is resized.
34+
*
35+
* @type Number
36+
*/
37+
length : {
38+
get : function() {
39+
return this._length;
40+
},
41+
42+
set : function(length) {
43+
this._length = length;
44+
if (length > this._array.length) {
45+
this._array.length = length;
46+
}
47+
}
48+
},
49+
50+
/**
51+
* Gets the internal array.
52+
*
53+
* @type Array
54+
* @readonly
55+
*/
56+
internalArray : {
57+
get : function() {
58+
return this._array;
59+
}
60+
}
61+
});
62+
63+
/**
64+
* Gets the element at an index.
65+
*
66+
* @param {Number} index The index to get.
67+
*/
68+
ManagedArray.prototype.get = function(index) {
69+
//>>includeStart('debug', pragmas.debug);
70+
Check.typeOf.number.lessThan('index', index, this._array.length);
71+
//>>includeEnd('debug');
72+
73+
return this._array[index];
74+
};
75+
76+
/**
77+
* Sets the element at an index. Resizes the array if index is greater than the length of the array.
78+
*
79+
* @param {Number} index The index to set.
80+
* @param {*} value The value to set at index.
81+
*/
82+
ManagedArray.prototype.set = function(index, value) {
83+
//>>includeStart('debug', pragmas.debug);
84+
Check.typeOf.number('index', index);
85+
//>>includeEnd('debug');
86+
87+
if (index >= this.length) {
88+
this.length = index + 1;
89+
}
90+
this._array[index] = value;
91+
};
92+
93+
/**
94+
* Push an element into the array.
95+
*/
96+
ManagedArray.prototype.push = function(element) {
97+
var index = this.length++;
98+
this._array[index] = element;
99+
};
100+
101+
/**
102+
* Pop an element from the array.
103+
*
104+
* @returns {*} The last element in the array.
105+
*/
106+
ManagedArray.prototype.pop = function() {
107+
return this._array[--this.length];
108+
};
109+
110+
/**
111+
* Resize the internal array if length > _array.length.
112+
*
113+
* @param {Number} length The length.
114+
*/
115+
ManagedArray.prototype.reserve = function(length) {
116+
//>>includeStart('debug', pragmas.debug);
117+
Check.typeOf.number.greaterThanOrEquals('length', length, 0);
118+
//>>includeEnd('debug');
119+
120+
if (length > this._array.length) {
121+
this._array.length = length;
122+
}
123+
};
124+
125+
/**
126+
* Resize the array.
127+
*
128+
* @param {Number} length The length.
129+
*/
130+
ManagedArray.prototype.resize = function(length) {
131+
//>>includeStart('debug', pragmas.debug);
132+
Check.typeOf.number.greaterThanOrEquals('length', length, 0);
133+
//>>includeEnd('debug');
134+
135+
this.length = length;
136+
};
137+
138+
/**
139+
* Trim the internal array to the specified length. Defaults to the current length.
140+
*
141+
* @param {Number} [length] The length.
142+
*/
143+
ManagedArray.prototype.trim = function(length) {
144+
length = defaultValue(length, this.length);
145+
this._array.length = length;
146+
};
147+
148+
return ManagedArray;
149+
});

Source/Renderer/ClearCommand.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ define([
7777
* @see Scene#debugCommandFilter
7878
*/
7979
this.owner = options.owner;
80+
81+
/**
82+
* The pass in which to run this command.
83+
*
84+
* @type {Pass}
85+
*
86+
* @default undefined
87+
*/
88+
this.pass = options.pass;
8089
}
8190

8291
/**

0 commit comments

Comments
 (0)