Skip to content

Commit

Permalink
feat(JOML): joml migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Dec 31, 2020
1 parent 55937ce commit 3ad183c
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.terasology.signalling.componentSystem;

import org.joml.RoundingMode;
import org.joml.Vector3i;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.event.ReceiveEvent;
import org.terasology.entitySystem.systems.BaseComponentSystem;
Expand All @@ -25,7 +27,6 @@
import org.terasology.math.JomlUtil;
import org.terasology.math.Rotation;
import org.terasology.math.Side;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.In;
import org.terasology.signalling.components.RotateableByScrewdriverComponent;
import org.terasology.signalling.components.ScrewdriverComponent;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void initialise() {
public void rotateGate(ActivateEvent event, EntityRef screwdriver) {
final EntityRef target = event.getTarget();
if (target.hasComponent(RotateableByScrewdriverComponent.class)) {
final Vector3i targetLocation = new Vector3i(JomlUtil.from(event.getTargetLocation()));
final Vector3i targetLocation = new Vector3i(event.getTargetLocation(), RoundingMode.FLOOR);
final Block block = worldProvider.getBlock(targetLocation);
final BlockFamily blockFamily = block.getBlockFamily();
if (blockFamily instanceof SideDefinedBlockFamily) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.terasology.signalling.componentSystem;

import org.joml.Vector3ic;
import org.terasology.blockNetwork.NetworkNode;
import org.terasology.math.geom.Vector3i;

Expand All @@ -28,7 +29,7 @@ public enum Type {

private Type type;

public SignalNetworkNode(Vector3i location, byte inputSides, byte outputSides, Type type) {
public SignalNetworkNode(Vector3ic location, byte inputSides, byte outputSides, Type type) {
super(location, inputSides, outputSides);
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import gnu.trove.iterator.TObjectLongIterator;
import gnu.trove.map.TObjectLongMap;
import gnu.trove.map.hash.TObjectLongHashMap;
import org.joml.RoundingMode;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.blockNetwork.BlockNetworkUtil;
Expand All @@ -38,9 +41,6 @@
import org.terasology.logic.delay.DelayedActionTriggeredEvent;
import org.terasology.logic.location.LocationComponent;
import org.terasology.math.Side;
import org.terasology.math.geom.ImmutableVector3i;
import org.terasology.math.geom.Vector3f;
import org.terasology.math.geom.Vector3i;
import org.terasology.registry.CoreRegistry;
import org.terasology.registry.In;
import org.terasology.signalling.components.SignalConsumerAdvancedStatusComponent;
Expand Down Expand Up @@ -100,7 +100,7 @@ public class SignalSwitchBehaviourSystem extends BaseComponentSystem implements

private Set<Vector3i> activatedPressurePlates = Sets.newHashSet();

private TObjectLongMap<ImmutableVector3i> gateLastSignalChangeTime = new TObjectLongHashMap<>();
private TObjectLongMap<Vector3i> gateLastSignalChangeTime = new TObjectLongHashMap<>();

private long lastSignalCleanupExecuteTime;

Expand Down Expand Up @@ -139,7 +139,7 @@ public void handleGateSignalChange(EntityRef entity) {
public void handleDelayedTrigger(String actionId, EntityRef entity) {
if (processOutputForNormalGate(entity)) {
BlockComponent block = entity.getComponent(BlockComponent.class);
gateLastSignalChangeTime.put(new ImmutableVector3i(block.getPosition()), time.getGameTimeInMs());
gateLastSignalChangeTime.put(block.getPosition(new Vector3i()), time.getGameTimeInMs());
}
}
};
Expand All @@ -159,7 +159,7 @@ public void handleGateSignalChange(EntityRef entity) {
public void handleDelayedTrigger(String actionId, EntityRef entity) {
if (processOutputForRevertedGate(entity)) {
BlockComponent block = entity.getComponent(BlockComponent.class);
gateLastSignalChangeTime.put(new ImmutableVector3i(block.getPosition()), time.getGameTimeInMs());
gateLastSignalChangeTime.put(block.getPosition(new Vector3i()), time.getGameTimeInMs());
}
}
});
Expand Down Expand Up @@ -201,7 +201,7 @@ public void handleGateSignalChange(EntityRef entity) {
public void handleDelayedTrigger(String actionId, EntityRef entity) {
if (processOutputForSetResetGate(entity)) {
BlockComponent block = entity.getComponent(BlockComponent.class);
gateLastSignalChangeTime.put(new ImmutableVector3i(block.getPosition()), time.getGameTimeInMs());
gateLastSignalChangeTime.put(block.getPosition(new Vector3i()), time.getGameTimeInMs());
}
}
});
Expand Down Expand Up @@ -256,7 +256,7 @@ public void delayedTriggerOnSignalGate(DelayedActionTriggeredEvent event, Entity
private void deleteOldSignalChangesForGates() {
long worldTime = time.getGameTimeInMs();
if (lastSignalCleanupExecuteTime + SIGNAL_CLEANUP_INTERVAL < worldTime) {
final TObjectLongIterator<ImmutableVector3i> iterator = gateLastSignalChangeTime.iterator();
final TObjectLongIterator<Vector3i> iterator = gateLastSignalChangeTime.iterator();
while (iterator.hasNext()) {
iterator.advance();
if (iterator.value() + GATE_MINIMUM_SIGNAL_CHANGE_INTERVAL < worldTime) {
Expand Down Expand Up @@ -360,8 +360,8 @@ private void handlePressurePlateEvents() {

Iterable<EntityRef> players = entityManager.getEntitiesWith(CharacterComponent.class, LocationComponent.class);
for (EntityRef player : players) {
Vector3f playerLocation = player.getComponent(LocationComponent.class).getWorldPosition();
Vector3i locationBeneathPlayer = new Vector3i(playerLocation.x + 0.5f, playerLocation.y - 0.5f, playerLocation.z + 0.5f);
Vector3f playerLocation = player.getComponent(LocationComponent.class).getWorldPosition(new Vector3f());
Vector3i locationBeneathPlayer = new Vector3i(new Vector3f(playerLocation.x + 0.5f, playerLocation.y - 0.5f, playerLocation.z + 0.5f), RoundingMode.FLOOR);
Block blockBeneathPlayer = worldProvider.getBlock(locationBeneathPlayer);
if (blockBeneathPlayer == signalPressurePlate) {
EntityRef entityBeneathPlayer = blockEntityRegistry.getBlockEntityAt(locationBeneathPlayer);
Expand Down Expand Up @@ -423,7 +423,7 @@ public void configureTimeDelay(SetSignalDelayEvent event, EntityRef entity) {
@ReceiveEvent(components = {BlockComponent.class, SignalProducerComponent.class})
public void producerActivated(ActivateEvent event, EntityRef entity) {
SignalProducerComponent producerComponent = entity.getComponent(SignalProducerComponent.class);
Vector3i blockLocation = new Vector3i(entity.getComponent(BlockComponent.class).getPosition());
Vector3i blockLocation = entity.getComponent(BlockComponent.class).getPosition(new Vector3i());
Block blockAtLocation = worldProvider.getBlock(blockLocation);
if (blockAtLocation == signalTransformer) {
signalTransformerActivated(entity, producerComponent);
Expand Down Expand Up @@ -549,7 +549,7 @@ public void gateConsumerModified(OnChangedComponent event, EntityRef entity, Sig
public void consumerModified(OnChangedComponent event, EntityRef entity) {
if (entity.hasComponent(BlockComponent.class)) {
SignalConsumerStatusComponent consumerStatusComponent = entity.getComponent(SignalConsumerStatusComponent.class);
Vector3i blockLocation = new Vector3i(entity.getComponent(BlockComponent.class).getPosition());
Vector3i blockLocation = entity.getComponent(BlockComponent.class).getPosition(new Vector3i());
Block block = worldProvider.getBlock(blockLocation);

SignalConsumerComponent signalConsumerComponent = entity.getComponent(SignalConsumerComponent.class);
Expand Down Expand Up @@ -609,7 +609,7 @@ private void delayGateSignalChangeIfNeeded(EntityRef entity, String actionId) {
// Schedule for the gate to be looked either immediately (during "update" method) or at least
// GATE_MINIMUM_SIGNAL_CHANGE_INTERVAL from the time it has last changed, whichever is later
long delay;
final ImmutableVector3i location = new ImmutableVector3i(entity.getComponent(BlockComponent.class).getPosition());
final Vector3i location = entity.getComponent(BlockComponent.class).getPosition(new Vector3i());
if (gateLastSignalChangeTime.containsKey(location)) {
delay = gateLastSignalChangeTime.get(location) + GATE_MINIMUM_SIGNAL_CHANGE_INTERVAL - time.getGameTimeInMs();
} else {
Expand Down
Loading

0 comments on commit 3ad183c

Please sign in to comment.