Skip to content

Commit

Permalink
let JS engine expand b2StackQueue capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
flyover committed Feb 10, 2020
1 parent f605385 commit 6f5cb30
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 75 deletions.
30 changes: 9 additions & 21 deletions Box2D/Particle/b2StackQueue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions Box2D/Particle/b2StackQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@

// #if B2_ENABLE_PARTICLE

// DEBUG: import { b2Assert } from "../Common/b2Settings.js";
import { b2MakeArray } from "../Common/b2Settings.js";
// DEBUG: import { b2Assert } from "../Common/b2Settings";

export class b2StackQueue<T> {
public m_buffer: Array<T | null>;
public readonly m_buffer: Array<T | null> = [];
public m_front: number = 0;
public m_back: number = 0;
public m_capacity: number = 0;
public get m_capacity(): number { return this.m_buffer.length; }
constructor(capacity: number) {
this.m_buffer = b2MakeArray(capacity, (index) => null);
this.m_capacity = capacity;
this.m_buffer.fill(null, 0, capacity);
}
public Push(item: T): void {
if (this.m_back >= this.m_capacity) {
Expand All @@ -37,15 +35,6 @@ export class b2StackQueue<T> {
}
this.m_back -= this.m_front;
this.m_front = 0;
if (this.m_back >= this.m_capacity) {
if (this.m_capacity > 0) {
this.m_buffer.concat(b2MakeArray(this.m_capacity, (index) => null));
this.m_capacity *= 2;
} else {
this.m_buffer.concat(b2MakeArray(1, (index) => null));
this.m_capacity = 1;
}
}
}
this.m_buffer[this.m_back] = item;
this.m_back++;
Expand Down
18 changes: 5 additions & 13 deletions Build/Box2D/box2d.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -14240,31 +14240,23 @@
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// #if B2_ENABLE_PARTICLE
// DEBUG: import { b2Assert } from "../Common/b2Settings";
class b2StackQueue {
constructor(capacity) {
this.m_buffer = [];
this.m_front = 0;
this.m_back = 0;
this.m_capacity = 0;
this.m_buffer = b2MakeArray(capacity, (index) => null);
this.m_capacity = capacity;
this.m_buffer.fill(null, 0, capacity);
}
get m_capacity() { return this.m_buffer.length; }
Push(item) {
if (this.m_back >= this.m_capacity) {
for (let i = this.m_front; i < this.m_back; i++) {
this.m_buffer[i - this.m_front] = this.m_buffer[i];
}
this.m_back -= this.m_front;
this.m_front = 0;
if (this.m_back >= this.m_capacity) {
if (this.m_capacity > 0) {
this.m_buffer.concat(b2MakeArray(this.m_capacity, (index) => null));
this.m_capacity *= 2;
}
else {
this.m_buffer.concat(b2MakeArray(1, (index) => null));
this.m_capacity = 1;
}
}
}
this.m_buffer[this.m_back] = item;
this.m_back++;
Expand Down
18 changes: 5 additions & 13 deletions Build/HelloWorld/helloworld.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -13595,31 +13595,23 @@
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// #if B2_ENABLE_PARTICLE
// DEBUG: import { b2Assert } from "../Common/b2Settings";
class b2StackQueue {
constructor(capacity) {
this.m_buffer = [];
this.m_front = 0;
this.m_back = 0;
this.m_capacity = 0;
this.m_buffer = b2MakeArray(capacity, (index) => null);
this.m_capacity = capacity;
this.m_buffer.fill(null, 0, capacity);
}
get m_capacity() { return this.m_buffer.length; }
Push(item) {
if (this.m_back >= this.m_capacity) {
for (let i = this.m_front; i < this.m_back; i++) {
this.m_buffer[i - this.m_front] = this.m_buffer[i];
}
this.m_back -= this.m_front;
this.m_front = 0;
if (this.m_back >= this.m_capacity) {
if (this.m_capacity > 0) {
this.m_buffer.concat(b2MakeArray(this.m_capacity, (index) => null));
this.m_capacity *= 2;
}
else {
this.m_buffer.concat(b2MakeArray(1, (index) => null));
this.m_capacity = 1;
}
}
}
this.m_buffer[this.m_back] = item;
this.m_back++;
Expand Down
18 changes: 5 additions & 13 deletions Build/Testbed/testbed.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -14109,31 +14109,23 @@
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
// #if B2_ENABLE_PARTICLE
// DEBUG: import { b2Assert } from "../Common/b2Settings";
class b2StackQueue {
constructor(capacity) {
this.m_buffer = [];
this.m_front = 0;
this.m_back = 0;
this.m_capacity = 0;
this.m_buffer = b2MakeArray(capacity, (index) => null);
this.m_capacity = capacity;
this.m_buffer.fill(null, 0, capacity);
}
get m_capacity() { return this.m_buffer.length; }
Push(item) {
if (this.m_back >= this.m_capacity) {
for (let i = this.m_front; i < this.m_back; i++) {
this.m_buffer[i - this.m_front] = this.m_buffer[i];
}
this.m_back -= this.m_front;
this.m_front = 0;
if (this.m_back >= this.m_capacity) {
if (this.m_capacity > 0) {
this.m_buffer.concat(b2MakeArray(this.m_capacity, (index) => null));
this.m_capacity *= 2;
}
else {
this.m_buffer.concat(b2MakeArray(1, (index) => null));
this.m_capacity = 1;
}
}
}
this.m_buffer[this.m_back] = item;
this.m_back++;
Expand Down

0 comments on commit 6f5cb30

Please sign in to comment.