Skip to content

Commit

Permalink
fix #2 duplicate shatter!!!
Browse files Browse the repository at this point in the history
-closes #2, fucking finally!!!!
turns out it wasn't a bug in my code after all. It was a precision issue with floating point values. Now calculates asteroid break using double math utils instead of Float.
-thank you @tommyettinger
  • Loading branch information
0XDE57 committed Oct 28, 2024
1 parent 6a72969 commit 988d27d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/src/com/spaceproject/systems/AsteroidBeltSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.math.*;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.Pools;
import com.badlogic.gdx.utils.ShortArray;
import com.badlogic.gdx.utils.*;
import com.spaceproject.SpaceProject;
import com.spaceproject.components.AsteroidBeltComponent;
import com.spaceproject.components.AsteroidComponent;
import com.spaceproject.components.PhysicsComponent;
import com.spaceproject.components.TransformComponent;
import com.spaceproject.config.DebugConfig;
import com.spaceproject.generation.EntityBuilder;
import com.spaceproject.math.DoubleDelaunayTriangulator;
import com.spaceproject.math.MyMath;
import com.spaceproject.screens.GameScreen;
import com.spaceproject.utility.DebugUtil;
import com.spaceproject.utility.Mappers;
import com.spaceproject.utility.SimpleTimer;

import java.lang.StringBuilder;


public class AsteroidBeltSystem extends EntitySystem {

Expand Down Expand Up @@ -59,7 +59,7 @@ public void reset() {
private final Pool<AsteroidRemovedQueue> removePool = Pools.get(AsteroidRemovedQueue.class, 100);
private final Array<AsteroidRemovedQueue> spawnQ = new Array<>(false, 100);

private final DelaunayTriangulator delaunay = new DelaunayTriangulator();
private final DoubleDelaunayTriangulator delaunay = new DoubleDelaunayTriangulator();
private final float minAsteroidSize = 100; //anything smaller than this will not create more
private final float maxDriftAngle = 0.05f; //angular drift when shatter
private final float minDriftAngle = 0.01f;
Expand Down Expand Up @@ -282,7 +282,12 @@ private void spawnChildAsteroid(Vector2 parentPos, Vector2 parentVel, float pare
int child = 0;
float childArea = 0;

ShortArray triangleIndices = delaunay.computeTriangles(vertices, false);
//copy float to double for higher precision triangulation
double[] vertsFloat = new double[vertices.length];
for (int i = 0; i < vertsFloat.length; i++) {
vertsFloat[i] = vertices[i];
}
IntArray triangleIndices = delaunay.computeTriangles(vertsFloat, false);

//create cells for each triangle
for (int index = 0; index < triangleIndices.size; index += 3) {
Expand Down

0 comments on commit 988d27d

Please sign in to comment.