Skip to content

Commit

Permalink
fix artifacts when drawing path
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Nov 7, 2023
1 parent 0dceaf2 commit 7184b4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public void render() {

if (atlas == null) {
atlas = manager.get(ATLAS, TextureAtlas.class);
zoneCache.setSharedAtlas(atlas);
}

if (normalFont == null) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MD5Key, Animation<TextureRegion>> animationMap = new HashMap<>();
private final Map<MD5Key, VideoPlayer> videoPlayerMap = new HashMap<>();

private final Map<String, Sprite> fetchedSprites = new HashMap<>();
private final Map<MD5Key, Sprite> isoSprites = new HashMap<>();
private final Map<String, TextureRegion> fetchedRegions = new HashMap<>();
private final Map<MD5Key, Sprite> bigSprites = new HashMap<>();

private final Map<MD5Key, Texture> paintTextures = new HashMap<>();
private final Texture whitePixel;
private final TextureRegion whitePixelRegion;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7184b4f

Please sign in to comment.