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

@ -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;