UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

83 lines (82 loc) 2.14 kB
export class b2ControllerEdge { constructor(t, i) { this.prevBody = null; this.nextBody = null; this.prevController = null; this.nextController = null; this.controller = t; this.body = i; } } export class b2Controller { constructor() { this.m_bodyList = null; this.m_bodyCount = 0; this.m_prev = null; this.m_next = null; } GetNext() { return this.m_next; } GetPrev() { return this.m_prev; } GetBodyList() { return this.m_bodyList; } AddBody(t) { const i = new b2ControllerEdge(this, t); i.nextBody = this.m_bodyList; i.prevBody = null; if (this.m_bodyList) { this.m_bodyList.prevBody = i; } this.m_bodyList = i; ++this.m_bodyCount; i.nextController = t.m_controllerList; i.prevController = null; if (t.m_controllerList) { t.m_controllerList.prevController = i; } t.m_controllerList = i; ++t.m_controllerCount; } RemoveBody(t) { if (this.m_bodyCount <= 0) { throw new Error; } let i = this.m_bodyList; while (i && i.body !== t) { i = i.nextBody; } if (i === null) { throw new Error; } if (i.prevBody) { i.prevBody.nextBody = i.nextBody; } if (i.nextBody) { i.nextBody.prevBody = i.prevBody; } if (this.m_bodyList === i) { this.m_bodyList = i.nextBody; } --this.m_bodyCount; if (i.nextController) { i.nextController.prevController = i.prevController; } if (i.prevController) { i.prevController.nextController = i.nextController; } if (t.m_controllerList === i) { t.m_controllerList = i.nextController; } --t.m_controllerCount; } Clear() { while (this.m_bodyList) { this.RemoveBody(this.m_bodyList.body); } this.m_bodyCount = 0; } }