Large package structure refactoring.

This commit is contained in:
Harrison Deng 2020-05-04 16:41:46 -05:00
parent 7fb858c7ca
commit 1167efbe4e
26 changed files with 201 additions and 196 deletions

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft;
package ca.recrown.islandsurvivalcraft.utilities;
import java.util.ArrayList;
import java.util.HashMap;
@ -7,9 +7,9 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
public class Utilities {
public class GeneralUtilities {
public final static int CHUNK_SIZE = 16;
public final static ExecutorService ISC_EXECUTOR_ALPHA = Executors.newFixedThreadPool(1, createThreadFactory("ALPHA", Thread.NORM_PRIORITY + 1));
public final static ExecutorService ISC_EXECUTOR_BETA = Executors.newFixedThreadPool(2, createThreadFactory("BETA", Thread.NORM_PRIORITY));

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.caching;
package ca.recrown.islandsurvivalcraft.utilities.caching;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.caching;
package ca.recrown.islandsurvivalcraft.utilities.caching;
import java.util.concurrent.locks.ReentrantLock;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.caching;
package ca.recrown.islandsurvivalcraft.utilities.caching;
class CacheValue<KeyType, ValueType> {
/**

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.datatypes;
package ca.recrown.islandsurvivalcraft.utilities.datatypes;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.datatypes;
package ca.recrown.islandsurvivalcraft.utilities.datatypes;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.datatypes;
package ca.recrown.islandsurvivalcraft.utilities.datatypes;
import java.util.Objects;

View File

@ -1,6 +1,6 @@
package ca.recrown.islandsurvivalcraft.floodfill;
package ca.recrown.islandsurvivalcraft.utilities.floodfill;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
public interface Floodable {
/**

View File

@ -1,9 +1,10 @@
package ca.recrown.islandsurvivalcraft.floodfill;
package ca.recrown.islandsurvivalcraft.utilities.floodfill;
import java.util.HashSet;
import java.util.LinkedList;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
public class Flooder {
private final Point2 start;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.pathfinding;
package ca.recrown.islandsurvivalcraft.utilities.pathfinding;
public interface CoordinateTargetValidatable {
/**

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.pathfinding;
package ca.recrown.islandsurvivalcraft.utilities.pathfinding;
public interface CoordinateValidatable {
public boolean validate(int x, int y);

View File

@ -1,8 +1,8 @@
package ca.recrown.islandsurvivalcraft.pathfinding;
package ca.recrown.islandsurvivalcraft.utilities.pathfinding;
import java.util.Objects;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
public class DFSNode extends Point2 implements Comparable<DFSNode> {
private DFSNode goal;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.pathfinding;
package ca.recrown.islandsurvivalcraft.utilities.pathfinding;
import java.util.HashSet;
import java.util.PriorityQueue;
@ -6,7 +6,7 @@ import java.util.Queue;
import org.apache.commons.lang.NullArgumentException;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
public class DepthFirstSearch {
private Queue<DFSNode> queue;

View File

@ -8,7 +8,7 @@ import java.util.Map.Entry;
import org.bukkit.block.Biome;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import ca.recrown.islandsurvivalcraft.Utilities;
import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities;
public class BiomeMap {
private final SimplexOctaveGenerator noise;
@ -74,7 +74,7 @@ public class BiomeMap {
landBiomeTemperatures.put(Biome.BADLANDS_PLATEAU, 2.0f);
landBiomeTemperatures.put(Biome.MODIFIED_BADLANDS_PLATEAU, 2.0f);
landBiomeTemperatures.put(Biome.SHATTERED_SAVANNA_PLATEAU, 1.0f);
temperaturesForLand = Utilities.invertHashMap(landBiomeTemperatures);
temperaturesForLand = GeneralUtilities.invertHashMap(landBiomeTemperatures);
for (Entry<Float, ArrayList<Biome>> entry : temperaturesForLand.entrySet()) {
if (entry.getKey() <= 0.05f) {
@ -95,7 +95,7 @@ public class BiomeMap {
oceanBiomeTemperatures.put(Biome.OCEAN, 0.3f);
oceanBiomeTemperatures.put(Biome.COLD_OCEAN, 0.3f);
oceanBiomeTemperatures.put(Biome.FROZEN_OCEAN, 0f);
temperaturesForOcean = Utilities.invertHashMap(oceanBiomeTemperatures);
temperaturesForOcean = GeneralUtilities.invertHashMap(oceanBiomeTemperatures);
for (Entry<Float, ArrayList<Biome>> entry : temperaturesForOcean.entrySet()) {
if (entry.getKey() <= 0.00f) {
temperaturePartitionedOceanBiomes.get(0.0f).addAll(entry.getValue());

View File

@ -4,10 +4,10 @@ import java.util.Random;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateValidatable;
import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.pathfinding.CoordinateValidatable;
import ca.recrown.islandsurvivalcraft.utilities.pathfinding.DepthFirstSearch;
public class IslandWorldMap implements CoordinateValidatable {
private final Cache<Point2, Double> blockValueCache;

View File

@ -4,8 +4,8 @@ import java.util.Random;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
public class TemperatureMap {
private final Cache<Point2, Float> temperatureCache;

View File

@ -3,8 +3,8 @@ package ca.recrown.islandsurvivalcraft.world.generation.biomes;
import org.bukkit.World;
import org.bukkit.block.Biome;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.world.BiomeMap;
import ca.recrown.islandsurvivalcraft.world.IslandWorldMap;
import ca.recrown.islandsurvivalcraft.world.TemperatureMap;

View File

@ -3,13 +3,13 @@ package ca.recrown.islandsurvivalcraft.world.generation.biomes;
import org.bukkit.World;
import org.bukkit.block.Biome;
import ca.recrown.islandsurvivalcraft.Utilities;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.floodfill.Floodable;
import ca.recrown.islandsurvivalcraft.floodfill.Flooder;
import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateTargetValidatable;
import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch;
import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.floodfill.Floodable;
import ca.recrown.islandsurvivalcraft.utilities.floodfill.Flooder;
import ca.recrown.islandsurvivalcraft.utilities.pathfinding.CoordinateTargetValidatable;
import ca.recrown.islandsurvivalcraft.utilities.pathfinding.DepthFirstSearch;
import ca.recrown.islandsurvivalcraft.world.BiomeMap;
import ca.recrown.islandsurvivalcraft.world.IslandWorldMap;
import ca.recrown.islandsurvivalcraft.world.TemperatureMap;
@ -19,7 +19,7 @@ public class UniqueBiomeGenerator implements BiomeGenerator {
public void generateBiomeColumn(Biome[][][] chunkBiomeSets, World world, int chunkX, int chunkZ, int localX, int localZ, IslandWorldMap mapper, BiomeMap biomeSelector, TemperatureMap tempGen, Cache<Point2, Biome[]> biomeCache, Cache<Point2, Boolean> chunkGenCache) {
int worldX = 16 * chunkX + localX;
int worldZ = 16 * chunkZ + localZ;
Point2 chunkCoords = Utilities.worldToChunkCoordinates(new Point2(worldX, worldZ));
Point2 chunkCoords = GeneralUtilities.worldToChunkCoordinates(new Point2(worldX, worldZ));
chunkGenCache.set(chunkCoords, false);
//Check if we can just give it something in cache.
@ -60,14 +60,14 @@ public class UniqueBiomeGenerator implements BiomeGenerator {
Biome[] res = null;
if (chunkBiomeSets != null) {
Point2 localCoords = Utilities.worldToLocalChunkCoordinates(worldCoords);
Point2 localCoords = GeneralUtilities.worldToLocalChunkCoordinates(worldCoords);
return chunkBiomeSets[localCoords.x][localCoords.y];
}
res = biomeCache.get(worldCoords);
if (res != null) return res;
Point2 chunkCoords = Utilities.worldToChunkCoordinates(worldCoords);
Point2 chunkCoords = GeneralUtilities.worldToChunkCoordinates(worldCoords);
Boolean chunkExists = existenceCache.get(chunkCoords);
if (chunkExists == null) {
chunkExists = world.isChunkGenerated(worldX, worldZ);
@ -85,7 +85,7 @@ public class UniqueBiomeGenerator implements BiomeGenerator {
private void setCacheBiome(int worldX, int worldZ, Biome[] biomeSet, Biome[][][] localBiomes, Cache<Point2, Biome[]> biomeCache) {
Point2 worldCoords = new Point2(worldX, worldZ);
if (localBiomes != null) {
Point2 localCoords = Utilities.worldToLocalChunkCoordinates(worldCoords);
Point2 localCoords = GeneralUtilities.worldToLocalChunkCoordinates(worldCoords);
localBiomes[localCoords.x][localCoords.y] = biomeSet;
}
biomeCache.set(worldCoords, biomeSet);
@ -145,7 +145,7 @@ public class UniqueBiomeGenerator implements BiomeGenerator {
@Override
public boolean flood(Point2 point) {
Point2 chunkCoords = Utilities.worldToChunkCoordinates(point);
Point2 chunkCoords = GeneralUtilities.worldToChunkCoordinates(point);
if (!this.chunkCoords.fastEquals(chunkCoords) || !mapper.validate(point.x, point.y)) return false;
int x = point.x;
int y = point.y;

View File

@ -15,9 +15,9 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import ca.recrown.islandsurvivalcraft.Utilities;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.world.BiomeMap;
import ca.recrown.islandsurvivalcraft.world.IslandWorldMap;
import ca.recrown.islandsurvivalcraft.world.TemperatureMap;
@ -39,8 +39,8 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
private volatile WorldLayerShader layerShader;
private volatile Cache<Point2, Biome[]> biomeCache = new Cache<>(131072);
private volatile Cache<Point2, Boolean> chunkLoadedCache = new Cache<>(4096);
private volatile ExecutorService exAlpha = Utilities.ISC_EXECUTOR_ALPHA;
private volatile ExecutorService exBeta = Utilities.ISC_EXECUTOR_BETA;
private volatile ExecutorService exAlpha = GeneralUtilities.ISC_EXECUTOR_ALPHA;
private volatile ExecutorService exBeta = GeneralUtilities.ISC_EXECUTOR_BETA;
public void initialize(Random random, boolean uniqueBiome, int seaLevel, int worldHeight) {
if (initialized) throw new IllegalStateException("This generator has already been initialized");
@ -76,22 +76,22 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
LinkedList<Future<Boolean>> tasks = new LinkedList<>();
ChunkData chunkData = createChunkData(world);
Future<Boolean> preLoader = exAlpha.submit(() -> {
for (int x = Utilities.CHUNK_SIZE - 1; x >= 0; x--) {
for (int z = Utilities.CHUNK_SIZE - 1; z >= 0; z--) {
for (int x = GeneralUtilities.CHUNK_SIZE - 1; x >= 0; x--) {
for (int z = GeneralUtilities.CHUNK_SIZE - 1; z >= 0; z--) {
if (Thread.currentThread().isInterrupted()) return false;
islandMap.getWorldValue(Utilities.CHUNK_SIZE * chunkX + x, Utilities.CHUNK_SIZE * chunkZ + z);
islandMap.getWorldValue(GeneralUtilities.CHUNK_SIZE * chunkX + x, GeneralUtilities.CHUNK_SIZE * chunkZ + z);
}
}
return true;
});
Biome[][][] biomeArraySet = new Biome[Utilities.CHUNK_SIZE][Utilities.CHUNK_SIZE][4];
for (int x = 0; x < Utilities.CHUNK_SIZE; x++) {
for (int z = 0; z < Utilities.CHUNK_SIZE; z++) {
Biome[][][] biomeArraySet = new Biome[GeneralUtilities.CHUNK_SIZE][GeneralUtilities.CHUNK_SIZE][4];
for (int x = 0; x < GeneralUtilities.CHUNK_SIZE; x++) {
for (int z = 0; z < GeneralUtilities.CHUNK_SIZE; z++) {
final int localX = x;
final int localZ = z;
final int worldX = Utilities.CHUNK_SIZE * chunkX + localX;
final int worldZ = Utilities.CHUNK_SIZE * chunkZ + localZ;
final int worldX = GeneralUtilities.CHUNK_SIZE * chunkX + localX;
final int worldZ = GeneralUtilities.CHUNK_SIZE * chunkZ + localZ;
if (biomeArraySet[localX][localZ][0] == null) {
biomeGenerator.generateBiomeColumn(biomeArraySet, world, chunkX, chunkZ, localX, localZ, islandMap, biomeMap,
temperatureMap, biomeCache, chunkLoadedCache);

View File

@ -7,8 +7,8 @@ import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.datatypes.Vector3;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Vector3;
import ca.recrown.islandsurvivalcraft.world.IslandWorldMap;
@SuppressWarnings("unused")

View File

@ -1,129 +0,0 @@
package ca.recrown.islandsurvivalcraft;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
/**
* Unit test for simple App.
*/
@TestInstance(Lifecycle.PER_CLASS)
public class UtilitiesTest {
/**
* Basic hashmap inversion test.
*/
@Test
public void testInvertHashMap()
{
HashMap<String, Integer> hashMap = new HashMap<>();
hashMap.put("a", 1);
hashMap.put("b", 1);
hashMap.put("c", 2);
hashMap.put("d", 2);
HashMap<Integer, ArrayList<String>> res = Utilities.invertHashMap(hashMap);
ArrayList<String> first = res.get(1);
ArrayList<String> expectedFirst = new ArrayList<>();
expectedFirst.add("a");
expectedFirst.add("b");
ArrayList<String> second = res.get(2);
ArrayList<String> expectedSecond = new ArrayList<>();
expectedSecond.add("c");
expectedSecond.add("d");
assertEquals(first, expectedFirst);
assertEquals(second, expectedSecond);
}
@Test
public void testMagnitudeAddPositive() {
assertEquals(2, Utilities.addMagnitude(1, 1));
}
@Test
public void testMagnitudeAddNegative() {
assertEquals(-2, Utilities.addMagnitude(-1, 1));
}
@Test
public void testWorldToChunkCoordinatesNegativePerfect() {
assertEquals(new Point2(-4, -3), Utilities.worldToChunkCoordinates(-64, -48));
}
@Test
public void testWorldToChunkCoordinatesNegativeOff() {
assertEquals(new Point2(-4, -3), Utilities.worldToChunkCoordinates(-55, -33));
}
@Test
public void testWorldToChunkCoordinatesNegativeOffClose() {
assertEquals(new Point2(15, -15), Utilities.worldToChunkCoordinates(255, -227));
}
@Test
public void testWorldToChunkCoordinatesPositivePerfect() {
assertEquals(new Point2(4, 5), Utilities.worldToChunkCoordinates(64, 80));
}
@Test
public void testWorldToChunkCoordinatesPositiveOff() {
assertEquals(new Point2(4, 5), Utilities.worldToChunkCoordinates(67, 84));
}
@Test
public void testWorldToLocalCoordinatesNegative() {
assertEquals(new Point2(2, 5), Utilities.worldToLocalChunkCoordinates(-62, -27));
assertEquals(new Point2(2, 5), Utilities.worldToLocalChunkCoordinates(new Point2(-62, -27)));
}
@Test
public void testWorldToLocalCoordinatesNegativePerfect() {
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(-128, -32));
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(new Point2(-256, -16)));
}
@Test
public void testWorldToLocalCoordinatesPositive() {
assertEquals(new Point2(7, 3), Utilities.worldToLocalChunkCoordinates(39, 83));
assertEquals(new Point2(7, 3), Utilities.worldToLocalChunkCoordinates(new Point2(39, 83)));
}
@Test
public void testWorldToLocalCoordinatesPositivePerfect() {
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(1024, 32));
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(new Point2(16, 80)));
}
@Test
public void testWorldToLocalCoordinatesPositiveEntirety() {
int chunkX = 4;
int chunkZ = 3;
for (int x = 0; x < Utilities.CHUNK_SIZE; x++) {
for (int z = 0; z < Utilities.CHUNK_SIZE; z++) {
int worldX = Utilities.CHUNK_SIZE * chunkX + x;
int worldZ = Utilities.CHUNK_SIZE * chunkZ + z;
assertEquals(new Point2(x, z), Utilities.worldToLocalChunkCoordinates(new Point2(worldX, worldZ)));
}
}
}
@Test
public void testWorldToLocalCoordinatesNegativeEntirety() {
int chunkX = -42;
int chunkZ = -3;
for (int x = 0; x < Utilities.CHUNK_SIZE; x++) {
for (int z = 0; z < Utilities.CHUNK_SIZE; z++) {
int worldX = Utilities.CHUNK_SIZE * chunkX + x;
int worldZ = Utilities.CHUNK_SIZE * chunkZ + z;
assertEquals(new Point2(x, z), Utilities.worldToLocalChunkCoordinates(new Point2(worldX, worldZ)));
}
}
}
}

