pull/2/head
Ivory 2023-01-09 03:42:01 -05:00
parent 85fe3d3538
commit 434b21955e
18 changed files with 313 additions and 99 deletions

3
.gitattributes vendored 100644
View File

@ -0,0 +1,3 @@
bin/jdk16-linux.gz filter=lfs diff=lfs merge=lfs -text
bin/jdk16-windows.zip filter=lfs diff=lfs merge=lfs -text
bin/jdk16-macos.gz filter=lfs diff=lfs merge=lfs -text

5
.gitignore vendored
View File

@ -1,5 +1,4 @@
target target
out out
bin output
SAVE_DATA.TXT SAVE_DATA.TXT
output

14
bin/build.sh 100755
View File

@ -0,0 +1,14 @@
#!/usr/bin/bash
mvn clean
mvn package -Pwindows
mvn package -Pmacos
mvn package -Plinux
echo " === Windows === "
java -jar ./bin/packr-all-4.0.0.jar ./bin/packr.windows.json
echo " ==== Macos ==== "
java -jar ./bin/packr-all-4.0.0.jar ./bin/packr.macos.json
echo " ==== Linux ==== "
java -jar ./bin/packr-all-4.0.0.jar ./bin/packr.linux.json

BIN
bin/jdk16-linux.gz (Stored with Git LFS) 100644

Binary file not shown.

BIN
bin/jdk16-macos.gz (Stored with Git LFS) 100644

Binary file not shown.

BIN
bin/jdk16-windows.zip (Stored with Git LFS) 100644

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"platform": "linux64",
"executable": "Hadean",
"jdk": "bin/jdk16-linux.gz",
"classpath": [
"output/linux/raw/hadean.jar"
],
"removelibs": [],
"mainclass": "xyz.valnet.hadean.HadeanGame",
"vmargs": [
],
"resources": [
"output/linux/raw/lib",
"output/linux/raw/res"
],
"output": "output/linux/built"
}

View File

@ -0,0 +1,18 @@
{
"platform": "mac",
"executable": "Hadean",
"jdk": "bin/jdk16-macos.gz",
"classpath": [
"output/macos/raw/hadean.jar"
],
"removelibs": [],
"mainclass": "xyz.valnet.hadean.HadeanGame",
"vmargs": [
],
"resources": [
"output/macos/raw/lib",
"output/macos/raw/res"
],
"output": "output/macos/built"
}

View File

@ -0,0 +1,18 @@
{
"platform": "windows64",
"executable": "Hadean",
"jdk": "bin/jdk16-windows.zip",
"classpath": [
"output/windows/raw/hadean.jar"
],
"removelibs": [],
"mainclass": "xyz.valnet.hadean.HadeanGame",
"vmargs": [
],
"resources": [
"output/windows/raw/lib",
"output/windows/raw/res"
],
"output": "output/windows/built"
}

View File

