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

chore(LocationComponent): provide convenience constructor for Vector3i #4901

Merged
merged 2 commits into from
Sep 13, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.joml.Quaternionfc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.joml.Vector3ic;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.math.Direction;
import org.terasology.engine.network.Replicate;
Expand Down Expand Up @@ -35,7 +36,7 @@ public final class LocationComponent implements Component<LocationComponent>, Re
// Standard position/rotation
@Replicate
@TextField
Vector3f position = new Vector3f();
final Vector3f position = new Vector3f();
Copy link
Member

@pollend pollend Sep 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can have this as final. how does the serialization work in gestalt, I thought it instantiated a new object and assigned it but you can't do that if the field is final.

@Replicate
Quaternionf rotation = new Quaternionf();
@Replicate
Expand All @@ -53,6 +54,10 @@ public LocationComponent(Vector3fc position) {
setLocalPosition(position);
}

public LocationComponent(Vector3ic position) {
this(new Vector3f(position));
}

private void dirty() {
if (!isDirty && parent == EntityRef.NULL) {
lastRotation.set(rotation);
Expand Down Expand Up @@ -280,11 +285,12 @@ public void copyFrom(LocationComponent other) {
this.replicateChanges = other.replicateChanges;
this.isDirty = other.isDirty;
this.parent = other.parent;
this.children = Lists.newArrayList(other.children);
this.position = new Vector3f(other.position);
this.rotation = new Quaternionf(other.rotation);
this.children.clear();
this.children.addAll(other.children);
this.position.set(other.position);
this.rotation.set(other.rotation);
this.scale = other.scale;
this.lastPosition = new Vector3f(other.lastPosition);
this.lastRotation = new Quaternionf(other.lastRotation);
this.lastPosition.set(other.lastPosition);
this.lastRotation.set(other.lastRotation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
package org.terasology.engine.world;

import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.terasology.gestalt.entitysystem.component.Component;

public class RelevanceRegionComponent implements Component<RelevanceRegionComponent> {

public Vector3i distance = new Vector3i(1, 1, 1);

public RelevanceRegionComponent() { }

public RelevanceRegionComponent(Vector3ic distance) {
this.distance.set(distance);
}

@Override
public void copyFrom(RelevanceRegionComponent other) {
this.distance = new Vector3i(other.distance);
this.distance.set(other.distance);
}
}