Skip to content

Commit

Permalink
Merge pull request #91 from xpenatan/master
Browse files Browse the repository at this point in the history
Release v1.0.0-b4
  • Loading branch information
xpenatan committed Feb 22, 2023
2 parents 7537664 8b4f57e commit a584fc1
Show file tree
Hide file tree
Showing 25 changed files with 398 additions and 291 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 1,12 @@
[1.0.0-SNAPSHOT]

[1.0.0-b4]
- Fix an issue with TeaClassloader that was giving annotation error when building artemis games
- Bugfix: Asset Loading should not re-Download 403 Errors
- Bugfix for density calculation.
- Bugfix: blank line on top of HTML body on mobile.
- Bugfix: Asset Loading & Error "ERR_HTTP2_SERVER_REFUSED_STREAM

[1.0.0-b3]
- Add gdx-bullet c module so desktop and web use the same c code/version
- Update teaVM to 0.8.0-dev-1 and project Java version to 11
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 1,15 @@
package com.artemis.utils.reflect;

import com.github.xpenatan.gdx.backends.teavm.gen.Emulate;

/**
* Provides information about, and access to, an annotation of a field, class or interface.
*
* @author dludwig
*/
@Emulate(valueStr = "com.artemis.utils.reflect.Annotation")
public final class AnnotationEmu {
public final class Annotation {

private java.lang.annotation.Annotation annotation;

AnnotationEmu(java.lang.annotation.Annotation annotation) {
Annotation(java.lang.annotation.Annotation annotation) {
this.annotation = annotation;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
package com.artemis.utils.reflect;

public final class Field extends FieldGen {
public Field(java.lang.reflect.Field field) {
super(field);
}
}
11 changes: 0 additions & 11 deletions backends/backend-teavm/emu/com/artemis/utils/reflect/FieldEmu.java

This file was deleted.

56 changes: 29 additions & 27 deletions backends/backend-teavm/emu/com/artemis/utils/reflect/FieldGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 157,30 @@ private static void getElementType(ReflectClass<?> cls, Value<String> fieldNameV
Value<Class> result = Metaprogramming.lazy(() -> null);
for(ReflectField field : cls.getDeclaredFields()) {
java.lang.reflect.Field javaField = genericTypeProvider.findField(field);
Type genericType = javaField.getGenericType();
if(genericType instanceof ParameterizedType) {
Type[] actualTypes = ((ParameterizedType)genericType).getActualTypeArguments();

if(actualTypes != null) {
for(int i = 0; i < actualTypes.length; i ) {
Class actualType = getActualType(actualTypes[i]);
if(actualType == null)
continue;
found = true;
final int index = i;

String fieldName = field.getName();
Value<Class> existing = result;
result = Metaprogramming.lazy(() -> {
if(index == indexValue.get()) {
if(fieldName.equals(fieldNameValue.get())) {
return actualType;
if (javaField != null) {
Type genericType = javaField.getGenericType();
if (genericType instanceof ParameterizedType) {
Type[] actualTypes = ((ParameterizedType) genericType).getActualTypeArguments();

if (actualTypes != null) {
for (int i = 0; i < actualTypes.length; i ) {
Class actualType = getActualType(actualTypes[i]);
if (actualType == null)
continue;
found = true;
final int index = i;

String fieldName = field.getName();
Value<Class> existing = result;
result = Metaprogramming.lazy(() -> {
if (index == indexValue.get()) {
if (fieldName.equals(fieldNameValue.get())) {
return actualType;
}
}
}
return existing.get();
});
return existing.get();
});
}
}
}
}
Expand All @@ -201,7 203,7 @@ public Class getElementType(int index) {
}

public <T extends java.lang.annotation.Annotation> T getAnnotation(Class<T> annotationClass) {
final AnnotationEmu declaredAnnotation = getDeclaredAnnotation(annotationClass);
final Annotation declaredAnnotation = getDeclaredAnnotation(annotationClass);
return declaredAnnotation != null ? declaredAnnotation.getAnnotation(annotationClass) : null;
}

Expand All @@ -212,23 214,23 @@ public boolean isAnnotationPresent(Class<? extends java.lang.annotation.Annotati
return field.isAnnotationPresent(annotationType);
}

public AnnotationEmu[] getDeclaredAnnotations() {
public Annotation[] getDeclaredAnnotations() {
java.lang.annotation.Annotation[] annotations = field.getDeclaredAnnotations();
AnnotationEmu[] result = new AnnotationEmu[annotations.length];
Annotation[] result = new Annotation[annotations.length];
for(int i = 0; i < annotations.length; i ) {
result[i] = new AnnotationEmu(annotations[i]);
result[i] = new Annotation(annotations[i]);
}
return result;
}

public AnnotationEmu getDeclaredAnnotation(Class<? extends java.lang.annotation.Annotation> annotationType) {
public Annotation getDeclaredAnnotation(Class<? extends java.lang.annotation.Annotation> annotationType) {
java.lang.annotation.Annotation[] annotations = field.getDeclaredAnnotations();
if(annotations == null) {
return null;
}
for(java.lang.annotation.Annotation annotation : annotations) {
if(annotation.annotationType().equals(annotationType)) {
return new AnnotationEmu(annotation);
return new Annotation(annotation);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 1,15 @@
package com.badlogic.gdx.utils.reflect;

import com.github.xpenatan.gdx.backends.teavm.gen.Emulate;

/**
* Provides information about, and access to, an annotation of a field, class or interface.
*
* @author dludwig
*/
@Emulate(Annotation.class)
public final class AnnotationEmu {
public final class Annotation {

private java.lang.annotation.Annotation annotation;

AnnotationEmu(java.lang.annotation.Annotation annotation) {
Annotation(java.lang.annotation.Annotation annotation) {
this.annotation = annotation;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
package com.badlogic.gdx.utils.reflect;

public final class Field extends FieldGen{
public Field(java.lang.reflect.Field field) {
super(field);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,6 @@

import com.badlogic.gdx.files.FileHandle;
import com.github.xpenatan.gdx.backends.teavm.gen.SkipClass;
import com.github.xpenatan.gdx.backends.teavm.plugins.TeaClassFilter;
import com.github.xpenatan.gdx.backends.teavm.plugins.TeaClassTransformer;
import com.github.xpenatan.gdx.backends.teavm.plugins.TeaReflectionSupplier;
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetFilter;
Expand All @@ -20,7 19,6 @@
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.reflections.Reflections;
import org.teavm.diagnostics.DefaultProblemTextConsumer;
import org.teavm.diagnostics.Problem;
import org.teavm.diagnostics.ProblemProvider;
Expand Down Expand Up @@ -204,7 202,8 @@ private static void preserveClasses(TeaVMTool tool, TeaBuildConfiguration config
ArrayList<String> configClassesToPreserve = configuration.getClassesToPreserve();
List<String> reflectionClasses = TeaReflectionSupplier.getReflectionClasses();
configClassesToPreserve.addAll(reflectionClasses);
ArrayList<String> preserveClasses = classLoader.getPreserveClasses(configClassesToPreserve);
// Get classes or packages from reflection. When path is a package, get all classes from it.
ArrayList<String> preserveClasses = classLoader.getAllClasses(configClassesToPreserve);
classesToPreserve.addAll(preserveClasses);
}

Expand Down Expand Up @@ -551,12 550,6 @@ public TeaVMProgressFeedback progressReached(int i) {
}
});
preserveClasses(tool, configuration, classLoader);

//TODO Remove
// Properties properties = tool.getProperties();
// properties.put("teavm.libgdx.fsJsonPath", webappDirectory File.separator webappName File.separator "filesystem.json");
// properties.put("teavm.libgdx.warAssetsDirectory", webappDirectory File.separator webappName File.separator "assets");

}

public static void configAssets(TeaClassLoader classLoader, TeaBuildConfiguration configuration, String webappDirectory, String webappName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,6 @@

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
Expand All @@ -28,68 27,6 @@ public TeaClassLoader(URL[] classPaths, ClassLoader parent, ArrayList<String> sk
this.skipClasses.addAll(skipClasses);
}

@Override
public URL getResource(String name) {
return getRes(name);
}

private URL getRes(String name) {
String fixName = name.replace(";.class", ".class");
fixName = fixName.replace("[L", "");
fixName = fixName.replace("[", "");

String toPackage = fixName.replace("/", ".");
if(containsSkipClass(toPackage)) {
return null;
}

URL resource = super.getResource(name);
for(int i = 0; i < jarFiles.length; i ) {
URL url = jarFiles[i];
String path = url.getPath();
String finalFile = "jar:file:" path "!/";
File file = new File(path);
if(file.exists()) {
if(!file.isDirectory()) {
try {
JarFile jarFile = new JarFile(file);
Enumeration<JarEntry> entries = jarFile.entries();
while(entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
if(!jarEntry.isDirectory()) {
String jarEntryName = jarEntry.getName();
if(jarEntryName.equals(fixName)) {
String filee = finalFile jarEntryName;
return new URL(filee);
}
}
}
}
catch(Exception e) {
e.printStackTrace();
}
}
else {
try {
ArrayList<String> allClasses = getAllFiles(path);
String resName = fixName.replace("\\", "/");
for(int j = 0; j < allClasses.size(); j ) {
String className = allClasses.get(j);
if(className.contains(resName)) {
String filee = path className;
return new File(filee).toURI().toURL();
}
}
}
catch(MalformedURLException e) {
e.printStackTrace();
}
}
}
}
return resource;
}

@Override
public InputStream getResourceAsStream(String name) {
String fixName = name.replace(";.class", ".class");
Expand Down Expand Up @@ -119,6 56,7 @@ public InputStream getResourceAsStream(String name) {
}
}
else {
// This probably not working and need to remove.
ArrayList<String> allClasses = getAllFiles(path);
String resName = fixName.replace("\\", "/");
for(int j = 0; j < allClasses.size(); j ) {
Expand All @@ -131,11 69,7 @@ public InputStream getResourceAsStream(String name) {
}
}

if(fixName.startsWith("org/teavm/")) {
return super.getResourceAsStream(name);
}

return null;
return super.getResourceAsStream(name);
}

private boolean containsSkipClass(String clazz) {
Expand Down Expand Up @@ -181,13 115,13 @@ private void getAllFiles(File rootFile, ArrayList<String> out, String packageNam
/**
* Convert packages to individual classes
*/
public ArrayList<String> getPreserveClasses(ArrayList<String> classesToPreserve) {
public ArrayList<String> getAllClasses(ArrayList<String> classOrPackage) {
// TeaVM only accept individual classes. We need to obtain all classes from package (if its set).
// If it's not a package just add the class.
ArrayList<String> array = new ArrayList<>();

for(int i = 0; i < classesToPreserve.size(); i ) {
String className = classesToPreserve.get(i);
for(int i = 0; i < classOrPackage.size(); i ) {
String className = classOrPackage.get(i);
String packagePath = className.replace(".", "/");
URL resource = getResource(packagePath ".class");
if(resource == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 186,13 @@ public GLVersion getGLVersion() {
}

@Override
public float getPpiX() {
return 96;
public float getPpiX () {
return 96f * (float)getNativeScreenDensity();
}

@Override
public float getPpiY() {
return 96;
public float getPpiY () {
return 96f * (float)getNativeScreenDensity();
}

@Override
Expand All @@ -206,8 206,9 @@ public float getPpcY() {
}

@Override
public float getDensity() {
return 96.0f / 160;
public float getDensity () {
float ppiX = getPpiX();
return (ppiX > 0 && ppiX <= Float.MAX_VALUE) ? ppiX / 160f : 1f;
}

@Override
Expand Down
Loading

0 comments on commit a584fc1

Please sign in to comment.