Skip to content

Commit

Permalink
feat(JOML): migrate with Polyworld (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend authored Jan 26, 2021
1 parent c24eead commit e73211e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/terasology/lost/LevelSpawnSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.terasology.lost;

import org.joml.RoundingMode;
import org.joml.Vector2fc;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.slf4j.Logger;
Expand Down Expand Up @@ -80,10 +81,10 @@ public void onBiomeChange(OnBiomeChangedEvent event, EntityRef player,
// fetch the current voronoi region
GraphRegion region = worldRegion.getFacet(GraphFacet.class).getWorldTriangle(Math.round(playerLocation.x),
Math.round(playerLocation.z)).getRegion();
ImmutableVector2f center = region.getCenter();
Vector2fc center = region.getCenter();

float distanceFromHut = center.distance(new Vector2f(progressTrackingComponent.hutPosition.x,
progressTrackingComponent.hutPosition.z));
float distanceFromHut = center.distance(progressTrackingComponent.hutPosition.x,
progressTrackingComponent.hutPosition.z);
if (distanceFromHut < MINIMUM_DISTANCE_FROM_HUT && !event.getNewBiome().getDisplayName().contains("forest")) {
return;
}
Expand All @@ -93,8 +94,8 @@ public void onBiomeChange(OnBiomeChangedEvent event, EntityRef player,
}
if (levelURI != null && progressTrackingComponent.isWellFound()) {
// round center coordinates to Integers
int x = Math.round(center.getX());
int y = Math.round(center.getY());
int x = Math.round(center.x());
int y = Math.round(center.y());
int height = Math.round(surfacesFacet.getPrimarySurface(elevationFacet, x, y).orElse(elevationFacet.getWorld(x, y)));

Vector3i spawnPosition = new Vector3i(x, height, y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package org.terasology.lost.generator;

import org.joml.RoundingMode;
import org.joml.Vector2fc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.joml.Vector3i;
Expand Down Expand Up @@ -143,7 +144,7 @@ public Vector3fc getSpawnPosition(EntityRef entity) {
continue;
}
if (!biome.equals(WhittakerBiome.OCEAN) && !biome.equals(WhittakerBiome.LAKE) && !biome.equals(WhittakerBiome.BEACH)) {
picker.offer(JomlUtil.from(r.getCenter()), r);
picker.offer(r.getCenter(), r);
locationFound = true;
break;
}
Expand All @@ -154,8 +155,8 @@ public Vector3fc getSpawnPosition(EntityRef entity) {
}
Vector2i target;
if (picker.getClosest() != null) {
ImmutableVector2f hit = picker.getClosest().getCenter();
target = new Vector2i(hit.getX(), hit.getY());
Vector2fc hit = picker.getClosest().getCenter();
target = new Vector2i(hit.x(), hit.y());
} else {
target = new Vector2i(desiredPos.x(), desiredPos.z());
}
Expand Down

0 comments on commit e73211e

Please sign in to comment.