addressed some issues mentioned in line comments on github

master
flying sheep 2013-04-12 14:26:53 +02:00
parent dafa8abd79
commit 187fa40413
7 changed files with 65 additions and 55 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>

View File

@ -25,8 +25,4 @@ public class Amidst {
public static FinderWindow getActiveWindow() {
return mainWindow;
}
public static String getPath() {
return ClassLoader.getSystemClassLoader().getResource(".").getPath();
}
}

View File

@ -61,6 +61,31 @@ public class Util {
color |= 0xFF & b;
return color;
}
private static final int TEMP_DIR_ATTEMPTS = 1000;
/** Guavas method, moved here to avoid a huge dependency
* TODO: maybe switch to JDK 7 to use its java.nio.file.Files#createTempDirectory()
*/
public static File createTempDir() {
return getTempDir(System.currentTimeMillis() + "");
}
public static File getTempDir(String name) {
File baseDir = new File(System.getProperty("java.io.tmpdir"));
String baseName = name + "-";
for (int counter=0; counter<TEMP_DIR_ATTEMPTS; counter++) {
File tempDir = new File(baseDir, baseName + counter);
if (tempDir.isDirectory() || tempDir.mkdir())
return tempDir;
}
throw new IllegalStateException("Failed to create directory within "
+ TEMP_DIR_ATTEMPTS + " attempts (tried "
+ baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');
}
// public static void main(String[] args) {
// try {
// int infinity = 1 / 0;

View File

@ -29,14 +29,14 @@ public class ByteArrayHub {
private int unitOffset;
public ByteArrayHub(long key, byte unitSize, int maxUnits, String strPath) {
public ByteArrayHub(long key, byte unitSize, int maxUnits, File basePath) {
this.unitSize = unitSize;
this.maxUnits = maxUnits;
this.key = key;
unitOffset = maxUnits*unitSize;
path = new File(strPath + Long.toHexString(key).toUpperCase() + ".acache");
path = new File(basePath, Long.toHexString(key).toUpperCase() + ".acache");
data = new byte[unitOffset*ByteArrayCache.CACHE_MAX_SIZE + ByteArrayCache.HEADER_SIZE];
returnCache = new byte[unitSize*maxUnits];
if (path.exists()) {
@ -52,9 +52,6 @@ public class ByteArrayHub {
}
//Log.i("@@@@@ " + inStream.read(data));
inStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -80,9 +77,6 @@ public class ByteArrayHub {
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View File

@ -2,21 +2,17 @@ package amidst.map;
import java.io.File;
import amidst.Amidst;
import amidst.Util;
public abstract class CacheManager {
protected String cachePath;
protected File cachePath;
public CacheManager() {
public CacheManager() {}
public void setCachePath(String name) {
cachePath = Util.getTempDir(name);
}
public void setCachePath(String path) {
cachePath = Amidst.getPath() + "cache/" + path;
(new File(cachePath)).mkdirs();
}
public abstract void save(Fragment frag);
public abstract void load(Fragment frag, int layerID);
public abstract void unload(Fragment frag);

View File

@ -12,36 +12,36 @@ import amidst.map.Layer;
public class BiomeLayer extends Layer {
private static int[] biomeColors = new int[] {
Util.makeColor(13 ,51 ,219), //Ocean;
Util.makeColor(104,222,104), //Plains;
Util.makeColor(226,242,131), //Desert;
Util.makeColor(171,105,34 ), //Extreme Hills;
Util.makeColor(40 ,181,22 ), //Forest;
Util.makeColor(32 ,110,22 ), //Taiga;
Util.makeColor(108,158,79), //Swampland;
Util.makeColor(14,127,227), //River;
Util.makeColor(143,25 ,10 ), //Hell;
Util.makeColor(209,233,235), //Sky;
Util.makeColor(70 ,104,199), //FrozenOcean;
Util.makeColor(171,216,255), //FrozenRiver;
Util.makeColor(156,214,190), //Ice Plains;
Util.makeColor(151,162,130), //Ice Mountains;
Util.makeColor(219,196,164), //MushroomIsland;
Util.makeColor(242,216,179), //MushroomIslandShore;
Util.makeColor(255,254,189), //Beach
Util.makeColor(230,202, 78), //DesertHills
Util.makeColor(89 ,176, 32), //ForestHills
Util.makeColor(66 ,110, 22), //TaigaHills
Util.makeColor(186,159, 39), //Extreme Hills Edge
Util.makeColor(26 ,87 ,34 ),
Util.makeColor(73 ,105,33 )
Util.makeColor(13 ,51 ,219), //Ocean;
Util.makeColor(104,222,104), //Plains;
Util.makeColor(226,242,131), //Desert;
Util.makeColor(171,105,34 ), //Extreme Hills;
Util.makeColor(40 ,181,22 ), //Forest;
Util.makeColor(32 ,110,22 ), //Taiga;
Util.makeColor(108,158,79), //Swampland;
Util.makeColor(14,127,227), //River;
Util.makeColor(143,25 ,10 ), //Hell;
Util.makeColor(209,233,235), //Sky;
Util.makeColor(70 ,104,199), //FrozenOcean;
Util.makeColor(171,216,255), //FrozenRiver;
Util.makeColor(156,214,190), //Ice Plains;
Util.makeColor(151,162,130), //Ice Mountains;
Util.makeColor(219,196,164), //MushroomIsland;
Util.makeColor(242,216,179), //MushroomIslandShore;
Util.makeColor(255,254,189), //Beach
Util.makeColor(230,202, 78), //DesertHills
Util.makeColor(89 ,176, 32), //ForestHills
Util.makeColor(66 ,110, 22), //TaigaHills
Util.makeColor(186,159, 39), //Extreme Hills Edge
Util.makeColor(26 ,87 ,34 ),
Util.makeColor(73 ,105,33 )
};
private static int size = Fragment.SIZE >> 2;

View File

@ -1,9 +1,7 @@
package test.amidst.map;
package amidst.map;
import java.io.IOException;
import amidst.map.MapMarkers;
/** Tests if MapMarkers finds all files*/
public class MapMarkersTest {
@org.junit.Test