Woraround bukkit schedule spin, add custom-models.txt, custom-texture.txt

This commit is contained in:
Mike Primm 2011-07-17 11:02:22 -05:00
parent a8f3f17513
commit 5208825555
6 changed files with 84 additions and 58 deletions

View file

@ -363,7 +363,7 @@ public class MapManager {
} }
scheduler.scheduleSyncRepeatingTask(plugin, new CheckWorldTimes(), 5*20, 5*20); /* Check very 5 seconds */ scheduler.scheduleSyncRepeatingTask(plugin, new CheckWorldTimes(), 5*20, 5*20); /* Check very 5 seconds */
scheduler.scheduleSyncRepeatingTask(plugin, new ProcessChunkLoads(), 1, 1); /* Chunk loader task */ scheduler.scheduleSyncRepeatingTask(plugin, new ProcessChunkLoads(), 1, 2); /* Chunk loader task - do every 2 to work around bukkit issue */
} }

View file

@ -1,7 +1,9 @@
package org.dynmap.hdmap; package org.dynmap.hdmap;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.util.ArrayList; import java.util.ArrayList;
@ -256,9 +258,28 @@ public class HDBlockModels {
return model; return model;
} }
/** /**
* Load models from model.txt file * Load models
*/ */
public static void loadModels(File plugindir) { public static void loadModels(File datadir) {
/* Load block models */
HDBlockModels.loadModelFile(new File(datadir, "models.txt"));
File custom = new File(datadir, "custom-models.txt");
if(custom.canRead()) {
HDBlockModels.loadModels(custom);
}
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
*/
private static void loadModelFile(File modelfile) {
LineNumberReader rdr = null; LineNumberReader rdr = null;
int cnt = 0; int cnt = 0;
try { try {
@ -267,7 +288,7 @@ public class HDBlockModels {
int layerbits = 0; int layerbits = 0;
int rownum = 0; int rownum = 0;
int scale = 0; int scale = 0;
rdr = new LineNumberReader(new FileReader(new File(plugindir, "models.txt"))); rdr = new LineNumberReader(new FileReader(modelfile));
while((line = rdr.readLine()) != null) { while((line = rdr.readLine()) != null) {
if(line.startsWith("block:")) { if(line.startsWith("block:")) {
ArrayList<Integer> blkids = new ArrayList<Integer>(); ArrayList<Integer> blkids = new ArrayList<Integer>();
@ -300,7 +321,7 @@ public class HDBlockModels {
} }
} }
else { else {
Log.severe("Block model missing required parameters = line " + rdr.getLineNumber() + " of models.txt"); Log.severe("Block model missing required parameters = line " + rdr.getLineNumber() + " of " + modelfile.getPath());
} }
layerbits = 0; layerbits = 0;
} }
@ -379,11 +400,11 @@ public class HDBlockModels {
} }
} }
} }
Log.info("Loaded " + cnt + " block models"); Log.verboseinfo("Loaded " + cnt + " block models from " + modelfile.getPath());
} catch (IOException iox) { } catch (IOException iox) {
Log.severe("Error reading models.txt - " + iox.toString()); Log.severe("Error reading models.txt - " + iox.toString());
} catch (NumberFormatException nfx) { } catch (NumberFormatException nfx) {
Log.severe("Format error - line " + rdr.getLineNumber() + " of models.txt"); Log.severe("Format error - line " + rdr.getLineNumber() + " of " + modelfile.getPath());
} finally { } finally {
if(rdr != null) { if(rdr != null) {
try { try {

View file

@ -1,5 +1,8 @@
package org.dynmap.hdmap; package org.dynmap.hdmap;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -23,7 +26,7 @@ public class HDMapManager {
public HashMap<String, HDLighting> lightings = new HashMap<String, HDLighting>(); public HashMap<String, HDLighting> lightings = new HashMap<String, HDLighting>();
public HashSet<HDMap> maps = new HashSet<HDMap>(); public HashSet<HDMap> maps = new HashSet<HDMap>();
public HashMap<String, ArrayList<HDMap>> maps_by_world_perspective = new HashMap<String, ArrayList<HDMap>>(); public HashMap<String, ArrayList<HDMap>> maps_by_world_perspective = new HashMap<String, ArrayList<HDMap>>();
public void loadHDShaders(ConfigurationNode shadercfg) { public void loadHDShaders(ConfigurationNode shadercfg) {
Log.verboseinfo("Loading shaders..."); Log.verboseinfo("Loading shaders...");
for(HDShader shader : shadercfg.<HDShader>createInstances("shaders", new Class<?>[0], new Object[0])) { for(HDShader shader : shadercfg.<HDShader>createInstances("shaders", new Class<?>[0], new Object[0])) {

View file

@ -59,5 +59,5 @@ public interface HDPerspectiveState {
/** /**
* Return subblock coordinates of current ray position * Return subblock coordinates of current ray position
*/ */
void getSubblockCoord(int[] xyz); int[] getSubblockCoord();
} }

View file

@ -89,6 +89,7 @@ public class IsoHDPerspective implements HDPerspective {
boolean nonairhit; boolean nonairhit;
int subalpha; int subalpha;
double mt; double mt;
int[] subblock_xyz = new int[3];
/** /**
* Get sky light level - only available if shader requested it * Get sky light level - only available if shader requested it
*/ */
@ -454,16 +455,17 @@ public class IsoHDPerspective implements HDPerspective {
} }
return true; return true;
} }
public void getSubblockCoord(int[] v) { public int[] getSubblockCoord() {
double tt = t + 0.000001; double tt = t + 0.000001;
if(subalpha >= 0) if(subalpha >= 0)
tt = mt; tt = mt;
double xx = top.x + tt * (bottom.x - top.x); double xx = top.x + tt * (bottom.x - top.x);
double yy = top.y + tt * (bottom.y - top.y); double yy = top.y + tt * (bottom.y - top.y);
double zz = top.z + tt * (bottom.z - top.z); double zz = top.z + tt * (bottom.z - top.z);
v[0] = (int)((xx - Math.floor(xx)) * modscale); subblock_xyz[0] = (int)((xx - Math.floor(xx)) * modscale);
v[1] = (int)((yy - Math.floor(yy)) * modscale); subblock_xyz[1] = (int)((yy - Math.floor(yy)) * modscale);
v[2] = (int)((zz - Math.floor(zz)) * modscale); subblock_xyz[2] = (int)((zz - Math.floor(zz)) * modscale);
return subblock_xyz;
} }
} }

View file

@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.LineNumberReader; import java.io.LineNumberReader;
@ -48,6 +49,10 @@ public class TexturePack {
private static final String FOLIAGECOLOR_PNG = "misc/foliagecolor.png"; private static final String FOLIAGECOLOR_PNG = "misc/foliagecolor.png";
private static final String WATERCOLOR_PNG = "misc/watercolor.png"; private static final String WATERCOLOR_PNG = "misc/watercolor.png";
private static final String WATER_PNG = "misc/water.png"; private static final String WATER_PNG = "misc/water.png";
private static final String CUSTOMLAVASTILL_PNG = "custom_lava_still.png";
private static final String CUSTOMLAVAFLOWING_PNG = "custom_lava_flowing.png";
private static final String CUSTOMWATERSTILL_PNG = "custom_water_still.png";
private static final String CUSTOMWATERFLOWING_PNG = "custom_water_flowing.png";
/* Color modifier codes (x1000 for value in mapping code) */ /* Color modifier codes (x1000 for value in mapping code) */
private static final int COLORMOD_GRASSTONED = 1; private static final int COLORMOD_GRASSTONED = 1;
@ -545,11 +550,31 @@ public class TexturePack {
BufferedImage img = KzedMap.createBufferedImage(outbuf, terrain_width, terrain_height); BufferedImage img = KzedMap.createBufferedImage(outbuf, terrain_width, terrain_height);
ImageIO.write(img, "png", f); ImageIO.write(img, "png", f);
} }
/**
* Load texture pack mappings
*/
public static void loadTextureMapping(File datadir) {
/* Load block models */
loadTextureFile(new File(datadir, "texture.txt"));
File custom = new File(datadir, "custom-texture.txt");
if(custom.canRead()) {
loadTextureFile(custom);
}
else {
try {
FileWriter fw = new FileWriter(custom);
fw.write("# The user is free to add new and custom texture mappings here - Dynmap's install will not overwrite it\n");
fw.close();
} catch (IOException iox) {
}
}
}
/** /**
* Load texture pack mappings from texture.txt file * Load texture pack mappings from texture.txt file
*/ */
public static void loadTextureMapping(File plugindir) { private static void loadTextureFile(File txtfile) {
LineNumberReader rdr = null; LineNumberReader rdr = null;
int cnt = 0; int cnt = 0;
/* Initialize map with blank map for all entries */ /* Initialize map with blank map for all entries */
@ -557,7 +582,7 @@ public class TexturePack {
try { try {
String line; String line;
rdr = new LineNumberReader(new FileReader(new File(plugindir, "texture.txt"))); rdr = new LineNumberReader(new FileReader(txtfile));
while((line = rdr.readLine()) != null) { while((line = rdr.readLine()) != null) {
if(line.startsWith("block:")) { if(line.startsWith("block:")) {
ArrayList<Integer> blkids = new ArrayList<Integer>(); ArrayList<Integer> blkids = new ArrayList<Integer>();
@ -620,17 +645,17 @@ public class TexturePack {
cnt++; cnt++;
} }
else { else {
Log.severe("Texture mapping missing required parameters = line " + rdr.getLineNumber() + " of texture.txt"); Log.severe("Texture mapping missing required parameters = line " + rdr.getLineNumber() + " of " + txtfile.getPath());
} }
} }
else if(line.startsWith("#") || line.startsWith(";")) { else if(line.startsWith("#") || line.startsWith(";")) {
} }
} }
Log.info("Loaded " + cnt + " texture mappings"); Log.verboseinfo("Loaded " + cnt + " texture mappings from " + txtfile.getPath());
} catch (IOException iox) { } catch (IOException iox) {
Log.severe("Error reading texture.txt - " + iox.toString()); Log.severe("Error reading " + txtfile.getPath() + " - " + iox.toString());
} catch (NumberFormatException nfx) { } catch (NumberFormatException nfx) {
Log.severe("Format error - line " + rdr.getLineNumber() + " of texture.txt"); Log.severe("Format error - line " + rdr.getLineNumber() + " of " + txtfile.getPath());
} finally { } finally {
if(rdr != null) { if(rdr != null) {
try { try {
@ -656,10 +681,18 @@ public class TexturePack {
/* See if not basic block texture */ /* See if not basic block texture */
int textop = textid / 1000; int textop = textid / 1000;
textid = textid % 1000; textid = textid % 1000;
/* If clear-inside op, get out early */
if(textop == COLORMOD_CLEARINSIDE) {
/* Check if previous block is same block type as we are: surface is transparent if it is */
if(blkid == lastblocktype) {
rslt.setTransparent();
return;
}
}
int[] texture = terrain_argb[textid]; int[] texture = terrain_argb[textid];
int clrval = 0; int[] xyz = ps.getSubblockCoord();
int[] xyz = new int[3];
ps.getSubblockCoord(xyz);
/* Get texture coordinates (U=horizontal(left=0),V=vertical(top=0)) */ /* Get texture coordinates (U=horizontal(left=0),V=vertical(top=0)) */
int u = 0, v = 0, tmp; int u = 0, v = 0, tmp;
@ -729,18 +762,10 @@ public class TexturePack {
} }
} }
break; break;
case COLORMOD_CLEARINSIDE:
/* Check if previous block is same block type as we are: surface is transparent if it is */
if(blkid == lastblocktype) {
rslt.setTransparent();
return;
}
break;
} }
} }
clrval = texture[v*native_scale + u]; /* Read color from texture */
rslt.setARGB(texture[v*native_scale + u]);
rslt.setARGB(clrval);
if(textop > 0) { if(textop > 0) {
/* Switch based on texture modifier */ /* Switch based on texture modifier */
switch(textop) { switch(textop) {
@ -777,29 +802,4 @@ public class TexturePack {
int h = width - (int)(temp*rainfall*(width-1)) - 1; int h = width - (int)(temp*rainfall*(width-1)) - 1;
return argb[width*h + t]; return argb[width*h + t];
} }
public static void main(String[] args) {
TexturePack.loadTextureMapping(new File("."));
TexturePack tp = TexturePack.getTexturePack("standard");
TexturePack tp2 = tp.resampleTexturePack(4);
try {
tp2.saveTerrainPNG(new File("test_terrain_4.png"));
} catch (IOException iox) {}
tp2 = tp.resampleTexturePack(16);
try {
tp2.saveTerrainPNG(new File("test_terrain_16.png"));
} catch (IOException iox) {}
tp2 = tp.resampleTexturePack(24);
try {
tp2.saveTerrainPNG(new File("test_terrain_24.png"));
} catch (IOException iox) {}
tp2 = tp.resampleTexturePack(64);
try {
tp2.saveTerrainPNG(new File("test_terrain_64.png"));
} catch (IOException iox) {}
tp2 = tp.resampleTexturePack(1);
try {
tp2.saveTerrainPNG(new File("test_terrain_1.png"));
} catch (IOException iox) {}
}
} }