Joshua Sigona 3 years ago
parent a4c086f976
commit bb56ba0896
  1. 15
      src/sig/Panel.java
  2. 5
      src/sig/SigRenderer.java
  3. 66
      src/sig/utils/DrawUtils.java

@ -23,7 +23,7 @@ import java.awt.GraphicsConfiguration;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.util.Queue; import java.util.Queue;
public class Panel extends JPanel implements Runnable { public class Panel extends JPanel{
long startTime = System.nanoTime(); long startTime = System.nanoTime();
long endTime = System.nanoTime(); long endTime = System.nanoTime();
public int pixel[]; public int pixel[];
@ -32,7 +32,6 @@ public class Panel extends JPanel implements Runnable {
private Image imageBuffer; private Image imageBuffer;
private MemoryImageSource mImageProducer; private MemoryImageSource mImageProducer;
private ColorModel cm; private ColorModel cm;
private Thread thread;
Thread[] workerThread = new Thread[9]; Thread[] workerThread = new Thread[9];
String[][] keySets = new String[9][]; String[][] keySets = new String[9][];
ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>();
@ -46,7 +45,6 @@ public class Panel extends JPanel implements Runnable {
public Panel() { public Panel() {
super(true); super(true);
thread = new Thread(this, "MyPanel Thread");
} }
/** /**
@ -77,9 +75,6 @@ public class Panel extends JPanel implements Runnable {
mImageProducer.setAnimated(true); mImageProducer.setAnimated(true);
mImageProducer.setFullBufferUpdates(true); mImageProducer.setFullBufferUpdates(true);
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
if(thread.isInterrupted() || !thread.isAlive()){
thread.start();
}
SigRenderer.depthBuffer = new float[width*height]; SigRenderer.depthBuffer = new float[width*height];
SigRenderer.depthBuffer_tri = new Triangle[width*height]; SigRenderer.depthBuffer_tri = new Triangle[width*height];
SigRenderer.translucencyBuffer = new boolean[width*height]; SigRenderer.translucencyBuffer = new boolean[width*height];
@ -588,12 +583,4 @@ public class Panel extends JPanel implements Runnable {
public boolean imageUpdate(Image image, int a, int b, int c, int d, int e) { public boolean imageUpdate(Image image, int a, int b, int c, int d, int e) {
return true; return true;
} }
@Override
public void run() {
while (true) {
// request a JPanel re-drawing
repaint();
try {Thread.sleep(5);} catch (InterruptedException e) {}
}
}
} }

@ -57,7 +57,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
public static float fAspectRatio = (float)SCREEN_HEIGHT/SCREEN_WIDTH; public static float fAspectRatio = (float)SCREEN_HEIGHT/SCREEN_WIDTH;
public static Matrix matProj = Matrix.MakeProjection(fFov,fAspectRatio,fNear,fFar); public static Matrix matProj = Matrix.MakeProjection(fFov,fAspectRatio,fNear,fFar);
public static Vector vCamera = new Vector(31.5f,20f,31.5f); public static Vector vCamera = new Vector(15.5f,20f,15.5f);
public static final float cameraCollisionPadding = 0.2f; public static final float cameraCollisionPadding = 0.2f;
public static final float cameraHeight = 1.75f; public static final float cameraHeight = 1.75f;
@ -402,6 +402,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
for (int x=0;x<64;x++) { for (int x=0;x<64;x++) {
for (int z=0;z<64;z++) { for (int z=0;z<64;z++) {
addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH); addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH);
addBlock(new Vector(x,1,z),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH);
//addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH); //addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH);
//addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH); //addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH);
/*for (int y=1;y<r.nextInt(5);y++) { /*for (int y=1;y<r.nextInt(5);y++) {
@ -428,7 +429,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
}*/ }*/
} }
} }
addBlock(new Vector(31,1,31),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH); //addBlock(new Vector(31,1,31),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH);
/*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST); /*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST);
addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST); addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST);
addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH); addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH);

@ -63,7 +63,7 @@ public class DrawUtils {
if (dy2!=0) {dw2_step=dw2/((float)Math.abs(dy2));} if (dy2!=0) {dw2_step=dw2/((float)Math.abs(dy2));}
if (dy1!=0) { if (dy1!=0) {
for (int i=y1;i<=y2;i++) { for (int i=y1;i<=y2-3;i+=4) {
int ax=(int)(x1+((float)(i-y1))*dax_step); int ax=(int)(x1+((float)(i-y1))*dax_step);
int bx=(int)(x1+((float)(i-y1))*dbx_step); int bx=(int)(x1+((float)(i-y1))*dbx_step);
@ -88,7 +88,7 @@ public class DrawUtils {
float tstep = 1.0f/(float)(bx-ax); float tstep = 1.0f/(float)(bx-ax);
float t=0.0f; float t=0.0f;
for (int j=ax;j<=bx;j++) { for (int j=ax;j<=bx-3;j+=4) {
tex_u=(1.0f-t)*tex_su+t*tex_eu; tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev; tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew; tex_w=(1.0f-t)*tex_sw+t*tex_ew;
@ -100,7 +100,10 @@ public class DrawUtils {
} }
} }
} }
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]&&
tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j]&&
tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)]&&
tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)]) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f); int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) { if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) { if (((col&0xFF000000)>>>24)!=255) {
@ -110,17 +113,38 @@ public class DrawUtils {
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true; SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true;
Draw(canvas,j+1,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = true;
Draw(canvas,j,i+1,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = true;
Draw(canvas,j+1,i+1,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = true;
} }
} else { } else {
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) { if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
Draw(canvas,j,i,col); Draw(canvas,j,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
Draw(canvas,j+1,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
Draw(canvas,j,i+1,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
Draw(canvas,j+1,i+1,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
} }
} }
} }
} }
t+=tstep; t+=tstep*4;
} }
} }
} }
@ -139,7 +163,7 @@ public class DrawUtils {
if (dy1!=0) {dw1_step=dw1/((float)Math.abs(dy1));} if (dy1!=0) {dw1_step=dw1/((float)Math.abs(dy1));}
if (dy1!=0) { if (dy1!=0) {
for (int i=y2;i<=y3;i++) { for (int i=y2;i<=y3-3;i+=4) {
int ax=(int)(x2+((float)(i-y2))*dax_step); int ax=(int)(x2+((float)(i-y2))*dax_step);
int bx=(int)(x1+((float)(i-y1))*dbx_step); int bx=(int)(x1+((float)(i-y1))*dbx_step);
@ -164,7 +188,7 @@ public class DrawUtils {
float tstep = 1.0f/(float)(bx-ax); float tstep = 1.0f/(float)(bx-ax);
float t=0.0f; float t=0.0f;
for (int j=ax;j<=bx;j++) { for (int j=ax;j<=bx-3;j+=4) {
tex_u=(1.0f-t)*tex_su+t*tex_eu; tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev; tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew; tex_w=(1.0f-t)*tex_sw+t*tex_ew;
@ -176,7 +200,10 @@ public class DrawUtils {
} }
} }
} }
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]&&
tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j]&&
tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)]&&
tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)]) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f); int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) { if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) { if (((col&0xFF000000)>>>24)!=255) {
@ -184,21 +211,42 @@ public class DrawUtils {
rendering_state==NORMAL_RENDERING) { rendering_state==NORMAL_RENDERING) {
Draw(canvas,j,i,col); Draw(canvas,j,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true;
Draw(canvas,j,i+1,col);
SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = true;
Draw(canvas,j+1,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = true;
Draw(canvas,j+1,i+1,col);
SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = true;
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) { if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
} }
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true;
} }
} else { } else {
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) { if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
Draw(canvas,j,i,col); Draw(canvas,j,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
Draw(canvas,j,i+1,col);
SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
Draw(canvas,j+1,i,col);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
Draw(canvas,j+1,i+1,col);
SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w;
SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri;
} }
} }
} }
} }
t+=tstep; t+=tstep*4;
} }
} }
} }

Loading…
Cancel
Save