@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.valnet.hadean</groupId>
<artifactId>hadean</artifactId>
<name>hadean</name>
<version>1.0-SNAPSHOT</version>
<url>http://www.example.com</url>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>output/${platform.name}/raw</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>xyz.valnet.hadean.HadeanGame</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>output/${platform.name}/raw/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>output</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources02</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>output/${platform.name}/raw/res</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/res</directory>
<include>**/*.*</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>foo.bar.Generate</mainClass>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</transformer>
<transformer />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>linux</id>
<properties>
<lwjgl.natives>natives-linux</lwjgl.natives>
<platform.name>linux</platform.name>
</properties>
</profile>
<profile>
<id>macos</id>
<properties>
<lwjgl.natives>natives-macos</lwjgl.natives>
<platform.name>macos</platform.name>
</properties>
</profile>
<profile>
<id>windows</id>
<properties>
<lwjgl.natives>natives-windows</lwjgl.natives>
<platform.name>windows</platform.name>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-bom</artifactId>
<version>${lwjgl.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jar.finalName>${project.name}</jar.finalName>
<lwjgl.version>3.3.1</lwjgl.version>
</properties>
</project>

31
pom.xml
View File

@ -14,15 +14,15 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>16</maven.compiler.target>
<lwjgl.version>3.3.1</lwjgl.version> <lwjgl.version>3.3.1</lwjgl.version>
<jar.finalName>${project.name}</jar.finalName> <jar.finalName>${project.name}</jar.finalName>
</properties> </properties>
<profiles> <profiles>
<profile> <profile>
<id>lwjgl-natives-linux-amd64</id> <id>linux</id>
<activation> <activation>
<os> <os>
<family>unix</family> <family>unix</family>
@ -31,10 +31,11 @@
</activation> </activation>
<properties> <properties>
<lwjgl.natives>natives-linux</lwjgl.natives> <lwjgl.natives>natives-linux</lwjgl.natives>
<platform.name>linux</platform.name>
</properties> </properties>
</profile> </profile>
<profile> <profile>
<id>lwjgl-natives-macos-x86_64</id> <id>macos</id>
<activation> <activation>
<os> <os>
<family>mac</family> <family>mac</family>
@ -43,10 +44,11 @@
</activation> </activation>
<properties> <properties>
<lwjgl.natives>natives-macos</lwjgl.natives> <lwjgl.natives>natives-macos</lwjgl.natives>
<platform.name>macos</platform.name>
</properties> </properties>
</profile> </profile>
<profile> <profile>
<id>lwjgl-natives-windows-amd64</id> <id>windows</id>
<activation> <activation>
<os> <os>
<family>windows</family> <family>windows</family>
@ -55,6 +57,7 @@
</activation> </activation>
<properties> <properties>
<lwjgl.natives>natives-windows</lwjgl.natives> <lwjgl.natives>natives-windows</lwjgl.natives>
<platform.name>windows</platform.name>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>
@ -72,7 +75,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.4</version>
</dependency>
<dependency> <dependency>
<groupId>org.lwjgl</groupId> <groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId> <artifactId>lwjgl</artifactId>
@ -135,7 +142,7 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<configuration> <configuration>
<outputDirectory>output</outputDirectory> <outputDirectory>output/${platform.name}/raw</outputDirectory>
<archive> <archive>
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
@ -156,7 +163,7 @@
<goal>copy-dependencies</goal> <goal>copy-dependencies</goal>
</goals> </goals>
<configuration> <configuration>
<outputDirectory>output/lib</outputDirectory> <outputDirectory>output/${platform.name}/raw/lib</outputDirectory>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@ -186,7 +193,7 @@
<goal>copy-resources</goal> <goal>copy-resources</goal>
</goals> </goals>
<configuration> <configuration>
<outputDirectory>output/res</outputDirectory> <outputDirectory>output/${platform.name}/raw/res</outputDirectory>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<resources> <resources>
<resource> <resource>
@ -206,8 +213,10 @@
<artifactId>maven-install-plugin</artifactId> <artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version> <version>2.5.2</version>
</plugin> </plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

View File

@ -29,6 +29,7 @@ public class App {
public void run() { public void run() {
init(); init();
loop(); loop();
@ -65,7 +66,7 @@ public class App {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE ) if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
}); });
glfwSetCursorPosCallback(window, new GLFWCursorPosCallback() { glfwSetCursorPosCallback(window, new GLFWCursorPosCallback() {
@Override @Override
@ -115,6 +116,7 @@ public class App {
); );
} // the stack frame is popped automatically } // the stack frame is popped automatically
// Make the OpenGL context current // Make the OpenGL context current
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
// Enable v-sync // Enable v-sync
@ -130,6 +132,7 @@ public class App {
// bindings available for use. // bindings available for use.
GL.createCapabilities(); GL.createCapabilities();
float clearBrightness = 0.09f; float clearBrightness = 0.09f;
glClearColor(clearBrightness, clearBrightness, clearBrightness, 1.0f); glClearColor(clearBrightness, clearBrightness, clearBrightness, 1.0f);
@ -140,6 +143,7 @@ public class App {
glDepthMask(true); glDepthMask(true);
glfwSwapInterval(1); glfwSwapInterval(1);
game.start(); game.start();
} }

View File

@ -19,7 +19,6 @@ public class SimpleShader extends Shader {
public void pushColor(Vector4f color) { public void pushColor(Vector4f color) {
colorStack.push(color); colorStack.push(color);
setUniform4f("uColor", color); setUniform4f("uColor", color);
} }

View File

@ -1,10 +1,13 @@
package xyz.valnet.hadean.designation; package xyz.valnet.hadean.designation;
import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item; import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
import xyz.valnet.hadean.interfaces.BuildableMetadata; import xyz.valnet.hadean.interfaces.BuildableMetadata;
@BuildableMetadata(category = "Jobs", name = "Haul Items") @BuildableMetadata(category = "Jobs", name = "Haul Items")
public class HaulItemDesignation extends Designation<Item> { public class HaulItemDesignation extends Designation<Item> {
@Override @Override
protected Class<Item> getType() { protected Class<Item> getType() {
return Item.class; return Item.class;

View File

@ -1,12 +1,7 @@
package xyz.valnet.hadean.gameobjects.ui.tabs; package xyz.valnet.hadean.gameobjects.ui.tabs;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -16,10 +11,15 @@ import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.GameObject; import xyz.valnet.engine.scenegraph.GameObject;
import xyz.valnet.engine.scenegraph.IMouseCaptureArea; import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
import xyz.valnet.hadean.designation.CutTreesDesignation;
import xyz.valnet.hadean.designation.HaulItemDesignation;
import xyz.valnet.hadean.gameobjects.BottomBar; import xyz.valnet.hadean.gameobjects.BottomBar;
import xyz.valnet.hadean.gameobjects.Camera; import xyz.valnet.hadean.gameobjects.Camera;
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer; import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer; import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
import xyz.valnet.hadean.gameobjects.worldobjects.Bed;
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
import xyz.valnet.hadean.gameobjects.worldobjects.Stockpile;
import xyz.valnet.hadean.input.Button; import xyz.valnet.hadean.input.Button;
import xyz.valnet.hadean.input.IButtonListener; import xyz.valnet.hadean.input.IButtonListener;
import xyz.valnet.hadean.input.SimpleButton; import xyz.valnet.hadean.input.SimpleButton;
@ -48,57 +48,57 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
private String selectedCategory = ""; private String selectedCategory = "";
private transient BuildableRecord selectedBuildable = null; private static transient Map<String, List<BuildableRecord>> buildables = new HashMap<String, List<BuildableRecord>>();
private transient Map<String, List<BuildableRecord>> buildables = null;
private transient Map<Button, BuildableRecord> buildableButtons = null; private transient Map<Button, BuildableRecord> buildableButtons = null;
private transient BuildableRecord selectedBuildable = null;
private int height = 0; private int height = Math.max((int)Math.ceil(buildables.size() / 2f) * 24, 24*3);
private record BuildableRecord( static {
BuildTab.registerBuildable(HaulItemDesignation.class);
BuildTab.registerBuildable(CutTreesDesignation.class);
BuildTab.registerBuildable(Bed.class);
BuildTab.registerBuildable(FarmPlot.class);
BuildTab.registerBuildable(Stockpile.class);
}
public record BuildableRecord(
String name, String name,
Constructor<? extends IBuildable> constructor, Constructor<? extends IBuildable> constructor,
int type int type
) { ) {}
} public static void registerBuildable(Class<? extends IBuildable> clazz) {
@SuppressWarnings("unchecked")
private void calculateBuildables() {
try { try {
Class<?>[] maybeBuildables = getClasses("xyz.valnet.hadean"); System.out.println("Its fine");
for(Class<?> clazz : maybeBuildables) { BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
if(clazz.isAnonymousClass()) continue; if(annotation == null) {
if(!IBuildable.class.isAssignableFrom(clazz)) continue; System.out.println(clazz + " has no buildable data annotation");
if(clazz.isInterface()) continue; return;
if(Modifier.isAbstract(clazz.getModifiers())) continue;
Constructor<? extends IBuildable> constructor = (Constructor<? extends IBuildable>) clazz.getConstructor();
if(constructor.getParameterCount() != 0) {
System.out.println(clazz + " has no default constructor (no params)");
continue;
}
BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
if(annotation == null) {
System.out.println(clazz + " has no buildable data annotation");
continue;
}
String category = annotation.category();
String name = annotation.name();
int type = annotation.type();
if(!buildables.containsKey(category))
buildables.put(category, new ArrayList<BuildableRecord>());
buildables.get(category).add(new BuildableRecord(name, constructor, type));
System.out.println("Added " + category + " / " + name);
} }
} catch (Exception e) { Constructor<? extends IBuildable> constructor = (Constructor<? extends IBuildable>) clazz.getConstructor();
System.out.println(e); if(constructor.getParameterCount() != 0) {
} System.out.println(clazz + " has no default constructor (no params)");
return;
}
height = Math.max((int)Math.ceil(buildables.size() / 2f) * 24, 24*3); String category = annotation.category();
String name = annotation.name();
int type = annotation.type();
System.out.println("Added " + category + " / " + name);
if(!buildables.containsKey(category))
buildables.put(category, new ArrayList<BuildableRecord>());
buildables.get(category).add(new BuildableRecord(name, constructor, type));
} catch (Exception e) {
e.printStackTrace();
}
} }
@Override @Override
@ -146,10 +146,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
selection.subscribe(this); selection.subscribe(this);
} }
buildables = new HashMap<String, List<BuildableRecord>>();
buildableButtons = new HashMap<Button, BuildableRecord>(); buildableButtons = new HashMap<Button, BuildableRecord>();
calculateBuildables();
} }
private List<Button> categoryButtons = new ArrayList<Button>(); private List<Button> categoryButtons = new ArrayList<Button>();
@ -315,40 +312,4 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
selectBuildable(newBuildableRecord); selectBuildable(newBuildableRecord);
} }
} }
@SuppressWarnings("rawtypes")
private static Class<?>[] getClasses(String packageName) throws ClassNotFoundException, IOException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
assert classLoader != null;
String path = packageName.replace('.', '/');
Enumeration<URL> resources = classLoader.getResources(path);
List<File> dirs = new ArrayList<File>();
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
dirs.add(new File(resource.getFile()));
}
ArrayList<Class> classes = new ArrayList<Class>();
for (File directory : dirs) {
classes.addAll(findClasses(directory, packageName));
}
return (Class<?>[]) classes.toArray(new Class[classes.size()]);
}
@SuppressWarnings("rawtypes")
private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException {
List<Class> classes = new ArrayList<Class>();
if (!directory.exists()) {
return classes;
}
File[] files = directory.listFiles();
for (File file : files) {
if (file.isDirectory()) {
assert !file.getName().contains(".");
classes.addAll(findClasses(file, packageName + "." + file.getName()));
} else if (file.getName().endsWith(".class")) {
classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
}
}
return classes;
}
} }

View File

@ -49,10 +49,14 @@ public class Assets {
public static final SimpleShader flat; public static final SimpleShader flat;
static { static {
System.out.println("START ASSETS");
flat = new SimpleShader("res/shaders/flat.vert", "res/shaders/flat.frag"); flat = new SimpleShader("res/shaders/flat.vert", "res/shaders/flat.frag");
System.out.println("SHADERS LOADED");
atlas = new Texture("res/textures.png"); atlas = new Texture("res/textures.png");
System.out.println("ATLAS LOADED");
System.out.println("CREATE SPRITES");
whiteBox = new Sprite(atlas, 0, 88, 8, 8); whiteBox = new Sprite(atlas, 0, 88, 8, 8);
defaultTerrain = new Sprite[] { defaultTerrain = new Sprite[] {
@ -300,5 +304,6 @@ public class Assets {
new Sprite(atlas, 7, 103, 1, 1) new Sprite(atlas, 7, 103, 1, 1)
); );
System.out.println("END ASSETS");
} }
} }