From 7184b4f8cde2dc47ac3ecb4e4ad3f03f6033205d Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Tue, 7 Nov 2023 23:30:09 +0100 Subject: [PATCH] fix artifacts when drawing path --- .../client/ui/zone/gdx/GdxRenderer.java | 11 +++-------- .../maptool/client/ui/zone/gdx/ZoneCache.java | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/ui/zone/gdx/GdxRenderer.java b/src/main/java/net/rptools/maptool/client/ui/zone/gdx/GdxRenderer.java index eddd6d69ce..67a8386174 100644 --- a/src/main/java/net/rptools/maptool/client/ui/zone/gdx/GdxRenderer.java +++ b/src/main/java/net/rptools/maptool/client/ui/zone/gdx/GdxRenderer.java @@ -309,6 +309,7 @@ public void render() { if (atlas == null) { atlas = manager.get(ATLAS, TextureAtlas.class); + zoneCache.setSharedAtlas(atlas); } if (normalFont == null) { @@ -728,8 +729,7 @@ private void paintlightSourceIconOverlay() { if (token.hasLightSources()) { boolean foundNormalLight = false; for (AttachedLightSource attachedLightSource : token.getLightSources()) { - LightSource lightSource = - MapTool.getCampaign().getLightSource(attachedLightSource.getLightSourceId()); + LightSource lightSource = attachedLightSource.resolve(token, MapTool.getCampaign()); if (lightSource != null && lightSource.getType() == LightSource.Type.NORMAL) { foundNormalLight = true; break; @@ -1658,16 +1658,11 @@ private void renderBoard() { } private void fillViewportWith(ZoneCache.GdxPaint paint) { - // var w = ((int) (cam.viewportWidth * zoom / texture.getWidth()) + 4) * texture.getWidth(); - // var h = ((int) (cam.viewportHeight * zoom / texture.getHeight()) + 4) * texture.getHeight(); - var w = cam.viewportWidth * zoom; var h = cam.viewportHeight * zoom; var startX = (cam.position.x - cam.viewportWidth * zoom / 2); - // startX = (((int) startX) / texture.getWidth()) * texture.getWidth() - texture.getWidth(); var startY = (cam.position.y - cam.viewportHeight * zoom / 2); - // startY = (((int) startY) / texture.getHeight()) * texture.getHeight() - texture.getHeight(); var vertices = new float[] { startX, startY, startX, startY + h, startX + w, startY + h, startX + w, startY @@ -3059,7 +3054,7 @@ private void renderPath(Path path, TokenFootprint footprint) { } previousPoint = p; } - drawer.path(tmpFloat.toArray(), drawer.getDefaultLineWidth(), JoinType.SMOOTH, true); + drawer.path(tmpFloat.toArray(), drawer.getDefaultLineWidth(), JoinType.NONE, true); } drawer.setColor(Color.WHITE); timer.stop("renderPath-2"); diff --git a/src/main/java/net/rptools/maptool/client/ui/zone/gdx/ZoneCache.java b/src/main/java/net/rptools/maptool/client/ui/zone/gdx/ZoneCache.java index 862a737ede..c7eb7820aa 100644 --- a/src/main/java/net/rptools/maptool/client/ui/zone/gdx/ZoneCache.java +++ b/src/main/java/net/rptools/maptool/client/ui/zone/gdx/ZoneCache.java @@ -47,28 +47,24 @@ import org.apache.logging.log4j.Logger; public class ZoneCache implements Disposable, AssetAvailableListener { + public record GdxPaint(Color color, TextureRegion textureRegion) {} - ; private static final Logger log = LogManager.getLogger(ZoneCache.class); private final Zone zone; private final ZoneRenderer zoneRenderer; private final PixmapPacker packer = new PixmapPacker(2048, 2048, Pixmap.Format.RGBA8888, 2, false); - private final TextureAtlas tokenAtlas = new TextureAtlas(); // this atlas is shared by all zones and must not be disposed here. - private final TextureAtlas sharedAtlas; - + private TextureAtlas sharedAtlas; private final Map> animationMap = new HashMap<>(); private final Map videoPlayerMap = new HashMap<>(); - private final Map fetchedSprites = new HashMap<>(); private final Map isoSprites = new HashMap<>(); private final Map fetchedRegions = new HashMap<>(); private final Map bigSprites = new HashMap<>(); - private final Map paintTextures = new HashMap<>(); private final Texture whitePixel; private final TextureRegion whitePixelRegion; @@ -81,6 +77,10 @@ public ZoneRenderer getZoneRenderer() { return zoneRenderer; } + public void setSharedAtlas(TextureAtlas atlas) { + sharedAtlas = atlas; + } + public ZoneCache(@Nonnull Zone zone, @Nonnull TextureAtlas sharedAtlas) { this.zone = zone; this.sharedAtlas = sharedAtlas; @@ -148,8 +148,11 @@ public void assetAvailable(MD5Key key) { pix.dispose(); }); } - packer.updateTextureAtlas( - tokenAtlas, Texture.TextureFilter.Linear, Texture.TextureFilter.Linear, false); + Gdx.app.postRunnable( + () -> { + packer.updateTextureAtlas( + tokenAtlas, Texture.TextureFilter.Linear, Texture.TextureFilter.Linear, false); + }); } public TextureRegion fetch(String regionName) {