the-world-engine
Version:
three.js based, unity like game engine for browser
36 lines • 889 B
JavaScript
export class b2StackQueue {
constructor(t) {
this.m_buffer = [];
this.m_front = 0;
this.m_back = 0;
this.m_buffer.fill(null, 0, t);
}
get m_capacity() {
return this.m_buffer.length;
}
Push(t) {
if (this.m_back >= this.m_capacity) {
for (let t = this.m_front; t < this.m_back; t++) {
this.m_buffer[t - this.m_front] = this.m_buffer[t];
}
this.m_back -= this.m_front;
this.m_front = 0;
}
this.m_buffer[this.m_back] = t;
this.m_back++;
}
Pop() {
this.m_buffer[this.m_front] = null;
this.m_front++;
}
Empty() {
return this.m_front === this.m_back;
}
Front() {
const t = this.m_buffer[this.m_front];
if (!t) {
throw new Error;
}
return t;
}
}