Merge commit '9642d25c34ae83ac68a28d0365d64e97cc84a1ab' into main

new
Joshua Sigona 3 years ago
commit 9e680ac9cb
  1. 30
      src/sig/Panel.java
  2. 5
      src/sig/SigRenderer.java
  3. 75
      src/sig/TestKernel.java

@ -33,8 +33,8 @@ 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 = new Thread[8]; Thread[] workerThread = new Thread[9];
String[][] keySets = new String[8][]; String[][] keySets = new String[9][];
ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>();
List<Triangle> accumulatedTris = new ArrayList<Triangle>(); List<Triangle> accumulatedTris = new ArrayList<Triangle>();
public static ConcurrentLinkedQueue<Triangle> accumulatedTris1 = new ConcurrentLinkedQueue<>(); public static ConcurrentLinkedQueue<Triangle> accumulatedTris1 = new ConcurrentLinkedQueue<>();
@ -134,15 +134,7 @@ public class Panel extends JPanel implements Runnable {
int currentSet=0; int currentSet=0;
for (String key : SigRenderer.blockGrid.keySet()) { for (String key : SigRenderer.blockGrid.keySet()) {
if (currentPiece==0) { if (currentPiece==0) {
if (currentSet==7) { keySets[currentSet] = new String[pieces];
if (SigRenderer.blockGrid.size()%8==0) {
keySets[currentSet] = new String[pieces];
} else {
keySets[currentSet] = new String[SigRenderer.blockGrid.size()%8];
}
} else {
keySets[currentSet] = new String[pieces];
}
} }
keySets[currentSet][currentPiece]=key; keySets[currentSet][currentPiece]=key;
currentPiece++; currentPiece++;
@ -167,16 +159,22 @@ public class Panel extends JPanel implements Runnable {
accumulatedTris1.clear(); accumulatedTris1.clear();
} }
final Matrix matWorld2 = matWorld; final Matrix matWorld2 = matWorld;
for (int i=0;i<8;i++) { for (int i=0;i<9;i++) {
final int id=i; final int id=i;
workerThread[i] = new Thread(){ workerThread[i] = new Thread(){
@Override @Override
public void run() { public void run() {
ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>();
for (String key : keySets[id]) { if (keySets[id]!=null) {
Block b = SigRenderer.blockGrid.get(key); for (String key : keySets[id]) {
for (Triangle t : b.block.prepareRender(b)) { if (key!=null) {
prepareTriForRender(matWorld2, matView, t, newTris); Block b = SigRenderer.blockGrid.get(key);
if (b!=null) {
for (Triangle t : b.block.prepareRender(b)) {
prepareTriForRender(matWorld2, matView, t, newTris);
}
}
}
} }
} }
if (renderFirst) { if (renderFirst) {

@ -36,7 +36,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
public static boolean windowActive=true; public static boolean windowActive=true;
public static boolean WIREFRAME = false; public static boolean WIREFRAME = false;
public static boolean PROFILING = true; public static boolean PROFILING = false;
public static boolean FLYING_MODE = false; public static boolean FLYING_MODE = false;
public static int SCREEN_WIDTH=1280; public static int SCREEN_WIDTH=1280;
public static int SCREEN_HEIGHT=720; public static int SCREEN_HEIGHT=720;
@ -402,8 +402,6 @@ 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++) {
@ -430,6 +428,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,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);

@ -0,0 +1,75 @@
package sig;
import java.util.Arrays;
import com.aparapi.Kernel;
import com.aparapi.Range;
import com.aparapi.device.Device;
public class TestKernel extends Kernel{
int[] a,b;
float[] sum;
boolean[] test;
final int val=55555555;
TestKernel(int[] a,int[] b,float[] sum,boolean[] test) {
this.a=a;
this.b=b;
this.sum=sum;
this.test=test;
}
public static void main(String[] args) {
int size = 1024;
final int[] a = new int[size];
int[] b = new int[size];
for (int i = 0; i < size; i++) {
a[i] = (int) (Math.random() * 100);
b[i] = (int) (Math.random() * 100);
}
float[] sum = new float[size];
TestKernel kernel = new TestKernel(a,b,sum,new boolean[]{true});
//System.out.println("Start...");
kernel.execute(Range.create(size));
//System.out.println("Running...");
//size=5;
kernel.b[0]=50;
kernel.b[1]=45;
/*for (int i = 0; i < size; i++) {
b[i] = (int) (Math.random() * 100);
}*/
long timer1=System.nanoTime();
for (int i=0;i<900;i++) {
kernel.execute(Range.create(size));
}
System.out.println((System.nanoTime()-timer1)+"ns");
kernel.dispose();
System.out.println(Arrays.toString(sum));
timer1=System.nanoTime();
for (int j=0;j<900;j++) {
for (int i=0;i<sum.length;i++) {
sum[i]=a[i]+b[i];
}
}
System.out.println((System.nanoTime()-timer1)+"ns");
}
@Override
public void run() {
int gid = getGlobalId();
sum[gid] = a[gid]+b[gid];
}
void addExtra(int numb,int id) {
a[id]+=numb;
b[id]+=numb;
}
}
Loading…
Cancel
Save