Skip to content

Commit

Permalink
v1.1.1: fix serializing chain with loop
Browse files Browse the repository at this point in the history
  • Loading branch information
shakiba committed Nov 30, 2024
1 parent b4d7ffa commit 0e58a85
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 39 deletions.
11 changes: 6 additions & 5 deletions dist/planck-with-testbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.planck = {}));
})(this, function(exports2) {
"use strict";/**
* Planck.js v1.1.0
* Planck.js v1.1.1
* @license The MIT license
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -6782,7 +6782,7 @@
ChainShape2.prototype._serialize = function() {
var data = {
type: this.m_type,
vertices: this.m_vertices,
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
isLoop: this.m_isLoop,
hasPrevVertex: this.m_hasPrevVertex,
hasNextVertex: this.m_hasNextVertex,
Expand Down Expand Up @@ -6844,19 +6844,20 @@
vertices[i - 1];
vertices[i];
}
this.m_vertices = [];
this.m_count = vertices.length;
for (var i = 0; i < vertices.length; ++i) {
this.m_vertices[i] = Vec2.clone(vertices[i]);
}
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
this.m_prevVertex = null;
this.m_nextVertex = null;
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
return this;
};
ChainShape2.prototype._reset = function() {
if (this.m_isLoop) {
this._createLoop(this.m_vertices);
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
} else {
this._createChain(this.m_vertices);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/planck-with-testbed.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/planck-with-testbed.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck-with-testbed.min.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/planck-with-testbed.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Planck.js v1.1.0
* Planck.js v1.1.1
* @license The MIT license
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -6778,7 +6778,7 @@ var ChainShape = (
ChainShape2.prototype._serialize = function() {
var data = {
type: this.m_type,
vertices: this.m_vertices,
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
isLoop: this.m_isLoop,
hasPrevVertex: this.m_hasPrevVertex,
hasNextVertex: this.m_hasNextVertex,
Expand Down Expand Up @@ -6840,19 +6840,20 @@ var ChainShape = (
vertices[i - 1];
vertices[i];
}
this.m_vertices = [];
this.m_count = vertices.length;
for (var i = 0; i < vertices.length; ++i) {
this.m_vertices[i] = Vec2.clone(vertices[i]);
}
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
this.m_prevVertex = null;
this.m_nextVertex = null;
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
return this;
};
ChainShape2.prototype._reset = function() {
if (this.m_isLoop) {
this._createLoop(this.m_vertices);
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
} else {
this._createChain(this.m_vertices);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/planck-with-testbed.mjs.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/planck.js

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

2 changes: 1 addition & 1 deletion dist/planck.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/planck.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck.min.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/planck.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Planck.js v1.1.0
* Planck.js v1.1.1
* @license The MIT license
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -6778,7 +6778,7 @@ var ChainShape = (
ChainShape2.prototype._serialize = function() {
var data = {
type: this.m_type,
vertices: this.m_vertices,
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
isLoop: this.m_isLoop,
hasPrevVertex: this.m_hasPrevVertex,
hasNextVertex: this.m_hasNextVertex,
Expand Down Expand Up @@ -6840,19 +6840,20 @@ var ChainShape = (
vertices[i - 1];
vertices[i];
}
this.m_vertices = [];
this.m_count = vertices.length;
for (var i = 0; i < vertices.length; ++i) {
this.m_vertices[i] = Vec2.clone(vertices[i]);
}
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
this.m_prevVertex = null;
this.m_nextVertex = null;
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
return this;
};
ChainShape2.prototype._reset = function() {
if (this.m_isLoop) {
this._createLoop(this.m_vertices);
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
} else {
this._createChain(this.m_vertices);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/planck.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "planck",
"version": "1.1.0",
"version": "1.1.1",
"description": "2D JavaScript/TypeScript physics engine for cross-platform HTML5 game development",
"homepage": "https://github.com/piqnt/planck.js",
"keywords": [
Expand Down
12 changes: 6 additions & 6 deletions src/collision/shape/ChainShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ChainShape extends Shape {
_serialize(): object {
const data = {
type: this.m_type,
vertices: this.m_vertices,
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
isLoop: this.m_isLoop,
hasPrevVertex: this.m_hasPrevVertex,
hasNextVertex: this.m_hasNextVertex,
Expand Down Expand Up @@ -138,7 +138,6 @@ export class ChainShape extends Shape {
* Create a loop. This automatically adjusts connectivity.
*
* @param vertices an array of vertices, these are copied
* @param count the vertex count
*/
_createLoop(vertices: Vec2Value[]): ChainShape {
_ASSERT && console.assert(this.m_vertices.length == 0 && this.m_count == 0);
Expand Down Expand Up @@ -178,28 +177,29 @@ export class ChainShape extends Shape {
_ASSERT && console.assert(this.m_vertices.length == 0 && this.m_count == 0);
_ASSERT && console.assert(vertices.length >= 2);
for (let i = 1; i < vertices.length; ++i) {
// If the code crashes here, it means your vertices are too close together.
const v1 = vertices[i - 1];
const v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
_ASSERT && console.assert(Vec2.distanceSquared(v1, v2) > Settings.linearSlopSquared);
}

this.m_vertices = [];
this.m_count = vertices.length;
for (let i = 0; i < vertices.length; ++i) {
this.m_vertices[i] = Vec2.clone(vertices[i]);
}

this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
this.m_prevVertex = null;
this.m_nextVertex = null;
this.m_hasPrevVertex = false;
this.m_hasNextVertex = false;
return this;
}

/** @hidden */
_reset(): void {
if (this.m_isLoop) {
this._createLoop(this.m_vertices);
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
} else {
this._createChain(this.m_vertices);
}
Expand Down

0 comments on commit 0e58a85

Please sign in to comment.