Skip to content

Commit

Permalink
Merge pull request #3 from Anuken/master
Browse files Browse the repository at this point in the history
merge 2
  • Loading branch information
j-vds committed Aug 19, 2020
2 parents 337d5b0 + 7ebe84c commit a95296e
Show file tree
Hide file tree
Showing 297 changed files with 12,970 additions and 7,766 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
java-version: 8
- name: Run unit tests with gradle and Java 8
run: ./gradlew test
run: ./gradlew compileJava

buildJava14:
runs-on: ubuntu-latest
Expand All @@ -25,4 +25,4 @@ jobs:
with:
java-version: 14
- name: Run unit tests with gradle and Java 14
run: ./gradlew test
run: ./gradlew compileJava
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ In general, if you are using IntelliJ, you should be warned about platform incom


#### Use `arc` collections and classes when possible.
Instead of using `java.util.List`, `java.util.HashMap`, and other standard Java collections, use `Array`, `ObjectMap` and other equivalents from `arc.struct`.
Instead of using `java.util.List`, `java.util.HashMap`, and other standard Java collections, use `Seq`, `ObjectMap` and other equivalents from `arc.struct`.
Why? Because that's what the rest of the codebase uses, and the standard collections have a lot of cruft and usability issues associated with them.
In the rare case that concurrency is required, you may use the standard Java classes for that purpose (e.g. `CopyOnWriteArrayList`).

What you'll usually need to change:
- `HashSet` -> `ObjectSet`
- `HashMap` -> `ObjectMap`
- `List` / `ArrayList` / `Stack` -> `Array`
- `List` / `ArrayList` / `Stack` -> `Seq`
- `java.util.Queue` -> `arc.struct.Queue`
- *Many others*


#### Avoid boxed types (Integer, Boolean)
Never create variables or collections with boxed types `Array<Integer>` or `ObjectMap<Integer, ...>`. Use the collections specialized for this task, e.g. `IntArray` and `IntMap`.
Never create variables or collections with boxed types `Seq<Integer>` or `ObjectMap<Integer, ...>`. Use the collections specialized for this task, e.g. `IntSeq` and `IntMap`.


#### Do not allocate anything if possible.
Expand Down
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript{
}

dependencies{
//IMPORTANT NOTICE: any version of the plugin after 3.4.1 will break builds for every API level < 24, perhaps even higher.
//IMPORTANT NOTICE: any version of the plugin after 3.4.1 will break builds
//it appears abstract methods don't get desugared properly (if at all)
classpath 'com.android.tools.build:gradle:3.4.1'
}
Expand All @@ -33,6 +33,8 @@ dependencies{
natives "com.github.Anuken.Arc:natives-android:${getArcHash()}"
natives "com.github.Anuken.Arc:natives-freetype-android:${getArcHash()}"
natives "com.github.Anuken.Arc:natives-box2d-android:${getArcHash()}"

if(localArc()) compileOnly fileTree(dir: '../../Arc/backends/backend-android/libs', include: ['*.jar'])
}

task deploy(type: Copy){
Expand Down
10 changes: 1 addition & 9 deletions android/src/mindustry/android/AndroidRhinoContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public Class<?> defineClass(String name, byte[] data){
}
return loadClass(dex, name);
}catch(IOException | ClassNotFoundException e){
throw new FatalLoadingException(e);
throw new RuntimeException("Failed to define class", e);
}
}

Expand Down Expand Up @@ -151,14 +151,6 @@ public Class<?> loadClass(String name, boolean resolve)
}
}


/** Might be thrown in any Rhino method that loads bytecode if the loading failed. */
public static class FatalLoadingException extends RuntimeException{
FatalLoadingException(Throwable t){
super("Failed to define class", t);
}
}

