|
@@ -1,9 +1,19 @@
|
|
|
package eu.tankernn.gameEngine.tester;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URISyntaxException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Enumeration;
|
|
|
import java.util.List;
|
|
|
import java.util.Random;
|
|
|
+import java.util.jar.JarEntry;
|
|
|
+import java.util.jar.JarFile;
|
|
|
+
|
|
|
+import javax.swing.JOptionPane;
|
|
|
|
|
|
import org.lwjgl.opengl.Display;
|
|
|
import org.lwjgl.util.vector.Vector2f;
|
|
@@ -49,12 +59,8 @@ public class MainLoop {
|
|
|
private static final int SEED = 1235;
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- File nativeDir = new File("natives");
|
|
|
- if (nativeDir.exists()) {
|
|
|
- System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath());
|
|
|
- }
|
|
|
+ exportNatives();
|
|
|
|
|
|
-
|
|
|
List<Entity> entities = new ArrayList<Entity>();
|
|
|
List<Entity> normalMapEntities = new ArrayList<Entity>();
|
|
|
TerrainPack terrainPack = new TerrainPack();
|
|
@@ -99,10 +105,10 @@ public class MainLoop {
|
|
|
List<Light> lights = new ArrayList<Light>();
|
|
|
lights.add(sun);
|
|
|
lights.add(flashLight);
|
|
|
- lights.add(new Light(new Vector3f(10, 100,0), new Vector3f(0,1,0)));
|
|
|
- lights.add(new Light(new Vector3f(20, 100,0), new Vector3f(0,0,1)));
|
|
|
- lights.add(new Light(new Vector3f(30, 100,0), new Vector3f(1,0,0)));
|
|
|
- lights.add(new Light(new Vector3f(40, 100,0), new Vector3f(1,1,0)));
|
|
|
+ lights.add(new Light(new Vector3f(10, 100, 0), new Vector3f(0, 1, 0)));
|
|
|
+ lights.add(new Light(new Vector3f(20, 100, 0), new Vector3f(0, 0, 1)));
|
|
|
+ lights.add(new Light(new Vector3f(30, 100, 0), new Vector3f(1, 0, 0)));
|
|
|
+ lights.add(new Light(new Vector3f(40, 100, 0), new Vector3f(1, 1, 0)));
|
|
|
|
|
|
// ### Terrain textures ###
|
|
|
|
|
@@ -219,4 +225,68 @@ public class MainLoop {
|
|
|
loader.cleanUp();
|
|
|
DisplayManager.closeDisplay();
|
|
|
}
|
|
|
+
|
|
|
+ private static void exportNatives() {
|
|
|
+ File nativeDir = new File("natives");
|
|
|
+ if (!nativeDir.isDirectory() || nativeDir.list().length == 0) {
|
|
|
+ try {
|
|
|
+ nativeDir.mkdir();
|
|
|
+
|
|
|
+ File jarFile = null;
|
|
|
+ try {
|
|
|
+ jarFile = new File(MainLoop.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
|
|
|
+ } catch (URISyntaxException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (jarFile != null && jarFile.isFile()) { // Run with JAR file
|
|
|
+ final JarFile jar = new JarFile(jarFile);
|
|
|
+ final Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
|
|
|
+ while (entries.hasMoreElements()) {
|
|
|
+ final String name = entries.nextElement().getName();
|
|
|
+ if (name.endsWith(".dll") || name.endsWith(".so") || name.endsWith(".dylib") || name.endsWith(".jnilb")) { //filter according to the path
|
|
|
+ System.out.println(name);
|
|
|
+ try {
|
|
|
+ exportFile(name, "natives");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jar.close();
|
|
|
+ System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath());
|
|
|
+ } else { // Run with IDE
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ JOptionPane.showMessageDialog(null, "Could not export natives. Execute in terminal to see full error output.", "Export natives", JOptionPane.ERROR_MESSAGE);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String exportFile(String classPath, String targetDir) throws Exception {
|
|
|
+ InputStream stream = null;
|
|
|
+ OutputStream resStreamOut = null;
|
|
|
+ try {
|
|
|
+ stream = MainLoop.class.getResourceAsStream("/" + classPath);//note that each / is a directory down in the "jar tree" been the jar the root of the tree
|
|
|
+ if (stream == null) {
|
|
|
+ throw new Exception("Cannot get resource \"" + classPath + "\" from Jar file.");
|
|
|
+ }
|
|
|
+
|
|
|
+ int readBytes;
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ File outFile = new File(targetDir + "/" + classPath);
|
|
|
+ outFile.getParentFile().mkdirs();
|
|
|
+ resStreamOut = new FileOutputStream(outFile);
|
|
|
+ while ((readBytes = stream.read(buffer)) > 0) {
|
|
|
+ resStreamOut.write(buffer, 0, readBytes);
|
|
|
+ }
|
|
|
+ stream.close();
|
|
|
+ resStreamOut.close();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw ex;
|
|
|
+ }
|
|
|
+
|
|
|
+ return classPath;
|
|
|
+ }
|
|
|
}
|