From f164206fb790e79368661a5c71742214d737ad78 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 May 2022 01:07:24 -0400 Subject: [PATCH 01/15] Use Array as GWT json does not support ArrayList --- .../mundus/commons/dto/GameObjectDTO.java | 19 +++++++++---------- .../mbrlabs/mundus/commons/dto/SceneDTO.java | 9 +++++---- .../mundus/editor/exporter/ExporterTest.java | 8 ++------ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/dto/GameObjectDTO.java b/commons/src/main/com/mbrlabs/mundus/commons/dto/GameObjectDTO.java index 10e5b1a23..35a26e419 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/dto/GameObjectDTO.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/dto/GameObjectDTO.java @@ -16,8 +16,7 @@ package com.mbrlabs.mundus.commons.dto; -import java.util.ArrayList; -import java.util.List; +import com.badlogic.gdx.utils.Array; /** * @author Tibor Zsuro @@ -31,16 +30,16 @@ public class GameObjectDTO { private float[] transform = new float[10]; - private List tags; - private List childs; + private Array tags; + private Array childs; private ModelComponentDTO modelComponent; private TerrainComponentDTO terrainComponent; private WaterComponentDTO waterComponent; public GameObjectDTO() { - childs = new ArrayList<>(); - tags = new ArrayList<>(); + childs = new Array<>(); + tags = new Array<>(); } public int getId() { @@ -71,19 +70,19 @@ public float[] getTransform() { return transform; } - public List getTags() { + public Array getTags() { return tags; } - public void setTags(List tags) { + public void setTags(Array tags) { this.tags = tags; } - public List getChilds() { + public Array getChilds() { return childs; } - public void setChilds(List childs) { + public void setChilds(Array childs) { this.childs = childs; } diff --git a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java index 66725e1b8..d52577d5b 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java @@ -16,6 +16,7 @@ package com.mbrlabs.mundus.commons.dto; +import com.badlogic.gdx.utils.Array; import com.mbrlabs.mundus.commons.water.WaterResolution; import java.util.ArrayList; @@ -30,7 +31,7 @@ public class SceneDTO { private long id; private String name; private String skyboxAssetId; - private List gameObjects; + private Array gameObjects; private FogDTO fog; private BaseLightDTO ambientLight; private float camPosX; @@ -43,7 +44,7 @@ public class SceneDTO { private WaterResolution waterResolution; public SceneDTO() { - gameObjects = new ArrayList<>(); + gameObjects = new Array<>(); } public long getId() { @@ -126,11 +127,11 @@ public void setAmbientLight(BaseLightDTO ambientLight) { this.ambientLight = ambientLight; } - public List getGameObjects() { + public Array getGameObjects() { return gameObjects; } - public void setGameObjects(List gameObjects) { + public void setGameObjects(Array gameObjects) { this.gameObjects = gameObjects; } diff --git a/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java b/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java index a87b549c7..c7d80c039 100644 --- a/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java +++ b/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java @@ -1,21 +1,17 @@ package com.mbrlabs.mundus.editor.exporter; +import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.JsonWriter; import com.mbrlabs.mundus.commons.dto.GameObjectDTO; import com.mbrlabs.mundus.commons.dto.SceneDTO; import com.mbrlabs.mundus.commons.dto.TerrainComponentDTO; import com.mbrlabs.mundus.editor.core.kryo.KryoManager; import com.mbrlabs.mundus.editor.core.project.ProjectContext; -import com.mbrlabs.mundus.editor.history.CommandHistory; -import com.mbrlabs.mundus.editor.history.HistoryTest; import org.junit.Before; import org.junit.Test; -import org.lwjgl.system.CallbackI; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; -import java.util.ArrayList; -import java.util.List; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -68,7 +64,7 @@ private GameObjectDTO buildTerrain(String name) { TerrainComponentDTO terrainComponent = new TerrainComponentDTO(); terrain.setTerrainComponent(terrainComponent); - List tags = new ArrayList<>(); + Array tags = new Array<>(); tags.add("grass"); terrain.setTags(tags); From 192a7ab51bbbc037a61e7e25042d3bc209842594 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 May 2022 01:11:22 -0400 Subject: [PATCH 02/15] Update AssetManager loadAssets for GWT support --- .../mundus/commons/assets/AssetManager.java | 72 ++++++++++++------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/AssetManager.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/AssetManager.java index aa1cee124..16da7d1da 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/AssetManager.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/AssetManager.java @@ -35,6 +35,7 @@ * @author Marcus Brummer * @version 06-10-2016 */ +@SuppressWarnings("NonJREEmulationClassesInClientCode") public class AssetManager implements Disposable { private static final String TAG = AssetManager.class.getSimpleName(); @@ -163,16 +164,10 @@ public Array getMaterialAssets() { * if a meta file can't be parsed */ public void loadAssets(AssetLoadingListener listener, boolean isRuntime) throws AssetNotFoundException, MetaFileParseException { - // create meta file filter - FileFilter metaFileFilter = new FileFilter() { - @Override - public boolean accept(File file) { - return file.getName().endsWith(Meta.META_EXTENSION); - } - }; - final MetaLoader metaLoader = new MetaLoader(); + String[] files; + FileHandle fileList; FileHandle[] metaFiles; if (isRuntime && Gdx.app.getType() == Application.ApplicationType.Desktop) { @@ -180,23 +175,22 @@ public boolean accept(File file) { // Application will need to provide an assets.txt file listing all Mundus assets // in the Mundus root directory. // https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/ - FileHandle fileList = rootFolder.child("assets.txt"); - String[] files = fileList.readString().split("\\n"); - - // Get meta file extension file names - Array metalFileNames = new Array<>(); - for (String filename: files) { - if (filename.endsWith(Meta.META_EXTENSION)) { - metalFileNames.add(filename); - } - } - - metaFiles = new FileHandle[metalFileNames.size]; - for (int i = 0; i < metaFiles.length; i++) { - metaFiles[i] = rootFolder.child(metalFileNames.get(i)); - } - + fileList = rootFolder.child("assets.txt"); + files = fileList.readString().split("\\n"); + metaFiles = getMetaFiles(files); + } else if (isRuntime && Gdx.app.getType() == Application.ApplicationType.WebGL) { + // For WebGL we use a native split method for string split + fileList = rootFolder.child("assets.txt"); + files = split(fileList.readString(), "\n"); + metaFiles = getMetaFiles(files); } else { + // Editor uses this block to load meta files + FileFilter metaFileFilter = new FileFilter() { + @Override + public boolean accept(File file) { + return file.getName().endsWith(Meta.META_EXTENSION); + } + }; metaFiles = rootFolder.list(metaFileFilter); } @@ -228,6 +222,29 @@ public boolean accept(File file) { } } + /** + * Get an array of Meta FileHandles for the given String array of file names. + * + * @param files the array of file names to retrieve meta filehandles from + * @return FileHandle array of meta files. + */ + private FileHandle[] getMetaFiles(String[] files) { + // Get meta file extension file names + Array metalFileNames = new Array<>(); + for (String filename: files) { + if (filename.endsWith(Meta.META_EXTENSION)) { + metalFileNames.add(filename); + } + } + + FileHandle[] metaFiles = new FileHandle[metalFileNames.size]; + for (int i = 0; i < metaFiles.length; i++) { + metaFiles[i] = rootFolder.child(metalFileNames.get(i)); + } + + return metaFiles; + } + /** * Loads an asset, given it's meta file. * @@ -336,6 +353,13 @@ public void dispose() { assetIndex.clear(); } + /** + * Native JavaScript string split method for GWT support + */ + public static final native String[] split(String string, String separator) /*-{ + return string.split(separator); + }-*/; + /** * Used to inform users about the current loading status. */ From 2002e035c6151fc4971432b6a76f01bfce54ecc8 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 May 2022 16:54:45 -0400 Subject: [PATCH 03/15] GWT no mipmap on mag filter --- .../mbrlabs/mundus/commons/utils/TextureUtils.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/utils/TextureUtils.java b/commons/src/main/com/mbrlabs/mundus/commons/utils/TextureUtils.java index 454dbc8ec..8b454e46b 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/utils/TextureUtils.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/utils/TextureUtils.java @@ -16,6 +16,8 @@ package com.mbrlabs.mundus.commons.utils; +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Texture; @@ -27,7 +29,16 @@ public class TextureUtils { public static Texture loadMipmapTexture(FileHandle fileHandle, boolean tilable) { Texture texture = new Texture(fileHandle, true); - texture.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.MipMapLinearLinear); + + Texture.TextureFilter magFilter; + + if (Gdx.app.getType() == Application.ApplicationType.WebGL) + // WebGL does not support mip map on Mag filter + magFilter = Texture.TextureFilter.Linear; + else + magFilter = Texture.TextureFilter.MipMapLinearLinear; + + texture.setFilter(Texture.TextureFilter.MipMapLinearLinear, magFilter); if (tilable) { texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat); From b7e8fcb401611cb74164ead4dc5cc7927770d175 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 May 2022 16:57:26 -0400 Subject: [PATCH 04/15] Use .readString() for GWT support --- gdx-runtime/src/com/mbrlabs/mundus/runtime/SceneLoader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdx-runtime/src/com/mbrlabs/mundus/runtime/SceneLoader.java b/gdx-runtime/src/com/mbrlabs/mundus/runtime/SceneLoader.java index dc3541818..6e323b94c 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus/runtime/SceneLoader.java +++ b/gdx-runtime/src/com/mbrlabs/mundus/runtime/SceneLoader.java @@ -53,7 +53,9 @@ public SceneLoader(Mundus mundus, FileHandle scenesRoot) { public Scene load(String name) { Json json = new Json(); - SceneDTO sceneDTO = json.fromJson(SceneDTO.class, root.child(name)); + + // Pass string using readString() instead of FileHandle to support GWT + SceneDTO sceneDTO = json.fromJson(SceneDTO.class, root.child(name).readString()); Scene scene = SceneConverter.convert(sceneDTO, mundus.getShaders(), assetManager); From 127cbee842ef4faa6bb0ed3c667c46a70a2f190d Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 May 2022 16:58:27 -0400 Subject: [PATCH 05/15] Update mundus.gwt to include new shaders --- gdx-runtime/src/com/mbrlabs/mundus.gwt.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml b/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml index 6591dcc9e..c2582e518 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml +++ b/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml @@ -10,5 +10,9 @@ + + + + From e7b05a1d39e713a0d74109db1b096de9121cc00f Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 May 2022 17:01:24 -0400 Subject: [PATCH 06/15] Add commons.gwt.xml --- commons/src/main/commons.gwt.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 commons/src/main/commons.gwt.xml diff --git a/commons/src/main/commons.gwt.xml b/commons/src/main/commons.gwt.xml new file mode 100644 index 000000000..4968cb755 --- /dev/null +++ b/commons/src/main/commons.gwt.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + From 034fa1e9fd3831f8a5330734753c20a7d87617f3 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 May 2022 08:51:29 -0400 Subject: [PATCH 07/15] Store Base64 strings for pixmaps to support GWT --- .../commons/assets/PixmapTextureAsset.java | 22 +++++++++++++++++++ .../mundus/commons/assets/TerrainAsset.java | 8 +++++++ .../commons/assets/meta/MetaLoader.java | 1 + .../commons/assets/meta/MetaTerrain.java | 13 ++++++++++- .../editor/assets/EditorAssetManager.kt | 7 ++++-- .../mbrlabs/mundus/editor/assets/MetaSaver.kt | 1 + 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java index d6e95d9e6..38d105822 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java @@ -19,6 +19,7 @@ import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.utils.GdxRuntimeException; import com.mbrlabs.mundus.commons.assets.meta.Meta; import java.util.Map; @@ -60,6 +61,27 @@ public void applyDependencies() { // no dependencies here } + + /** + * Initiate loading of a Base64 string image into the pixmap. + * + * @param base64 a base64 encoded string of a PNG file + */ + public void loadBase64(String base64) { + Pixmap.downloadFromUrl(base64, new Pixmap.DownloadPixmapResponseListener() { + @Override + public void downloadComplete(Pixmap downloadedPixmap) { + pixmap = downloadedPixmap; + texture = new Texture(pixmap); + } + + @Override + public void downloadFailed(Throwable t) { + throw new GdxRuntimeException(t); + } + }); + } + @Override public void dispose() { pixmap.dispose(); diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/TerrainAsset.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/TerrainAsset.java index bdc6fb153..743eacfba 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/TerrainAsset.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/TerrainAsset.java @@ -15,6 +15,8 @@ */ package com.mbrlabs.mundus.commons.assets; +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.FloatArray; @@ -171,6 +173,12 @@ public void resolveDependencies(Map assets) { String id = meta.getTerrain().getSplatmap(); if (id != null && assets.containsKey(id)) { setSplatmap((PixmapTextureAsset) assets.get(id)); + + // If WebGL, we use base64 string for pixmap since pixmap cannot read from binaries on GWT + if (Gdx.app.getType() == Application.ApplicationType.WebGL) { + ((PixmapTextureAsset) assets.get(id)).loadBase64(meta.getTerrain().getSplatBase64()); + } + } // splat channel base diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaLoader.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaLoader.java index a3c7fb946..866263197 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaLoader.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaLoader.java @@ -60,6 +60,7 @@ private void parseTerrain(Meta meta, JsonValue jsonTerrain) { terrain.setSize(jsonTerrain.getInt(MetaTerrain.JSON_SIZE)); terrain.setUv(jsonTerrain.getFloat(MetaTerrain.JSON_UV_SCALE, Terrain.DEFAULT_UV_SCALE)); terrain.setSplatmap(jsonTerrain.getString(MetaTerrain.JSON_SPLATMAP, null)); + terrain.setSplatBase64(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_BASE64, null)); terrain.setSplatBase(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_BASE, null)); terrain.setSplatR(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_R, null)); terrain.setSplatG(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_G, null)); diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaTerrain.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaTerrain.java index 10ec3f0a6..f9c718f78 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaTerrain.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/meta/MetaTerrain.java @@ -26,6 +26,7 @@ public class MetaTerrain { public static final String JSON_SIZE = "size"; public static final String JSON_SPLATMAP = "map"; public static final String JSON_SPLAT_BASE = "base"; + public static final String JSON_SPLAT_BASE64 = "base64"; public static final String JSON_SPLAT_R = "r"; public static final String JSON_SPLAT_G = "g"; public static final String JSON_SPLAT_B = "b"; @@ -36,6 +37,7 @@ public class MetaTerrain { private float uv; private String splatmap; private String splatBase; + private String splatBase64; private String splatR; private String splatG; private String splatB; @@ -57,6 +59,14 @@ public void setSplatBase(String splatBase) { this.splatBase = splatBase; } + public String getSplatBase64() { + return splatBase64; + } + + public void setSplatBase64(String splatBase64) { + this.splatBase64 = splatBase64; + } + public String getSplatR() { return splatR; } @@ -109,13 +119,14 @@ public void setUv(float uv) { public String toString() { return "MetaTerrain{" + "size=" + size + + ", uv=" + uv + ", splatmap='" + splatmap + '\'' + ", splatBase='" + splatBase + '\'' + + ", splatBase64='" + splatBase64 + '\'' + ", splatR='" + splatR + '\'' + ", splatG='" + splatG + '\'' + ", splatB='" + splatB + '\'' + ", splatA='" + splatA + '\'' + - ", uv='" + uv + '\'' + '}'; } } diff --git a/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt b/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt index 9c423ebdc..8abdef50d 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/assets/EditorAssetManager.kt @@ -30,9 +30,8 @@ import com.mbrlabs.mundus.commons.assets.meta.MetaTerrain import com.mbrlabs.mundus.commons.scene3d.GameObject import com.mbrlabs.mundus.commons.scene3d.components.AssetUsage import com.mbrlabs.mundus.commons.utils.FileFormatUtils -import com.mbrlabs.mundus.commons.water.Water -import com.mbrlabs.mundus.editor.Mundus import com.mbrlabs.mundus.commons.water.WaterFloatAttribute +import com.mbrlabs.mundus.editor.Mundus import com.mbrlabs.mundus.editor.core.EditorScene import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.events.LogEvent @@ -588,6 +587,10 @@ class EditorAssetManager(assetsRoot: FileHandle) : AssetManager(assetsRoot) { val splatmap = terrain.splatmap if (splatmap != null) { PixmapIO.writePNG(splatmap.file, splatmap.pixmap) + + // Encode splatmap PNG file to base64 string, used for pixmap on GWT + val encoded = Base64.getEncoder().encodeToString(splatmap.file.readBytes()) + terrain.meta.terrain.splatBase64 = "data:image/png;base64,$encoded" } // save meta file diff --git a/editor/src/main/com/mbrlabs/mundus/editor/assets/MetaSaver.kt b/editor/src/main/com/mbrlabs/mundus/editor/assets/MetaSaver.kt index 2d6942345..9dbf83bf1 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/assets/MetaSaver.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/assets/MetaSaver.kt @@ -75,6 +75,7 @@ class MetaSaver { json.writeObjectStart(Meta.JSON_TERRAIN) json.writeValue(MetaTerrain.JSON_SIZE, terrain.size) json.writeValue(MetaTerrain.JSON_UV_SCALE, terrain.uv) + json.writeValue(MetaTerrain.JSON_SPLAT_BASE64, terrain.splatBase64) if (terrain.splatmap != null) json.writeValue(MetaTerrain.JSON_SPLATMAP, terrain.splatmap) if (terrain.splatBase != null) json.writeValue(MetaTerrain.JSON_SPLAT_BASE, terrain.splatBase) if (terrain.splatR != null) json.writeValue(MetaTerrain.JSON_SPLAT_R, terrain.splatR) From ac23e6018c5c04ecf27a85db77657b865b079062 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 May 2022 08:56:27 -0400 Subject: [PATCH 08/15] Skip clearChannel on GWT --- .../main/com/mbrlabs/mundus/commons/terrain/SplatMap.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/terrain/SplatMap.java b/commons/src/main/com/mbrlabs/mundus/commons/terrain/SplatMap.java index 0c6f17361..4ef040eef 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/terrain/SplatMap.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/terrain/SplatMap.java @@ -16,6 +16,8 @@ package com.mbrlabs.mundus.commons.terrain; +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; @@ -53,6 +55,12 @@ public Pixmap getPixmap() { } public void clearChannel(SplatTexture.Channel channel) { + // There seems to be no point in running this code on WebGL so we skip it + // because GWT has performance issues when passing data from the same pixmap into its draw parameters + // the work around is to have a clone of the pixmap like clone.getPixel if we needed this on GWT. + if (Gdx.app.getType() == Application.ApplicationType.WebGL) + return; + Pixmap pixmap = getPixmap(); for (int smX = 0; smX < pixmap.getWidth(); smX++) { for (int smY = 0; smY < pixmap.getHeight(); smY++) { From 604cb87184b413958ae8e1c0613e56265ae11648 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 May 2022 08:56:47 -0400 Subject: [PATCH 09/15] Remove unused imports --- .../main/com/mbrlabs/mundus/commons/shaders/TerrainShader.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainShader.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainShader.java index 1942e976b..59cbedb2f 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainShader.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/TerrainShader.java @@ -20,11 +20,9 @@ import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g3d.Renderable; import com.badlogic.gdx.graphics.g3d.Shader; -import com.badlogic.gdx.graphics.g3d.shaders.BaseShader; import com.badlogic.gdx.graphics.g3d.utils.RenderContext; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Array; import com.mbrlabs.mundus.commons.env.Fog; import com.mbrlabs.mundus.commons.env.MundusEnvironment; From 3a87f726d34d8ddbf9120d46324a856b2874ce8a Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 May 2022 10:04:51 -0400 Subject: [PATCH 10/15] Address GWT long reflection issue --- .../mbrlabs/mundus/commons/dto/SceneDTO.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java index d52577d5b..3d11b68fc 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java @@ -17,18 +17,17 @@ package com.mbrlabs.mundus.commons.dto; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Json; +import com.badlogic.gdx.utils.JsonValue; import com.mbrlabs.mundus.commons.water.WaterResolution; -import java.util.ArrayList; -import java.util.List; - /** * @author Tibor Zsuro * @version 12-08-2021 */ -public class SceneDTO { +public class SceneDTO implements Json.Serializable { - private long id; + private transient long id; private String name; private String skyboxAssetId; private Array gameObjects; @@ -158,4 +157,20 @@ public void setSkyboxAssetId(String skyboxAssetId) { public String getSkyboxAssetId() { return skyboxAssetId; } + + @Override + public void write(Json json) { + // ID is written separately due to GWT technical limitations on Long emulation and reflection + json.writeValue("id", id); + json.writeFields(this); + } + + @Override + public void read(Json json, JsonValue jsonData) { + json.setIgnoreUnknownFields(true); + // ID is read in separately due to GWT technical limitations on Long emulation and reflection + id = Long.parseLong(jsonData.getString("id")); + json.readFields(this, jsonData); + json.setIgnoreUnknownFields(false); + } } From f2dc21fc69dadf524c70b33517f4dc0a567261c1 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 May 2022 10:35:15 -0400 Subject: [PATCH 11/15] Include project sources for HTML support --- build.gradle | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 221895037..2e81aeff5 100644 --- a/build.gradle +++ b/build.gradle @@ -54,9 +54,15 @@ project(":commons") { dependencies { implementation "com.badlogicgames.gdx:gdx:$gdxVersion" + // Include HTML sources in commons as well for GWT support api "com.github.mgsx-dev.gdx-gltf:gltf:$gltfVersion" + api "com.github.mgsx-dev.gdx-gltf:gltf:$gltfVersion:sources" - implementation "com.github.crykn.guacamole:gdx:$guacamoleVersion" + api "com.github.crykn.guacamole:gdx:$guacamoleVersion" + api "com.github.crykn.guacamole:core:$guacamoleVersion:sources" + api "com.github.crykn.guacamole:gdx:$guacamoleVersion:sources" + api "com.github.crykn.guacamole:gdx-gwt:$guacamoleVersion" + api "com.github.crykn.guacamole:gdx-gwt:$guacamoleVersion:sources" testImplementation "junit:junit:$junitVersion" From 6cf0040ca16375f95d041fed831e715dd5ed52da Mon Sep 17 00:00:00 2001 From: James Date: Tue, 24 May 2022 22:43:43 -0400 Subject: [PATCH 12/15] Handle ids of default scenes --- .../src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java index 3d11b68fc..bdcbc45fb 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java @@ -168,8 +168,11 @@ public void write(Json json) { @Override public void read(Json json, JsonValue jsonData) { json.setIgnoreUnknownFields(true); - // ID is read in separately due to GWT technical limitations on Long emulation and reflection - id = Long.parseLong(jsonData.getString("id")); + // Default scenes do not have an ID, so we check for it first + if (jsonData.has("id")) { + // ID is read in separately due to GWT technical limitations on Long emulation and reflection + id = Long.parseLong(jsonData.getString("id")); + } json.readFields(this, jsonData); json.setIgnoreUnknownFields(false); } From 3b2c7c828922595d3b0e44a19b352d4685bcc25b Mon Sep 17 00:00:00 2001 From: James Date: Tue, 24 May 2022 22:59:58 -0400 Subject: [PATCH 13/15] Remove guacamole module --- commons/src/main/commons.gwt.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/commons/src/main/commons.gwt.xml b/commons/src/main/commons.gwt.xml index 4968cb755..bad18a4af 100644 --- a/commons/src/main/commons.gwt.xml +++ b/commons/src/main/commons.gwt.xml @@ -2,8 +2,6 @@ - - From ca30f5bfe553aad2dd44d1e61f7da5781f64991c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 24 May 2022 23:20:33 -0400 Subject: [PATCH 14/15] Minor comment and log updates --- .../com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java | 2 ++ commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java b/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java index 38d105822..3e4798aca 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/assets/PixmapTextureAsset.java @@ -16,6 +16,7 @@ package com.mbrlabs.mundus.commons.assets; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; @@ -77,6 +78,7 @@ public void downloadComplete(Pixmap downloadedPixmap) { @Override public void downloadFailed(Throwable t) { + Gdx.app.error(getClass().getName(), "Unable to Download Base64 Pixmap"); throw new GdxRuntimeException(t); } }); diff --git a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java index bdcbc45fb..8b6efdba5 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/dto/SceneDTO.java @@ -168,7 +168,7 @@ public void write(Json json) { @Override public void read(Json json, JsonValue jsonData) { json.setIgnoreUnknownFields(true); - // Default scenes do not have an ID, so we check for it first + // Default scenes may not have an ID, so we check for it first if (jsonData.has("id")) { // ID is read in separately due to GWT technical limitations on Long emulation and reflection id = Long.parseLong(jsonData.getString("id")); From cb08addbf00392620c110e46382c1db083a2244d Mon Sep 17 00:00:00 2001 From: James Date: Wed, 25 May 2022 11:23:23 -0400 Subject: [PATCH 15/15] Update runtime CHANGES --- gdx-runtime/CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/gdx-runtime/CHANGES b/gdx-runtime/CHANGES index 6a5ce87bf..9c9c4d391 100644 --- a/gdx-runtime/CHANGES +++ b/gdx-runtime/CHANGES @@ -1,5 +1,6 @@ [0.3.1] ~ TBD - Set Source Compatibility to 1.7, PR #47 +- Update to support GWT builds [0.3.0] - Enable fog in runtime