Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision mesh building #625

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions engine/src/main/java/org/destinationsol/SolApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.destinationsol.assets.Assets;
import org.destinationsol.assets.music.OggMusicManager;
import org.destinationsol.assets.sound.OggSoundManager;
import org.destinationsol.asteroids.components.AsteroidMesh;
import org.destinationsol.body.components.BodyLinked;
import org.destinationsol.common.SolColor;
import org.destinationsol.common.SolMath;
Expand Down Expand Up @@ -284,6 +283,7 @@ private void draw() {
element.tint = Color.YELLOW;
element.setSize(size.size);
element.graphicsOffset = new Vector2();
element.density = 10;
Renderable graphicsComponent = new Renderable();
graphicsComponent.elements.add(element);

Expand All @@ -294,10 +294,14 @@ private void draw() {
Health health = new Health();
health.currentHealth = 1;

EntityRef entityRef = entitySystemManager.getEntityManager().createEntity(graphicsComponent, position, size,
new Angle(), new Velocity(), new AsteroidMesh(), health, new DropsMoneyOnDestruction(), new CreatesRubbleOnDestruction());
BodyLinked bodyLinked = new BodyLinked();
bodyLinked.setJsonSchemaFileName("engine:schemaCollisionMesh");
bodyLinked.setJsonPath("engine:asteroids");

EntityRef entityRef = entitySystemManager.getEntityManager().createEntity(graphicsComponent, position,
size, bodyLinked, new Angle(), new Velocity(), health,
new DropsMoneyOnDestruction(), new CreatesRubbleOnDestruction());

entityRef.setComponent(new BodyLinked());
entityCreated = true;
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class BodyLinked implements Component<BodyLinked> {

private float mass;

private String jsonPath = "";
private String jsonSchemaFileName = "";

/**
* Sets the mass of the entity. This is called every tick by the {@link BodyHandlerSystem}.
*/
Expand All @@ -46,8 +49,26 @@ public float getMass() {
return mass;
}

public String getJsonPath() {
return jsonPath;
}

public void setJsonPath(String jsonPath) {
this.jsonPath = jsonPath;
}

public String getJsonSchemaFileName() {
return jsonSchemaFileName;
}

public void setJsonSchemaFileName(String jsonSchemaFileName) {
this.jsonSchemaFileName = jsonSchemaFileName;
}

@Override
public void copy(BodyLinked other) {
this.mass = other.getMass();
this.jsonPath = other.getJsonPath();
this.jsonSchemaFileName = other.jsonSchemaFileName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class BodyHandlerSystem implements EventReceiver {
public EventResult onBodyUpdate(BodyUpdateEvent event, EntityRef entity) {

createBodyIfNonexistent(entity);
if (!referenceToBodyObjects.containsKey(entity)) {
return EventResult.CANCEL;
}
Body body = referenceToBodyObjects.get(entity);
BodyLinked bodyLinkedComponent = entity.getComponent(BodyLinked.class).get();
bodyLinkedComponent.setMass(body.getMass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public static class RigidBodyModel {

public static class PolygonModel {
public final List<Vector2> vertices = new ArrayList<>();
private Vector2[] tmpArray; // Used to avoid allocation in attachFixture()
public Vector2[] tmpArray; // Used to avoid allocation in attachFixture()
}

public static class CircleModel {
Expand Down
Loading