static class FileAndroidClassLoader extends BaseAndroidClassLoader{
private static int instanceCounter = 0;
private final File dexFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public class Annotations{
String fallback() default "error";
}

/** Registers a statement for auto serialization. */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface RegisterStatement{
String value();
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface StyleDefaults{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ public void process(RoundEnvironment env) throws Exception{

TypeSpec.Builder builder = TypeSpec.classBuilder(name).addModifiers(Modifier.PUBLIC);

if(isFinal && !typeIsBase) builder.addModifiers(Modifier.FINAL);

//add serialize() boolean
builder.addMethod(MethodSpec.methodBuilder("serialize").addModifiers(Modifier.PUBLIC).returns(boolean.class).addStatement("return " + ann.serialize()).build());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package mindustry.annotations.misc;

import arc.func.*;
import arc.struct.*;
import com.squareup.javapoet.*;
import mindustry.annotations.Annotations.*;
import mindustry.annotations.*;
import mindustry.annotations.util.*;

import javax.annotation.processing.*;
import javax.lang.model.element.*;

@SupportedAnnotationTypes("mindustry.annotations.Annotations.RegisterStatement")
public class LogicStatementProcessor extends BaseProcessor{

@Override
public void process(RoundEnvironment env) throws Exception{
TypeSpec.Builder type = TypeSpec.classBuilder("LogicIO")
.addModifiers(Modifier.PUBLIC);

MethodSpec.Builder writer = MethodSpec.methodBuilder("write")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addParameter(Object.class, "obj")
.addParameter(StringBuilder.class, "out");

MethodSpec.Builder reader = MethodSpec.methodBuilder("read")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(tname("mindustry.logic.LStatement"))
.addParameter(String[].class, "tokens");

Seq<Stype> types = types(RegisterStatement.class);

type.addField(FieldSpec.builder(
ParameterizedTypeName.get(
ClassName.get(Seq.class),
ParameterizedTypeName.get(ClassName.get(Prov.class),
tname("mindustry.logic.LStatement"))), "allStatements", Modifier.PUBLIC, Modifier.STATIC)
.initializer("Seq.with(" + types.toString(", ", t -> "" + t.toString() + "::new") + ")").build());

boolean beganWrite = false, beganRead = false;

for(Stype c : types){
String name = c.annotation(RegisterStatement.class).value();

if(beganWrite){
writer.nextControlFlow("else if(obj instanceof $T)", c.mirror());
}else{
writer.beginControlFlow("if(obj instanceof $T)", c.mirror());
beganWrite = true;
}

//write the name & individual fields
writer.addStatement("out.append($S)", name);

Seq<Svar> fields = c.fields();

String readSt = "if(tokens[0].equals($S))";
if(beganRead){
reader.nextControlFlow("else " + readSt, name);
}else{
reader.beginControlFlow(readSt, name);
beganRead = true;
}

reader.addStatement("$T result = new $T()", c.mirror(), c.mirror());

int index = 0;

for(Svar field : fields){
if(field.is(Modifier.TRANSIENT)) continue;

writer.addStatement("out.append(\" \")");
writer.addStatement("out.append((($T)obj).$L$L)", c.mirror(), field.name(),
field.mirror().toString().equals("java.lang.String") ?
".replace(\"\\n\", \"\\\\n\")" :
Seq.with(typeu.directSupertypes(field.mirror())).contains(t -> t.toString().contains("java.lang.Enum")) ? ".name()" :
"");

//reading primitives, strings and enums is supported; nothing else is
reader.addStatement("if(tokens.length > $L) result.$L = $L(tokens[$L])$L",
index + 1,
field.name(),
field.mirror().toString().equals("java.lang.String") ?
"" : (field.tname().isPrimitive() ? field.tname().box().toString() :
field.mirror().toString()) + ".valueOf", //if it's not a string, it must have a valueOf method
index + 1,
field.mirror().toString().equals("java.lang.String") ?
".replace(\"\\\\n\", \"\\n\")" :
""
);

index ++;
}

reader.addStatement("result.afterRead()");
reader.addStatement("return result");
}

reader.endControlFlow();
writer.endControlFlow();

reader.addStatement("return null");

type.addMethod(writer.build());
type.addMethod(reader.build());

write(type);
}
}
1 change: 1 addition & 0 deletions annotations/src/main/resources/revisions/Bullet/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:1,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
1 change: 1 addition & 0 deletions annotations/src/main/resources/revisions/Bullet/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:2,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:mindustry.gen.Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
1 change: 1 addition & 0 deletions annotations/src/main/resources/revisions/Bullet/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:3,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
1 change: 1 addition & 0 deletions annotations/src/main/resources/revisions/Bullet/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:4,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
1 change: 1 addition & 0 deletions annotations/src/main/resources/revisions/Bullet/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:5,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:1,fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:2,fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:mindustry.gen.Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:3,fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:4,fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:5,fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{version:1,fields:[{name:effectTimer,type:float,size:4},{name:intensity,type:float,size:4},{name:life,type:float,size:4},{name:opacity,type:float,size:4},{name:weather,type:mindustry.type.Weather,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ allprojects{
}
}

//compile with java 8 compatibility for everything except the annotati project
configure(subprojects - project(":annotations")){
tasks.withType(JavaCompile){
if(JavaVersion.current() != JavaVersion.VERSION_1_8){
options.compilerArgs.addAll(['--release', '8'])
}
}
}

project(":desktop"){
apply plugin: "java"

Expand Down Expand Up @@ -310,6 +319,7 @@ project(":tests"){
workingDir = new File("../core/assets")
testLogging {
exceptionFormat = 'full'
showStandardStreams = true
}
}
}
Expand Down
40 changes: 27 additions & 13 deletions core/assets-raw/fontgen/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,26 @@
"command-retreat"
]
},
{
"uid": "2073dbd997e5d8e1ffc1322d13ba5585",
"css": "chat",
"code": 59484,
"src": "custom_icons",
"selected": true,
"svg": {
"path": "M129 64.5Q161.3 32.3 209.7 16.1 258.1 0 322.6 0 387.1 0 451.6 0 516.1 0 580.6 0 645.2 0 709.7 0 774.2 0 822.6 16.1 871 32.3 903.2 64.5 935.5 96.8 967.7 129 1000 161.3 1016.1 209.7 1032.3 258.1 1032.3 322.6 1032.3 387.1 1032.3 451.6 1032.3 516.1 1016.1 564.5 1000 612.9 967.7 645.2 935.5 677.4 903.2 709.7 871 741.9 822.6 758.1 774.2 774.2 709.7 774.2 645.2 774.2 580.6 774.2 516.1 774.2 451.6 774.2 387.1 774.2 338.7 790.3 290.3 806.5 274.2 854.8 258.1 903.2 241.9 951.6 225.8 1000 193.5 1000 161.3 1000 129 967.7 96.8 935.5 64.5 903.2 32.3 871 16.1 822.6 0 774.2 0 709.7 0 645.2 0 580.6 0 516.1 0 451.6 0 387.1 0 322.6 0 258.1 16.1 209.7 32.3 161.3 64.5 129 96.8 96.8 129 64.5",
"width": 1032
},
"search": [
"chat"
]
},
{
"uid": "9dd9e835aebe1060ba7190ad2b2ed951",
"css": "zoom",
"code": 59415,
"src": "fontawesome"
},
{
"uid": "1bc31b80669cb5edc2ee5d1370554bc9",
"css": "players",
Expand All @@ -901,24 +921,18 @@
]
},
{
"uid": "2073dbd997e5d8e1ffc1322d13ba5585",
"css": "chat",
"code": 59484,
"uid": "dd1e5d774d1ced68cb7c439d8ed102f5",
"css": "logic",
"code": 59420,
"src": "custom_icons",
"selected": true,
"svg": {
"path": "M129 64.5Q161.3 32.3 209.7 16.1 258.1 0 322.6 0 387.1 0 451.6 0 516.1 0 580.6 0 645.2 0 709.7 0 774.2 0 822.6 16.1 871 32.3 903.2 64.5 935.5 96.8 967.7 129 1000 161.3 1016.1 209.7 1032.3 258.1 1032.3 322.6 1032.3 387.1 1032.3 451.6 1032.3 516.1 1016.1 564.5 1000 612.9 967.7 645.2 935.5 677.4 903.2 709.7 871 741.9 822.6 758.1 774.2 774.2 709.7 774.2 645.2 774.2 580.6 774.2 516.1 774.2 451.6 774.2 387.1 774.2 338.7 790.3 290.3 806.5 274.2 854.8 258.1 903.2 241.9 951.6 225.8 1000 193.5 1000 161.3 1000 129 967.7 96.8 935.5 64.5 903.2 32.3 871 16.1 822.6 0 774.2 0 709.7 0 645.2 0 580.6 0 516.1 0 451.6 0 387.1 0 322.6 0 258.1 16.1 209.7 32.3 161.3 64.5 129 96.8 96.8 129 64.5",
"width": 1032
"path": "M375 0L250 125H125V250L0 375 125 500 0 625 125 750V875H250L375 1000 500 875 625 1000 750 875H875V750L1000 625 875 500 1000 375 875 250V125H750L625 0 500 125ZM250 250H750V750H250ZM375 375V625H625V375Z",
"width": 1000
},
"search": [
"chat"
"logic"
]
},
{
"uid": "9dd9e835aebe1060ba7190ad2b2ed951",
"css": "zoom",
"code": 59415,
"src": "fontawesome"
}
]
}
}
67 changes: 67 additions & 0 deletions core/assets-raw/fontgen/icons/logic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/fonts/Arturito Slab_v2.ttf
Binary file not shown.
Binary file removed core/assets-raw/fonts/RussoOne-Regular.ttf
Binary file not shown.
Binary file not shown.
Binary file removed core/assets-raw/sprites/blocks/extra/message.png
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/blocks/logic/memory-cell.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/blocks/logic/message.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/blocks/logic/switch-on.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/blocks/logic/switch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified core/assets-raw/sprites/blocks/props/white-tree-dead.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified core/assets-raw/sprites/blocks/props/white-tree.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/ui/logic-node.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/ui/underline-white.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets-raw/sprites/ui/white-pane.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a95296e

Please sign in to comment.