Skip to content

Commit

Permalink
Texture Atlases can use a different height scale now
Browse files Browse the repository at this point in the history
  • Loading branch information
Interrupt committed Dec 2, 2018
1 parent 4c7d585 commit 3de100d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ private void focusChanged (FocusEvent event) {
protected void makeRegionButtons() {
buttonLayout.reset();

TextureAtlas atlas = atlases.get(selectBox.getSelectedIndex());

int num = 0;
for(TextureRegion region : atlases.get(selectBox.getSelectedIndex()).getSpriteRegions()) {
for(TextureRegion region : atlas.getSpriteRegions()) {
ImageButton button = new ImageButton(new TextureRegionDrawable(region));
button.getImage().setScaling(Scaling.fill);
button.getImageCell().width(spriteSize).height(spriteSize);
button.getImageCell().width(spriteSize).height(spriteSize * atlas.rowScale);

button(button, num++, ((TextureAtlas)selectBox.getSelected()).name);

Expand Down
5 changes: 2 additions & 3 deletions Dungeoneer/src/com/interrupt/dungeoneer/gfx/GlRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.interrupt.dungeoneer.gfx.drawables.DrawableMesh;
import com.interrupt.dungeoneer.gfx.drawables.DrawableProjectedDecal;
import com.interrupt.dungeoneer.gfx.drawables.DrawableSprite;
import com.interrupt.dungeoneer.gfx.shaders.ShaderData;
import com.interrupt.dungeoneer.gfx.shaders.ShaderInfo;
import com.interrupt.dungeoneer.gfx.shaders.WaterShaderInfo;
import com.interrupt.dungeoneer.overlays.OverlayManager;
Expand Down Expand Up @@ -2614,9 +2613,9 @@ public Color GetLightmapAt(float posx, float posy, float posz)
else return t;
}

public float GetTexVAt(float posy)
public float GetTexVAt(float posy, TextureAtlas atlas)
{
return -posy + 0.5f;
return (-posy + 0.5f) / atlas.rowScale;
}

public GL20 getGL() {
Expand Down
32 changes: 17 additions & 15 deletions Dungeoneer/src/com/interrupt/dungeoneer/gfx/Tesselator.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ else if(c.tileSpaceType == TileSpaceType.OPEN_NW)
if (c.tileSpaceType != TileSpaceType.EMPTY || c.tileSpaceType != TileSpaceType.SOLID) {
boolean makeAngledWall = false;
if (c.tileSpaceType==TileSpaceType.OPEN_SE) {
reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(c.wallTex);
normal.set((float)Math.sin(Math.PI/4),0,(float)Math.cos(Math.PI/4));

x_offsets.set(0, 1);
Expand All @@ -518,7 +517,6 @@ else if(c.tileSpaceType == TileSpaceType.OPEN_NW)
makeAngledWall = true;
}
else if (c.tileSpaceType==TileSpaceType.OPEN_SW) {
reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(c.wallTex);
normal.set((float)Math.sin(-Math.PI/4),0,(float)Math.cos(-Math.PI/4));

x_offsets.set(0, 1);
Expand All @@ -530,7 +528,6 @@ else if (c.tileSpaceType==TileSpaceType.OPEN_SW) {
makeAngledWall = true;
}
else if (c.tileSpaceType==TileSpaceType.OPEN_NE) {
reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(c.wallTex);
normal.set((float)Math.sin(3*Math.PI/4),0,(float)Math.cos(3*Math.PI/4));

x_offsets.set(1, 0);
Expand All @@ -542,7 +539,6 @@ else if (c.tileSpaceType==TileSpaceType.OPEN_NE) {
makeAngledWall = true;
}
else if (c.tileSpaceType==TileSpaceType.OPEN_NW) {
reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(c.wallTex);
normal.set((float)Math.sin(-3*Math.PI/4),0,(float)Math.cos(-3*Math.PI/4));

x_offsets.set(1, 0);
Expand All @@ -555,6 +551,9 @@ else if (c.tileSpaceType==TileSpaceType.OPEN_NW) {
}

if(makeAngledWall) {
TextureAtlas atlas = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas);
reg = atlas.getSprite(c.wallTex);

// subdivide the wall if needed
float h = Math.min(ceilPairTuple.val1, ceilPairTuple.val2) - Math.max(floorPairTuple.val1, floorPairTuple.val2);
if(h > subdivideSize) {
Expand All @@ -579,10 +578,10 @@ else if (c.tileSpaceType==TileSpaceType.OPEN_NW) {
// now have enough info to add vertices for all the collected wall segments
for(int i = 0; i < starts.size; i++)
{
selectedTesselator.addVertex(x + x_offsets.val1, ends.get(i).val1 , y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(ends.get(i).val1) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, ends.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(starts.get(i).val1) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(ends.get(i).val2) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(starts.get(i).val2) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val1, ends.get(i).val1 , y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(ends.get(i).val1, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, ends.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(starts.get(i).val1, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(ends.get(i).val2, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(starts.get(i).val2, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.finishQuad();
}

Expand Down Expand Up @@ -735,7 +734,8 @@ else if(dir == TileEdges.East) {

selectedTesselator = tesselators.world.getTesselatorByAtlas(selectedAtlas);

reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(checkDir.getWallTex(dir));
TextureAtlas atlas = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas);
reg = atlas.getSprite(checkDir.getWallTex(dir));

// paint the bottom wall
if(bottomWallIndex != null && bottomWallIndex >= i) {
Expand All @@ -745,7 +745,8 @@ else if(dir == TileEdges.East) {
selectedAtlas = checkDir.floorTexAtlas;
if(selectedAtlas == null) selectedAtlas = defaultTextureAtlas;

reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(TileManager.instance.getFlowTexture(checkDir));
atlas = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas);
reg = atlas.getSprite(TileManager.instance.getFlowTexture(checkDir));
selectedTesselator = tesselators.waterfall.getTesselatorByAtlas(selectedAtlas);

ends.get(i).val1 -= 0.1f;
Expand All @@ -757,14 +758,15 @@ else if(dir == TileEdges.East) {

selectedTesselator = tesselators.world.getTesselatorByAtlas(selectedAtlas);

reg = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas).getSprite(checkDir.getWallBottomTex(dir));
atlas = TextureAtlas.getRepeatingAtlasByIndex(selectedAtlas);
reg = atlas.getSprite(checkDir.getWallBottomTex(dir));
}
}

selectedTesselator.addVertex(x + x_offsets.val1, ends.get(i).val1 , y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(ends.get(i).val1) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, ends.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(starts.get(i).val1) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(ends.get(i).val2) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(starts.get(i).val2) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val1, ends.get(i).val1 , y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(ends.get(i).val1, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, ends.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, reg.getU(), renderer.GetTexVAt(starts.get(i).val1, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val1, starts.get(i).val1, y + y_offsets.val1, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(ends.get(i).val2, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, ends.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.addVertex(x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, reg.getU2(), renderer.GetTexVAt(starts.get(i).val2, atlas) + reg.getV(), showLights ? getLightColorAt(level,x + x_offsets.val2, starts.get(i).val2, y + y_offsets.val2, normal) : fullBrightColor);
selectedTesselator.finishQuad();

tuplePool.freeAll();
Expand Down
14 changes: 8 additions & 6 deletions Dungeoneer/src/com/interrupt/dungeoneer/gfx/TextureAtlas.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.interrupt.dungeoneer.gfx;

import java.util.HashMap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
Expand All @@ -19,6 +17,8 @@ public class TextureAtlas {
public int columns = 16;
public int rows = 1;

public int rowScale = 1;

public String filename = "";
public String name = "";
public String shader = null;
Expand Down Expand Up @@ -130,15 +130,17 @@ public void loadRepeating() {
Pixmap pixmap = Art.loadPixmap(filename);
spriteSize = pixmap.getWidth() / columns;

final int atlasHeight = pixmap.getHeight() / spriteSize;
int spriteVerticalSize = spriteSize * rowScale;

final int atlasHeight = pixmap.getHeight() / spriteVerticalSize;
int next_pow = GetNextPowerOf2(columns * atlasHeight);
Pixmap remappedWall = new Pixmap(spriteSize * next_pow, spriteSize, Pixmap.Format.RGBA8888);
Pixmap remappedWall = new Pixmap(spriteSize * next_pow, spriteVerticalSize, Pixmap.Format.RGBA8888);

// redraw them horizontally
int pos = 0;
for(int y = 0; y < atlasHeight; y++) {
for(int x = 0; x < columns; x++) {
remappedWall.drawPixmap(pixmap, pos * spriteSize, 0, x * spriteSize, y * spriteSize, spriteSize, spriteSize);
remappedWall.drawPixmap(pixmap, pos * spriteSize, 0, x * spriteSize, y * spriteVerticalSize, spriteSize, spriteVerticalSize);
pos++;
}
}
Expand All @@ -154,7 +156,7 @@ public void loadRepeating() {
float xMod = (1f / pos) * 0.001f;

for(int i = 0; i < sprite_regions.length; i++) {
TextureRegion wallRegion = new TextureRegion(texture, i * spriteSize, 0, spriteSize, spriteSize);
TextureRegion wallRegion = new TextureRegion(texture, i * spriteSize, 0, spriteSize, spriteVerticalSize);

// clamp the region some
wallRegion.setU(wallRegion.getU() + xMod);
Expand Down

0 comments on commit 3de100d

Please sign in to comment.