View File

@ -0,0 +1,129 @@
package ca.recrown.islandsurvivalcraft.utilities;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
/**
* Unit test for simple App.
*/
@TestInstance(Lifecycle.PER_CLASS)
public class GeneralUtilitiesTest {
/**
* Basic hashmap inversion test.
*/
@Test
public void testInvertHashMap()
{
HashMap<String, Integer> hashMap = new HashMap<>();
hashMap.put("a", 1);
hashMap.put("b", 1);
hashMap.put("c", 2);
hashMap.put("d", 2);
HashMap<Integer, ArrayList<String>> res = GeneralUtilities.invertHashMap(hashMap);
ArrayList<String> first = res.get(1);
ArrayList<String> expectedFirst = new ArrayList<>();
expectedFirst.add("a");
expectedFirst.add("b");
ArrayList<String> second = res.get(2);
ArrayList<String> expectedSecond = new ArrayList<>();
expectedSecond.add("c");
expectedSecond.add("d");
assertEquals(first, expectedFirst);
assertEquals(second, expectedSecond);
}
@Test
public void testMagnitudeAddPositive() {
assertEquals(2, GeneralUtilities.addMagnitude(1, 1));
}
@Test
public void testMagnitudeAddNegative() {
assertEquals(-2, GeneralUtilities.addMagnitude(-1, 1));
}
@Test
public void testWorldToChunkCoordinatesNegativePerfect() {
assertEquals(new Point2(-4, -3), GeneralUtilities.worldToChunkCoordinates(-64, -48));
}
@Test
public void testWorldToChunkCoordinatesNegativeOff() {
assertEquals(new Point2(-4, -3), GeneralUtilities.worldToChunkCoordinates(-55, -33));
}
@Test
public void testWorldToChunkCoordinatesNegativeOffClose() {
assertEquals(new Point2(15, -15), GeneralUtilities.worldToChunkCoordinates(255, -227));
}
@Test
public void testWorldToChunkCoordinatesPositivePerfect() {
assertEquals(new Point2(4, 5), GeneralUtilities.worldToChunkCoordinates(64, 80));
}
@Test
public void testWorldToChunkCoordinatesPositiveOff() {
assertEquals(new Point2(4, 5), GeneralUtilities.worldToChunkCoordinates(67, 84));
}
@Test
public void testWorldToLocalCoordinatesNegative() {
assertEquals(new Point2(2, 5), GeneralUtilities.worldToLocalChunkCoordinates(-62, -27));
assertEquals(new Point2(2, 5), GeneralUtilities.worldToLocalChunkCoordinates(new Point2(-62, -27)));
}
@Test
public void testWorldToLocalCoordinatesNegativePerfect() {
assertEquals(new Point2(0, 0), GeneralUtilities.worldToLocalChunkCoordinates(-128, -32));
assertEquals(new Point2(0, 0), GeneralUtilities.worldToLocalChunkCoordinates(new Point2(-256, -16)));
}
@Test
public void testWorldToLocalCoordinatesPositive() {
assertEquals(new Point2(7, 3), GeneralUtilities.worldToLocalChunkCoordinates(39, 83));
assertEquals(new Point2(7, 3), GeneralUtilities.worldToLocalChunkCoordinates(new Point2(39, 83)));
}
@Test
public void testWorldToLocalCoordinatesPositivePerfect() {
assertEquals(new Point2(0, 0), GeneralUtilities.worldToLocalChunkCoordinates(1024, 32));
assertEquals(new Point2(0, 0), GeneralUtilities.worldToLocalChunkCoordinates(new Point2(16, 80)));
}
@Test
public void testWorldToLocalCoordinatesPositiveEntirety() {
int chunkX = 4;
int chunkZ = 3;
for (int x = 0; x < GeneralUtilities.CHUNK_SIZE; x++) {
for (int z = 0; z < GeneralUtilities.CHUNK_SIZE; z++) {
int worldX = GeneralUtilities.CHUNK_SIZE * chunkX + x;
int worldZ = GeneralUtilities.CHUNK_SIZE * chunkZ + z;
assertEquals(new Point2(x, z), GeneralUtilities.worldToLocalChunkCoordinates(new Point2(worldX, worldZ)));
}
}
}
@Test
public void testWorldToLocalCoordinatesNegativeEntirety() {
int chunkX = -42;
int chunkZ = -3;
for (int x = 0; x < GeneralUtilities.CHUNK_SIZE; x++) {
for (int z = 0; z < GeneralUtilities.CHUNK_SIZE; z++) {
int worldX = GeneralUtilities.CHUNK_SIZE * chunkX + x;
int worldZ = GeneralUtilities.CHUNK_SIZE * chunkZ + z;
assertEquals(new Point2(x, z), GeneralUtilities.worldToLocalChunkCoordinates(new Point2(worldX, worldZ)));
}
}
}
}

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.caching;
package ca.recrown.islandsurvivalcraft.utilities.caching;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.floodfill;
package ca.recrown.islandsurvivalcraft.utilities.floodfill;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -13,7 +13,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.floodfill.Floodable;
@TestInstance(Lifecycle.PER_CLASS)
public class FloodFillTest {

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.pathfinding;
package ca.recrown.islandsurvivalcraft.utilities.pathfinding;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@ -14,6 +14,9 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import ca.recrown.islandsurvivalcraft.utilities.pathfinding.CoordinateTargetValidatable;
import ca.recrown.islandsurvivalcraft.utilities.pathfinding.CoordinateValidatable;
/**
* Unit test for simple App.
*/

View File

@ -19,9 +19,9 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import ca.recrown.islandsurvivalcraft.Utilities;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities;
import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;
import ca.recrown.islandsurvivalcraft.world.BiomeMap;
import ca.recrown.islandsurvivalcraft.world.IslandWorldMap;
import ca.recrown.islandsurvivalcraft.world.TemperatureMap;
@ -60,9 +60,9 @@ public class UniqueBiomeGeneratorTest {
TemperatureMap temperatureMapGenerator = new TemperatureMap(random);
BiomeGenerator biomeGenerator = new UniqueBiomeGenerator();
Biome[][][] biomes = new Biome[Utilities.CHUNK_SIZE][Utilities.CHUNK_SIZE][4];
for (int localX = 0; localX < Utilities.CHUNK_SIZE; localX++) {
for (int localZ = 0; localZ < Utilities.CHUNK_SIZE; localZ++) {
Biome[][][] biomes = new Biome[GeneralUtilities.CHUNK_SIZE][GeneralUtilities.CHUNK_SIZE][4];
for (int localX = 0; localX < GeneralUtilities.CHUNK_SIZE; localX++) {
for (int localZ = 0; localZ < GeneralUtilities.CHUNK_SIZE; localZ++) {
if (biomes[localX][localZ] == null) {
biomeGenerator.generateBiomeColumn(biomes, dummyWorld, chunkX, chunkZ, localX, localZ, mapper,
biomeSelector, temperatureMapGenerator, biomeCache, chunkExistenceCache);