Add basic wire support rendering for IC2

This commit is contained in:
Mike Primm 2011-10-29 00:47:24 -05:00
parent 827b172bed
commit 4a6d30f8a2
4 changed files with 320 additions and 30 deletions

View File

@ -0,0 +1,198 @@
# Wire - set render alg
linkmap:id=228,linkalg=5,linkid=223,linkid=225,linkid=226,linkid=227,linkid=228,linkid=233,linkid=237,linkid=246,linkid=250
# Wire - (data is faked: 1=north,2=east,4=south,8=west)
# Wire - no neighbors
block:id=228,data=0,scale=16
layer:6,7,8,9
----------------
----------------
----------------
----------------
----------------
----------------
------****------
------****------
------****------
------****------
----------------
----------------
----------------
----------------
----------------
----------------
# Wire - just north neighbor
block:id=228,data=1,scale=16
layer:6,7,8,9
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
----------------
----------------
----------------
----------------
----------------
----------------
# Wire - just east neighbor
block:id=228,data=2,scale=16
rotate:id=228,data=1,rot=90
# Wire - just south neighbor
block:id=228,id=113,data=4,scale=16
rotate:id=228,data=1,rot=180
# Wire - just south neighbor
block:id=228,data=8,scale=16
rotate:id=228,data=1,rot=270
# Wire - north and east neighbor
block:id=228,data=3,scale=16
layer:6,7,8,9
------****------
------****------
------****------
------****------
------****------
------****------
------**********
------**********
------**********
------**********
----------------
----------------
----------------
----------------
----------------
----------------
# Wire - east and south neighbor
block:id=228,data=6,scale=16
rotate:id=228,data=3,rot=90
# Wire - south and west neighbor
block:id=228,data=12,scale=16
rotate:id=228,data=3,rot=180
# Wire - west and north neighbor
block:id=228,data=9,scale=16
rotate:id=228,data=3,rot=270
# Wire - north and south neighbor
block:id=228,data=5,scale=16
layer:6,7,8,9
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
------****------
# Wire - east and west neighbor
block:id=228,data=10,scale=16
rotate:id=228,data=5,rot=90
# Wire - north, east and south neighbor
block:id=228,data=7,scale=16
layer:6,7,8,9
------****------
------****------
------****------
------****------
------****------
------****------
------**********
------**********
------**********
------**********
------****------
------****------
------****------
------****------
------****------
------****------
# Wire - east, south and west neighbor
block:id=228,data=14,scale=16
rotate:id=228,data=7,rot=90
# Wire - south, west and north neighbor
block:id=228,data=13,scale=16
rotate:id=228,data=7,rot=180
# Wire - west, north and east neighbor
block:id=228,data=11,scale=16
rotate:id=228,data=7,rot=270
# Wire - north, south, east, west neightbors
block:id=228,data=15,scale=16
layer:6,7,8,9
------****------
------****------
------****------
------****------
------****------
------****------
****************
****************
****************
****************
------****------
------****------
------****------
------****------
------****------
------****------
# Iron Fence - set render algorithm
linkmap:id=232,linkalg=1
# Iron Fence - (data is faked: 1=north,2=east,4=south,8=west)
# Iron Fence - no neighbors
block:id=232,data=0,scale=16
rotate:id=85,data=0,rot=0
# Iron Fence - just north neighbor
block:id=232,data=1,scale=16
rotate:id=85,data=1,rot=0
# Iron Fence - just east neighbor
block:id=232,data=2,scale=16
rotate:id=232,data=1,rot=90
# Iron Fence - just south neighbor
block:id=232,data=4,scale=16
rotate:id=232,data=1,rot=180
# Iron Fence - just south neighbor
block:id=232,data=8,scale=16
rotate:id=232,data=1,rot=270
# Iron Fence - north and east neighbor
block:id=232,data=3,scale=16
rotate:id=85,data=3,rot=0
# Iron Fence - east and south neighbor
block:id=232,data=6,scale=16
rotate:id=232,data=3,rot=90
# Iron Fence - south and west neighbor
block:id=232,data=12,scale=16
rotate:id=85,data=3,rot=180
# Iron Fence - west and north neighbor
block:id=232,data=9,scale=16
rotate:id=85,data=3,rot=270
# Iron Fence - north and south neighbor
block:id=232,data=5,scale=16
rotate:id=85,data=5,rot=0
# Iron Fence - east and west neighbor
block:id=232,id=113,data=10,scale=16
rotate:id=232,data=5,rot=90
# Iron Fence - north, east and south neighbor
block:id=232,data=7,scale=16
rotate:id=85,data=7,rot=0
# Iron Fence - east, south and west neighbor
block:id=232,data=14,scale=16
rotate:id=232,data=7,rot=90
# Iron Fence - south, west and north neighbor
block:id=232,data=13,scale=16
rotate:id=232,data=7,rot=180
# Iron Fence - west, north and east neighbor
block:id=232,data=11,scale=16
rotate:id=232,data=7,rot=270
# Iron Fence - north, south, east, west neightbors
block:id=232,data=15,scale=16
layer:id=232,data=15,rot=0

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Material;
import org.dynmap.Log;
@ -25,6 +26,8 @@ public class HDBlockModels {
private long blockflags[];
private int nativeres;
private HashMap<Integer, short[]> scaledblocks;
private static int linkalg[] = new int[256];
private static int linkmap[][] = new int[256][];
private static HashMap<Integer, HDBlockModels> models_by_id_data = new HashMap<Integer, HDBlockModels>();
@ -49,10 +52,6 @@ public class HDBlockModels {
this.databits = databits;
this.nativeres = m.nativeres;
this.blockflags = m.blockflags;
for(int i = 0; i < 16; i++) {
if((databits & (1<<i)) != 0)
models_by_id_data.put((blockid<<4)+i, this);
}
}
/**
* Block definition - positions correspond to Bukkit coordinates (+X is south, +Y is up, +Z is west)
@ -100,6 +99,22 @@ public class HDBlockModels {
else
blockflags[nativeres*y+z] &= ~(1 << x);
}
/**
* Get link algorithm
* @param blkid - block ID
* @return 0=no link alg
*/
public static final int getLinkAlgID(int blkid) {
return linkalg[blkid];
}
/**
* Get link block IDs
* @param blkid - block ID
* @return array of block IDs to link with
*/
public static final int[] getLinkIDs(int blkid) {
return linkmap[blkid];
}
/**
* Get scaled map of block: will return array of alpha levels, corresponding to how much of the
* scaled subblocks are occupied by the original blocks (indexed by Y*res*res + Z*res + X)
@ -276,28 +291,26 @@ public class HDBlockModels {
loadModelFile(in, "models.txt");
try { in.close(); } catch (IOException iox) {} in = null;
}
File custom = new File(datadir, "renderdata/custom-models.txt");
if(custom.canRead()) {
try {
in = new FileInputStream(custom);
loadModelFile(in, custom.getPath());
} catch (IOException iox) {
Log.severe("Error loading " + custom.getPath());
} finally {
if(in != null) {
try { in.close(); } catch (IOException iox) {}
in = null;
File customdir = new File(datadir, "renderdata");
String[] files = customdir.list();
for(String fn : files) {
if(fn.endsWith("-models.txt") == false)
continue;
File custom = new File(customdir, fn);
if(custom.canRead()) {
try {
in = new FileInputStream(custom);
loadModelFile(in, custom.getPath());
} catch (IOException iox) {
Log.severe("Error loading " + custom.getPath());
} finally {
if(in != null) {
try { in.close(); } catch (IOException iox) {}
in = null;
}
}
}
}
else {
try {
FileWriter fw = new FileWriter(custom);
fw.write("# The user is free to add new and custom models here - Dynmap's install will not overwrite it\n");
fw.close();
} catch (IOException iox) {
}
}
}
/**
* Load models from file
@ -400,6 +413,36 @@ public class HDBlockModels {
}
}
}
else if(line.startsWith("linkmap:")) {
ArrayList<Integer> blkids = new ArrayList<Integer>();
line = line.substring(8);
String[] args = line.split(",");
List<Integer> map = null;
int linktype = 0;
for(String a : args) {
String[] av = a.split("=");
if(av.length < 2) continue;
if(av[0].equals("id")) {
blkids.add(Integer.parseInt(av[1]));
}
else if(av[0].equals("linkalg")) {
linktype = Integer.parseInt(av[1]);
}
else if(av[0].equals("linkid")) {
if(map == null) map = new ArrayList<Integer>();
map.add(Integer.parseInt(av[1]));
}
}
if(map != null) {
int[] mapids = new int[map.size()];
for(int i = 0; i < mapids.length; i++)
mapids[i] = map.get(i);
for(Integer bid : blkids) {
linkalg[bid] = linktype;
linkmap[bid] = mapids;
}
}
}
else if(line.startsWith("#") || line.startsWith(";")) {
}
else if(layerbits != 0) { /* If we're working pattern lines */

View File

@ -516,6 +516,38 @@ public class IsoHDPerspective implements HDPerspective {
}
return blockdata;
}
private final boolean containsID(int id, int[] linkids) {
for(int lid: linkids)
if(id == lid)
return true;
return false;
}
private int generateWireBlockData(MapIterator mapiter, int[] linkids) {
int blockdata = 0;
int id;
/* Check north */
id = mapiter.getBlockTypeIDAt(BlockStep.X_MINUS);
if(containsID(id, linkids)) {
blockdata |= 1;
}
/* Look east */
id = mapiter.getBlockTypeIDAt(BlockStep.Z_MINUS);
if(containsID(id, linkids)) {
blockdata |= 2;
}
/* Look south */
id = mapiter.getBlockTypeIDAt(BlockStep.X_PLUS);
if(containsID(id, linkids)) {
blockdata |= 4;
}
/* Look west */
id = mapiter.getBlockTypeIDAt(BlockStep.Z_PLUS);
if(containsID(id, linkids)) {
blockdata |= 8;
}
return blockdata;
}
private final boolean handleSubModel(short[] model, HDShaderState[] shaderstate, boolean[] shaderdone) {
boolean firststep = true;
@ -535,6 +567,11 @@ public class IsoHDPerspective implements HDPerspective {
}
return false;
}
private static final int FENCE_ALGORITHM = 1;
private static final int CHEST_ALGORITHM = 2;
private static final int REDSTONE_ALGORITHM = 3;
private static final int GLASS_IRONFENCE_ALG = 4;
private static final int WIRE_ALGORITHM = 5;
/**
* Process visit of ray to block
*/
@ -547,21 +584,23 @@ public class IsoHDPerspective implements HDPerspective {
}
else if(nonairhit || (blocktypeid != 0)) {
blockdata = mapiter.getBlockData();
switch(blocktypeid) {
case FENCE_BLKTYPEID: /* Special case for fence - need to fake data so we can render properly */
case NETHERFENCE_BLKTYPEID:
switch(HDBlockModels.getLinkAlgID(blocktypeid)) {
case FENCE_ALGORITHM: /* Fence algorithm */
blockrenderdata = generateFenceBlockData(mapiter, blocktypeid);
break;
case CHEST_BLKTYPEID: /* Special case for chest - need to fake data so we can render */
case CHEST_ALGORITHM:
blockrenderdata = generateChestBlockData(mapiter);
break;
case REDSTONE_BLKTYPEID: /* Special case for redstone - fake data for wire pattern */
case REDSTONE_ALGORITHM:
blockrenderdata = generateRedstoneWireBlockData(mapiter);
break;
case IRONFENCE_BLKTYPEID: /* Special case for iron fence - fake data for adjacent block info */
case GLASSPANE_BLKTYPEID: /* Special case for glass pane - fake data for adjacent block info */
case GLASS_IRONFENCE_ALG:
blockrenderdata = generateIronFenceGlassBlockData(mapiter, blocktypeid);
break;
case WIRE_ALGORITHM:
blockrenderdata = generateWireBlockData(mapiter, HDBlockModels.getLinkIDs(blocktypeid));
break;
case 0:
default:
blockrenderdata = -1;
break;

View File

@ -31,6 +31,8 @@ rotate:id=53,data=0,rot=90
# Nether brick stair - up east
block:id=53,id=67,id=108,id=109,id=114,data=3,scale=2
rotate:id=53,data=0,rot=270
# Chest - set render alg
linkmap:id=54,linkalg=2
# Slab (stone, sandstone, wood, cobblestone)
block:id=44,data=*,scale=4
layer:0,1
@ -173,6 +175,9 @@ rotate:id=50,data=1,rot=90
# Redstone torch off - pointing east
block:id=50,id=75,id=76,data=4,scale=16
rotate:id=50,data=1,rot=270
# Fence - set render algorithm
# Nether brick fence - set render alg
linkmap:id=85,id=113,linkalg=1
# Fence - (data is faked: 1=north,2=east,4=south,8=west)
# Fence - no neighbors
# Nether Brick Fence
@ -876,6 +881,8 @@ rotate:id=68,data=2,rot=270
# Wall sign - facing south
block:id=68,data=5,scale=8
rotate:id=68,data=2,rot=90
# Redstone - render alg
linkmap:id=55,linkalg=3
# Redstone wire (NSEW)
block:id=55,data=0,scale=16
layer:0,1
@ -1904,6 +1911,9 @@ rotate:id=34,data=2,rot=270
# Piston extension - extended facing west
block:id=34,data=5,data=13,scale=8
rotate:id=34,data=2,rot=90
# Glass pane - render alg
# Iron fence - render alg
linkmap:id=101,id=102,linkalg=4
# Glass pane - no adjacent (0), all adjacent (15)
# Iron fence - no adjacent (0), all adjacent (15)
block:id=102,id=101,data=0,data=15,scale=16