diff --git a/core/assets/sounds/pew_.ogg b/core/assets/sounds/pew_.ogg deleted file mode 100644 index 0c1df7f711..0000000000 Binary files a/core/assets/sounds/pew_.ogg and /dev/null differ diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 7a0bbdae7e..eb34bab55f 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -137,7 +137,7 @@ public class Rules{ } /** A simple map for storing TeamRules in an efficient way without hashing. */ - public static class TeamRules implements Serializable{ + public static class TeamRules implements JsonSerializable{ final TeamRule[] values = new TeamRule[Team.all.length]; public TeamRule get(Team team){ diff --git a/core/src/mindustry/game/SpawnGroup.java b/core/src/mindustry/game/SpawnGroup.java index 86ba7b6324..2b7e8625c9 100644 --- a/core/src/mindustry/game/SpawnGroup.java +++ b/core/src/mindustry/game/SpawnGroup.java @@ -18,7 +18,7 @@ import static mindustry.Vars.*; * weapon equipped, ammo used, and status effects. * Each spawn group can have multiple sub-groups spawned in different areas of the map. */ -public class SpawnGroup implements Serializable{ +public class SpawnGroup implements JsonSerializable{ public static final int never = Integer.MAX_VALUE; /** The unit type spawned */ diff --git a/core/src/mindustry/type/ItemSeq.java b/core/src/mindustry/type/ItemSeq.java index 4fb7409796..a02f29bdb6 100644 --- a/core/src/mindustry/type/ItemSeq.java +++ b/core/src/mindustry/type/ItemSeq.java @@ -10,7 +10,7 @@ import mindustry.world.modules.ItemModule.*; import java.util.*; -public class ItemSeq implements Iterable, Serializable{ +public class ItemSeq implements Iterable, JsonSerializable{ protected final int[] values = new int[Vars.content.items().size]; public int total; diff --git a/core/src/mindustry/world/blocks/Attributes.java b/core/src/mindustry/world/blocks/Attributes.java index ff96a2bb63..38a39bd2e3 100644 --- a/core/src/mindustry/world/blocks/Attributes.java +++ b/core/src/mindustry/world/blocks/Attributes.java @@ -6,7 +6,7 @@ import mindustry.world.meta.*; import java.util.*; -public class Attributes implements Serializable{ +public class Attributes implements JsonSerializable{ private final float[] arr = new float[Attribute.all.length]; public void clear(){ diff --git a/gradle.properties b/gradle.properties index 75d98185c9..86948088f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=eac865a8a0f4fde121fdcd8850d9f039f725b546 +archash=e00afb8e4fb58902255b782b074e2836c027df9a diff --git a/tools/src/mindustry/tools/BindingsGenerator.java b/tools/src/mindustry/tools/BindingsGenerator.java index 8363e4a857..b0fe2b358a 100644 --- a/tools/src/mindustry/tools/BindingsGenerator.java +++ b/tools/src/mindustry/tools/BindingsGenerator.java @@ -10,6 +10,8 @@ import static mindustry.tools.ScriptMainGenerator.*; //experimental public class BindingsGenerator{ + //list of touchy class names that lead to conflicts; all typedefs and procs containing these are ignored + static Seq ignored = Seq.with(".Entry", ".MapIterator"); public static void main(String[] args) throws Exception{ @@ -18,19 +20,28 @@ public class BindingsGenerator{ getClasses("mindustry"), getClasses("arc") ); - classes.sort(Structs.comparing(Class::getName)); classes.removeAll(type -> type.isSynthetic() || type.isAnonymousClass() || type.getCanonicalName() == null || Modifier.isPrivate(type.getModifiers()) || blacklist.contains(s -> type.getName().startsWith(s))); + classes.add(Enum.class); + classes.distinct(); - classes.sortComparing(Class::getName); + + classes = sorted(classes); + classes.removeAll(BindingsGenerator::ignore); StringBuilder result = new StringBuilder(); result.append("import jnim, jnim/java/lang\n\n{.experimental: \"codeReordering\".}\n\n"); for(Class type : classes){ - String name = type.getCanonicalName(); + result.append("jclassDef ").append(type.getCanonicalName()).append(" of `") + .append(repr(type.getSuperclass())).append("`\n"); + } + + result.append("\n"); + + for(Class type : classes){ Seq exec = new Seq<>(); @@ -38,14 +49,15 @@ public class BindingsGenerator{ exec.addAll(type.getDeclaredConstructors()); exec.removeAll(e -> !Modifier.isPublic(e.getModifiers())); + exec.removeAll(e -> Structs.contains(e.getParameterTypes(), BindingsGenerator::ignore)); Seq fields = Seq.select(type.getDeclaredFields(), f -> Modifier.isPublic(f.getModifiers())); - result.append("jclass ").append(name).append(" of `") - .append(type.getSuperclass() == null ? "JVMObject" : type.getSuperclass().getSimpleName()).append("`").append(exec.size + fields.size > 0 ? ":" : "").append("\n"); + result.append("jclassImpl ").append(type.getCanonicalName()).append(" of `") + .append(repr(type.getSuperclass())).append("`").append(exec.size + fields.size > 0 ? ":" : "").append("\n"); for(Field field : fields){ - result.append(" proc `").append(field.getName()).append("`*"); + result.append(" proc `").append(field.getName()).append("`"); result.append(": ").append(str(field.getType())); result.append(" {.prop"); if(Modifier.isStatic(field.getModifiers())) result.append(", `static`"); @@ -54,7 +66,7 @@ public class BindingsGenerator{ } for(Executable method : exec){ - String mname = method.getName().equals("") || method.getName().equals(type.getCanonicalName()) ? "new" : method.getName(); + String mname = method.getName().equals("") || method.getName().equals(type.getName()) ? "new" : method.getName(); result.append(" proc `").append(mname).append("`"); if(method.getParameterCount() > 0){ @@ -94,6 +106,39 @@ public class BindingsGenerator{ Log.info(result); } + static boolean ignore(Class type){ + if(type == null) return false; + return ignored.contains(s -> type.getCanonicalName().contains(s)) || ignore(type.getSuperclass()); + } + + static Seq> sorted(Seq> classes){ + ObjectSet> visited = new ObjectSet<>(); + Seq> result = new Seq<>(); + for(Class c : classes){ + if(!visited.contains(c)){ + topoSort(c, result, visited); + } + } + return result; + } + + static void topoSort(Class c, Seq> stack, ObjectSet> visited){ + visited.add(c); + for(Class sup : c.getInterfaces()){ + if(!visited.contains(sup)){ + topoSort(sup, stack, visited); + } + } + if(c.getSuperclass() != null && !c.getSuperclass().equals(Object.class) && !visited.contains(c.getSuperclass())){ + topoSort(c.getSuperclass(), stack, visited); + } + stack.add(c); + } + + static String repr(Class type){ + return type == null ? "JVMObject" : type.getSimpleName(); + } + static String str(Class type){ if(type.isArray()){ return "seq[" + str(type.getComponentType()) + "]";