the current Path2d triangulatePath() method :
|
triangulatePath() { |
|
var i = 0; |
|
var points = this.points; |
|
var vertices = this.vertices; |
|
var indices = earcut(points.flatMap(p => [p.x, p.y])); |
|
|
|
// pre-allocate vertices if necessary |
|
while (vertices.length < indices.length) { |
|
vertices.push(pool.pull("Point")); |
|
} |
|
|
|
// calculate all vertices |
|
for (i = 0; i < indices.length; i++ ) { |
|
var point = points[indices[i]]; |
|
vertices[i].set(point.x, point.y); |
|
} |
|
|
|
// recycle overhead from a previous triangulation |
|
while (vertices.length > indices.length) { |
|
pool.push(vertices[vertices.length-1]); |
|
vertices.length -= 1; |
|
} |
|
|
|
return vertices; |
does not cache the generated data, forcing melonJS to recalculate every thing when using directly method like
fillRect() and friends, and create a huge performance bottleneck.
For reference here below is an extract from a benchmark on fill operation for both rectangle and circle:
| melonJS 15.0.0 (M1 Max) |
Fill (rect) |
Fill (circle) |
| 500 op/s |
60 fps |
60 fps |
| 1000 op/s |
60 fps |
32 fps |
| 2500 op/s |
35 fps |
12 fps |
| 5000 op/s |
16 fps |
6 fps |
| 10000 op/s |
6 fps |
4 fps |
| 15000 op/s |
4 fps |
3 fps |
which shows performances dropping when drawing more than 1'000 shapes per frame.
the current Path2d
triangulatePath()method :melonJS/src/geometries/path2d.js
Lines 55 to 78 in bb2c020
fillRect()and friends, and create a huge performance bottleneck.For reference here below is an extract from a benchmark on fill operation for both rectangle and circle:
which shows performances dropping when drawing more than 1'000 shapes per frame.