Merge branch 'stable' into world-object-unification-project

world-object-unification-project
Ivory 2023-01-09 22:31:04 -05:00
commit e31a164871
20 changed files with 393 additions and 139 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

3
.gitignore vendored
View File

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

15
bin/build.sh 100755
View File

@ -0,0 +1,15 @@
#!/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
mv output/macos/built output/macos/Hadean.app
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": [
"-XstartOnFirstThread"
],
"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>

108
pom.xml
View File

@ -6,22 +6,23 @@
<groupId>xyz.valnet.hadean</groupId>
<artifactId>hadean</artifactId>
<version>0.1-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hadean</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<lwjgl.version>3.3.1</lwjgl.version>
<jar.finalName>${project.name}</jar.finalName>
</properties>
<profiles>
<profile>
<id>lwjgl-natives-linux-amd64</id>
<id>linux</id>
<activation>
<os>
<family>unix</family>
@ -30,10 +31,11 @@
</activation>
<properties>
<lwjgl.natives>natives-linux</lwjgl.natives>
<platform.name>linux</platform.name>
</properties>
</profile>
<profile>
<id>lwjgl-natives-macos-x86_64</id>
<id>macos</id>
<activation>
<os>
<family>mac</family>
@ -42,10 +44,11 @@
</activation>
<properties>
<lwjgl.natives>natives-macos</lwjgl.natives>
<platform.name>macos</platform.name>
</properties>
</profile>
<profile>
<id>lwjgl-natives-windows-amd64</id>
<id>windows</id>
<activation>
<os>
<family>windows</family>
@ -54,6 +57,7 @@
</activation>
<properties>
<lwjgl.natives>natives-windows</lwjgl.natives>
<platform.name>windows</platform.name>
</properties>
</profile>
</profiles>
@ -71,7 +75,11 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
@ -129,48 +137,86 @@
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<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>
<groupId>org.apache.maven.plugins</groupId>
<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>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<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-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

View File

@ -29,6 +29,7 @@ public class App {
public void run() {
init();
loop();
@ -115,6 +116,7 @@ public class App {
);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
@ -131,6 +133,7 @@ public class App {
GL.createCapabilities();
float clearBrightness = 0.09f;
glClearColor(clearBrightness, clearBrightness, clearBrightness, 1.0f);
glEnable(GL_BLEND);
@ -140,6 +143,7 @@ public class App {
glDepthMask(true);
glfwSwapInterval(1);
game.start();
}

View File

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

View File

@ -1,10 +1,13 @@
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.interfaces.BuildableMetadata;
@BuildableMetadata(category = "Jobs", name = "Haul Items")
public class HaulItemDesignation extends Designation<Item> {
@Override
protected Class<Item> getType() {
return Item.class;

View File

@ -1,12 +1,7 @@
package xyz.valnet.hadean.gameobjects.ui.tabs;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -16,10 +11,15 @@ import xyz.valnet.engine.math.Vector2i;
import xyz.valnet.engine.math.Vector4f;
import xyz.valnet.engine.scenegraph.GameObject;
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.Camera;
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
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.IButtonListener;
import xyz.valnet.hadean.input.SimpleButton;
@ -48,57 +48,57 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
private String selectedCategory = "";
private transient BuildableRecord selectedBuildable = null;
private transient Map<String, List<BuildableRecord>> buildables = null;
private static transient Map<String, List<BuildableRecord>> buildables = new HashMap<String, List<BuildableRecord>>();
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,
Constructor<? extends IBuildable> constructor,
BuildableMetadata.Type type
) {
) {}
}
@SuppressWarnings("unchecked")
private void calculateBuildables() {
public static void registerBuildable(Class<? extends IBuildable> clazz) {
try {
Class<?>[] maybeBuildables = getClasses("xyz.valnet.hadean");
System.out.println("Its fine");
for(Class<?> clazz : maybeBuildables) {
if(clazz.isAnonymousClass()) continue;
if(!IBuildable.class.isAssignableFrom(clazz)) continue;
if(clazz.isInterface()) continue;
if(Modifier.isAbstract(clazz.getModifiers())) continue;
BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
if(annotation == null) {
System.out.println(clazz + " has no buildable data annotation");
return;
}
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;
return;
}
String category = annotation.category();
String name = annotation.name();
BuildableMetadata.Type 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));
System.out.println("Added " + category + " / " + name);
}
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
height = Math.max((int)Math.ceil(buildables.size() / 2f) * 24, 24*3);
}
@Override
@ -146,10 +146,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
selection.subscribe(this);
}
buildables = new HashMap<String, List<BuildableRecord>>();
buildableButtons = new HashMap<Button, BuildableRecord>();
calculateBuildables();
}
private List<Button> categoryButtons = new ArrayList<Button>();
@ -336,40 +333,4 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
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;
static {
flat = new SimpleShader("shaders/flat.vert", "shaders/flat.frag");
System.out.println("START ASSETS");
flat = new SimpleShader("res/shaders/flat.vert", "res/shaders/flat.frag");
System.out.println("SHADERS LOADED");
atlas = new Texture("res/textures.png");
System.out.println("ATLAS LOADED");
System.out.println("CREATE SPRITES");
whiteBox = new Sprite(atlas, 0, 88, 8, 8);
defaultTerrain = new Sprite[] {
@ -300,5 +304,6 @@ public class Assets {
new Sprite(atlas, 7, 103, 1, 1)
);
System.out.println("END ASSETS");
}
}