Skip to content

Commit

Permalink
feat(JOML): migrate (parts of) LocationComponent
Browse files Browse the repository at this point in the history
* feat(JOML): migrate `LocationComponent#getWorldPosition?
* feat(JOML): migrate `LocationComponent` constructor

Contributes to #3832
  • Loading branch information
skaldarnar committed Jan 30, 2021
1 parent faa9eff commit f0e32cf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void addChunksToRegionComponent(EntityRef entity, Collection<Vecto
/**
* Watched chunks are defined as the union of:
* <ul>
* <li>The chunk in which the {@link LocationComponent#getWorldPosition()} resides, if any</li>
* <li>The chunk in which the {@link LocationComponent#getWorldPosition(Vector3f)} resides, if any</li>
* <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
* </ul>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,26 @@
*/
package org.terasology.logic.inventory.events;

import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.terasology.entitySystem.event.Event;
import org.terasology.math.JomlUtil;
import org.terasology.math.geom.Vector3f;
import org.terasology.network.ServerEvent;

/**
* Fire this event on an item in order for the authority to add the necessary components to put it in the world.
*/
@ServerEvent
public class DropItemEvent implements Event {
private Vector3f position;
private Vector3f position = new Vector3f();

public DropItemEvent() {
}

/**
* @deprecated This method is scheduled for removal in an upcoming version.
* Use the JOML implementation instead: {@link #DropItemEvent(org.joml.Vector3f)}.
*/
public DropItemEvent(Vector3f position) {
this.position = position;
public DropItemEvent(Vector3fc position) {
this.position.set(position);
}

public DropItemEvent(org.joml.Vector3f position) {
this.position = JomlUtil.from(position);
}

public Vector3f getPosition() {
public Vector3fc getPosition() {
return position;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ public final class LocationComponent implements Component, ReplicationCheck {
public LocationComponent() {
}

/**
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #LocationComponent(Vector3fc)}.
*/
@Deprecated
public LocationComponent(Vector3f position) {
setLocalPosition(position);
}

public LocationComponent(Vector3fc position) {
setLocalPosition(position);
}
Expand All @@ -75,7 +66,6 @@ public Quat4f getLocalRotation() {
return rotation;
}


/**
* @param newQuat
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
Expand All @@ -97,7 +87,6 @@ public void setLocalRotation(Quaternionfc rot) {
rotation.set(JomlUtil.from(rot));
}


/**
* @return The position of this component relative to any parent. Can be directly modified to update the component
* TODO: make this readonly Vector3fc -- Michael Pollind
Expand All @@ -117,7 +106,6 @@ public void setLocalPosition(Vector3f pos) {
position.set(pos);
}


/**
* the local position of this location component
*
Expand All @@ -128,18 +116,6 @@ public void setLocalPosition(Vector3fc pos) {
position.set(JomlUtil.from(pos));
}

/**
* @return
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #getLocalDirection(org.joml.Vector3f)}.
*/
@Deprecated
public Vector3f getLocalDirection() {
Vector3f result = Direction.FORWARD.getVector3f();
getLocalRotation().rotate(result, result);
return result;
}

/**
* gets the local direction of the given entity in
*
Expand All @@ -150,7 +126,6 @@ public org.joml.Vector3f getLocalDirection(org.joml.Vector3f dest) {
return dest.set(Direction.FORWARD.asVector3i()).rotate(JomlUtil.from(getLocalRotation()));
}


/**
* set the local scale
* @param value the scale
Expand All @@ -174,19 +149,7 @@ public float getLocalScale() {
*/
@Deprecated
public Vector3f getWorldPosition() {
return getWorldPosition(new Vector3f());
}

/**
* @param output
* @return
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #getWorldPosition(org.joml.Vector3f)}.
*/
@Deprecated
public Vector3f getWorldPosition(Vector3f output) {
output.set(JomlUtil.from(getWorldPosition(new org.joml.Vector3f())));
return output;
return JomlUtil.from(getWorldPosition(new org.joml.Vector3f()));
}

/**
Expand Down Expand Up @@ -234,7 +197,6 @@ public Vector3f getWorldDirection() {
return result;
}


public org.joml.Vector3f getWorldDirection(org.joml.Vector3f dest) {
return dest.set(Direction.FORWARD.asVector3f()).rotate(JomlUtil.from(getWorldRotation()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public BlockComponent() {
}
/**
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #BlockComponent(Block, org.joml.Vector3i)}.
* {@link #BlockComponent(Block, org.joml.Vector3ic)}.
*/
@Deprecated
public BlockComponent(Block block, Vector3i pos) {
this.block = block;
this.position.set(pos);
}

public BlockComponent(Block block, org.joml.Vector3i pos) {
public BlockComponent(Block block, org.joml.Vector3ic pos) {
this.block = block;
this.position.set(JomlUtil.from(pos));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public EntityRef getBlockEntityAt(Vector3ic blockPosition) {
EntityRef blockEntity = getExistingBlockEntityAt(blockPosition);
if ((!blockEntity.exists() || !blockEntity.hasComponent(NetworkComponent.class)) && isBlockRelevant(blockPosition.x(), blockPosition.y(), blockPosition.z())) {
Block block = getBlock(blockPosition.x(), blockPosition.y(), blockPosition.z());
blockEntity = createBlockEntity(JomlUtil.from(blockPosition), block);
blockEntity = createBlockEntity(blockPosition, block);
}
return blockEntity;
}
Expand Down Expand Up @@ -375,9 +375,9 @@ private <T extends Component> void updateComponent(EntityRef blockEntity, Compon
}
}

private EntityRef createBlockEntity(Vector3i blockPosition, Block block) {
private EntityRef createBlockEntity(Vector3ic blockPosition, Block block) {
EntityBuilder builder = entityManager.newBuilder(block.getPrefab().orElse(null));
builder.addComponent(new LocationComponent(blockPosition.toVector3f()));
builder.addComponent(new LocationComponent(new org.joml.Vector3f(blockPosition)));
builder.addComponent(new BlockComponent(block, blockPosition));
boolean isTemporary = isTemporaryBlock(builder, block);
if (!isTemporary && !builder.hasComponent(NetworkComponent.class)) {
Expand All @@ -392,7 +392,7 @@ private EntityRef createBlockEntity(Vector3i blockPosition, Block block) {
blockEntity = builder.build();
}

blockEntityLookup.put(new Vector3i(blockPosition), blockEntity);
blockEntityLookup.put(JomlUtil.from(blockPosition), blockEntity);
return blockEntity;
}

Expand Down

0 comments on commit f0e32cf

Please sign in to comment.