UNPKG

@box2d/debug-draw

Version:

Debug drawing helper for @box2d

88 lines (87 loc) 4.89 kB
"use strict"; // MIT License Object.defineProperty(exports, "__esModule", { value: true }); exports.b2ContactFactory = void 0; // Copyright (c) 2019 Erin Catto // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // DEBUG: import { b2Assert } from "../common/b2_common"; const b2_shape_1 = require("../collision/b2_shape"); const b2_circle_contact_1 = require("./b2_circle_contact"); const b2_polygon_contact_1 = require("./b2_polygon_contact"); const b2_polygon_circle_contact_1 = require("./b2_polygon_circle_contact"); const b2_edge_circle_contact_1 = require("./b2_edge_circle_contact"); const b2_edge_polygon_contact_1 = require("./b2_edge_polygon_contact"); const b2_chain_circle_contact_1 = require("./b2_chain_circle_contact"); const b2_chain_polygon_contact_1 = require("./b2_chain_polygon_contact"); class b2ContactFactory { constructor() { const result = new Array(b2_shape_1.b2ShapeType.e_typeCount); for (let i = 0; i < b2_shape_1.b2ShapeType.e_typeCount; i++) result[i] = new Array(b2_shape_1.b2ShapeType.e_typeCount); this.m_registers = result; this.AddType(b2_circle_contact_1.b2CircleContact, b2_shape_1.b2ShapeType.e_circle, b2_shape_1.b2ShapeType.e_circle); this.AddType(b2_polygon_circle_contact_1.b2PolygonAndCircleContact, b2_shape_1.b2ShapeType.e_polygon, b2_shape_1.b2ShapeType.e_circle); this.AddType(b2_polygon_contact_1.b2PolygonContact, b2_shape_1.b2ShapeType.e_polygon, b2_shape_1.b2ShapeType.e_polygon); this.AddType(b2_edge_circle_contact_1.b2EdgeAndCircleContact, b2_shape_1.b2ShapeType.e_edge, b2_shape_1.b2ShapeType.e_circle); this.AddType(b2_edge_polygon_contact_1.b2EdgeAndPolygonContact, b2_shape_1.b2ShapeType.e_edge, b2_shape_1.b2ShapeType.e_polygon); this.AddType(b2_chain_circle_contact_1.b2ChainAndCircleContact, b2_shape_1.b2ShapeType.e_chain, b2_shape_1.b2ShapeType.e_circle); this.AddType(b2_chain_polygon_contact_1.b2ChainAndPolygonContact, b2_shape_1.b2ShapeType.e_chain, b2_shape_1.b2ShapeType.e_polygon); } AddType(Contact, typeA, typeB) { const pool = []; const destroyFcn = (contact) => { pool.push(contact); }; this.m_registers[typeA][typeB] = { createFcn(fixtureA, indexA, fixtureB, indexB) { var _a; const c = (_a = pool.pop()) !== null && _a !== void 0 ? _a : new Contact(); c.Reset(fixtureA, indexA, fixtureB, indexB); return c; }, destroyFcn, }; if (typeA !== typeB) { this.m_registers[typeB][typeA] = { createFcn(fixtureA, indexA, fixtureB, indexB) { var _a; const c = (_a = pool.pop()) !== null && _a !== void 0 ? _a : new Contact(); c.Reset(fixtureB, indexB, fixtureA, indexA); return c; }, destroyFcn, }; } } Create(fixtureA, indexA, fixtureB, indexB) { const typeA = fixtureA.GetType(); const typeB = fixtureB.GetType(); // DEBUG: b2Assert(0 <= typeA && typeA < b2ShapeType.e_typeCount); // DEBUG: b2Assert(0 <= typeB && typeB < b2ShapeType.e_typeCount); const reg = this.m_registers[typeA][typeB]; return reg ? reg.createFcn(fixtureA, indexA, fixtureB, indexB) : null; } Destroy(contact) { const typeA = contact.m_fixtureA.GetType(); const typeB = contact.m_fixtureB.GetType(); // DEBUG: b2Assert(0 <= typeA && typeB < b2ShapeType.e_typeCount); // DEBUG: b2Assert(0 <= typeA && typeB < b2ShapeType.e_typeCount); const reg = this.m_registers[typeA][typeB]; reg === null || reg === void 0 ? void 0 : reg.destroyFcn(contact); } } exports.b2ContactFactory = b2ContactFactory;