|
|
@ -11,6 +11,7 @@ import java.awt.image.MemoryImageSource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue; |
|
|
|
import java.awt.image.ColorModel; |
|
|
|
import java.awt.image.ColorModel; |
|
|
|
import java.awt.GraphicsEnvironment; |
|
|
|
import java.awt.GraphicsEnvironment; |
|
|
|
import java.awt.GraphicsConfiguration; |
|
|
|
import java.awt.GraphicsConfiguration; |
|
|
@ -26,7 +27,13 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
private MemoryImageSource mImageProducer; |
|
|
|
private MemoryImageSource mImageProducer; |
|
|
|
private ColorModel cm; |
|
|
|
private ColorModel cm; |
|
|
|
private Thread thread; |
|
|
|
private Thread thread; |
|
|
|
|
|
|
|
Thread workerThread; |
|
|
|
List<Triangle> accumulatedTris = new ArrayList<Triangle>(); |
|
|
|
List<Triangle> accumulatedTris = new ArrayList<Triangle>(); |
|
|
|
|
|
|
|
public static ConcurrentLinkedQueue<Triangle> accumulatedTris1 = new ConcurrentLinkedQueue<>(); |
|
|
|
|
|
|
|
public static ConcurrentLinkedQueue<Triangle> accumulatedTris2 = new ConcurrentLinkedQueue<>(); |
|
|
|
|
|
|
|
boolean renderFirst=false; |
|
|
|
|
|
|
|
boolean lastRender=renderFirst; |
|
|
|
|
|
|
|
boolean renderNeeded=false; |
|
|
|
long profileStartTime; |
|
|
|
long profileStartTime; |
|
|
|
|
|
|
|
|
|
|
|
public Panel() { |
|
|
|
public Panel() { |
|
|
@ -90,7 +97,7 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
accumulatedTris.clear(); |
|
|
|
//accumulatedTris2.clear();
|
|
|
|
|
|
|
|
|
|
|
|
//Matrix matRotZ = Matrix.MakeRotationZ(fTheta*0.5f),matRotX = Matrix.MakeRotationX(fTheta);
|
|
|
|
//Matrix matRotZ = Matrix.MakeRotationZ(fTheta*0.5f),matRotX = Matrix.MakeRotationX(fTheta);
|
|
|
|
Matrix matRotZ = Matrix.IDENTITY; |
|
|
|
Matrix matRotZ = Matrix.IDENTITY; |
|
|
@ -109,32 +116,51 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
Matrix matCamera = Matrix.PointAt(SigRenderer.vCamera, vTarget, vUp); |
|
|
|
Matrix matCamera = Matrix.PointAt(SigRenderer.vCamera, vTarget, vUp); |
|
|
|
Matrix matView = Matrix.QuickInverse(matCamera); |
|
|
|
Matrix matView = Matrix.QuickInverse(matCamera); |
|
|
|
|
|
|
|
|
|
|
|
for (String key : SigRenderer.blockGrid.keySet()) { |
|
|
|
if (workerThread==null||(!workerThread.isAlive()&&renderNeeded)) { |
|
|
|
Block b = SigRenderer.blockGrid.get(key); |
|
|
|
renderFirst=!renderFirst; |
|
|
|
if (!b.neighbors.UP) { |
|
|
|
final Matrix matWorld2 = matWorld; |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(8), accumulatedTris); |
|
|
|
workerThread = new Thread() { |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(9), accumulatedTris); |
|
|
|
@Override |
|
|
|
} |
|
|
|
public void run() { |
|
|
|
if (!b.neighbors.DOWN) { |
|
|
|
ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(10), accumulatedTris); |
|
|
|
for (String key : SigRenderer.blockGrid.keySet()) { |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(11), accumulatedTris); |
|
|
|
Block b = SigRenderer.blockGrid.get(key); |
|
|
|
} |
|
|
|
if (!b.neighbors.UP) { |
|
|
|
if (!b.neighbors.LEFT) { |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(8), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(6), accumulatedTris); |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(9), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(7), accumulatedTris); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!b.neighbors.DOWN) { |
|
|
|
if (!b.neighbors.RIGHT) { |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(10), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(2), accumulatedTris); |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(11), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(3), accumulatedTris); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!b.neighbors.LEFT) { |
|
|
|
if (!b.neighbors.FORWARD) { |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(6), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(4), accumulatedTris); |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(7), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(5), accumulatedTris); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!b.neighbors.RIGHT) { |
|
|
|
if (!b.neighbors.BACKWARD) { |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(2), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(0), accumulatedTris); |
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(3), newTris); |
|
|
|
prepareTriForRender(matWorld, matView, b.block.triangles.get(1), accumulatedTris); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!b.neighbors.FORWARD) { |
|
|
|
|
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(4), newTris); |
|
|
|
|
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(5), newTris); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!b.neighbors.BACKWARD) { |
|
|
|
|
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(0), newTris); |
|
|
|
|
|
|
|
prepareTriForRender(matWorld2, matView, b.block.triangles.get(1), newTris); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (renderFirst) { |
|
|
|
|
|
|
|
accumulatedTris2.clear(); |
|
|
|
|
|
|
|
accumulatedTris2.addAll(newTris); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
accumulatedTris1.clear(); |
|
|
|
|
|
|
|
accumulatedTris1.addAll(newTris); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
renderNeeded=false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
workerThread.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (SigRenderer.PROFILING) { |
|
|
|
if (SigRenderer.PROFILING) { |
|
|
|
System.out.println((System.currentTimeMillis()-profileStartTime)+"ms");profileStartTime=System.currentTimeMillis(); |
|
|
|
System.out.println((System.currentTimeMillis()-profileStartTime)+"ms");profileStartTime=System.currentTimeMillis(); |
|
|
@ -150,8 +176,8 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
SigRenderer.tempAnswer=null; |
|
|
|
SigRenderer.tempAnswer=null; |
|
|
|
long totalTime=0; |
|
|
|
long totalTime=0; |
|
|
|
long startTime2=0; |
|
|
|
long startTime2=0; |
|
|
|
for (Triangle t : accumulatedTris) { |
|
|
|
ConcurrentLinkedQueue<Triangle> currentRender = (renderFirst)?accumulatedTris1:accumulatedTris2; |
|
|
|
|
|
|
|
for (Triangle t : currentRender) { |
|
|
|
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()}; |
|
|
|
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()}; |
|
|
|
List<Triangle> triList = new ArrayList<>(); |
|
|
|
List<Triangle> triList = new ArrayList<>(); |
|
|
|
triList.add(t); |
|
|
|
triList.add(t); |
|
|
@ -180,7 +206,7 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
for (Triangle tt : triList) { |
|
|
|
for (Triangle tt : triList) { |
|
|
|
if (tt.tex!=null) { |
|
|
|
if (tt.tex!=null) { |
|
|
|
tt.unmodifiedTri.nextRenderTime=System.currentTimeMillis()+200; |
|
|
|
//tt.unmodifiedTri.nextRenderTime=System.currentTimeMillis()+200;
|
|
|
|
DrawUtils.TexturedTriangle(p, |
|
|
|
DrawUtils.TexturedTriangle(p, |
|
|
|
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w, |
|
|
|
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w, |
|
|
|
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w, |
|
|
|
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w, |
|
|
@ -197,6 +223,7 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
totalTime+=System.nanoTime()-startTime2; |
|
|
|
totalTime+=System.nanoTime()-startTime2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
renderNeeded=true; |
|
|
|
for (int x=0;x<SigRenderer.SCREEN_WIDTH;x++) { |
|
|
|
for (int x=0;x<SigRenderer.SCREEN_WIDTH;x++) { |
|
|
|
for (int y=0;y<SigRenderer.SCREEN_HEIGHT;y++) { |
|
|
|
for (int y=0;y<SigRenderer.SCREEN_HEIGHT;y++) { |
|
|
|
Triangle t = SigRenderer.depthBuffer_tri[x+y*SigRenderer.SCREEN_WIDTH]; |
|
|
|
Triangle t = SigRenderer.depthBuffer_tri[x+y*SigRenderer.SCREEN_WIDTH]; |
|
|
@ -212,7 +239,7 @@ public class Panel extends JPanel implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void prepareTriForRender(Matrix matWorld, Matrix matView, Triangle t, List<Triangle> accumulatedTris) { |
|
|
|
private void prepareTriForRender(Matrix matWorld, Matrix matView, Triangle t, ConcurrentLinkedQueue<Triangle> accumulatedTris) { |
|
|
|
if (t.nextRenderTime<=System.currentTimeMillis()) { |
|
|
|
if (t.nextRenderTime<=System.currentTimeMillis()) { |
|
|
|
Triangle triProjected = new Triangle(),triTransformed=new Triangle(),triViewed=new Triangle(); |
|
|
|
Triangle triProjected = new Triangle(),triTransformed=new Triangle(),triViewed=new Triangle(); |
|
|
|
|
|
|
|
|
|
|
|